MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / Node

Class Node

chapter21/src/main/java/com/seaofnodes/simple/node/Node.java:19–728  ·  view source on GitHub ↗

All Nodes in the Sea of Nodes IR inherit from the Node class. The Node class provides common functionality used by all subtypes. Subtypes of Node specialize by overriding methods.

Source from the content-addressed store, hash-verified

17 * Subtypes of Node specialize by overriding methods.
18 */
19public abstract class Node implements Cloneable {
20
21 /**
22 * Each node has a unique dense Node ID within a compilation context
23 * The ID is useful for debugging, for using as an offset in a bitvector,
24 * as well as for computing equality of nodes (to be implemented later).
25 */
26 public int _nid;
27
28 /**
29 * Inputs to the node. These are use-def references to Nodes.
30 * <p>
31 * Generally fixed length, ordered, nulls allowed, no unused trailing space.
32 * Ordering is required because e.g. "a/b" is different from "b/a".
33 * The first input (offset 0) is often a {@link CFGNode} node.
34 */
35 public Ary<Node> _inputs;
36
37 /**
38 * Outputs reference Nodes that are not null and have this Node as an
39 * input. These nodes are users of this node, thus these are def-use
40 * references to Nodes.
41 * <p>
42 * Outputs directly match inputs, making a directed graph that can be
43 * walked in either direction. These outputs are typically used for
44 * efficient optimizations but otherwise have no semantics meaning.
45 */
46 public Ary<Node> _outputs;
47
48
49 /**
50 * Current computed type for this Node. This value changes as the graph
51 * changes and more knowledge is gained about the program.
52 */
53 public Type _type;
54
55
56 Node(Node... inputs) {
57 _nid = CODE.getUID(); // allocate unique dense ID
58 _inputs = new Ary<>(Node.class);
59 Collections.addAll(_inputs,inputs);
60 _outputs = new Ary<>(Node.class);
61 for( Node n : _inputs )
62 if( n != null )
63 n.addUse( this );
64 }
65
66 // Make a Node using the existing arrays of nodes.
67 // Used by any pass rewriting all Node classes but not the edges.
68 Node( Node n ) {
69 assert CodeGen.CODE._phase.ordinal() >= CodeGen.Phase.InstSelect.ordinal();
70 _nid = CODE.getUID(); // allocate unique dense ID
71 _inputs = new Ary<>(n==null ? new Node[0] : n._inputs.asAry());
72 _outputs = new Ary<>(Node.class);
73 _type = n==null ? Type.BOTTOM : n._type;
74 _deps = null;
75 _hash = 0;
76 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected