I have some questions about SDValue and SDNode

Each node is an instance of the SDNode class and edges are instances of the SDValue class, but I don’t know how they’re actually connected.Here is the definition of SDvalue.

class SDValue {
  friend struct DenseMapInfo<SDValue>;

  SDNode *Node = nullptr; // The node defining the value we are using.
  unsigned ResNo = 0;     // Which return value of the node we are using.

public:
  SDValue() = default;
  SDValue(SDNode *node, unsigned resno);

  /// get the index which selects a specific result in the SDNode
  unsigned getResNo() const { return ResNo; }

  /// get the SDNode which holds the desired result
  SDNode *getNode() const { return Node; }

  /// set the SDNode
  void setNode(SDNode *N) { Node = N; }

  inline SDNode *operator->() const { return Node; }
 .....

I don’t understand unsigned ResNo = 0, although there are comments here.If anyone can help me, I would appreciate it,thanks!

The reason SDValue exists is because an SDNode can produce multiple results. For example add-with-overflow ones will produce the arithmetic result and (initially) an i1 saying whether it overflowed. Or a load will produce both the value loaded and another chain result to enforce code-ordering.

So because the edges in the DAG need to point to values there’s this small wrapper to say which result of an SDNode the operand actually wants to use.

4 Likes

I really appreciate your answer, I probably understand that the ResNo in SDValue is used to indicate one of the multiple results in the SDNode,thanks!