]> git.proxmox.com Git - rustc.git/blob - src/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / include / llvm / CodeGen / SelectionDAGNodes.h
1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
14 //
15 // Clients should include the SelectionDAG.h file instead of this file directly.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22 #include "llvm/ADT/BitVector.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallPtrSet.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/ilist_node.h"
29 #include "llvm/ADT/iterator_range.h"
30 #include "llvm/CodeGen/ISDOpcodes.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/CodeGen/ValueTypes.h"
33 #include "llvm/IR/Constants.h"
34 #include "llvm/IR/DebugLoc.h"
35 #include "llvm/IR/Instructions.h"
36 #include "llvm/Support/DataTypes.h"
37 #include "llvm/Support/MathExtras.h"
38 #include <cassert>
39
40 namespace llvm {
41
42 class SelectionDAG;
43 class GlobalValue;
44 class MachineBasicBlock;
45 class MachineConstantPoolValue;
46 class SDNode;
47 class Value;
48 class MCSymbol;
49 template <typename T> struct DenseMapInfo;
50 template <typename T> struct simplify_type;
51 template <typename T> struct ilist_traits;
52
53 /// isBinOpWithFlags - Returns true if the opcode is a binary operation
54 /// with flags.
55 static bool isBinOpWithFlags(unsigned Opcode) {
56 switch (Opcode) {
57 case ISD::SDIV:
58 case ISD::UDIV:
59 case ISD::SRA:
60 case ISD::SRL:
61 case ISD::MUL:
62 case ISD::ADD:
63 case ISD::SUB:
64 case ISD::SHL:
65 return true;
66 default:
67 return false;
68 }
69 }
70
71 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
72 bool force = false);
73
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(...).
77 ///
78 struct SDVTList {
79 const EVT *VTs;
80 unsigned int NumVTs;
81 };
82
83 namespace ISD {
84 /// Node predicates
85
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);
89
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);
93
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);
97
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);
102
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
107
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
113 /// of values).
114 ///
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.
118 ///
119 class SDValue {
120 friend struct DenseMapInfo<SDValue>;
121
122 SDNode *Node; // The node defining the value we are using.
123 unsigned ResNo; // Which return value of the node we are using.
124 public:
125 SDValue() : Node(nullptr), ResNo(0) {}
126 SDValue(SDNode *node, unsigned resno);
127
128 /// get the index which selects a specific result in the SDNode
129 unsigned getResNo() const { return ResNo; }
130
131 /// get the SDNode which holds the desired result
132 SDNode *getNode() const { return Node; }
133
134 /// set the SDNode
135 void setNode(SDNode *N) { Node = N; }
136
137 inline SDNode *operator->() const { return Node; }
138
139 bool operator==(const SDValue &O) const {
140 return Node == O.Node && ResNo == O.ResNo;
141 }
142 bool operator!=(const SDValue &O) const {
143 return !operator==(O);
144 }
145 bool operator<(const SDValue &O) const {
146 return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
147 }
148 LLVM_EXPLICIT operator bool() const {
149 return Node != nullptr;
150 }
151
152 SDValue getValue(unsigned R) const {
153 return SDValue(Node, R);
154 }
155
156 // isOperandOf - Return true if this node is an operand of N.
157 bool isOperandOf(SDNode *N) const;
158
159 /// getValueType - Return the ValueType of the referenced return value.
160 ///
161 inline EVT getValueType() const;
162
163 /// Return the simple ValueType of the referenced return value.
164 MVT getSimpleValueType() const {
165 return getValueType().getSimpleVT();
166 }
167
168 /// getValueSizeInBits - Returns the size of the value in bits.
169 ///
170 unsigned getValueSizeInBits() const {
171 return getValueType().getSizeInBits();
172 }
173
174 unsigned getScalarValueSizeInBits() const {
175 return getValueType().getScalarType().getSizeInBits();
176 }
177
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;
190
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;
198
199 /// use_empty - Return true if there are no nodes using value ResNo
200 /// of Node.
201 ///
202 inline bool use_empty() const;
203
204 /// hasOneUse - Return true if there is exactly one node using value
205 /// ResNo of Node.
206 ///
207 inline bool hasOneUse() const;
208 };
209
210
211 template<> struct DenseMapInfo<SDValue> {
212 static inline SDValue getEmptyKey() {
213 SDValue V;
214 V.ResNo = -1U;
215 return V;
216 }
217 static inline SDValue getTombstoneKey() {
218 SDValue V;
219 V.ResNo = -2U;
220 return V;
221 }
222 static unsigned getHashValue(const SDValue &Val) {
223 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
224 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
225 }
226 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
227 return LHS == RHS;
228 }
229 };
230 template <> struct isPodLike<SDValue> { static const bool value = true; };
231
232
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();
239 }
240 };
241 template<> struct simplify_type<const SDValue> {
242 typedef /*const*/ SDNode* SimpleType;
243 static SimpleType getSimplifiedValue(const SDValue &Val) {
244 return Val.getNode();
245 }
246 };
247
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.
252 ///
253 class SDUse {
254 /// Val - The value being used.
255 SDValue Val;
256 /// User - The user of this value.
257 SDNode *User;
258 /// Prev, Next - Pointers to the uses list of the SDNode referred by
259 /// this operand.
260 SDUse **Prev, *Next;
261
262 SDUse(const SDUse &U) LLVM_DELETED_FUNCTION;
263 void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
264
265 public:
266 SDUse() : Val(), User(nullptr), Prev(nullptr), Next(nullptr) {}
267
268 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
269 operator const SDValue&() const { return Val; }
270
271 /// If implicit conversion to SDValue doesn't work, the get() method returns
272 /// the SDValue.
273 const SDValue &get() const { return Val; }
274
275 /// getUser - This returns the SDNode that contains this Use.
276 SDNode *getUser() { return User; }
277
278 /// getNext - Get the next SDUse in the use list.
279 SDUse *getNext() const { return Next; }
280
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(); }
287
288 /// operator== - Convenience function for get().operator==
289 bool operator==(const SDValue &V) const {
290 return Val == V;
291 }
292
293 /// operator!= - Convenience function for get().operator!=
294 bool operator!=(const SDValue &V) const {
295 return Val != V;
296 }
297
298 /// operator< - Convenience function for get().operator<
299 bool operator<(const SDValue &V) const {
300 return Val < V;
301 }
302
303 private:
304 friend class SelectionDAG;
305 friend class SDNode;
306
307 void setUser(SDNode *p) { User = p; }
308
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);
318
319 void addToList(SDUse **List) {
320 Next = *List;
321 if (Next) Next->Prev = &Next;
322 Prev = List;
323 *List = this;
324 }
325
326 void removeFromList() {
327 *Prev = Next;
328 if (Next) Next->Prev = Prev;
329 }
330 };
331
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();
338 }
339 };
340
341
342 /// SDNode - Represents one node in the SelectionDAG.
343 ///
344 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
345 private:
346 /// NodeType - The operation that this node performs.
347 ///
348 int16_t NodeType;
349
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;
353
354 /// HasDebugValue - This tracks whether this node has one or more dbg_value
355 /// nodes corresponding to it.
356 uint16_t HasDebugValue : 1;
357
358 protected:
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;
363
364 private:
365 /// NodeId - Unique id per SDNode in the DAG.
366 int NodeId;
367
368 /// OperandList - The values that are used by this operation.
369 ///
370 SDUse *OperandList;
371
372 /// ValueList - The types of the values this node defines. SDNode's may
373 /// define multiple values simultaneously.
374 const EVT *ValueList;
375
376 /// UseList - List of uses for this SDNode.
377 SDUse *UseList;
378
379 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
380 unsigned short NumOperands, NumValues;
381
382 /// debugLoc - source line information.
383 DebugLoc debugLoc;
384
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
389 // this ordering.
390 unsigned IROrder;
391
392 /// getValueTypeList - Return a pointer to the specified value type.
393 static const EVT *getValueTypeList(EVT VT);
394
395 friend class SelectionDAG;
396 friend struct ilist_traits<SDNode>;
397
398 public:
399 //===--------------------------------------------------------------------===//
400 // Accessors
401 //
402
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; }
408
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; }
412
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;
418 }
419
420 /// Test if this node is a memory intrinsic (with valid pointer information).
421 /// INTRINSIC_W_CHAIN and INTRINSIC_VOID nodes are sometimes created for
422 /// non-memory intrinsics (with chains) that are not really instances of
423 /// MemSDNode. For such nodes, we need some extra state to determine the
424 /// proper classof relationship.
425 bool isMemIntrinsic() const {
426 return (NodeType == ISD::INTRINSIC_W_CHAIN ||
427 NodeType == ISD::INTRINSIC_VOID) && ((SubclassData >> 13) & 1);
428 }
429
430 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
431 /// corresponding to a MachineInstr opcode.
432 bool isMachineOpcode() const { return NodeType < 0; }
433
434 /// getMachineOpcode - This may only be called if isMachineOpcode returns
435 /// true. It returns the MachineInstr opcode value that the node's opcode
436 /// corresponds to.
437 unsigned getMachineOpcode() const {
438 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
439 return ~NodeType;
440 }
441
442 /// getHasDebugValue - get this bit.
443 bool getHasDebugValue() const { return HasDebugValue; }
444
445 /// setHasDebugValue - set this bit.
446 void setHasDebugValue(bool b) { HasDebugValue = b; }
447
448 /// use_empty - Return true if there are no uses of this node.
449 ///
450 bool use_empty() const { return UseList == nullptr; }
451
452 /// hasOneUse - Return true if there is exactly one use of this node.
453 ///
454 bool hasOneUse() const {
455 return !use_empty() && std::next(use_begin()) == use_end();
456 }
457
458 /// use_size - Return the number of uses of this node. This method takes
459 /// time proportional to the number of uses.
460 ///
461 size_t use_size() const { return std::distance(use_begin(), use_end()); }
462
463 /// getNodeId - Return the unique node id.
464 ///
465 int getNodeId() const { return NodeId; }
466
467 /// setNodeId - Set unique node id.
468 void setNodeId(int Id) { NodeId = Id; }
469
470 /// getIROrder - Return the node ordering.
471 ///
472 unsigned getIROrder() const { return IROrder; }
473
474 /// setIROrder - Set the node ordering.
475 ///
476 void setIROrder(unsigned Order) { IROrder = Order; }
477
478 /// getDebugLoc - Return the source location info.
479 const DebugLoc getDebugLoc() const { return debugLoc; }
480
481 /// setDebugLoc - Set source location info. Try to avoid this, putting
482 /// it in the constructor is preferable.
483 void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
484
485 /// use_iterator - This class provides iterator support for SDUse
486 /// operands that use a specific SDNode.
487 class use_iterator
488 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
489 SDUse *Op;
490 explicit use_iterator(SDUse *op) : Op(op) {
491 }
492 friend class SDNode;
493 public:
494 typedef std::iterator<std::forward_iterator_tag,
495 SDUse, ptrdiff_t>::reference reference;
496 typedef std::iterator<std::forward_iterator_tag,
497 SDUse, ptrdiff_t>::pointer pointer;
498
499 use_iterator(const use_iterator &I) : Op(I.Op) {}
500 use_iterator() : Op(nullptr) {}
501
502 bool operator==(const use_iterator &x) const {
503 return Op == x.Op;
504 }
505 bool operator!=(const use_iterator &x) const {
506 return !operator==(x);
507 }
508
509 /// atEnd - return true if this iterator is at the end of uses list.
510 bool atEnd() const { return Op == nullptr; }
511
512 // Iterator traversal: forward iteration only.
513 use_iterator &operator++() { // Preincrement
514 assert(Op && "Cannot increment end iterator!");
515 Op = Op->getNext();
516 return *this;
517 }
518
519 use_iterator operator++(int) { // Postincrement
520 use_iterator tmp = *this; ++*this; return tmp;
521 }
522
523 /// Retrieve a pointer to the current user node.
524 SDNode *operator*() const {
525 assert(Op && "Cannot dereference end iterator!");
526 return Op->getUser();
527 }
528
529 SDNode *operator->() const { return operator*(); }
530
531 SDUse &getUse() const { return *Op; }
532
533 /// getOperandNo - Retrieve the operand # of this use in its user.
534 ///
535 unsigned getOperandNo() const {
536 assert(Op && "Cannot dereference end iterator!");
537 return (unsigned)(Op - Op->getUser()->OperandList);
538 }
539 };
540
541 /// use_begin/use_end - Provide iteration support to walk over all uses
542 /// of an SDNode.
543
544 use_iterator use_begin() const {
545 return use_iterator(UseList);
546 }
547
548 static use_iterator use_end() { return use_iterator(nullptr); }
549
550 inline iterator_range<use_iterator> uses() {
551 return iterator_range<use_iterator>(use_begin(), use_end());
552 }
553 inline iterator_range<use_iterator> uses() const {
554 return iterator_range<use_iterator>(use_begin(), use_end());
555 }
556
557 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
558 /// indicated value. This method ignores uses of other values defined by this
559 /// operation.
560 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
561
562 /// hasAnyUseOfValue - Return true if there are any use of the indicated
563 /// value. This method ignores uses of other values defined by this operation.
564 bool hasAnyUseOfValue(unsigned Value) const;
565
566 /// isOnlyUserOf - Return true if this node is the only use of N.
567 ///
568 bool isOnlyUserOf(SDNode *N) const;
569
570 /// isOperandOf - Return true if this node is an operand of N.
571 ///
572 bool isOperandOf(SDNode *N) const;
573
574 /// isPredecessorOf - Return true if this node is a predecessor of N.
575 /// NOTE: Implemented on top of hasPredecessor and every bit as
576 /// expensive. Use carefully.
577 bool isPredecessorOf(const SDNode *N) const {
578 return N->hasPredecessor(this);
579 }
580
581 /// hasPredecessor - Return true if N is a predecessor of this node.
582 /// N is either an operand of this node, or can be reached by recursively
583 /// traversing up the operands.
584 /// NOTE: This is an expensive method. Use it carefully.
585 bool hasPredecessor(const SDNode *N) const;
586
587 /// hasPredecesorHelper - Return true if N is a predecessor of this node.
588 /// N is either an operand of this node, or can be reached by recursively
589 /// traversing up the operands.
590 /// In this helper the Visited and worklist sets are held externally to
591 /// cache predecessors over multiple invocations. If you want to test for
592 /// multiple predecessors this method is preferable to multiple calls to
593 /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
594 /// changes.
595 /// NOTE: This is still very expensive. Use carefully.
596 bool hasPredecessorHelper(const SDNode *N,
597 SmallPtrSetImpl<const SDNode *> &Visited,
598 SmallVectorImpl<const SDNode *> &Worklist) const;
599
600 /// getNumOperands - Return the number of values used by this operation.
601 ///
602 unsigned getNumOperands() const { return NumOperands; }
603
604 /// getConstantOperandVal - Helper method returns the integer value of a
605 /// ConstantSDNode operand.
606 uint64_t getConstantOperandVal(unsigned Num) const;
607
608 const SDValue &getOperand(unsigned Num) const {
609 assert(Num < NumOperands && "Invalid child # of SDNode!");
610 return OperandList[Num];
611 }
612
613 typedef SDUse* op_iterator;
614 op_iterator op_begin() const { return OperandList; }
615 op_iterator op_end() const { return OperandList+NumOperands; }
616 ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
617
618 SDVTList getVTList() const {
619 SDVTList X = { ValueList, NumValues };
620 return X;
621 }
622
623 /// getGluedNode - If this node has a glue operand, return the node
624 /// to which the glue operand points. Otherwise return NULL.
625 SDNode *getGluedNode() const {
626 if (getNumOperands() != 0 &&
627 getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
628 return getOperand(getNumOperands()-1).getNode();
629 return nullptr;
630 }
631
632 // If this is a pseudo op, like copyfromreg, look to see if there is a
633 // real target node glued to it. If so, return the target node.
634 const SDNode *getGluedMachineNode() const {
635 const SDNode *FoundNode = this;
636
637 // Climb up glue edges until a machine-opcode node is found, or the
638 // end of the chain is reached.
639 while (!FoundNode->isMachineOpcode()) {
640 const SDNode *N = FoundNode->getGluedNode();
641 if (!N) break;
642 FoundNode = N;
643 }
644
645 return FoundNode;
646 }
647
648 /// getGluedUser - If this node has a glue value with a user, return
649 /// the user (there is at most one). Otherwise return NULL.
650 SDNode *getGluedUser() const {
651 for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
652 if (UI.getUse().get().getValueType() == MVT::Glue)
653 return *UI;
654 return nullptr;
655 }
656
657 /// getNumValues - Return the number of values defined/returned by this
658 /// operator.
659 ///
660 unsigned getNumValues() const { return NumValues; }
661
662 /// getValueType - Return the type of a specified result.
663 ///
664 EVT getValueType(unsigned ResNo) const {
665 assert(ResNo < NumValues && "Illegal result number!");
666 return ValueList[ResNo];
667 }
668
669 /// Return the type of a specified result as a simple type.
670 ///
671 MVT getSimpleValueType(unsigned ResNo) const {
672 return getValueType(ResNo).getSimpleVT();
673 }
674
675 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
676 ///
677 unsigned getValueSizeInBits(unsigned ResNo) const {
678 return getValueType(ResNo).getSizeInBits();
679 }
680
681 typedef const EVT* value_iterator;
682 value_iterator value_begin() const { return ValueList; }
683 value_iterator value_end() const { return ValueList+NumValues; }
684
685 /// getOperationName - Return the opcode of this operation for printing.
686 ///
687 std::string getOperationName(const SelectionDAG *G = nullptr) const;
688 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
689 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
690 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
691 void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
692 void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
693
694 /// printrFull - Print a SelectionDAG node and all children down to
695 /// the leaves. The given SelectionDAG allows target-specific nodes
696 /// to be printed in human-readable form. Unlike printr, this will
697 /// print the whole DAG, including children that appear multiple
698 /// times.
699 ///
700 void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
701
702 /// printrWithDepth - Print a SelectionDAG node and children up to
703 /// depth "depth." The given SelectionDAG allows target-specific
704 /// nodes to be printed in human-readable form. Unlike printr, this
705 /// will print children that appear multiple times wherever they are
706 /// used.
707 ///
708 void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
709 unsigned depth = 100) const;
710
711
712 /// dump - Dump this node, for debugging.
713 void dump() const;
714
715 /// dumpr - Dump (recursively) this node and its use-def subgraph.
716 void dumpr() const;
717
718 /// dump - Dump this node, for debugging.
719 /// The given SelectionDAG allows target-specific nodes to be printed
720 /// in human-readable form.
721 void dump(const SelectionDAG *G) const;
722
723 /// dumpr - Dump (recursively) this node and its use-def subgraph.
724 /// The given SelectionDAG allows target-specific nodes to be printed
725 /// in human-readable form.
726 void dumpr(const SelectionDAG *G) const;
727
728 /// dumprFull - printrFull to dbgs(). The given SelectionDAG allows
729 /// target-specific nodes to be printed in human-readable form.
730 /// Unlike dumpr, this will print the whole DAG, including children
731 /// that appear multiple times.
732 ///
733 void dumprFull(const SelectionDAG *G = nullptr) const;
734
735 /// dumprWithDepth - printrWithDepth to dbgs(). The given
736 /// SelectionDAG allows target-specific nodes to be printed in
737 /// human-readable form. Unlike dumpr, this will print children
738 /// that appear multiple times wherever they are used.
739 ///
740 void dumprWithDepth(const SelectionDAG *G = nullptr,
741 unsigned depth = 100) const;
742
743 /// Profile - Gather unique data for the node.
744 ///
745 void Profile(FoldingSetNodeID &ID) const;
746
747 /// addUse - This method should only be used by the SDUse class.
748 ///
749 void addUse(SDUse &U) { U.addToList(&UseList); }
750
751 protected:
752 static SDVTList getSDVTList(EVT VT) {
753 SDVTList Ret = { getValueTypeList(VT), 1 };
754 return Ret;
755 }
756
757 SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs,
758 ArrayRef<SDValue> Ops)
759 : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
760 SubclassData(0), NodeId(-1),
761 OperandList(Ops.size() ? new SDUse[Ops.size()] : nullptr),
762 ValueList(VTs.VTs), UseList(nullptr),
763 NumOperands(Ops.size()), NumValues(VTs.NumVTs),
764 debugLoc(dl), IROrder(Order) {
765 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
766 assert(NumOperands == Ops.size() &&
767 "NumOperands wasn't wide enough for its operands!");
768 assert(NumValues == VTs.NumVTs &&
769 "NumValues wasn't wide enough for its operands!");
770 for (unsigned i = 0; i != Ops.size(); ++i) {
771 assert(OperandList && "no operands available");
772 OperandList[i].setUser(this);
773 OperandList[i].setInitial(Ops[i]);
774 }
775 checkForCycles(this);
776 }
777
778 /// This constructor adds no operands itself; operands can be
779 /// set later with InitOperands.
780 SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs)
781 : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
782 SubclassData(0), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
783 UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs), debugLoc(dl),
784 IROrder(Order) {
785 assert(debugLoc.hasTrivialDestructor() && "Expected trivial destructor");
786 assert(NumValues == VTs.NumVTs &&
787 "NumValues wasn't wide enough for its operands!");
788 }
789
790 /// InitOperands - Initialize the operands list of this with 1 operand.
791 void InitOperands(SDUse *Ops, const SDValue &Op0) {
792 Ops[0].setUser(this);
793 Ops[0].setInitial(Op0);
794 NumOperands = 1;
795 OperandList = Ops;
796 checkForCycles(this);
797 }
798
799 /// InitOperands - Initialize the operands list of this with 2 operands.
800 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
801 Ops[0].setUser(this);
802 Ops[0].setInitial(Op0);
803 Ops[1].setUser(this);
804 Ops[1].setInitial(Op1);
805 NumOperands = 2;
806 OperandList = Ops;
807 checkForCycles(this);
808 }
809
810 /// InitOperands - Initialize the operands list of this with 3 operands.
811 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
812 const SDValue &Op2) {
813 Ops[0].setUser(this);
814 Ops[0].setInitial(Op0);
815 Ops[1].setUser(this);
816 Ops[1].setInitial(Op1);
817 Ops[2].setUser(this);
818 Ops[2].setInitial(Op2);
819 NumOperands = 3;
820 OperandList = Ops;
821 checkForCycles(this);
822 }
823
824 /// InitOperands - Initialize the operands list of this with 4 operands.
825 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
826 const SDValue &Op2, const SDValue &Op3) {
827 Ops[0].setUser(this);
828 Ops[0].setInitial(Op0);
829 Ops[1].setUser(this);
830 Ops[1].setInitial(Op1);
831 Ops[2].setUser(this);
832 Ops[2].setInitial(Op2);
833 Ops[3].setUser(this);
834 Ops[3].setInitial(Op3);
835 NumOperands = 4;
836 OperandList = Ops;
837 checkForCycles(this);
838 }
839
840 /// InitOperands - Initialize the operands list of this with N operands.
841 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
842 for (unsigned i = 0; i != N; ++i) {
843 Ops[i].setUser(this);
844 Ops[i].setInitial(Vals[i]);
845 }
846 NumOperands = N;
847 assert(NumOperands == N &&
848 "NumOperands wasn't wide enough for its operands!");
849 OperandList = Ops;
850 checkForCycles(this);
851 }
852
853 /// DropOperands - Release the operands and set this node to have
854 /// zero operands.
855 void DropOperands();
856 };
857
858 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
859 /// into SDNode creation functions.
860 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
861 /// from the original Instruction, and IROrder is the ordinal position of
862 /// the instruction.
863 /// When an SDNode is created after the DAG is being built, both DebugLoc and
864 /// the IROrder are propagated from the original SDNode.
865 /// So SDLoc class provides two constructors besides the default one, one to
866 /// be used by the DAGBuilder, the other to be used by others.
867 class SDLoc {
868 private:
869 // Ptr could be used for either Instruction* or SDNode*. It is used for
870 // Instruction* if IROrder is not -1.
871 const void *Ptr;
872 int IROrder;
873
874 public:
875 SDLoc() : Ptr(nullptr), IROrder(0) {}
876 SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
877 assert(N && "null SDNode");
878 }
879 SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
880 assert(Ptr && "null SDNode");
881 }
882 SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
883 assert(Order >= 0 && "bad IROrder");
884 }
885 unsigned getIROrder() {
886 if (IROrder >= 0 || Ptr == nullptr) {
887 return (unsigned)IROrder;
888 }
889 const SDNode *N = (const SDNode*)(Ptr);
890 return N->getIROrder();
891 }
892 DebugLoc getDebugLoc() {
893 if (!Ptr) {
894 return DebugLoc();
895 }
896 if (IROrder >= 0) {
897 const Instruction *I = (const Instruction*)(Ptr);
898 return I->getDebugLoc();
899 }
900 const SDNode *N = (const SDNode*)(Ptr);
901 return N->getDebugLoc();
902 }
903 };
904
905
906 // Define inline functions from the SDValue class.
907
908 inline SDValue::SDValue(SDNode *node, unsigned resno)
909 : Node(node), ResNo(resno) {
910 assert((!Node || ResNo < Node->getNumValues()) &&
911 "Invalid result number for the given node!");
912 assert(ResNo < -2U && "Cannot use result numbers reserved for DenseMaps.");
913 }
914
915 inline unsigned SDValue::getOpcode() const {
916 return Node->getOpcode();
917 }
918 inline EVT SDValue::getValueType() const {
919 return Node->getValueType(ResNo);
920 }
921 inline unsigned SDValue::getNumOperands() const {
922 return Node->getNumOperands();
923 }
924 inline const SDValue &SDValue::getOperand(unsigned i) const {
925 return Node->getOperand(i);
926 }
927 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
928 return Node->getConstantOperandVal(i);
929 }
930 inline bool SDValue::isTargetOpcode() const {
931 return Node->isTargetOpcode();
932 }
933 inline bool SDValue::isTargetMemoryOpcode() const {
934 return Node->isTargetMemoryOpcode();
935 }
936 inline bool SDValue::isMachineOpcode() const {
937 return Node->isMachineOpcode();
938 }
939 inline unsigned SDValue::getMachineOpcode() const {
940 return Node->getMachineOpcode();
941 }
942 inline bool SDValue::use_empty() const {
943 return !Node->hasAnyUseOfValue(ResNo);
944 }
945 inline bool SDValue::hasOneUse() const {
946 return Node->hasNUsesOfValue(1, ResNo);
947 }
948 inline const DebugLoc SDValue::getDebugLoc() const {
949 return Node->getDebugLoc();
950 }
951 inline void SDValue::dump() const {
952 return Node->dump();
953 }
954 inline void SDValue::dumpr() const {
955 return Node->dumpr();
956 }
957 // Define inline functions from the SDUse class.
958
959 inline void SDUse::set(const SDValue &V) {
960 if (Val.getNode()) removeFromList();
961 Val = V;
962 if (V.getNode()) V.getNode()->addUse(*this);
963 }
964
965 inline void SDUse::setInitial(const SDValue &V) {
966 Val = V;
967 V.getNode()->addUse(*this);
968 }
969
970 inline void SDUse::setNode(SDNode *N) {
971 if (Val.getNode()) removeFromList();
972 Val.setNode(N);
973 if (N) N->addUse(*this);
974 }
975
976 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
977 /// to allow co-allocation of node operands with the node itself.
978 class UnarySDNode : public SDNode {
979 SDUse Op;
980 public:
981 UnarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
982 SDValue X)
983 : SDNode(Opc, Order, dl, VTs) {
984 InitOperands(&Op, X);
985 }
986 };
987
988 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
989 /// to allow co-allocation of node operands with the node itself.
990 class BinarySDNode : public SDNode {
991 SDUse Ops[2];
992 public:
993 BinarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
994 SDValue X, SDValue Y)
995 : SDNode(Opc, Order, dl, VTs) {
996 InitOperands(Ops, X, Y);
997 }
998 };
999
1000 /// BinaryWithFlagsSDNode - This class is an extension of BinarySDNode
1001 /// used from those opcodes that have associated extra flags.
1002 class BinaryWithFlagsSDNode : public BinarySDNode {
1003 enum { NUW = (1 << 0), NSW = (1 << 1), EXACT = (1 << 2) };
1004
1005 public:
1006 BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1007 SDValue X, SDValue Y)
1008 : BinarySDNode(Opc, Order, dl, VTs, X, Y) {}
1009 /// getRawSubclassData - Return the SubclassData value, which contains an
1010 /// encoding of the flags.
1011 /// This function should be used to add subclass data to the NodeID value.
1012 unsigned getRawSubclassData() const { return SubclassData; }
1013 void setHasNoUnsignedWrap(bool b) {
1014 SubclassData = (SubclassData & ~NUW) | (b ? NUW : 0);
1015 }
1016 void setHasNoSignedWrap(bool b) {
1017 SubclassData = (SubclassData & ~NSW) | (b ? NSW : 0);
1018 }
1019 void setIsExact(bool b) {
1020 SubclassData = (SubclassData & ~EXACT) | (b ? EXACT : 0);
1021 }
1022 bool hasNoUnsignedWrap() const { return SubclassData & NUW; }
1023 bool hasNoSignedWrap() const { return SubclassData & NSW; }
1024 bool isExact() const { return SubclassData & EXACT; }
1025 static bool classof(const SDNode *N) {
1026 return isBinOpWithFlags(N->getOpcode());
1027 }
1028 };
1029
1030 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1031 /// to allow co-allocation of node operands with the node itself.
1032 class TernarySDNode : public SDNode {
1033 SDUse Ops[3];
1034 public:
1035 TernarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1036 SDValue X, SDValue Y, SDValue Z)
1037 : SDNode(Opc, Order, dl, VTs) {
1038 InitOperands(Ops, X, Y, Z);
1039 }
1040 };
1041
1042
1043 /// HandleSDNode - This class is used to form a handle around another node that
1044 /// is persistent and is updated across invocations of replaceAllUsesWith on its
1045 /// operand. This node should be directly created by end-users and not added to
1046 /// the AllNodes list.
1047 class HandleSDNode : public SDNode {
1048 SDUse Op;
1049 public:
1050 explicit HandleSDNode(SDValue X)
1051 : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
1052 InitOperands(&Op, X);
1053 }
1054 ~HandleSDNode();
1055 const SDValue &getValue() const { return Op; }
1056 };
1057
1058 class AddrSpaceCastSDNode : public UnarySDNode {
1059 private:
1060 unsigned SrcAddrSpace;
1061 unsigned DestAddrSpace;
1062
1063 public:
1064 AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
1065 unsigned SrcAS, unsigned DestAS);
1066
1067 unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
1068 unsigned getDestAddressSpace() const { return DestAddrSpace; }
1069
1070 static bool classof(const SDNode *N) {
1071 return N->getOpcode() == ISD::ADDRSPACECAST;
1072 }
1073 };
1074
1075 /// Abstact virtual class for operations for memory operations
1076 class MemSDNode : public SDNode {
1077 private:
1078 // MemoryVT - VT of in-memory value.
1079 EVT MemoryVT;
1080
1081 protected:
1082 /// MMO - Memory reference information.
1083 MachineMemOperand *MMO;
1084
1085 public:
1086 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1087 EVT MemoryVT, MachineMemOperand *MMO);
1088
1089 MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1090 ArrayRef<SDValue> Ops, EVT MemoryVT, MachineMemOperand *MMO);
1091
1092 bool readMem() const { return MMO->isLoad(); }
1093 bool writeMem() const { return MMO->isStore(); }
1094
1095 /// Returns alignment and volatility of the memory access
1096 unsigned getOriginalAlignment() const {
1097 return MMO->getBaseAlignment();
1098 }
1099 unsigned getAlignment() const {
1100 return MMO->getAlignment();
1101 }
1102
1103 /// getRawSubclassData - Return the SubclassData value, which contains an
1104 /// encoding of the volatile flag, as well as bits used by subclasses. This
1105 /// function should only be used to compute a FoldingSetNodeID value.
1106 unsigned getRawSubclassData() const {
1107 return SubclassData;
1108 }
1109
1110 // We access subclass data here so that we can check consistency
1111 // with MachineMemOperand information.
1112 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1113 bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
1114 bool isInvariant() const { return (SubclassData >> 7) & 1; }
1115
1116 AtomicOrdering getOrdering() const {
1117 return AtomicOrdering((SubclassData >> 8) & 15);
1118 }
1119 SynchronizationScope getSynchScope() const {
1120 return SynchronizationScope((SubclassData >> 12) & 1);
1121 }
1122
1123 // Returns the offset from the location of the access.
1124 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1125
1126 /// Returns the AA info that describes the dereference.
1127 AAMDNodes getAAInfo() const { return MMO->getAAInfo(); }
1128
1129 /// Returns the Ranges that describes the dereference.
1130 const MDNode *getRanges() const { return MMO->getRanges(); }
1131
1132 /// getMemoryVT - Return the type of the in-memory value.
1133 EVT getMemoryVT() const { return MemoryVT; }
1134
1135 /// getMemOperand - Return a MachineMemOperand object describing the memory
1136 /// reference performed by operation.
1137 MachineMemOperand *getMemOperand() const { return MMO; }
1138
1139 const MachinePointerInfo &getPointerInfo() const {
1140 return MMO->getPointerInfo();
1141 }
1142
1143 /// getAddressSpace - Return the address space for the associated pointer
1144 unsigned getAddressSpace() const {
1145 return getPointerInfo().getAddrSpace();
1146 }
1147
1148 /// refineAlignment - Update this MemSDNode's MachineMemOperand information
1149 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1150 /// This must only be used when the new alignment applies to all users of
1151 /// this MachineMemOperand.
1152 void refineAlignment(const MachineMemOperand *NewMMO) {
1153 MMO->refineAlignment(NewMMO);
1154 }
1155
1156 const SDValue &getChain() const { return getOperand(0); }
1157 const SDValue &getBasePtr() const {
1158 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1159 }
1160
1161 // Methods to support isa and dyn_cast
1162 static bool classof(const SDNode *N) {
1163 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1164 // with either an intrinsic or a target opcode.
1165 return N->getOpcode() == ISD::LOAD ||
1166 N->getOpcode() == ISD::STORE ||
1167 N->getOpcode() == ISD::PREFETCH ||
1168 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1169 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1170 N->getOpcode() == ISD::ATOMIC_SWAP ||
1171 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1172 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1173 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1174 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1175 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1176 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1177 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1178 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1179 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1180 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1181 N->getOpcode() == ISD::ATOMIC_LOAD ||
1182 N->getOpcode() == ISD::ATOMIC_STORE ||
1183 N->getOpcode() == ISD::MLOAD ||
1184 N->getOpcode() == ISD::MSTORE ||
1185 N->isMemIntrinsic() ||
1186 N->isTargetMemoryOpcode();
1187 }
1188 };
1189
1190 /// AtomicSDNode - A SDNode reprenting atomic operations.
1191 ///
1192 class AtomicSDNode : public MemSDNode {
1193 SDUse Ops[4];
1194
1195 /// For cmpxchg instructions, the ordering requirements when a store does not
1196 /// occur.
1197 AtomicOrdering FailureOrdering;
1198
1199 void InitAtomic(AtomicOrdering SuccessOrdering,
1200 AtomicOrdering FailureOrdering,
1201 SynchronizationScope SynchScope) {
1202 // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1203 assert((SuccessOrdering & 15) == SuccessOrdering &&
1204 "Ordering may not require more than 4 bits!");
1205 assert((FailureOrdering & 15) == FailureOrdering &&
1206 "Ordering may not require more than 4 bits!");
1207 assert((SynchScope & 1) == SynchScope &&
1208 "SynchScope may not require more than 1 bit!");
1209 SubclassData |= SuccessOrdering << 8;
1210 SubclassData |= SynchScope << 12;
1211 this->FailureOrdering = FailureOrdering;
1212 assert(getSuccessOrdering() == SuccessOrdering &&
1213 "Ordering encoding error!");
1214 assert(getFailureOrdering() == FailureOrdering &&
1215 "Ordering encoding error!");
1216 assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1217 }
1218
1219 public:
1220 // Opc: opcode for atomic
1221 // VTL: value type list
1222 // Chain: memory chain for operaand
1223 // Ptr: address to update as a SDValue
1224 // Cmp: compare value
1225 // Swp: swap value
1226 // SrcVal: address to update as a Value (used for MemOperand)
1227 // Align: alignment of memory
1228 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1229 EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
1230 MachineMemOperand *MMO, AtomicOrdering Ordering,
1231 SynchronizationScope SynchScope)
1232 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1233 InitAtomic(Ordering, Ordering, SynchScope);
1234 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1235 }
1236 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1237 EVT MemVT,
1238 SDValue Chain, SDValue Ptr,
1239 SDValue Val, MachineMemOperand *MMO,
1240 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1241 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1242 InitAtomic(Ordering, Ordering, SynchScope);
1243 InitOperands(Ops, Chain, Ptr, Val);
1244 }
1245 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
1246 EVT MemVT,
1247 SDValue Chain, SDValue Ptr,
1248 MachineMemOperand *MMO,
1249 AtomicOrdering Ordering, SynchronizationScope SynchScope)
1250 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1251 InitAtomic(Ordering, Ordering, SynchScope);
1252 InitOperands(Ops, Chain, Ptr);
1253 }
1254 AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
1255 const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
1256 MachineMemOperand *MMO,
1257 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
1258 SynchronizationScope SynchScope)
1259 : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
1260 InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
1261 assert((DynOps || NumOps <= array_lengthof(Ops)) &&
1262 "Too many ops for internal storage!");
1263 InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
1264 }
1265
1266 const SDValue &getBasePtr() const { return getOperand(1); }
1267 const SDValue &getVal() const { return getOperand(2); }
1268
1269 AtomicOrdering getSuccessOrdering() const {
1270 return getOrdering();
1271 }
1272
1273 // Not quite enough room in SubclassData for everything, so failure gets its
1274 // own field.
1275 AtomicOrdering getFailureOrdering() const {
1276 return FailureOrdering;
1277 }
1278
1279 bool isCompareAndSwap() const {
1280 unsigned Op = getOpcode();
1281 return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
1282 }
1283
1284 // Methods to support isa and dyn_cast
1285 static bool classof(const SDNode *N) {
1286 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1287 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
1288 N->getOpcode() == ISD::ATOMIC_SWAP ||
1289 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1290 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1291 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1292 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1293 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1294 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1295 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1296 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1297 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1298 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1299 N->getOpcode() == ISD::ATOMIC_LOAD ||
1300 N->getOpcode() == ISD::ATOMIC_STORE;
1301 }
1302 };
1303
1304 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1305 /// memory and need an associated MachineMemOperand. Its opcode may be
1306 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1307 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1308 class MemIntrinsicSDNode : public MemSDNode {
1309 public:
1310 MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
1311 ArrayRef<SDValue> Ops, EVT MemoryVT,
1312 MachineMemOperand *MMO)
1313 : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
1314 SubclassData |= 1u << 13;
1315 }
1316
1317 // Methods to support isa and dyn_cast
1318 static bool classof(const SDNode *N) {
1319 // We lower some target intrinsics to their target opcode
1320 // early a node with a target opcode can be of this class
1321 return N->isMemIntrinsic() ||
1322 N->getOpcode() == ISD::PREFETCH ||
1323 N->isTargetMemoryOpcode();
1324 }
1325 };
1326
1327 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1328 /// support for the llvm IR shufflevector instruction. It combines elements
1329 /// from two input vectors into a new input vector, with the selection and
1330 /// ordering of elements determined by an array of integers, referred to as
1331 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1332 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1333 /// An index of -1 is treated as undef, such that the code generator may put
1334 /// any value in the corresponding element of the result.
1335 class ShuffleVectorSDNode : public SDNode {
1336 SDUse Ops[2];
1337
1338 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1339 // is freed when the SelectionDAG object is destroyed.
1340 const int *Mask;
1341 protected:
1342 friend class SelectionDAG;
1343 ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
1344 SDValue N2, const int *M)
1345 : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
1346 InitOperands(Ops, N1, N2);
1347 }
1348 public:
1349
1350 ArrayRef<int> getMask() const {
1351 EVT VT = getValueType(0);
1352 return makeArrayRef(Mask, VT.getVectorNumElements());
1353 }
1354 int getMaskElt(unsigned Idx) const {
1355 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1356 return Mask[Idx];
1357 }
1358
1359 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1360 int getSplatIndex() const {
1361 assert(isSplat() && "Cannot get splat index for non-splat!");
1362 EVT VT = getValueType(0);
1363 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1364 if (Mask[i] >= 0)
1365 return Mask[i];
1366 }
1367 llvm_unreachable("Splat with all undef indices?");
1368 }
1369 static bool isSplatMask(const int *Mask, EVT VT);
1370
1371 static bool classof(const SDNode *N) {
1372 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1373 }
1374 };
1375
1376 class ConstantSDNode : public SDNode {
1377 const ConstantInt *Value;
1378 friend class SelectionDAG;
1379 ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
1380 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1381 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1382 SubclassData |= (uint16_t)isOpaque;
1383 }
1384 public:
1385
1386 const ConstantInt *getConstantIntValue() const { return Value; }
1387 const APInt &getAPIntValue() const { return Value->getValue(); }
1388 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1389 int64_t getSExtValue() const { return Value->getSExtValue(); }
1390
1391 bool isOne() const { return Value->isOne(); }
1392 bool isNullValue() const { return Value->isNullValue(); }
1393 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1394
1395 bool isOpaque() const { return SubclassData & 1; }
1396
1397 static bool classof(const SDNode *N) {
1398 return N->getOpcode() == ISD::Constant ||
1399 N->getOpcode() == ISD::TargetConstant;
1400 }
1401 };
1402
1403 class ConstantFPSDNode : public SDNode {
1404 const ConstantFP *Value;
1405 friend class SelectionDAG;
1406 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1407 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1408 0, DebugLoc(), getSDVTList(VT)), Value(val) {
1409 }
1410 public:
1411
1412 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1413 const ConstantFP *getConstantFPValue() const { return Value; }
1414
1415 /// isZero - Return true if the value is positive or negative zero.
1416 bool isZero() const { return Value->isZero(); }
1417
1418 /// isNaN - Return true if the value is a NaN.
1419 bool isNaN() const { return Value->isNaN(); }
1420
1421 /// isInfinity - Return true if the value is an infinity
1422 bool isInfinity() const { return Value->isInfinity(); }
1423
1424 /// isNegative - Return true if the value is negative.
1425 bool isNegative() const { return Value->isNegative(); }
1426
1427 /// isExactlyValue - We don't rely on operator== working on double values, as
1428 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1429 /// As such, this method can be used to do an exact bit-for-bit comparison of
1430 /// two floating point values.
1431
1432 /// We leave the version with the double argument here because it's just so
1433 /// convenient to write "2.0" and the like. Without this function we'd
1434 /// have to duplicate its logic everywhere it's called.
1435 bool isExactlyValue(double V) const {
1436 bool ignored;
1437 APFloat Tmp(V);
1438 Tmp.convert(Value->getValueAPF().getSemantics(),
1439 APFloat::rmNearestTiesToEven, &ignored);
1440 return isExactlyValue(Tmp);
1441 }
1442 bool isExactlyValue(const APFloat& V) const;
1443
1444 static bool isValueValidForType(EVT VT, const APFloat& Val);
1445
1446 static bool classof(const SDNode *N) {
1447 return N->getOpcode() == ISD::ConstantFP ||
1448 N->getOpcode() == ISD::TargetConstantFP;
1449 }
1450 };
1451
1452 class GlobalAddressSDNode : public SDNode {
1453 const GlobalValue *TheGlobal;
1454 int64_t Offset;
1455 unsigned char TargetFlags;
1456 friend class SelectionDAG;
1457 GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
1458 const GlobalValue *GA, EVT VT, int64_t o,
1459 unsigned char TargetFlags);
1460 public:
1461
1462 const GlobalValue *getGlobal() const { return TheGlobal; }
1463 int64_t getOffset() const { return Offset; }
1464 unsigned char getTargetFlags() const { return TargetFlags; }
1465 // Return the address space this GlobalAddress belongs to.
1466 unsigned getAddressSpace() const;
1467
1468 static bool classof(const SDNode *N) {
1469 return N->getOpcode() == ISD::GlobalAddress ||
1470 N->getOpcode() == ISD::TargetGlobalAddress ||
1471 N->getOpcode() == ISD::GlobalTLSAddress ||
1472 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1473 }
1474 };
1475
1476 class FrameIndexSDNode : public SDNode {
1477 int FI;
1478 friend class SelectionDAG;
1479 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1480 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1481 0, DebugLoc(), getSDVTList(VT)), FI(fi) {
1482 }
1483 public:
1484
1485 int getIndex() const { return FI; }
1486
1487 static bool classof(const SDNode *N) {
1488 return N->getOpcode() == ISD::FrameIndex ||
1489 N->getOpcode() == ISD::TargetFrameIndex;
1490 }
1491 };
1492
1493 class JumpTableSDNode : public SDNode {
1494 int JTI;
1495 unsigned char TargetFlags;
1496 friend class SelectionDAG;
1497 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1498 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1499 0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1500 }
1501 public:
1502
1503 int getIndex() const { return JTI; }
1504 unsigned char getTargetFlags() const { return TargetFlags; }
1505
1506 static bool classof(const SDNode *N) {
1507 return N->getOpcode() == ISD::JumpTable ||
1508 N->getOpcode() == ISD::TargetJumpTable;
1509 }
1510 };
1511
1512 class ConstantPoolSDNode : public SDNode {
1513 union {
1514 const Constant *ConstVal;
1515 MachineConstantPoolValue *MachineCPVal;
1516 } Val;
1517 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1518 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1519 unsigned char TargetFlags;
1520 friend class SelectionDAG;
1521 ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1522 unsigned Align, unsigned char TF)
1523 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1524 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1525 TargetFlags(TF) {
1526 assert(Offset >= 0 && "Offset is too large");
1527 Val.ConstVal = c;
1528 }
1529 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1530 EVT VT, int o, unsigned Align, unsigned char TF)
1531 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
1532 DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
1533 TargetFlags(TF) {
1534 assert(Offset >= 0 && "Offset is too large");
1535 Val.MachineCPVal = v;
1536 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1537 }
1538 public:
1539
1540 bool isMachineConstantPoolEntry() const {
1541 return Offset < 0;
1542 }
1543
1544 const Constant *getConstVal() const {
1545 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1546 return Val.ConstVal;
1547 }
1548
1549 MachineConstantPoolValue *getMachineCPVal() const {
1550 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1551 return Val.MachineCPVal;
1552 }
1553
1554 int getOffset() const {
1555 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1556 }
1557
1558 // Return the alignment of this constant pool object, which is either 0 (for
1559 // default alignment) or the desired value.
1560 unsigned getAlignment() const { return Alignment; }
1561 unsigned char getTargetFlags() const { return TargetFlags; }
1562
1563 Type *getType() const;
1564
1565 static bool classof(const SDNode *N) {
1566 return N->getOpcode() == ISD::ConstantPool ||
1567 N->getOpcode() == ISD::TargetConstantPool;
1568 }
1569 };
1570
1571 /// Completely target-dependent object reference.
1572 class TargetIndexSDNode : public SDNode {
1573 unsigned char TargetFlags;
1574 int Index;
1575 int64_t Offset;
1576 friend class SelectionDAG;
1577 public:
1578
1579 TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1580 : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
1581 TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1582 public:
1583
1584 unsigned char getTargetFlags() const { return TargetFlags; }
1585 int getIndex() const { return Index; }
1586 int64_t getOffset() const { return Offset; }
1587
1588 static bool classof(const SDNode *N) {
1589 return N->getOpcode() == ISD::TargetIndex;
1590 }
1591 };
1592
1593 class BasicBlockSDNode : public SDNode {
1594 MachineBasicBlock *MBB;
1595 friend class SelectionDAG;
1596 /// Debug info is meaningful and potentially useful here, but we create
1597 /// blocks out of order when they're jumped to, which makes it a bit
1598 /// harder. Let's see if we need it first.
1599 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1600 : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
1601 {}
1602 public:
1603
1604 MachineBasicBlock *getBasicBlock() const { return MBB; }
1605
1606 static bool classof(const SDNode *N) {
1607 return N->getOpcode() == ISD::BasicBlock;
1608 }
1609 };
1610
1611 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1612 /// BUILD_VECTORs.
1613 class BuildVectorSDNode : public SDNode {
1614 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1615 explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1616 public:
1617 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1618 /// smallest element size that splats the vector. If MinSplatBits is
1619 /// nonzero, the element size must be at least that large. Note that the
1620 /// splat element may be the entire vector (i.e., a one element vector).
1621 /// Returns the splat element value in SplatValue. Any undefined bits in
1622 /// that value are zero, and the corresponding bits in the SplatUndef mask
1623 /// are set. The SplatBitSize value is set to the splat element size in
1624 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1625 /// undefined. isBigEndian describes the endianness of the target.
1626 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1627 unsigned &SplatBitSize, bool &HasAnyUndefs,
1628 unsigned MinSplatBits = 0,
1629 bool isBigEndian = false) const;
1630
1631 /// \brief Returns the splatted value or a null value if this is not a splat.
1632 ///
1633 /// If passed a non-null UndefElements bitvector, it will resize it to match
1634 /// the vector width and set the bits where elements are undef.
1635 SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
1636
1637 /// \brief Returns the splatted constant or null if this is not a constant
1638 /// splat.
1639 ///
1640 /// If passed a non-null UndefElements bitvector, it will resize it to match
1641 /// the vector width and set the bits where elements are undef.
1642 ConstantSDNode *
1643 getConstantSplatNode(BitVector *UndefElements = nullptr) const;
1644
1645 /// \brief Returns the splatted constant FP or null if this is not a constant
1646 /// FP splat.
1647 ///
1648 /// If passed a non-null UndefElements bitvector, it will resize it to match
1649 /// the vector width and set the bits where elements are undef.
1650 ConstantFPSDNode *
1651 getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
1652
1653 bool isConstant() const;
1654
1655 static inline bool classof(const SDNode *N) {
1656 return N->getOpcode() == ISD::BUILD_VECTOR;
1657 }
1658 };
1659
1660 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1661 /// used when the SelectionDAG needs to make a simple reference to something
1662 /// in the LLVM IR representation.
1663 ///
1664 class SrcValueSDNode : public SDNode {
1665 const Value *V;
1666 friend class SelectionDAG;
1667 /// Create a SrcValue for a general value.
1668 explicit SrcValueSDNode(const Value *v)
1669 : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1670
1671 public:
1672 /// getValue - return the contained Value.
1673 const Value *getValue() const { return V; }
1674
1675 static bool classof(const SDNode *N) {
1676 return N->getOpcode() == ISD::SRCVALUE;
1677 }
1678 };
1679
1680 class MDNodeSDNode : public SDNode {
1681 const MDNode *MD;
1682 friend class SelectionDAG;
1683 explicit MDNodeSDNode(const MDNode *md)
1684 : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
1685 {}
1686 public:
1687
1688 const MDNode *getMD() const { return MD; }
1689
1690 static bool classof(const SDNode *N) {
1691 return N->getOpcode() == ISD::MDNODE_SDNODE;
1692 }
1693 };
1694
1695 class RegisterSDNode : public SDNode {
1696 unsigned Reg;
1697 friend class SelectionDAG;
1698 RegisterSDNode(unsigned reg, EVT VT)
1699 : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1700 }
1701 public:
1702
1703 unsigned getReg() const { return Reg; }
1704
1705 static bool classof(const SDNode *N) {
1706 return N->getOpcode() == ISD::Register;
1707 }
1708 };
1709
1710 class RegisterMaskSDNode : public SDNode {
1711 // The memory for RegMask is not owned by the node.
1712 const uint32_t *RegMask;
1713 friend class SelectionDAG;
1714 RegisterMaskSDNode(const uint32_t *mask)
1715 : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
1716 RegMask(mask) {}
1717 public:
1718
1719 const uint32_t *getRegMask() const { return RegMask; }
1720
1721 static bool classof(const SDNode *N) {
1722 return N->getOpcode() == ISD::RegisterMask;
1723 }
1724 };
1725
1726 class BlockAddressSDNode : public SDNode {
1727 const BlockAddress *BA;
1728 int64_t Offset;
1729 unsigned char TargetFlags;
1730 friend class SelectionDAG;
1731 BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1732 int64_t o, unsigned char Flags)
1733 : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
1734 BA(ba), Offset(o), TargetFlags(Flags) {
1735 }
1736 public:
1737 const BlockAddress *getBlockAddress() const { return BA; }
1738 int64_t getOffset() const { return Offset; }
1739 unsigned char getTargetFlags() const { return TargetFlags; }
1740
1741 static bool classof(const SDNode *N) {
1742 return N->getOpcode() == ISD::BlockAddress ||
1743 N->getOpcode() == ISD::TargetBlockAddress;
1744 }
1745 };
1746
1747 class EHLabelSDNode : public SDNode {
1748 SDUse Chain;
1749 MCSymbol *Label;
1750 friend class SelectionDAG;
1751 EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
1752 : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
1753 InitOperands(&Chain, ch);
1754 }
1755 public:
1756 MCSymbol *getLabel() const { return Label; }
1757
1758 static bool classof(const SDNode *N) {
1759 return N->getOpcode() == ISD::EH_LABEL;
1760 }
1761 };
1762
1763 class ExternalSymbolSDNode : public SDNode {
1764 const char *Symbol;
1765 unsigned char TargetFlags;
1766
1767 friend class SelectionDAG;
1768 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1769 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1770 0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1771 }
1772 public:
1773
1774 const char *getSymbol() const { return Symbol; }
1775 unsigned char getTargetFlags() const { return TargetFlags; }
1776
1777 static bool classof(const SDNode *N) {
1778 return N->getOpcode() == ISD::ExternalSymbol ||
1779 N->getOpcode() == ISD::TargetExternalSymbol;
1780 }
1781 };
1782
1783 class CondCodeSDNode : public SDNode {
1784 ISD::CondCode Condition;
1785 friend class SelectionDAG;
1786 explicit CondCodeSDNode(ISD::CondCode Cond)
1787 : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1788 Condition(Cond) {
1789 }
1790 public:
1791
1792 ISD::CondCode get() const { return Condition; }
1793
1794 static bool classof(const SDNode *N) {
1795 return N->getOpcode() == ISD::CONDCODE;
1796 }
1797 };
1798
1799 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1800 /// future and most targets don't support it.
1801 class CvtRndSatSDNode : public SDNode {
1802 ISD::CvtCode CvtCode;
1803 friend class SelectionDAG;
1804 explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
1805 ArrayRef<SDValue> Ops, ISD::CvtCode Code)
1806 : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
1807 CvtCode(Code) {
1808 assert(Ops.size() == 5 && "wrong number of operations");
1809 }
1810 public:
1811 ISD::CvtCode getCvtCode() const { return CvtCode; }
1812
1813 static bool classof(const SDNode *N) {
1814 return N->getOpcode() == ISD::CONVERT_RNDSAT;
1815 }
1816 };
1817
1818 /// VTSDNode - This class is used to represent EVT's, which are used
1819 /// to parameterize some operations.
1820 class VTSDNode : public SDNode {
1821 EVT ValueType;
1822 friend class SelectionDAG;
1823 explicit VTSDNode(EVT VT)
1824 : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
1825 ValueType(VT) {
1826 }
1827 public:
1828
1829 EVT getVT() const { return ValueType; }
1830
1831 static bool classof(const SDNode *N) {
1832 return N->getOpcode() == ISD::VALUETYPE;
1833 }
1834 };
1835
1836 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1837 ///
1838 class LSBaseSDNode : public MemSDNode {
1839 //! Operand array for load and store
1840 /*!
1841 \note Moving this array to the base class captures more
1842 common functionality shared between LoadSDNode and
1843 StoreSDNode
1844 */
1845 SDUse Ops[4];
1846 public:
1847 LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1848 SDValue *Operands, unsigned numOperands,
1849 SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
1850 MachineMemOperand *MMO)
1851 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1852 SubclassData |= AM << 2;
1853 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1854 InitOperands(Ops, Operands, numOperands);
1855 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1856 "Only indexed loads and stores have a non-undef offset operand");
1857 }
1858
1859 const SDValue &getOffset() const {
1860 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1861 }
1862
1863 /// getAddressingMode - Return the addressing mode for this load or store:
1864 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1865 ISD::MemIndexedMode getAddressingMode() const {
1866 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1867 }
1868
1869 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1870 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1871
1872 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1873 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1874
1875 static bool classof(const SDNode *N) {
1876 return N->getOpcode() == ISD::LOAD ||
1877 N->getOpcode() == ISD::STORE;
1878 }
1879 };
1880
1881 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1882 ///
1883 class LoadSDNode : public LSBaseSDNode {
1884 friend class SelectionDAG;
1885 LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
1886 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1887 MachineMemOperand *MMO)
1888 : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
1889 SubclassData |= (unsigned short)ETy;
1890 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1891 assert(readMem() && "Load MachineMemOperand is not a load!");
1892 assert(!writeMem() && "Load MachineMemOperand is a store!");
1893 }
1894 public:
1895
1896 /// getExtensionType - Return whether this is a plain node,
1897 /// or one of the varieties of value-extending loads.
1898 ISD::LoadExtType getExtensionType() const {
1899 return ISD::LoadExtType(SubclassData & 3);
1900 }
1901
1902 const SDValue &getBasePtr() const { return getOperand(1); }
1903 const SDValue &getOffset() const { return getOperand(2); }
1904
1905 static bool classof(const SDNode *N) {
1906 return N->getOpcode() == ISD::LOAD;
1907 }
1908 };
1909
1910 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1911 ///
1912 class StoreSDNode : public LSBaseSDNode {
1913 friend class SelectionDAG;
1914 StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
1915 SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1916 MachineMemOperand *MMO)
1917 : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
1918 VTs, AM, MemVT, MMO) {
1919 SubclassData |= (unsigned short)isTrunc;
1920 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1921 assert(!readMem() && "Store MachineMemOperand is a load!");
1922 assert(writeMem() && "Store MachineMemOperand is not a store!");
1923 }
1924 public:
1925
1926 /// isTruncatingStore - Return true if the op does a truncation before store.
1927 /// For integers this is the same as doing a TRUNCATE and storing the result.
1928 /// For floats, it is the same as doing an FP_ROUND and storing the result.
1929 bool isTruncatingStore() const { return SubclassData & 1; }
1930
1931 const SDValue &getValue() const { return getOperand(1); }
1932 const SDValue &getBasePtr() const { return getOperand(2); }
1933 const SDValue &getOffset() const { return getOperand(3); }
1934
1935 static bool classof(const SDNode *N) {
1936 return N->getOpcode() == ISD::STORE;
1937 }
1938 };
1939
1940 /// MaskedLoadStoreSDNode - This is a base class is used to represent MLOAD and
1941 /// MSTORE nodes
1942 ///
1943 class MaskedLoadStoreSDNode : public MemSDNode {
1944 // Operands
1945 SDUse Ops[4];
1946 public:
1947 friend class SelectionDAG;
1948 MaskedLoadStoreSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
1949 SDValue *Operands, unsigned numOperands,
1950 SDVTList VTs, EVT MemVT, MachineMemOperand *MMO)
1951 : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
1952 InitOperands(Ops, Operands, numOperands);
1953 }
1954
1955 // In the both nodes address is Op1, mask is Op2:
1956 // MaskedLoadSDNode (Chain, ptr, mask, src0), src0 is a passthru value
1957 // MaskedStoreSDNode (Chain, ptr, mask, data)
1958 // Mask is a vector of i1 elements
1959 const SDValue &getBasePtr() const { return getOperand(1); }
1960 const SDValue &getMask() const { return getOperand(2); }
1961
1962 static bool classof(const SDNode *N) {
1963 return N->getOpcode() == ISD::MLOAD ||
1964 N->getOpcode() == ISD::MSTORE;
1965 }
1966 };
1967
1968 /// MaskedLoadSDNode - This class is used to represent an MLOAD node
1969 ///
1970 class MaskedLoadSDNode : public MaskedLoadStoreSDNode {
1971 public:
1972 friend class SelectionDAG;
1973 MaskedLoadSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1974 unsigned numOperands, SDVTList VTs, ISD::LoadExtType ETy,
1975 EVT MemVT, MachineMemOperand *MMO)
1976 : MaskedLoadStoreSDNode(ISD::MLOAD, Order, dl, Operands, numOperands,
1977 VTs, MemVT, MMO) {
1978 SubclassData |= (unsigned short)ETy;
1979 }
1980
1981 ISD::LoadExtType getExtensionType() const {
1982 return ISD::LoadExtType(SubclassData & 3);
1983 }
1984 const SDValue &getSrc0() const { return getOperand(3); }
1985 static bool classof(const SDNode *N) {
1986 return N->getOpcode() == ISD::MLOAD;
1987 }
1988 };
1989
1990 /// MaskedStoreSDNode - This class is used to represent an MSTORE node
1991 ///
1992 class MaskedStoreSDNode : public MaskedLoadStoreSDNode {
1993
1994 public:
1995 friend class SelectionDAG;
1996 MaskedStoreSDNode(unsigned Order, DebugLoc dl, SDValue *Operands,
1997 unsigned numOperands, SDVTList VTs, bool isTrunc, EVT MemVT,
1998 MachineMemOperand *MMO)
1999 : MaskedLoadStoreSDNode(ISD::MSTORE, Order, dl, Operands, numOperands,
2000 VTs, MemVT, MMO) {
2001 SubclassData |= (unsigned short)isTrunc;
2002 }
2003 /// isTruncatingStore - Return true if the op does a truncation before store.
2004 /// For integers this is the same as doing a TRUNCATE and storing the result.
2005 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2006 bool isTruncatingStore() const { return SubclassData & 1; }
2007
2008 const SDValue &getValue() const { return getOperand(3); }
2009
2010 static bool classof(const SDNode *N) {
2011 return N->getOpcode() == ISD::MSTORE;
2012 }
2013 };
2014
2015 /// MachineSDNode - An SDNode that represents everything that will be needed
2016 /// to construct a MachineInstr. These nodes are created during the
2017 /// instruction selection proper phase.
2018 ///
2019 class MachineSDNode : public SDNode {
2020 public:
2021 typedef MachineMemOperand **mmo_iterator;
2022
2023 private:
2024 friend class SelectionDAG;
2025 MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
2026 : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
2027
2028 /// LocalOperands - Operands for this instruction, if they fit here. If
2029 /// they don't, this field is unused.
2030 SDUse LocalOperands[4];
2031
2032 /// MemRefs - Memory reference descriptions for this instruction.
2033 mmo_iterator MemRefs;
2034 mmo_iterator MemRefsEnd;
2035
2036 public:
2037 mmo_iterator memoperands_begin() const { return MemRefs; }
2038 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2039 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2040
2041 /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
2042 /// list. This does not transfer ownership.
2043 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2044 for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
2045 assert(*MMI && "Null mem ref detected!");
2046 MemRefs = NewMemRefs;
2047 MemRefsEnd = NewMemRefsEnd;
2048 }
2049
2050 static bool classof(const SDNode *N) {
2051 return N->isMachineOpcode();
2052 }
2053 };
2054
2055 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2056 SDNode, ptrdiff_t> {
2057 const SDNode *Node;
2058 unsigned Operand;
2059
2060 SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2061 public:
2062 bool operator==(const SDNodeIterator& x) const {
2063 return Operand == x.Operand;
2064 }
2065 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2066
2067 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2068 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2069 Operand = I.Operand;
2070 return *this;
2071 }
2072
2073 pointer operator*() const {
2074 return Node->getOperand(Operand).getNode();
2075 }
2076 pointer operator->() const { return operator*(); }
2077
2078 SDNodeIterator& operator++() { // Preincrement
2079 ++Operand;
2080 return *this;
2081 }
2082 SDNodeIterator operator++(int) { // Postincrement
2083 SDNodeIterator tmp = *this; ++*this; return tmp;
2084 }
2085 size_t operator-(SDNodeIterator Other) const {
2086 assert(Node == Other.Node &&
2087 "Cannot compare iterators of two different nodes!");
2088 return Operand - Other.Operand;
2089 }
2090
2091 static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
2092 static SDNodeIterator end (const SDNode *N) {
2093 return SDNodeIterator(N, N->getNumOperands());
2094 }
2095
2096 unsigned getOperand() const { return Operand; }
2097 const SDNode *getNode() const { return Node; }
2098 };
2099
2100 template <> struct GraphTraits<SDNode*> {
2101 typedef SDNode NodeType;
2102 typedef SDNodeIterator ChildIteratorType;
2103 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2104 static inline ChildIteratorType child_begin(NodeType *N) {
2105 return SDNodeIterator::begin(N);
2106 }
2107 static inline ChildIteratorType child_end(NodeType *N) {
2108 return SDNodeIterator::end(N);
2109 }
2110 };
2111
2112 /// LargestSDNode - The largest SDNode class.
2113 ///
2114 typedef AtomicSDNode LargestSDNode;
2115
2116 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2117 /// requirement.
2118 ///
2119 typedef GlobalAddressSDNode MostAlignedSDNode;
2120
2121 namespace ISD {
2122 /// isNormalLoad - Returns true if the specified node is a non-extending
2123 /// and unindexed load.
2124 inline bool isNormalLoad(const SDNode *N) {
2125 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2126 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2127 Ld->getAddressingMode() == ISD::UNINDEXED;
2128 }
2129
2130 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2131 /// load.
2132 inline bool isNON_EXTLoad(const SDNode *N) {
2133 return isa<LoadSDNode>(N) &&
2134 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2135 }
2136
2137 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2138 ///
2139 inline bool isEXTLoad(const SDNode *N) {
2140 return isa<LoadSDNode>(N) &&
2141 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2142 }
2143
2144 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2145 ///
2146 inline bool isSEXTLoad(const SDNode *N) {
2147 return isa<LoadSDNode>(N) &&
2148 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2149 }
2150
2151 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2152 ///
2153 inline bool isZEXTLoad(const SDNode *N) {
2154 return isa<LoadSDNode>(N) &&
2155 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2156 }
2157
2158 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2159 ///
2160 inline bool isUNINDEXEDLoad(const SDNode *N) {
2161 return isa<LoadSDNode>(N) &&
2162 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2163 }
2164
2165 /// isNormalStore - Returns true if the specified node is a non-truncating
2166 /// and unindexed store.
2167 inline bool isNormalStore(const SDNode *N) {
2168 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2169 return St && !St->isTruncatingStore() &&
2170 St->getAddressingMode() == ISD::UNINDEXED;
2171 }
2172
2173 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2174 /// store.
2175 inline bool isNON_TRUNCStore(const SDNode *N) {
2176 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2177 }
2178
2179 /// isTRUNCStore - Returns true if the specified node is a truncating
2180 /// store.
2181 inline bool isTRUNCStore(const SDNode *N) {
2182 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2183 }
2184
2185 /// isUNINDEXEDStore - Returns true if the specified node is an
2186 /// unindexed store.
2187 inline bool isUNINDEXEDStore(const SDNode *N) {
2188 return isa<StoreSDNode>(N) &&
2189 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2190 }
2191 }
2192
2193 } // end llvm namespace
2194
2195 #endif