Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1865 lines
63 KiB

  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. #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
  19. #define LLVM_CODEGEN_SELECTIONDAGNODES_H
  20. #include "llvm/ADT/FoldingSet.h"
  21. #include "llvm/ADT/GraphTraits.h"
  22. #include "llvm/ADT/STLExtras.h"
  23. #include "llvm/ADT/SmallPtrSet.h"
  24. #include "llvm/ADT/SmallVector.h"
  25. #include "llvm/ADT/ilist_node.h"
  26. #include "llvm/CodeGen/ISDOpcodes.h"
  27. #include "llvm/CodeGen/MachineMemOperand.h"
  28. #include "llvm/CodeGen/ValueTypes.h"
  29. #include "llvm/IR/Constants.h"
  30. #include "llvm/IR/Instructions.h"
  31. #include "llvm/Support/DataTypes.h"
  32. #include "llvm/Support/DebugLoc.h"
  33. #include "llvm/Support/MathExtras.h"
  34. #include <cassert>
  35. namespace llvm {
  36. class SelectionDAG;
  37. class GlobalValue;
  38. class MachineBasicBlock;
  39. class MachineConstantPoolValue;
  40. class SDNode;
  41. class Value;
  42. class MCSymbol;
  43. template <typename T> struct DenseMapInfo;
  44. template <typename T> struct simplify_type;
  45. template <typename T> struct ilist_traits;
  46. void checkForCycles(const SDNode *N);
  47. /// SDVTList - This represents a list of ValueType's that has been intern'd by
  48. /// a SelectionDAG. Instances of this simple value class are returned by
  49. /// SelectionDAG::getVTList(...).
  50. ///
  51. struct SDVTList {
  52. const EVT *VTs;
  53. unsigned int NumVTs;
  54. };
  55. namespace ISD {
  56. /// Node predicates
  57. /// isBuildVectorAllOnes - Return true if the specified node is a
  58. /// BUILD_VECTOR where all of the elements are ~0 or undef.
  59. bool isBuildVectorAllOnes(const SDNode *N);
  60. /// isBuildVectorAllZeros - Return true if the specified node is a
  61. /// BUILD_VECTOR where all of the elements are 0 or undef.
  62. bool isBuildVectorAllZeros(const SDNode *N);
  63. /// isScalarToVector - Return true if the specified node is a
  64. /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
  65. /// element is not an undef.
  66. bool isScalarToVector(const SDNode *N);
  67. /// allOperandsUndef - Return true if the node has at least one operand
  68. /// and all operands of the specified node are ISD::UNDEF.
  69. bool allOperandsUndef(const SDNode *N);
  70. } // end llvm:ISD namespace
  71. //===----------------------------------------------------------------------===//
  72. /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
  73. /// values as the result of a computation. Many nodes return multiple values,
  74. /// from loads (which define a token and a return value) to ADDC (which returns
  75. /// a result and a carry value), to calls (which may return an arbitrary number
  76. /// of values).
  77. ///
  78. /// As such, each use of a SelectionDAG computation must indicate the node that
  79. /// computes it as well as which return value to use from that node. This pair
  80. /// of information is represented with the SDValue value type.
  81. ///
  82. class SDValue {
  83. SDNode *Node; // The node defining the value we are using.
  84. unsigned ResNo; // Which return value of the node we are using.
  85. public:
  86. SDValue() : Node(0), ResNo(0) {}
  87. SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
  88. /// get the index which selects a specific result in the SDNode
  89. unsigned getResNo() const { return ResNo; }
  90. /// get the SDNode which holds the desired result
  91. SDNode *getNode() const { return Node; }
  92. /// set the SDNode
  93. void setNode(SDNode *N) { Node = N; }
  94. inline SDNode *operator->() const { return Node; }
  95. bool operator==(const SDValue &O) const {
  96. return Node == O.Node && ResNo == O.ResNo;
  97. }
  98. bool operator!=(const SDValue &O) const {
  99. return !operator==(O);
  100. }
  101. bool operator<(const SDValue &O) const {
  102. return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
  103. }
  104. SDValue getValue(unsigned R) const {
  105. return SDValue(Node, R);
  106. }
  107. // isOperandOf - Return true if this node is an operand of N.
  108. bool isOperandOf(SDNode *N) const;
  109. /// getValueType - Return the ValueType of the referenced return value.
  110. ///
  111. inline EVT getValueType() const;
  112. /// Return the simple ValueType of the referenced return value.
  113. MVT getSimpleValueType() const {
  114. return getValueType().getSimpleVT();
  115. }
  116. /// getValueSizeInBits - Returns the size of the value in bits.
  117. ///
  118. unsigned getValueSizeInBits() const {
  119. return getValueType().getSizeInBits();
  120. }
  121. // Forwarding methods - These forward to the corresponding methods in SDNode.
  122. inline unsigned getOpcode() const;
  123. inline unsigned getNumOperands() const;
  124. inline const SDValue &getOperand(unsigned i) const;
  125. inline uint64_t getConstantOperandVal(unsigned i) const;
  126. inline bool isTargetMemoryOpcode() const;
  127. inline bool isTargetOpcode() const;
  128. inline bool isMachineOpcode() const;
  129. inline unsigned getMachineOpcode() const;
  130. inline const DebugLoc getDebugLoc() const;
  131. inline void dump() const;
  132. inline void dumpr() const;
  133. /// reachesChainWithoutSideEffects - Return true if this operand (which must
  134. /// be a chain) reaches the specified operand without crossing any
  135. /// side-effecting instructions. In practice, this looks through token
  136. /// factors and non-volatile loads. In order to remain efficient, this only
  137. /// looks a couple of nodes in, it does not do an exhaustive search.
  138. bool reachesChainWithoutSideEffects(SDValue Dest,
  139. unsigned Depth = 2) const;
  140. /// use_empty - Return true if there are no nodes using value ResNo
  141. /// of Node.
  142. ///
  143. inline bool use_empty() const;
  144. /// hasOneUse - Return true if there is exactly one node using value
  145. /// ResNo of Node.
  146. ///
  147. inline bool hasOneUse() const;
  148. };
  149. template<> struct DenseMapInfo<SDValue> {
  150. static inline SDValue getEmptyKey() {
  151. return SDValue((SDNode*)-1, -1U);
  152. }
  153. static inline SDValue getTombstoneKey() {
  154. return SDValue((SDNode*)-1, 0);
  155. }
  156. static unsigned getHashValue(const SDValue &Val) {
  157. return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
  158. (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
  159. }
  160. static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
  161. return LHS == RHS;
  162. }
  163. };
  164. template <> struct isPodLike<SDValue> { static const bool value = true; };
  165. /// simplify_type specializations - Allow casting operators to work directly on
  166. /// SDValues as if they were SDNode*'s.
  167. template<> struct simplify_type<SDValue> {
  168. typedef SDNode* SimpleType;
  169. static SimpleType getSimplifiedValue(SDValue &Val) {
  170. return Val.getNode();
  171. }
  172. };
  173. template<> struct simplify_type<const SDValue> {
  174. typedef /*const*/ SDNode* SimpleType;
  175. static SimpleType getSimplifiedValue(const SDValue &Val) {
  176. return Val.getNode();
  177. }
  178. };
  179. /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
  180. /// which records the SDNode being used and the result number, a
  181. /// pointer to the SDNode using the value, and Next and Prev pointers,
  182. /// which link together all the uses of an SDNode.
  183. ///
  184. class SDUse {
  185. /// Val - The value being used.
  186. SDValue Val;
  187. /// User - The user of this value.
  188. SDNode *User;
  189. /// Prev, Next - Pointers to the uses list of the SDNode referred by
  190. /// this operand.
  191. SDUse **Prev, *Next;
  192. SDUse(const SDUse &U) LLVM_DELETED_FUNCTION;
  193. void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
  194. public:
  195. SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
  196. /// Normally SDUse will just implicitly convert to an SDValue that it holds.
  197. operator const SDValue&() const { return Val; }
  198. /// If implicit conversion to SDValue doesn't work, the get() method returns
  199. /// the SDValue.
  200. const SDValue &get() const { return Val; }
  201. /// getUser - This returns the SDNode that contains this Use.
  202. SDNode *getUser() { return User; }
  203. /// getNext - Get the next SDUse in the use list.
  204. SDUse *getNext() const { return Next; }
  205. /// getNode - Convenience function for get().getNode().
  206. SDNode *getNode() const { return Val.getNode(); }
  207. /// getResNo - Convenience function for get().getResNo().
  208. unsigned getResNo() const { return Val.getResNo(); }
  209. /// getValueType - Convenience function for get().getValueType().
  210. EVT getValueType() const { return Val.getValueType(); }
  211. /// operator== - Convenience function for get().operator==
  212. bool operator==(const SDValue &V) const {
  213. return Val == V;
  214. }
  215. /// operator!= - Convenience function for get().operator!=
  216. bool operator!=(const SDValue &V) const {
  217. return Val != V;
  218. }
  219. /// operator< - Convenience function for get().operator<
  220. bool operator<(const SDValue &V) const {
  221. return Val < V;
  222. }
  223. private:
  224. friend class SelectionDAG;
  225. friend class SDNode;
  226. void setUser(SDNode *p) { User = p; }
  227. /// set - Remove this use from its existing use list, assign it the
  228. /// given value, and add it to the new value's node's use list.
  229. inline void set(const SDValue &V);
  230. /// setInitial - like set, but only supports initializing a newly-allocated
  231. /// SDUse with a non-null value.
  232. inline void setInitial(const SDValue &V);
  233. /// setNode - like set, but only sets the Node portion of the value,
  234. /// leaving the ResNo portion unmodified.
  235. inline void setNode(SDNode *N);
  236. void addToList(SDUse **List) {
  237. Next = *List;
  238. if (Next) Next->Prev = &Next;
  239. Prev = List;
  240. *List = this;
  241. }
  242. void removeFromList() {
  243. *Prev = Next;
  244. if (Next) Next->Prev = Prev;
  245. }
  246. };
  247. /// simplify_type specializations - Allow casting operators to work directly on
  248. /// SDValues as if they were SDNode*'s.
  249. template<> struct simplify_type<SDUse> {
  250. typedef SDNode* SimpleType;
  251. static SimpleType getSimplifiedValue(SDUse &Val) {
  252. return Val.getNode();
  253. }
  254. };
  255. /// SDNode - Represents one node in the SelectionDAG.
  256. ///
  257. class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
  258. private:
  259. /// NodeType - The operation that this node performs.
  260. ///
  261. int16_t NodeType;
  262. /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
  263. /// then they will be delete[]'d when the node is destroyed.
  264. uint16_t OperandsNeedDelete : 1;
  265. /// HasDebugValue - This tracks whether this node has one or more dbg_value
  266. /// nodes corresponding to it.
  267. uint16_t HasDebugValue : 1;
  268. protected:
  269. /// SubclassData - This member is defined by this class, but is not used for
  270. /// anything. Subclasses can use it to hold whatever state they find useful.
  271. /// This field is initialized to zero by the ctor.
  272. uint16_t SubclassData : 14;
  273. private:
  274. /// NodeId - Unique id per SDNode in the DAG.
  275. int NodeId;
  276. /// OperandList - The values that are used by this operation.
  277. ///
  278. SDUse *OperandList;
  279. /// ValueList - The types of the values this node defines. SDNode's may
  280. /// define multiple values simultaneously.
  281. const EVT *ValueList;
  282. /// UseList - List of uses for this SDNode.
  283. SDUse *UseList;
  284. /// NumOperands/NumValues - The number of entries in the Operand/Value list.
  285. unsigned short NumOperands, NumValues;
  286. /// debugLoc - source line information.
  287. DebugLoc debugLoc;
  288. /// getValueTypeList - Return a pointer to the specified value type.
  289. static const EVT *getValueTypeList(EVT VT);
  290. friend class SelectionDAG;
  291. friend struct ilist_traits<SDNode>;
  292. public:
  293. //===--------------------------------------------------------------------===//
  294. // Accessors
  295. //
  296. /// getOpcode - Return the SelectionDAG opcode value for this node. For
  297. /// pre-isel nodes (those for which isMachineOpcode returns false), these
  298. /// are the opcode values in the ISD and <target>ISD namespaces. For
  299. /// post-isel opcodes, see getMachineOpcode.
  300. unsigned getOpcode() const { return (unsigned short)NodeType; }
  301. /// isTargetOpcode - Test if this node has a target-specific opcode (in the
  302. /// \<target\>ISD namespace).
  303. bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
  304. /// isTargetMemoryOpcode - Test if this node has a target-specific
  305. /// memory-referencing opcode (in the \<target\>ISD namespace and
  306. /// greater than FIRST_TARGET_MEMORY_OPCODE).
  307. bool isTargetMemoryOpcode() const {
  308. return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
  309. }
  310. /// isMachineOpcode - Test if this node has a post-isel opcode, directly
  311. /// corresponding to a MachineInstr opcode.
  312. bool isMachineOpcode() const { return NodeType < 0; }
  313. /// getMachineOpcode - This may only be called if isMachineOpcode returns
  314. /// true. It returns the MachineInstr opcode value that the node's opcode
  315. /// corresponds to.
  316. unsigned getMachineOpcode() const {
  317. assert(isMachineOpcode() && "Not a MachineInstr opcode!");
  318. return ~NodeType;
  319. }
  320. /// getHasDebugValue - get this bit.
  321. bool getHasDebugValue() const { return HasDebugValue; }
  322. /// setHasDebugValue - set this bit.
  323. void setHasDebugValue(bool b) { HasDebugValue = b; }
  324. /// use_empty - Return true if there are no uses of this node.
  325. ///
  326. bool use_empty() const { return UseList == NULL; }
  327. /// hasOneUse - Return true if there is exactly one use of this node.
  328. ///
  329. bool hasOneUse() const {
  330. return !use_empty() && llvm::next(use_begin()) == use_end();
  331. }
  332. /// use_size - Return the number of uses of this node. This method takes
  333. /// time proportional to the number of uses.
  334. ///
  335. size_t use_size() const { return std::distance(use_begin(), use_end()); }
  336. /// getNodeId - Return the unique node id.
  337. ///
  338. int getNodeId() const { return NodeId; }
  339. /// setNodeId - Set unique node id.
  340. void setNodeId(int Id) { NodeId = Id; }
  341. /// getDebugLoc - Return the source location info.
  342. const DebugLoc getDebugLoc() const { return debugLoc; }
  343. /// setDebugLoc - Set source location info. Try to avoid this, putting
  344. /// it in the constructor is preferable.
  345. void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
  346. /// use_iterator - This class provides iterator support for SDUse
  347. /// operands that use a specific SDNode.
  348. class use_iterator
  349. : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
  350. SDUse *Op;
  351. explicit use_iterator(SDUse *op) : Op(op) {
  352. }
  353. friend class SDNode;
  354. public:
  355. typedef std::iterator<std::forward_iterator_tag,
  356. SDUse, ptrdiff_t>::reference reference;
  357. typedef std::iterator<std::forward_iterator_tag,
  358. SDUse, ptrdiff_t>::pointer pointer;
  359. use_iterator(const use_iterator &I) : Op(I.Op) {}
  360. use_iterator() : Op(0) {}
  361. bool operator==(const use_iterator &x) const {
  362. return Op == x.Op;
  363. }
  364. bool operator!=(const use_iterator &x) const {
  365. return !operator==(x);
  366. }
  367. /// atEnd - return true if this iterator is at the end of uses list.
  368. bool atEnd() const { return Op == 0; }
  369. // Iterator traversal: forward iteration only.
  370. use_iterator &operator++() { // Preincrement
  371. assert(Op && "Cannot increment end iterator!");
  372. Op = Op->getNext();
  373. return *this;
  374. }
  375. use_iterator operator++(int) { // Postincrement
  376. use_iterator tmp = *this; ++*this; return tmp;
  377. }
  378. /// Retrieve a pointer to the current user node.
  379. SDNode *operator*() const {
  380. assert(Op && "Cannot dereference end iterator!");
  381. return Op->getUser();
  382. }
  383. SDNode *operator->() const { return operator*(); }
  384. SDUse &getUse() const { return *Op; }
  385. /// getOperandNo - Retrieve the operand # of this use in its user.
  386. ///
  387. unsigned getOperandNo() const {
  388. assert(Op && "Cannot dereference end iterator!");
  389. return (unsigned)(Op - Op->getUser()->OperandList);
  390. }
  391. };
  392. /// use_begin/use_end - Provide iteration support to walk over all uses
  393. /// of an SDNode.
  394. use_iterator use_begin() const {
  395. return use_iterator(UseList);
  396. }
  397. static use_iterator use_end() { return use_iterator(0); }
  398. /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
  399. /// indicated value. This method ignores uses of other values defined by this
  400. /// operation.
  401. bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
  402. /// hasAnyUseOfValue - Return true if there are any use of the indicated
  403. /// value. This method ignores uses of other values defined by this operation.
  404. bool hasAnyUseOfValue(unsigned Value) const;
  405. /// isOnlyUserOf - Return true if this node is the only use of N.
  406. ///
  407. bool isOnlyUserOf(SDNode *N) const;
  408. /// isOperandOf - Return true if this node is an operand of N.
  409. ///
  410. bool isOperandOf(SDNode *N) const;
  411. /// isPredecessorOf - Return true if this node is a predecessor of N.
  412. /// NOTE: Implemented on top of hasPredecessor and every bit as
  413. /// expensive. Use carefully.
  414. bool isPredecessorOf(const SDNode *N) const { return N->hasPredecessor(this); }
  415. /// hasPredecessor - Return true if N is a predecessor of this node.
  416. /// N is either an operand of this node, or can be reached by recursively
  417. /// traversing up the operands.
  418. /// NOTE: This is an expensive method. Use it carefully.
  419. bool hasPredecessor(const SDNode *N) const;
  420. /// hasPredecesorHelper - Return true if N is a predecessor of this node.
  421. /// N is either an operand of this node, or can be reached by recursively
  422. /// traversing up the operands.
  423. /// In this helper the Visited and worklist sets are held externally to
  424. /// cache predecessors over multiple invocations. If you want to test for
  425. /// multiple predecessors this method is preferable to multiple calls to
  426. /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
  427. /// changes.
  428. /// NOTE: This is still very expensive. Use carefully.
  429. bool hasPredecessorHelper(const SDNode *N,
  430. SmallPtrSet<const SDNode *, 32> &Visited,
  431. SmallVector<const SDNode *, 16> &Worklist) const;
  432. /// getNumOperands - Return the number of values used by this operation.
  433. ///
  434. unsigned getNumOperands() const { return NumOperands; }
  435. /// getConstantOperandVal - Helper method returns the integer value of a
  436. /// ConstantSDNode operand.
  437. uint64_t getConstantOperandVal(unsigned Num) const;
  438. const SDValue &getOperand(unsigned Num) const {
  439. assert(Num < NumOperands && "Invalid child # of SDNode!");
  440. return OperandList[Num];
  441. }
  442. typedef SDUse* op_iterator;
  443. op_iterator op_begin() const { return OperandList; }
  444. op_iterator op_end() const { return OperandList+NumOperands; }
  445. SDVTList getVTList() const {
  446. SDVTList X = { ValueList, NumValues };
  447. return X;
  448. }
  449. /// getGluedNode - If this node has a glue operand, return the node
  450. /// to which the glue operand points. Otherwise return NULL.
  451. SDNode *getGluedNode() const {
  452. if (getNumOperands() != 0 &&
  453. getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
  454. return getOperand(getNumOperands()-1).getNode();
  455. return 0;
  456. }
  457. // If this is a pseudo op, like copyfromreg, look to see if there is a
  458. // real target node glued to it. If so, return the target node.
  459. const SDNode *getGluedMachineNode() const {
  460. const SDNode *FoundNode = this;
  461. // Climb up glue edges until a machine-opcode node is found, or the
  462. // end of the chain is reached.
  463. while (!FoundNode->isMachineOpcode()) {
  464. const SDNode *N = FoundNode->getGluedNode();
  465. if (!N) break;
  466. FoundNode = N;
  467. }
  468. return FoundNode;
  469. }
  470. /// getGluedUser - If this node has a glue value with a user, return
  471. /// the user (there is at most one). Otherwise return NULL.
  472. SDNode *getGluedUser() const {
  473. for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
  474. if (UI.getUse().get().getValueType() == MVT::Glue)
  475. return *UI;
  476. return 0;
  477. }
  478. /// getNumValues - Return the number of values defined/returned by this
  479. /// operator.
  480. ///
  481. unsigned getNumValues() const { return NumValues; }
  482. /// getValueType - Return the type of a specified result.
  483. ///
  484. EVT getValueType(unsigned ResNo) const {
  485. assert(ResNo < NumValues && "Illegal result number!");
  486. return ValueList[ResNo];
  487. }
  488. /// Return the type of a specified result as a simple type.
  489. ///
  490. MVT getSimpleValueType(unsigned ResNo) const {
  491. return getValueType(ResNo).getSimpleVT();
  492. }
  493. /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
  494. ///
  495. unsigned getValueSizeInBits(unsigned ResNo) const {
  496. return getValueType(ResNo).getSizeInBits();
  497. }
  498. typedef const EVT* value_iterator;
  499. value_iterator value_begin() const { return ValueList; }
  500. value_iterator value_end() const { return ValueList+NumValues; }
  501. /// getOperationName - Return the opcode of this operation for printing.
  502. ///
  503. std::string getOperationName(const SelectionDAG *G = 0) const;
  504. static const char* getIndexedModeName(ISD::MemIndexedMode AM);
  505. void print_types(raw_ostream &OS, const SelectionDAG *G) const;
  506. void print_details(raw_ostream &OS, const SelectionDAG *G) const;
  507. void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
  508. void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
  509. /// printrFull - Print a SelectionDAG node and all children down to
  510. /// the leaves. The given SelectionDAG allows target-specific nodes
  511. /// to be printed in human-readable form. Unlike printr, this will
  512. /// print the whole DAG, including children that appear multiple
  513. /// times.
  514. ///
  515. void printrFull(raw_ostream &O, const SelectionDAG *G = 0) const;
  516. /// printrWithDepth - Print a SelectionDAG node and children up to
  517. /// depth "depth." The given SelectionDAG allows target-specific
  518. /// nodes to be printed in human-readable form. Unlike printr, this
  519. /// will print children that appear multiple times wherever they are
  520. /// used.
  521. ///
  522. void printrWithDepth(raw_ostream &O, const SelectionDAG *G = 0,
  523. unsigned depth = 100) const;
  524. /// dump - Dump this node, for debugging.
  525. void dump() const;
  526. /// dumpr - Dump (recursively) this node and its use-def subgraph.
  527. void dumpr() const;
  528. /// dump - Dump this node, for debugging.
  529. /// The given SelectionDAG allows target-specific nodes to be printed
  530. /// in human-readable form.
  531. void dump(const SelectionDAG *G) const;
  532. /// dumpr - Dump (recursively) this node and its use-def subgraph.
  533. /// The given SelectionDAG allows target-specific nodes to be printed
  534. /// in human-readable form.
  535. void dumpr(const SelectionDAG *G) const;
  536. /// dumprFull - printrFull to dbgs(). The given SelectionDAG allows
  537. /// target-specific nodes to be printed in human-readable form.
  538. /// Unlike dumpr, this will print the whole DAG, including children
  539. /// that appear multiple times.
  540. ///
  541. void dumprFull(const SelectionDAG *G = 0) const;
  542. /// dumprWithDepth - printrWithDepth to dbgs(). The given
  543. /// SelectionDAG allows target-specific nodes to be printed in
  544. /// human-readable form. Unlike dumpr, this will print children
  545. /// that appear multiple times wherever they are used.
  546. ///
  547. void dumprWithDepth(const SelectionDAG *G = 0, unsigned depth = 100) const;
  548. /// Profile - Gather unique data for the node.
  549. ///
  550. void Profile(FoldingSetNodeID &ID) const;
  551. /// addUse - This method should only be used by the SDUse class.
  552. ///
  553. void addUse(SDUse &U) { U.addToList(&UseList); }
  554. protected:
  555. static SDVTList getSDVTList(EVT VT) {
  556. SDVTList Ret = { getValueTypeList(VT), 1 };
  557. return Ret;
  558. }
  559. SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
  560. unsigned NumOps)
  561. : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
  562. SubclassData(0), NodeId(-1),
  563. OperandList(NumOps ? new SDUse[NumOps] : 0),
  564. ValueList(VTs.VTs), UseList(NULL),
  565. NumOperands(NumOps), NumValues(VTs.NumVTs),
  566. debugLoc(dl) {
  567. for (unsigned i = 0; i != NumOps; ++i) {
  568. OperandList[i].setUser(this);
  569. OperandList[i].setInitial(Ops[i]);
  570. }
  571. checkForCycles(this);
  572. }
  573. /// This constructor adds no operands itself; operands can be
  574. /// set later with InitOperands.
  575. SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
  576. : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
  577. SubclassData(0), NodeId(-1), OperandList(0), ValueList(VTs.VTs),
  578. UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs),
  579. debugLoc(dl) {}
  580. /// InitOperands - Initialize the operands list of this with 1 operand.
  581. void InitOperands(SDUse *Ops, const SDValue &Op0) {
  582. Ops[0].setUser(this);
  583. Ops[0].setInitial(Op0);
  584. NumOperands = 1;
  585. OperandList = Ops;
  586. checkForCycles(this);
  587. }
  588. /// InitOperands - Initialize the operands list of this with 2 operands.
  589. void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
  590. Ops[0].setUser(this);
  591. Ops[0].setInitial(Op0);
  592. Ops[1].setUser(this);
  593. Ops[1].setInitial(Op1);
  594. NumOperands = 2;
  595. OperandList = Ops;
  596. checkForCycles(this);
  597. }
  598. /// InitOperands - Initialize the operands list of this with 3 operands.
  599. void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
  600. const SDValue &Op2) {
  601. Ops[0].setUser(this);
  602. Ops[0].setInitial(Op0);
  603. Ops[1].setUser(this);
  604. Ops[1].setInitial(Op1);
  605. Ops[2].setUser(this);
  606. Ops[2].setInitial(Op2);
  607. NumOperands = 3;
  608. OperandList = Ops;
  609. checkForCycles(this);
  610. }
  611. /// InitOperands - Initialize the operands list of this with 4 operands.
  612. void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
  613. const SDValue &Op2, const SDValue &Op3) {
  614. Ops[0].setUser(this);
  615. Ops[0].setInitial(Op0);
  616. Ops[1].setUser(this);
  617. Ops[1].setInitial(Op1);
  618. Ops[2].setUser(this);
  619. Ops[2].setInitial(Op2);
  620. Ops[3].setUser(this);
  621. Ops[3].setInitial(Op3);
  622. NumOperands = 4;
  623. OperandList = Ops;
  624. checkForCycles(this);
  625. }
  626. /// InitOperands - Initialize the operands list of this with N operands.
  627. void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
  628. for (unsigned i = 0; i != N; ++i) {
  629. Ops[i].setUser(this);
  630. Ops[i].setInitial(Vals[i]);
  631. }
  632. NumOperands = N;
  633. OperandList = Ops;
  634. checkForCycles(this);
  635. }
  636. /// DropOperands - Release the operands and set this node to have
  637. /// zero operands.
  638. void DropOperands();
  639. };
  640. // Define inline functions from the SDValue class.
  641. inline unsigned SDValue::getOpcode() const {
  642. return Node->getOpcode();
  643. }
  644. inline EVT SDValue::getValueType() const {
  645. return Node->getValueType(ResNo);
  646. }
  647. inline unsigned SDValue::getNumOperands() const {
  648. return Node->getNumOperands();
  649. }
  650. inline const SDValue &SDValue::getOperand(unsigned i) const {
  651. return Node->getOperand(i);
  652. }
  653. inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
  654. return Node->getConstantOperandVal(i);
  655. }
  656. inline bool SDValue::isTargetOpcode() const {
  657. return Node->isTargetOpcode();
  658. }
  659. inline bool SDValue::isTargetMemoryOpcode() const {
  660. return Node->isTargetMemoryOpcode();
  661. }
  662. inline bool SDValue::isMachineOpcode() const {
  663. return Node->isMachineOpcode();
  664. }
  665. inline unsigned SDValue::getMachineOpcode() const {
  666. return Node->getMachineOpcode();
  667. }
  668. inline bool SDValue::use_empty() const {
  669. return !Node->hasAnyUseOfValue(ResNo);
  670. }
  671. inline bool SDValue::hasOneUse() const {
  672. return Node->hasNUsesOfValue(1, ResNo);
  673. }
  674. inline const DebugLoc SDValue::getDebugLoc() const {
  675. return Node->getDebugLoc();
  676. }
  677. inline void SDValue::dump() const {
  678. return Node->dump();
  679. }
  680. inline void SDValue::dumpr() const {
  681. return Node->dumpr();
  682. }
  683. // Define inline functions from the SDUse class.
  684. inline void SDUse::set(const SDValue &V) {
  685. if (Val.getNode()) removeFromList();
  686. Val = V;
  687. if (V.getNode()) V.getNode()->addUse(*this);
  688. }
  689. inline void SDUse::setInitial(const SDValue &V) {
  690. Val = V;
  691. V.getNode()->addUse(*this);
  692. }
  693. inline void SDUse::setNode(SDNode *N) {
  694. if (Val.getNode()) removeFromList();
  695. Val.setNode(N);
  696. if (N) N->addUse(*this);
  697. }
  698. /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
  699. /// to allow co-allocation of node operands with the node itself.
  700. class UnarySDNode : public SDNode {
  701. SDUse Op;
  702. public:
  703. UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
  704. : SDNode(Opc, dl, VTs) {
  705. InitOperands(&Op, X);
  706. }
  707. };
  708. /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
  709. /// to allow co-allocation of node operands with the node itself.
  710. class BinarySDNode : public SDNode {
  711. SDUse Ops[2];
  712. public:
  713. BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
  714. : SDNode(Opc, dl, VTs) {
  715. InitOperands(Ops, X, Y);
  716. }
  717. };
  718. /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
  719. /// to allow co-allocation of node operands with the node itself.
  720. class TernarySDNode : public SDNode {
  721. SDUse Ops[3];
  722. public:
  723. TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
  724. SDValue Z)
  725. : SDNode(Opc, dl, VTs) {
  726. InitOperands(Ops, X, Y, Z);
  727. }
  728. };
  729. /// HandleSDNode - This class is used to form a handle around another node that
  730. /// is persistent and is updated across invocations of replaceAllUsesWith on its
  731. /// operand. This node should be directly created by end-users and not added to
  732. /// the AllNodes list.
  733. class HandleSDNode : public SDNode {
  734. SDUse Op;
  735. public:
  736. // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
  737. // fixed.
  738. #if __GNUC__==4 && __GNUC_MINOR__==2 && defined(__APPLE__) && !defined(__llvm__)
  739. explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
  740. #else
  741. explicit HandleSDNode(SDValue X)
  742. #endif
  743. : SDNode(ISD::HANDLENODE, DebugLoc(), getSDVTList(MVT::Other)) {
  744. InitOperands(&Op, X);
  745. }
  746. ~HandleSDNode();
  747. const SDValue &getValue() const { return Op; }
  748. };
  749. /// Abstact virtual class for operations for memory operations
  750. class MemSDNode : public SDNode {
  751. private:
  752. // MemoryVT - VT of in-memory value.
  753. EVT MemoryVT;
  754. protected:
  755. /// MMO - Memory reference information.
  756. MachineMemOperand *MMO;
  757. public:
  758. MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
  759. MachineMemOperand *MMO);
  760. MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
  761. unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
  762. bool readMem() const { return MMO->isLoad(); }
  763. bool writeMem() const { return MMO->isStore(); }
  764. /// Returns alignment and volatility of the memory access
  765. unsigned getOriginalAlignment() const {
  766. return MMO->getBaseAlignment();
  767. }
  768. unsigned getAlignment() const {
  769. return MMO->getAlignment();
  770. }
  771. /// getRawSubclassData - Return the SubclassData value, which contains an
  772. /// encoding of the volatile flag, as well as bits used by subclasses. This
  773. /// function should only be used to compute a FoldingSetNodeID value.
  774. unsigned getRawSubclassData() const {
  775. return SubclassData;
  776. }
  777. // We access subclass data here so that we can check consistency
  778. // with MachineMemOperand information.
  779. bool isVolatile() const { return (SubclassData >> 5) & 1; }
  780. bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
  781. bool isInvariant() const { return (SubclassData >> 7) & 1; }
  782. AtomicOrdering getOrdering() const {
  783. return AtomicOrdering((SubclassData >> 8) & 15);
  784. }
  785. SynchronizationScope getSynchScope() const {
  786. return SynchronizationScope((SubclassData >> 12) & 1);
  787. }
  788. /// Returns the SrcValue and offset that describes the location of the access
  789. const Value *getSrcValue() const { return MMO->getValue(); }
  790. int64_t getSrcValueOffset() const { return MMO->getOffset(); }
  791. /// Returns the TBAAInfo that describes the dereference.
  792. const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
  793. /// Returns the Ranges that describes the dereference.
  794. const MDNode *getRanges() const { return MMO->getRanges(); }
  795. /// getMemoryVT - Return the type of the in-memory value.
  796. EVT getMemoryVT() const { return MemoryVT; }
  797. /// getMemOperand - Return a MachineMemOperand object describing the memory
  798. /// reference performed by operation.
  799. MachineMemOperand *getMemOperand() const { return MMO; }
  800. const MachinePointerInfo &getPointerInfo() const {
  801. return MMO->getPointerInfo();
  802. }
  803. /// getAddressSpace - Return the address space for the associated pointer
  804. unsigned getAddressSpace() const {
  805. return getPointerInfo().getAddrSpace();
  806. }
  807. /// refineAlignment - Update this MemSDNode's MachineMemOperand information
  808. /// to reflect the alignment of NewMMO, if it has a greater alignment.
  809. /// This must only be used when the new alignment applies to all users of
  810. /// this MachineMemOperand.
  811. void refineAlignment(const MachineMemOperand *NewMMO) {
  812. MMO->refineAlignment(NewMMO);
  813. }
  814. const SDValue &getChain() const { return getOperand(0); }
  815. const SDValue &getBasePtr() const {
  816. return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
  817. }
  818. // Methods to support isa and dyn_cast
  819. static bool classof(const SDNode *N) {
  820. // For some targets, we lower some target intrinsics to a MemIntrinsicNode
  821. // with either an intrinsic or a target opcode.
  822. return N->getOpcode() == ISD::LOAD ||
  823. N->getOpcode() == ISD::STORE ||
  824. N->getOpcode() == ISD::PREFETCH ||
  825. N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
  826. N->getOpcode() == ISD::ATOMIC_SWAP ||
  827. N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
  828. N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
  829. N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
  830. N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
  831. N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
  832. N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
  833. N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
  834. N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
  835. N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
  836. N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
  837. N->getOpcode() == ISD::ATOMIC_LOAD ||
  838. N->getOpcode() == ISD::ATOMIC_STORE ||
  839. N->isTargetMemoryOpcode();
  840. }
  841. };
  842. /// AtomicSDNode - A SDNode reprenting atomic operations.
  843. ///
  844. class AtomicSDNode : public MemSDNode {
  845. SDUse Ops[4];
  846. void InitAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope) {
  847. // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
  848. assert((Ordering & 15) == Ordering &&
  849. "Ordering may not require more than 4 bits!");
  850. assert((SynchScope & 1) == SynchScope &&
  851. "SynchScope may not require more than 1 bit!");
  852. SubclassData |= Ordering << 8;
  853. SubclassData |= SynchScope << 12;
  854. assert(getOrdering() == Ordering && "Ordering encoding error!");
  855. assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
  856. }
  857. public:
  858. // Opc: opcode for atomic
  859. // VTL: value type list
  860. // Chain: memory chain for operaand
  861. // Ptr: address to update as a SDValue
  862. // Cmp: compare value
  863. // Swp: swap value
  864. // SrcVal: address to update as a Value (used for MemOperand)
  865. // Align: alignment of memory
  866. AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
  867. SDValue Chain, SDValue Ptr,
  868. SDValue Cmp, SDValue Swp, MachineMemOperand *MMO,
  869. AtomicOrdering Ordering, SynchronizationScope SynchScope)
  870. : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
  871. InitAtomic(Ordering, SynchScope);
  872. InitOperands(Ops, Chain, Ptr, Cmp, Swp);
  873. }
  874. AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
  875. SDValue Chain, SDValue Ptr,
  876. SDValue Val, MachineMemOperand *MMO,
  877. AtomicOrdering Ordering, SynchronizationScope SynchScope)
  878. : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
  879. InitAtomic(Ordering, SynchScope);
  880. InitOperands(Ops, Chain, Ptr, Val);
  881. }
  882. AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
  883. SDValue Chain, SDValue Ptr,
  884. MachineMemOperand *MMO,
  885. AtomicOrdering Ordering, SynchronizationScope SynchScope)
  886. : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
  887. InitAtomic(Ordering, SynchScope);
  888. InitOperands(Ops, Chain, Ptr);
  889. }
  890. const SDValue &getBasePtr() const { return getOperand(1); }
  891. const SDValue &getVal() const { return getOperand(2); }
  892. bool isCompareAndSwap() const {
  893. unsigned Op = getOpcode();
  894. return Op == ISD::ATOMIC_CMP_SWAP;
  895. }
  896. // Methods to support isa and dyn_cast
  897. static bool classof(const SDNode *N) {
  898. return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
  899. N->getOpcode() == ISD::ATOMIC_SWAP ||
  900. N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
  901. N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
  902. N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
  903. N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
  904. N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
  905. N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
  906. N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
  907. N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
  908. N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
  909. N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
  910. N->getOpcode() == ISD::ATOMIC_LOAD ||
  911. N->getOpcode() == ISD::ATOMIC_STORE;
  912. }
  913. };
  914. /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
  915. /// memory and need an associated MachineMemOperand. Its opcode may be
  916. /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
  917. /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
  918. class MemIntrinsicSDNode : public MemSDNode {
  919. public:
  920. MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
  921. const SDValue *Ops, unsigned NumOps,
  922. EVT MemoryVT, MachineMemOperand *MMO)
  923. : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
  924. }
  925. // Methods to support isa and dyn_cast
  926. static bool classof(const SDNode *N) {
  927. // We lower some target intrinsics to their target opcode
  928. // early a node with a target opcode can be of this class
  929. return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
  930. N->getOpcode() == ISD::INTRINSIC_VOID ||
  931. N->getOpcode() == ISD::PREFETCH ||
  932. N->isTargetMemoryOpcode();
  933. }
  934. };
  935. /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
  936. /// support for the llvm IR shufflevector instruction. It combines elements
  937. /// from two input vectors into a new input vector, with the selection and
  938. /// ordering of elements determined by an array of integers, referred to as
  939. /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
  940. /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
  941. /// An index of -1 is treated as undef, such that the code generator may put
  942. /// any value in the corresponding element of the result.
  943. class ShuffleVectorSDNode : public SDNode {
  944. SDUse Ops[2];
  945. // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
  946. // is freed when the SelectionDAG object is destroyed.
  947. const int *Mask;
  948. protected:
  949. friend class SelectionDAG;
  950. ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2,
  951. const int *M)
  952. : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
  953. InitOperands(Ops, N1, N2);
  954. }
  955. public:
  956. ArrayRef<int> getMask() const {
  957. EVT VT = getValueType(0);
  958. return makeArrayRef(Mask, VT.getVectorNumElements());
  959. }
  960. int getMaskElt(unsigned Idx) const {
  961. assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
  962. return Mask[Idx];
  963. }
  964. bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
  965. int getSplatIndex() const {
  966. assert(isSplat() && "Cannot get splat index for non-splat!");
  967. EVT VT = getValueType(0);
  968. for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
  969. if (Mask[i] != -1)
  970. return Mask[i];
  971. }
  972. return -1;
  973. }
  974. static bool isSplatMask(const int *Mask, EVT VT);
  975. static bool classof(const SDNode *N) {
  976. return N->getOpcode() == ISD::VECTOR_SHUFFLE;
  977. }
  978. };
  979. class ConstantSDNode : public SDNode {
  980. const ConstantInt *Value;
  981. friend class SelectionDAG;
  982. ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
  983. : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
  984. DebugLoc(), getSDVTList(VT)), Value(val) {
  985. }
  986. public:
  987. const ConstantInt *getConstantIntValue() const { return Value; }
  988. const APInt &getAPIntValue() const { return Value->getValue(); }
  989. uint64_t getZExtValue() const { return Value->getZExtValue(); }
  990. int64_t getSExtValue() const { return Value->getSExtValue(); }
  991. bool isOne() const { return Value->isOne(); }
  992. bool isNullValue() const { return Value->isNullValue(); }
  993. bool isAllOnesValue() const { return Value->isAllOnesValue(); }
  994. static bool classof(const SDNode *N) {
  995. return N->getOpcode() == ISD::Constant ||
  996. N->getOpcode() == ISD::TargetConstant;
  997. }
  998. };
  999. class ConstantFPSDNode : public SDNode {
  1000. const ConstantFP *Value;
  1001. friend class SelectionDAG;
  1002. ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
  1003. : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
  1004. DebugLoc(), getSDVTList(VT)), Value(val) {
  1005. }
  1006. public:
  1007. const APFloat& getValueAPF() const { return Value->getValueAPF(); }
  1008. const ConstantFP *getConstantFPValue() const { return Value; }
  1009. /// isZero - Return true if the value is positive or negative zero.
  1010. bool isZero() const { return Value->isZero(); }
  1011. /// isNaN - Return true if the value is a NaN.
  1012. bool isNaN() const { return Value->isNaN(); }
  1013. /// isExactlyValue - We don't rely on operator== working on double values, as
  1014. /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
  1015. /// As such, this method can be used to do an exact bit-for-bit comparison of
  1016. /// two floating point values.
  1017. /// We leave the version with the double argument here because it's just so
  1018. /// convenient to write "2.0" and the like. Without this function we'd
  1019. /// have to duplicate its logic everywhere it's called.
  1020. bool isExactlyValue(double V) const {
  1021. bool ignored;
  1022. APFloat Tmp(V);
  1023. Tmp.convert(Value->getValueAPF().getSemantics(),
  1024. APFloat::rmNearestTiesToEven, &ignored);
  1025. return isExactlyValue(Tmp);
  1026. }
  1027. bool isExactlyValue(const APFloat& V) const;
  1028. static bool isValueValidForType(EVT VT, const APFloat& Val);
  1029. static bool classof(const SDNode *N) {
  1030. return N->getOpcode() == ISD::ConstantFP ||
  1031. N->getOpcode() == ISD::TargetConstantFP;
  1032. }
  1033. };
  1034. class GlobalAddressSDNode : public SDNode {
  1035. const GlobalValue *TheGlobal;
  1036. int64_t Offset;
  1037. unsigned char TargetFlags;
  1038. friend class SelectionDAG;
  1039. GlobalAddressSDNode(unsigned Opc, DebugLoc DL, const GlobalValue *GA, EVT VT,
  1040. int64_t o, unsigned char TargetFlags);
  1041. public:
  1042. const GlobalValue *getGlobal() const { return TheGlobal; }
  1043. int64_t getOffset() const { return Offset; }
  1044. unsigned char getTargetFlags() const { return TargetFlags; }
  1045. // Return the address space this GlobalAddress belongs to.
  1046. unsigned getAddressSpace() const;
  1047. static bool classof(const SDNode *N) {
  1048. return N->getOpcode() == ISD::GlobalAddress ||
  1049. N->getOpcode() == ISD::TargetGlobalAddress ||
  1050. N->getOpcode() == ISD::GlobalTLSAddress ||
  1051. N->getOpcode() == ISD::TargetGlobalTLSAddress;
  1052. }
  1053. };
  1054. class FrameIndexSDNode : public SDNode {
  1055. int FI;
  1056. friend class SelectionDAG;
  1057. FrameIndexSDNode(int fi, EVT VT, bool isTarg)
  1058. : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
  1059. DebugLoc(), getSDVTList(VT)), FI(fi) {
  1060. }
  1061. public:
  1062. int getIndex() const { return FI; }
  1063. static bool classof(const SDNode *N) {
  1064. return N->getOpcode() == ISD::FrameIndex ||
  1065. N->getOpcode() == ISD::TargetFrameIndex;
  1066. }
  1067. };
  1068. class JumpTableSDNode : public SDNode {
  1069. int JTI;
  1070. unsigned char TargetFlags;
  1071. friend class SelectionDAG;
  1072. JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
  1073. : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
  1074. DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
  1075. }
  1076. public:
  1077. int getIndex() const { return JTI; }
  1078. unsigned char getTargetFlags() const { return TargetFlags; }
  1079. static bool classof(const SDNode *N) {
  1080. return N->getOpcode() == ISD::JumpTable ||
  1081. N->getOpcode() == ISD::TargetJumpTable;
  1082. }
  1083. };
  1084. class ConstantPoolSDNode : public SDNode {
  1085. union {
  1086. const Constant *ConstVal;
  1087. MachineConstantPoolValue *MachineCPVal;
  1088. } Val;
  1089. int Offset; // It's a MachineConstantPoolValue if top bit is set.
  1090. unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
  1091. unsigned char TargetFlags;
  1092. friend class SelectionDAG;
  1093. ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
  1094. unsigned Align, unsigned char TF)
  1095. : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
  1096. DebugLoc(),
  1097. getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
  1098. assert(Offset >= 0 && "Offset is too large");
  1099. Val.ConstVal = c;
  1100. }
  1101. ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
  1102. EVT VT, int o, unsigned Align, unsigned char TF)
  1103. : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
  1104. DebugLoc(),
  1105. getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
  1106. assert(Offset >= 0 && "Offset is too large");
  1107. Val.MachineCPVal = v;
  1108. Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
  1109. }
  1110. public:
  1111. bool isMachineConstantPoolEntry() const {
  1112. return Offset < 0;
  1113. }
  1114. const Constant *getConstVal() const {
  1115. assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
  1116. return Val.ConstVal;
  1117. }
  1118. MachineConstantPoolValue *getMachineCPVal() const {
  1119. assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
  1120. return Val.MachineCPVal;
  1121. }
  1122. int getOffset() const {
  1123. return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
  1124. }
  1125. // Return the alignment of this constant pool object, which is either 0 (for
  1126. // default alignment) or the desired value.
  1127. unsigned getAlignment() const { return Alignment; }
  1128. unsigned char getTargetFlags() const { return TargetFlags; }
  1129. Type *getType() const;
  1130. static bool classof(const SDNode *N) {
  1131. return N->getOpcode() == ISD::ConstantPool ||
  1132. N->getOpcode() == ISD::TargetConstantPool;
  1133. }
  1134. };
  1135. /// Completely target-dependent object reference.
  1136. class TargetIndexSDNode : public SDNode {
  1137. unsigned char TargetFlags;
  1138. int Index;
  1139. int64_t Offset;
  1140. friend class SelectionDAG;
  1141. public:
  1142. TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
  1143. : SDNode(ISD::TargetIndex, DebugLoc(), getSDVTList(VT)),
  1144. TargetFlags(TF), Index(Idx), Offset(Ofs) {}
  1145. public:
  1146. unsigned char getTargetFlags() const { return TargetFlags; }
  1147. int getIndex() const { return Index; }
  1148. int64_t getOffset() const { return Offset; }
  1149. static bool classof(const SDNode *N) {
  1150. return N->getOpcode() == ISD::TargetIndex;
  1151. }
  1152. };
  1153. class BasicBlockSDNode : public SDNode {
  1154. MachineBasicBlock *MBB;
  1155. friend class SelectionDAG;
  1156. /// Debug info is meaningful and potentially useful here, but we create
  1157. /// blocks out of order when they're jumped to, which makes it a bit
  1158. /// harder. Let's see if we need it first.
  1159. explicit BasicBlockSDNode(MachineBasicBlock *mbb)
  1160. : SDNode(ISD::BasicBlock, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb) {
  1161. }
  1162. public:
  1163. MachineBasicBlock *getBasicBlock() const { return MBB; }
  1164. static bool classof(const SDNode *N) {
  1165. return N->getOpcode() == ISD::BasicBlock;
  1166. }
  1167. };
  1168. /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
  1169. /// BUILD_VECTORs.
  1170. class BuildVectorSDNode : public SDNode {
  1171. // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
  1172. explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
  1173. public:
  1174. /// isConstantSplat - Check if this is a constant splat, and if so, find the
  1175. /// smallest element size that splats the vector. If MinSplatBits is
  1176. /// nonzero, the element size must be at least that large. Note that the
  1177. /// splat element may be the entire vector (i.e., a one element vector).
  1178. /// Returns the splat element value in SplatValue. Any undefined bits in
  1179. /// that value are zero, and the corresponding bits in the SplatUndef mask
  1180. /// are set. The SplatBitSize value is set to the splat element size in
  1181. /// bits. HasAnyUndefs is set to true if any bits in the vector are
  1182. /// undefined. isBigEndian describes the endianness of the target.
  1183. bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
  1184. unsigned &SplatBitSize, bool &HasAnyUndefs,
  1185. unsigned MinSplatBits = 0, bool isBigEndian = false);
  1186. static inline bool classof(const SDNode *N) {
  1187. return N->getOpcode() == ISD::BUILD_VECTOR;
  1188. }
  1189. };
  1190. /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
  1191. /// used when the SelectionDAG needs to make a simple reference to something
  1192. /// in the LLVM IR representation.
  1193. ///
  1194. class SrcValueSDNode : public SDNode {
  1195. const Value *V;
  1196. friend class SelectionDAG;
  1197. /// Create a SrcValue for a general value.
  1198. explicit SrcValueSDNode(const Value *v)
  1199. : SDNode(ISD::SRCVALUE, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
  1200. public:
  1201. /// getValue - return the contained Value.
  1202. const Value *getValue() const { return V; }
  1203. static bool classof(const SDNode *N) {
  1204. return N->getOpcode() == ISD::SRCVALUE;
  1205. }
  1206. };
  1207. class MDNodeSDNode : public SDNode {
  1208. const MDNode *MD;
  1209. friend class SelectionDAG;
  1210. explicit MDNodeSDNode(const MDNode *md)
  1211. : SDNode(ISD::MDNODE_SDNODE, DebugLoc(), getSDVTList(MVT::Other)), MD(md) {}
  1212. public:
  1213. const MDNode *getMD() const { return MD; }
  1214. static bool classof(const SDNode *N) {
  1215. return N->getOpcode() == ISD::MDNODE_SDNODE;
  1216. }
  1217. };
  1218. class RegisterSDNode : public SDNode {
  1219. unsigned Reg;
  1220. friend class SelectionDAG;
  1221. RegisterSDNode(unsigned reg, EVT VT)
  1222. : SDNode(ISD::Register, DebugLoc(), getSDVTList(VT)), Reg(reg) {
  1223. }
  1224. public:
  1225. unsigned getReg() const { return Reg; }
  1226. static bool classof(const SDNode *N) {
  1227. return N->getOpcode() == ISD::Register;
  1228. }
  1229. };
  1230. class RegisterMaskSDNode : public SDNode {
  1231. // The memory for RegMask is not owned by the node.
  1232. const uint32_t *RegMask;
  1233. friend class SelectionDAG;
  1234. RegisterMaskSDNode(const uint32_t *mask)
  1235. : SDNode(ISD::RegisterMask, DebugLoc(), getSDVTList(MVT::Untyped)),
  1236. RegMask(mask) {}
  1237. public:
  1238. const uint32_t *getRegMask() const { return RegMask; }
  1239. static bool classof(const SDNode *N) {
  1240. return N->getOpcode() == ISD::RegisterMask;
  1241. }
  1242. };
  1243. class BlockAddressSDNode : public SDNode {
  1244. const BlockAddress *BA;
  1245. int64_t Offset;
  1246. unsigned char TargetFlags;
  1247. friend class SelectionDAG;
  1248. BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
  1249. int64_t o, unsigned char Flags)
  1250. : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
  1251. BA(ba), Offset(o), TargetFlags(Flags) {
  1252. }
  1253. public:
  1254. const BlockAddress *getBlockAddress() const { return BA; }
  1255. int64_t getOffset() const { return Offset; }
  1256. unsigned char getTargetFlags() const { return TargetFlags; }
  1257. static bool classof(const SDNode *N) {
  1258. return N->getOpcode() == ISD::BlockAddress ||
  1259. N->getOpcode() == ISD::TargetBlockAddress;
  1260. }
  1261. };
  1262. class EHLabelSDNode : public SDNode {
  1263. SDUse Chain;
  1264. MCSymbol *Label;
  1265. friend class SelectionDAG;
  1266. EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
  1267. : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
  1268. InitOperands(&Chain, ch);
  1269. }
  1270. public:
  1271. MCSymbol *getLabel() const { return Label; }
  1272. static bool classof(const SDNode *N) {
  1273. return N->getOpcode() == ISD::EH_LABEL;
  1274. }
  1275. };
  1276. class ExternalSymbolSDNode : public SDNode {
  1277. const char *Symbol;
  1278. unsigned char TargetFlags;
  1279. friend class SelectionDAG;
  1280. ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
  1281. : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
  1282. DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
  1283. }
  1284. public:
  1285. const char *getSymbol() const { return Symbol; }
  1286. unsigned char getTargetFlags() const { return TargetFlags; }
  1287. static bool classof(const SDNode *N) {
  1288. return N->getOpcode() == ISD::ExternalSymbol ||
  1289. N->getOpcode() == ISD::TargetExternalSymbol;
  1290. }
  1291. };
  1292. class CondCodeSDNode : public SDNode {
  1293. ISD::CondCode Condition;
  1294. friend class SelectionDAG;
  1295. explicit CondCodeSDNode(ISD::CondCode Cond)
  1296. : SDNode(ISD::CONDCODE, DebugLoc(), getSDVTList(MVT::Other)),
  1297. Condition(Cond) {
  1298. }
  1299. public:
  1300. ISD::CondCode get() const { return Condition; }
  1301. static bool classof(const SDNode *N) {
  1302. return N->getOpcode() == ISD::CONDCODE;
  1303. }
  1304. };
  1305. /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
  1306. /// future and most targets don't support it.
  1307. class CvtRndSatSDNode : public SDNode {
  1308. ISD::CvtCode CvtCode;
  1309. friend class SelectionDAG;
  1310. explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
  1311. unsigned NumOps, ISD::CvtCode Code)
  1312. : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
  1313. CvtCode(Code) {
  1314. assert(NumOps == 5 && "wrong number of operations");
  1315. }
  1316. public:
  1317. ISD::CvtCode getCvtCode() const { return CvtCode; }
  1318. static bool classof(const SDNode *N) {
  1319. return N->getOpcode() == ISD::CONVERT_RNDSAT;
  1320. }
  1321. };
  1322. /// VTSDNode - This class is used to represent EVT's, which are used
  1323. /// to parameterize some operations.
  1324. class VTSDNode : public SDNode {
  1325. EVT ValueType;
  1326. friend class SelectionDAG;
  1327. explicit VTSDNode(EVT VT)
  1328. : SDNode(ISD::VALUETYPE, DebugLoc(), getSDVTList(MVT::Other)),
  1329. ValueType(VT) {
  1330. }
  1331. public:
  1332. EVT getVT() const { return ValueType; }
  1333. static bool classof(const SDNode *N) {
  1334. return N->getOpcode() == ISD::VALUETYPE;
  1335. }
  1336. };
  1337. /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
  1338. ///
  1339. class LSBaseSDNode : public MemSDNode {
  1340. //! Operand array for load and store
  1341. /*!
  1342. \note Moving this array to the base class captures more
  1343. common functionality shared between LoadSDNode and
  1344. StoreSDNode
  1345. */
  1346. SDUse Ops[4];
  1347. public:
  1348. LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
  1349. unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
  1350. EVT MemVT, MachineMemOperand *MMO)
  1351. : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
  1352. SubclassData |= AM << 2;
  1353. assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
  1354. InitOperands(Ops, Operands, numOperands);
  1355. assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
  1356. "Only indexed loads and stores have a non-undef offset operand");
  1357. }
  1358. const SDValue &getOffset() const {
  1359. return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
  1360. }
  1361. /// getAddressingMode - Return the addressing mode for this load or store:
  1362. /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
  1363. ISD::MemIndexedMode getAddressingMode() const {
  1364. return ISD::MemIndexedMode((SubclassData >> 2) & 7);
  1365. }
  1366. /// isIndexed - Return true if this is a pre/post inc/dec load/store.
  1367. bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
  1368. /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
  1369. bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
  1370. static bool classof(const SDNode *N) {
  1371. return N->getOpcode() == ISD::LOAD ||
  1372. N->getOpcode() == ISD::STORE;
  1373. }
  1374. };
  1375. /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
  1376. ///
  1377. class LoadSDNode : public LSBaseSDNode {
  1378. friend class SelectionDAG;
  1379. LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
  1380. ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
  1381. MachineMemOperand *MMO)
  1382. : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
  1383. VTs, AM, MemVT, MMO) {
  1384. SubclassData |= (unsigned short)ETy;
  1385. assert(getExtensionType() == ETy && "LoadExtType encoding error!");
  1386. assert(readMem() && "Load MachineMemOperand is not a load!");
  1387. assert(!writeMem() && "Load MachineMemOperand is a store!");
  1388. }
  1389. public:
  1390. /// getExtensionType - Return whether this is a plain node,
  1391. /// or one of the varieties of value-extending loads.
  1392. ISD::LoadExtType getExtensionType() const {
  1393. return ISD::LoadExtType(SubclassData & 3);
  1394. }
  1395. const SDValue &getBasePtr() const { return getOperand(1); }
  1396. const SDValue &getOffset() const { return getOperand(2); }
  1397. static bool classof(const SDNode *N) {
  1398. return N->getOpcode() == ISD::LOAD;
  1399. }
  1400. };
  1401. /// StoreSDNode - This class is used to represent ISD::STORE nodes.
  1402. ///
  1403. class StoreSDNode : public LSBaseSDNode {
  1404. friend class SelectionDAG;
  1405. StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
  1406. ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
  1407. MachineMemOperand *MMO)
  1408. : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
  1409. VTs, AM, MemVT, MMO) {
  1410. SubclassData |= (unsigned short)isTrunc;
  1411. assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
  1412. assert(!readMem() && "Store MachineMemOperand is a load!");
  1413. assert(writeMem() && "Store MachineMemOperand is not a store!");
  1414. }
  1415. public:
  1416. /// isTruncatingStore - Return true if the op does a truncation before store.
  1417. /// For integers this is the same as doing a TRUNCATE and storing the result.
  1418. /// For floats, it is the same as doing an FP_ROUND and storing the result.
  1419. bool isTruncatingStore() const { return SubclassData & 1; }
  1420. const SDValue &getValue() const { return getOperand(1); }
  1421. const SDValue &getBasePtr() const { return getOperand(2); }
  1422. const SDValue &getOffset() const { return getOperand(3); }
  1423. static bool classof(const SDNode *N) {
  1424. return N->getOpcode() == ISD::STORE;
  1425. }
  1426. };
  1427. /// MachineSDNode - An SDNode that represents everything that will be needed
  1428. /// to construct a MachineInstr. These nodes are created during the
  1429. /// instruction selection proper phase.
  1430. ///
  1431. class MachineSDNode : public SDNode {
  1432. public:
  1433. typedef MachineMemOperand **mmo_iterator;
  1434. private:
  1435. friend class SelectionDAG;
  1436. MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
  1437. : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
  1438. /// LocalOperands - Operands for this instruction, if they fit here. If
  1439. /// they don't, this field is unused.
  1440. SDUse LocalOperands[4];
  1441. /// MemRefs - Memory reference descriptions for this instruction.
  1442. mmo_iterator MemRefs;
  1443. mmo_iterator MemRefsEnd;
  1444. public:
  1445. mmo_iterator memoperands_begin() const { return MemRefs; }
  1446. mmo_iterator memoperands_end() const { return MemRefsEnd; }
  1447. bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
  1448. /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
  1449. /// list. This does not transfer ownership.
  1450. void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
  1451. for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
  1452. assert(*MMI && "Null mem ref detected!");
  1453. MemRefs = NewMemRefs;
  1454. MemRefsEnd = NewMemRefsEnd;
  1455. }
  1456. static bool classof(const SDNode *N) {
  1457. return N->isMachineOpcode();
  1458. }
  1459. };
  1460. class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
  1461. SDNode, ptrdiff_t> {
  1462. const SDNode *Node;
  1463. unsigned Operand;
  1464. SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
  1465. public:
  1466. bool operator==(const SDNodeIterator& x) const {
  1467. return Operand == x.Operand;
  1468. }
  1469. bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
  1470. const SDNodeIterator &operator=(const SDNodeIterator &I) {
  1471. assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
  1472. Operand = I.Operand;
  1473. return *this;
  1474. }
  1475. pointer operator*() const {
  1476. return Node->getOperand(Operand).getNode();
  1477. }
  1478. pointer operator->() const { return operator*(); }
  1479. SDNodeIterator& operator++() { // Preincrement
  1480. ++Operand;
  1481. return *this;
  1482. }
  1483. SDNodeIterator operator++(int) { // Postincrement
  1484. SDNodeIterator tmp = *this; ++*this; return tmp;
  1485. }
  1486. size_t operator-(SDNodeIterator Other) const {
  1487. assert(Node == Other.Node &&
  1488. "Cannot compare iterators of two different nodes!");
  1489. return Operand - Other.Operand;
  1490. }
  1491. static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
  1492. static SDNodeIterator end (const SDNode *N) {
  1493. return SDNodeIterator(N, N->getNumOperands());
  1494. }
  1495. unsigned getOperand() const { return Operand; }
  1496. const SDNode *getNode() const { return Node; }
  1497. };
  1498. template <> struct GraphTraits<SDNode*> {
  1499. typedef SDNode NodeType;
  1500. typedef SDNodeIterator ChildIteratorType;
  1501. static inline NodeType *getEntryNode(SDNode *N) { return N; }
  1502. static inline ChildIteratorType child_begin(NodeType *N) {
  1503. return SDNodeIterator::begin(N);
  1504. }
  1505. static inline ChildIteratorType child_end(NodeType *N) {
  1506. return SDNodeIterator::end(N);
  1507. }
  1508. };
  1509. /// LargestSDNode - The largest SDNode class.
  1510. ///
  1511. typedef LoadSDNode LargestSDNode;
  1512. /// MostAlignedSDNode - The SDNode class with the greatest alignment
  1513. /// requirement.
  1514. ///
  1515. typedef GlobalAddressSDNode MostAlignedSDNode;
  1516. namespace ISD {
  1517. /// isNormalLoad - Returns true if the specified node is a non-extending
  1518. /// and unindexed load.
  1519. inline bool isNormalLoad(const SDNode *N) {
  1520. const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
  1521. return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
  1522. Ld->getAddressingMode() == ISD::UNINDEXED;
  1523. }
  1524. /// isNON_EXTLoad - Returns true if the specified node is a non-extending
  1525. /// load.
  1526. inline bool isNON_EXTLoad(const SDNode *N) {
  1527. return isa<LoadSDNode>(N) &&
  1528. cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
  1529. }
  1530. /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
  1531. ///
  1532. inline bool isEXTLoad(const SDNode *N) {
  1533. return isa<LoadSDNode>(N) &&
  1534. cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
  1535. }
  1536. /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
  1537. ///
  1538. inline bool isSEXTLoad(const SDNode *N) {
  1539. return isa<LoadSDNode>(N) &&
  1540. cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
  1541. }
  1542. /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
  1543. ///
  1544. inline bool isZEXTLoad(const SDNode *N) {
  1545. return isa<LoadSDNode>(N) &&
  1546. cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
  1547. }
  1548. /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
  1549. ///
  1550. inline bool isUNINDEXEDLoad(const SDNode *N) {
  1551. return isa<LoadSDNode>(N) &&
  1552. cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
  1553. }
  1554. /// isNormalStore - Returns true if the specified node is a non-truncating
  1555. /// and unindexed store.
  1556. inline bool isNormalStore(const SDNode *N) {
  1557. const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
  1558. return St && !St->isTruncatingStore() &&
  1559. St->getAddressingMode() == ISD::UNINDEXED;
  1560. }
  1561. /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
  1562. /// store.
  1563. inline bool isNON_TRUNCStore(const SDNode *N) {
  1564. return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
  1565. }
  1566. /// isTRUNCStore - Returns true if the specified node is a truncating
  1567. /// store.
  1568. inline bool isTRUNCStore(const SDNode *N) {
  1569. return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
  1570. }
  1571. /// isUNINDEXEDStore - Returns true if the specified node is an
  1572. /// unindexed store.
  1573. inline bool isUNINDEXEDStore(const SDNode *N) {
  1574. return isa<StoreSDNode>(N) &&
  1575. cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
  1576. }
  1577. }
  1578. } // end llvm namespace
  1579. #endif