Reduct  v4.1.3-1-gd06c383
A functional and immutable language.
Loading...
Searching...
No Matches
rvsdg.h
Go to the documentation of this file.
1#ifndef REDUCT_RVSDG_H
2#define REDUCT_RVSDG_H 1
3
4#include <reduct/defs.h>
5#include <reduct/inst.h>
6
7#include <stdbool.h>
8#include <stdio.h>
9
10struct reduct;
11struct reduct_rvsdg_origin;
12struct reduct_rvsdg_user;
13struct reduct_rvsdg_edge;
14
15/**
16 * @file rvsdg.h
17 * @brief Intermediate Representation
18 * @defgroup rvsdg RVSDG
19 *
20 * Reduct uses a IR (Intermediate representation) heavily inspired by the RVSDG (Regionalized Value State
21 * Dependence Graph).
22 *
23 * ## Nodes, Regions and Edges
24 *
25 * A RVSDG representation is made up of nodes, regions and edges. Nodes represent operations (addition, subtraction,
26 * branches, functions, etc.), regions represent computations (a sequence of nodes) and edges represent data
27 * dependencies between nodes.
28 *
29 * Each node can have any number of inputs but will always have exactly one output. Each region can have any number of
30 * arguments but will also always have exactly one result.
31 *
32 * The output of nodes and the arguments of regions are the origins of edges, while the input or results of a region
33 * are the users of edges.
34 *
35 * @note Nodes having one output and regions having one result is a deviation from the paper, however, since Reduct is
36 * immutable, we can know that any expression will always produce exactly one output/result. So we can simply things.
37 *
38 * ## Structure
39 *
40 * Included is a simple description of how data flows through the RVSDG:
41 *
42 * - A node takes in some number of inputs which get passed as arguments to the regions within the node (details depend
43 * on node type, see below)
44 * - A region contains some number of nodes which connect to its result and may connect to its arguments.
45 * - The result of the regions within a node get passed as the output of the node (details depend on node type, see
46 * below).
47 * - The output of the node can then connect to other nodes or be returned as results of the parent region.
48 *
49 * ## Node Types
50 *
51 * A node can either be simple or structural, a simple node represents a primitive operation such as addition or
52 * subtraction. Structural nodes contain regions and represent more complex logic such as function calls, loops or
53 * conditionals.
54 *
55 * There are multiple types of structural node which defines how it passes data to and from the regions it might
56 * contain. Included below is a list of all such types.
57 *
58 * @note Since Reduct is immutable and does not have traditional global variables, some node types, for example
59 * delta nodes, will not be used. Omega nodes are also replaced with lambda nodes.
60 *
61 * ### Gamma Nodes
62 *
63 * A gamma node represents a branch or decision point. The first input to a gamma node is a predicate, if the output of
64 * the predicate is truthy region 1 is executed, if it is falsy region 0 is executed. The remaining inputs are passed as
65 * arguments to the corresponding region with that regions outputs mapped to the gamma nodes outputs.
66 *
67 * @note In the paper describes a gamma node as taking in a selector instead of a predicate, this selector then outputs
68 * the index of the region to execute. For simplicity, we will not be using this system.
69 *
70 * ### Lambda Nodes
71 *
72 * A lambda node represents a function and contains a single region representing a function's body. The inputs are not
73 * the arguments to the lambda but instead captured variables. The single output is the function itself, not the result
74 * of the function.
75 *
76 * @note The paper describes an "apply" node to represent a function invocation. For simplicity, this is represented as
77 * simple `REDUCT_OPCODE_CALL` or `REDUCT_OPCODE_CALL_CONST` node.
78 *
79 * ### Phi Nodes
80 *
81 * A phi node allows a function to recursively call itself. It contains a single region containing a lambda
82 * node, the output of the lambda node should be connected to the result of this region with the arguments
83 * of this region connected to the inputs of the lambda node. The phi node itself only takes inputs for captured
84 * variables and a outputs the lambda.
85 *
86 * @note The paper describes a phi node as being able to contain multiple lambda nodes for mutual recursion. This will
87 * not be needed within Reduct.
88 *
89 * @see https://arxiv.org/abs/1912.05036 "RVSDG: An Intermediate Representation for Optimizing Compilers" (Nico
90 * Reissmann et al., 2020)
91 *
92 * @{
93 */
94
95/**
96 * @brief Owner of a data dependency origin or user.
97 * @enum reduct_rvsdg_owner_kind_t
98 */
104
105/**
106 * @brief Origin of a data dependency edge.
107 * @struct reduct_rvsdg_origin_t
108 */
109typedef struct reduct_rvsdg_origin
110{
111 reduct_rvsdg_owner_kind_t ownerKind; ///< The kind of owner (node or region).
112 union {
113 struct reduct_rvsdg_node* node; ///< The node this origin belongs to.
114 struct reduct_rvsdg_region* region; ///< The region this origin belongs to.
115 };
116 struct reduct_rvsdg_edge* firstEdge; ///< List of edges originating from this output/argument.
117 struct reduct_rvsdg_origin* next; ///< Next origin in the node/region list.
118 struct reduct_rvsdg_origin* map; ///< Used during optimization passes to copy nodes.
119 uint16_t index; ///< The index for the associated output/argument.
120 uint16_t edgeCount; ///< The number of edges originating from this output/argument.
122
123/**
124 * @brief User of a data dependency edge.
125 * @struct reduct_rvsdg_user_t
126 */
127typedef struct reduct_rvsdg_user
128{
129 reduct_rvsdg_owner_kind_t ownerKind; ///< The kind of owner (node or region).
130 union {
131 struct reduct_rvsdg_node* node; ///< The node this user belongs to.
132 struct reduct_rvsdg_region* region; ///< The region this user belongs to.
133 };
134 uint16_t index; ///< The index for the associated input/result.
135 struct reduct_rvsdg_edge* edge; ///< The single edge connecting to this input's/result's origin.
136 struct reduct_rvsdg_user* next; ///< Next user in the node/region list.
138
139/**
140 * @brief Edge structure representing a data dependency.
141 * @struct reduct_rvsdg_edge_t
142 */
143typedef struct reduct_rvsdg_edge
144{
145 struct reduct_rvsdg_origin* origin; ///< The node where the edge originates.
146 struct reduct_rvsdg_user* user; ///< The node where the edge ends.
147 struct reduct_rvsdg_edge* next; ///< The next edge in the list.
148 struct reduct_rvsdg_edge* prev; ///< The previous edge in the list.
150
151/**
152 * @brief Node type.
153 */
155#define REDUCT_RVSDG_NODE_TYPE_INVALID 0 ///< Invalid node type.
156#define REDUCT_RVSDG_NODE_TYPE_SIMPLE_OPCODE 1 ///< Represents a primitive operation (opcode).
157#define REDUCT_RVSDG_NODE_TYPE_SIMPLE_CONST 2 ///< Represents a constant.
158#define REDUCT_RVSDG_NODE_TYPE_GAMMA 3 ///< Represents a branch or decision point.
159#define REDUCT_RVSDG_NODE_TYPE_LAMBDA 4 ///< Represents a function.
160#define REDUCT_RVSDG_NODE_TYPE_PHI 5 ///< Represents a phi node.
161
162/**
163 * @brief Node flags.
164 */
166#define REDUCT_RVSDG_NODE_FLAGS_NONE 0 ///< No flags.
167#define REDUCT_RVSDG_NODE_FLAGS_LAMBDA_VARIADIC (1 << 0) ///< Lambda node is variadic.
168
169/**
170 * @brief Information about a node type.
171 * @struct reduct_rvsdg_node_info_t
172 */
173typedef struct reduct_rvsdg_node_info
174{
175 const char* name; ///< The name of the node type.
176 const char* color; ///< The color of the node type for visualization.
177 uint8_t dataInputOffset; ///< The index where data inputs begin (skipping control inputs).
179
180/**
181 * @brief Get information about a node type.
182 *
183 * @param type The node type.
184 * @return Pointer to the node info structure.
185 */
187
188/**
189 * @brief A node in the RVSDG.
190 * @enum reduct_rvsdg_node_t
191 */
192typedef struct reduct_rvsdg_node
193{
194 reduct_rvsdg_node_type_t type; ///< The type of the node.
195 uint8_t inputCount; ///< Number of input edges.
196 uint8_t regionCount; ///< Number of regions in the node.
197 reduct_rvsdg_node_flags_t flags; ///< Node flags, interpretation depends on node type.
198 uint8_t _reserved[4];
199 struct reduct_rvsdg_user* firstInput; ///< List of input ports.
200 struct reduct_rvsdg_origin* output; ///< The output port.
201 struct reduct_rvsdg_region* firstRegion; ///< List of regions in the node.
202 struct reduct_rvsdg_region* parent; ///< The region this node belongs to.
203 struct reduct_rvsdg_node* next; ///< Next node in the region's list.
204 union {
205 reduct_opcode_t opcode; ///< The opcode associated with the node.
206 reduct_handle_t constant; ///< The constant value associated with the node.
207 };
209
210/**
211 * @brief Represents a computation.
212 * @enum reduct_rvsdg_region_t
213 */
214typedef struct reduct_rvsdg_region
215{
216 uint16_t argumentCount; ///< Number of arguments to the region.
217 uint8_t _reserved[6];
218 reduct_rvsdg_origin_t* firstArgument; ///< List of argument ports.
219 reduct_rvsdg_user_t* result; ///< The result port.
220 struct reduct_rvsdg_node* firstNode; ///< First node in the region.
221 struct reduct_rvsdg_node* lastNode; ///< Last node in the region.
222 struct reduct_rvsdg_node* parent; ///< The node that owns this region.
223 struct reduct_rvsdg_region* next; ///< Next region in the parent node's list.
225
226/**
227 * @brief Allocate a new IR edge.
228 *
229 * @param reduct Pointer to the Reduct structure.
230 * @return The newly allocated edge.
231 */
233
234/**
235 * @brief Connects an origin to a user via an edge.
236 *
237 * @param reduct Pointer to the Reduct structure.
238 * @param origin Pointer to the origin port.
239 * @param user Pointer to the user port.
240 */
242 reduct_rvsdg_user_t* user);
243
244/**
245 * @brief Disconnect an edge from its origin and user.
246 *
247 * @param edge Pointer to the edge to disconnect.
248 */
250
251/**
252 * @brief Allocate a new IR node.
253 *
254 * @param reduct Pointer to the Reduct structure.
255 * @return The newly allocated node.
256 */
258
259/**
260 * @brief Create a simple opcode node.
261 *
262 * @param reduct Pointer to the Reduct structure.
263 * @param region The region to add the node to, or NULL.
264 * @param opcode The opcode to use.
265 * @return The newly allocated node.
266 */
268 reduct_rvsdg_region_t* region, reduct_opcode_t opcode);
269
270/**
271 * @brief Create a simple constant node.
272 *
273 * @param reduct Pointer to the Reduct structure.
274 * @param region The region to add the node to, or NULL.
275 * @param constant The constant to use.
276 * @return The newly allocated node.
277 */
279 reduct_rvsdg_region_t* region, reduct_handle_t constant);
280
281/**
282 * @brief Create a simple unary opcode node.
283 *
284 * @param reduct Pointer to the Reduct structure.
285 * @param region The region to add the node to, or NULL.
286 * @param opcode The opcode to use.
287 * @param input The origin of the input.
288 * @return The newly allocated node.
289 */
291 reduct_opcode_t opcode, struct reduct_rvsdg_origin* input);
292
293/**
294 * @brief Create a simple binary opcode node.
295 *
296 * @param reduct Pointer to the Reduct structure.
297 * @param region The region to add the node to, or NULL.
298 * @param opcode The opcode to use.
299 * @param left The origin of the left input.
300 * @param right The origin of the right input.
301 * @return The newly allocated node.
302 */
304 reduct_rvsdg_region_t* region, reduct_opcode_t opcode, struct reduct_rvsdg_origin* left,
305 struct reduct_rvsdg_origin* right);
306
307/**
308 * @brief Create a simple ternary opcode node.
309 *
310 * @param reduct Pointer to the Reduct structure.
311 * @param region The region to add the node to, or NULL.
312 * @param opcode The opcode to use.
313 * @param a The origin of the first input.
314 * @param b The origin of the second input.
315 * @param c The origin of the third input.
316 * @return The newly allocated node.
317 */
319 reduct_rvsdg_region_t* region, reduct_opcode_t opcode, struct reduct_rvsdg_origin* a, struct reduct_rvsdg_origin* b,
320 struct reduct_rvsdg_origin* c);
321
322/**
323 * @brief Create a lambda node.
324 *
325 * @param reduct Pointer to the Reduct structure.
326 * @param region The region to add the node to, or NULL.
327 * @return The newly allocated node.
328 */
330
331/**
332 * @brief Create a phi node.
333 *
334 * @param reduct Pointer to the Reduct structure.
335 * @param region The region to add the node to, or NULL.
336 * @return The newly allocated node.
337 */
339
340/**
341 * @brief Create a gamma node.
342 *
343 * @param reduct Pointer to the Reduct structure.
344 * @param region The region to add the node to, or NULL.
345 * @return The newly allocated node.
346 */
348
349/**
350 * @brief Get an input port of a node by index.
351 *
352 * @param node The node to search.
353 * @param index The index of the input port.
354 * @return The user port, or NULL if not found.
355 */
356REDUCT_API struct reduct_rvsdg_user* reduct_rvsdg_node_get_input(reduct_rvsdg_node_t* node, uint16_t index);
357
358/**
359 * @brief Get the output of the node connected to an input node of a node by index.
360 *
361 * @param node The node to search.
362 * @param index The index of the input port.
363 * @return The origin port, or NULL if not found or not connected.
364 */
365REDUCT_API struct reduct_rvsdg_origin* reduct_rvsdg_node_get_input_origin(reduct_rvsdg_node_t* node, uint16_t index);
366
367/**
368 * @brief Get the node connected to an input node of a node by index.
369 *
370 * @param node The node to search.
371 * @param index The index of the input port.
372 * @return The input node, or NULL if not found or the port is not connected to a node.
373 */
374REDUCT_API struct reduct_rvsdg_node* reduct_rvsdg_node_get_input_node(reduct_rvsdg_node_t* node, uint16_t index);
375
376/**
377 * @brief Redirect all users of a origin to a new origin.
378 *
379 * @param origin The current origin.
380 * @param newOrigin The new origin to redirect users to.
381 */
382REDUCT_API void reduct_rvsdg_origin_redirect_users(struct reduct_rvsdg_origin* origin,
383 struct reduct_rvsdg_origin* newOrigin);
384
385/**
386 * @brief Get an argument port of a region by index.
387 *
388 * @param region The region to search.
389 * @param index The index of the argument port.
390 * @return The origin port, or NULL if not found.
391 */
392REDUCT_API struct reduct_rvsdg_origin* reduct_rvsdg_region_get_argument(reduct_rvsdg_region_t* region, uint16_t index);
393
394/**
395 * @brief Check if a region is an ancestor of another, or if they are the same.
396 *
397 * @param region The region to start from.
398 * @param ancestor The potential ancestor region.
399 * @return true if `ancestor` is an ancestor of (or the same as) `region`.
400 */
402
403/**
404 * @brief Redirect an existing edge from its current origin to a new origin.
405 *
406 * @param edge The edge to redirect.
407 * @param newOrigin The new origin to connect the edge to.
408 */
410
411/**
412 * @brief Wrap a lambda node in a phi node for recursive calls.
413 *
414 * @param reduct Pointer to the Reduct structure.
415 * @param lambda The lambda node to wrap.
416 */
418
419/**
420 * @brief Check if a nodes grandparent is a phi node.
421 *
422 * @param node The node to check.
423 * @return true if the node is nested inside a phi node's region.
424 */
426
427/**
428 * @brief Create a CALL opcode node and connect a callable as its first input.
429 *
430 * @param reduct Pointer to the Reduct structure.
431 * @param region The region to add the call node to.
432 * @param callable The origin representing the function to call.
433 * @return The newly created call node.
434 */
436 reduct_rvsdg_origin_t* callable);
437
438/**
439 * @brief Map a node input index to a region argument index.
440 *
441 * @param node The parent node.
442 * @param region The target region.
443 * @param inputIndex The input index on the node.
444 * @param outArgIndex Pointer to store the mapped argument index.
445 * @return true if the input is mapped to an argument.
446 */
447REDUCT_API bool reduct_rvsdg_node_map_input_to_argument(reduct_rvsdg_node_t* node, struct reduct_rvsdg_region* region,
448 uint16_t inputIndex, uint16_t* outArgIndex);
449
450/**
451 * @brief Map a region argument index to an input index of the parent node.
452 *
453 * Usefull since the index of an input port associated with an input port might not be equal, for example, a gamma node
454 * uses the first input port for its predicate and a lambda node can have more arguments than inputs.
455 *
456 * @param region The region containing the argument.
457 * @param argIndex The argument index within the region.
458 * @param outInputIndex Pointer to store the mapped input index.
459 * @return true if the argument is mapped from an input.
460 */
461REDUCT_API bool reduct_rvsdg_node_argument_to_input(struct reduct_rvsdg_region* region, uint16_t argIndex,
462 uint16_t* outInputIndex);
463
464/**
465 * @brief Check if an origin is a recursion target for a given phi node.
466 *
467 * @param node The phi node.
468 * @param origin The origin to check.
469 * @return true if the origin is a recursion target.
470 */
471REDUCT_API bool reduct_rvsdg_node_is_recur_origin(reduct_rvsdg_node_t* node, struct reduct_rvsdg_origin* origin);
472
473/**
474 * @brief Allocate a new IR region.
475 *
476 * @param reduct Pointer to the Reduct structure.
477 * @return The newly allocated region.
478 */
480
481/**
482 * @brief Allocate a new IR user port.
483 *
484 * @param reduct Pointer to the Reduct structure.
485 * @return The newly allocated user port.
486 */
488
489/**
490 * @brief Allocate a new IR origin port.
491 *
492 * @param reduct Pointer to the Reduct structure.
493 * @return The newly allocated origin port.
494 */
496
497/**
498 * @brief Add a new input port to a node.
499 *
500 * @param reduct Pointer to the Reduct structure.
501 * @param node The node to add the input to.
502 * @return The newly created user port.
503 */
505
506/**
507 * @brief Remove an input port from a node.
508 *
509 * This will disconnect the edge and shift the indices of subsequent inputs.
510 *
511 * @param user The user port to remove.
512 */
514
515/**
516 * @brief Remove an argument port from a region.
517 *
518 * @param origin The origin port to remove.
519 */
521
522/**
523 * @brief Add a new region to a node.
524 *
525 * @param reduct Pointer to the Reduct structure.
526 * @param node The node to add the region to.
527 * @return The newly created region.
528 */
530
531/**
532 * @brief Add a new argument port to a region.
533 *
534 * @param reduct Pointer to the Reduct structure.
535 * @param region The region to add the argument to.
536 * @return The newly created origin port.
537 */
539 reduct_rvsdg_region_t* region);
540
541/**
542 * @brief Adds a node to a region.
543 *
544 * @param region Pointer to the region to add the node to.
545 * @param node Pointer to the node to add.
546 */
548
549/**
550 * @brief Removes a node from its region.
551 *
552 * @param node Pointer to the node to remove.
553 */
555
556/**
557 * @brief Removes from the region and disconnects from any connections a node and any nodes connected to its input.
558 *
559 * @param reduct Pointer to the Reduct structure.
560 * @param node Pointer to the node to delete.
561 */
562REDUCT_API void reduct_rvsdg_node_delete(struct reduct* reduct, reduct_rvsdg_node_t* node);
563
564/**
565 * @brief Check if two nodes are structurally identical.
566 *
567 * @param reduct Pointer to the Reduct structure.
568 * @param nodeA First node.
569 * @param nodeB Second node.
570 * @return true if the nodes are identical, false otherwise.
571 */
573 reduct_rvsdg_node_t* nodeB);
574
575/**
576 * @brief Lift an origin from an outer region to an inner region, creating a new argument in the inner region and
577 * connecting it to the outer origin.
578 *
579 * @param reduct Pointer to the Reduct structure.
580 * @param region The inner region to lift the origin into.
581 * @param outerValue The origin in the outer region to lift.
582 * @return The new origin in the inner region representing the lifted value.
583 */
585 reduct_rvsdg_origin_t* outerValue);
586
587/**
588 * @brief Resolve an origin to its final source, traversing through ports.
589 *
590 * @param origin The starting origin to resolve.
591 * @return The resolved origin, which is the source of the value.
592 */
594
595/**
596 * @brief Get the node connected to an input node of a node by index, traversing through ports
597 *
598 * @param node The node to search.
599 * @param index The index of the input port.
600 * @return The input node, or `NULL` if not found.
601 */
603 uint16_t index);
604
605/** @} */
606
607#endif
#define REDUCT_API
Definition defs.h:24
reduct_opcode_t
Opcode enumeration.
Definition opcode.h:49
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_call(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_rvsdg_origin_t *callable)
Create a CALL opcode node and connect a callable as its first input.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_simple_ternary(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_opcode_t opcode, struct reduct_rvsdg_origin *a, struct reduct_rvsdg_origin *b, struct reduct_rvsdg_origin *c)
Create a simple ternary opcode node.
REDUCT_API reduct_rvsdg_origin_t * reduct_rvsdg_region_lift_origin(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_rvsdg_origin_t *outerValue)
Lift an origin from an outer region to an inner region, creating a new argument in the inner region a...
REDUCT_API bool reduct_rvsdg_node_argument_to_input(struct reduct_rvsdg_region *region, uint16_t argIndex, uint16_t *outInputIndex)
Map a region argument index to an input index of the parent node.
REDUCT_API struct reduct_rvsdg_origin * reduct_rvsdg_region_get_argument(reduct_rvsdg_region_t *region, uint16_t index)
Get an argument port of a region by index.
REDUCT_API reduct_rvsdg_region_t * reduct_rvsdg_node_add_region(struct reduct *reduct, reduct_rvsdg_node_t *node)
Add a new region to a node.
REDUCT_API void reduct_rvsdg_node_delete(struct reduct *reduct, reduct_rvsdg_node_t *node)
Removes from the region and disconnects from any connections a node and any nodes connected to its in...
REDUCT_API void reduct_rvsdg_region_remove_node(reduct_rvsdg_node_t *node)
Removes a node from its region.
REDUCT_API bool reduct_rvsdg_node_is_inside_phi(reduct_rvsdg_node_t *node)
Check if a nodes grandparent is a phi node.
REDUCT_API reduct_rvsdg_user_t * reduct_rvsdg_node_add_input(struct reduct *reduct, reduct_rvsdg_node_t *node)
Add a new input port to a node.
REDUCT_API struct reduct_rvsdg_node * reduct_rvsdg_node_get_resolved_input_node(reduct_rvsdg_node_t *node, uint16_t index)
Get the node connected to an input node of a node by index, traversing through ports.
REDUCT_API reduct_rvsdg_origin_t * reduct_rvsdg_origin_new(struct reduct *reduct)
Allocate a new IR origin port.
REDUCT_API const reduct_rvsdg_node_info_t * reduct_rvsdg_node_get_info(reduct_rvsdg_node_type_t type)
Get information about a node type.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new(struct reduct *reduct)
Allocate a new IR node.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_simple_unary(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_opcode_t opcode, struct reduct_rvsdg_origin *input)
Create a simple unary opcode node.
uint8_t reduct_rvsdg_node_flags_t
Node flags.
Definition rvsdg.h:165
REDUCT_API reduct_rvsdg_user_t * reduct_rvsdg_user_new(struct reduct *reduct)
Allocate a new IR user port.
REDUCT_API reduct_rvsdg_origin_t * reduct_rvsdg_region_add_argument(struct reduct *reduct, reduct_rvsdg_region_t *region)
Add a new argument port to a region.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_gamma(struct reduct *reduct, reduct_rvsdg_region_t *region)
Create a gamma node.
REDUCT_API bool reduct_rvsdg_node_map_input_to_argument(reduct_rvsdg_node_t *node, struct reduct_rvsdg_region *region, uint16_t inputIndex, uint16_t *outArgIndex)
Map a node input index to a region argument index.
REDUCT_API struct reduct_rvsdg_node * reduct_rvsdg_node_get_input_node(reduct_rvsdg_node_t *node, uint16_t index)
Get the node connected to an input node of a node by index.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_simple_opcode(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_opcode_t opcode)
Create a simple opcode node.
REDUCT_API void reduct_rvsdg_node_phi_wrap_lambda(struct reduct *reduct, reduct_rvsdg_node_t *lambda)
Wrap a lambda node in a phi node for recursive calls.
REDUCT_API void reduct_rvsdg_region_add_node(reduct_rvsdg_region_t *region, reduct_rvsdg_node_t *node)
Adds a node to a region.
reduct_rvsdg_owner_kind_t
Owner of a data dependency origin or user.
Definition rvsdg.h:100
REDUCT_API void reduct_rvsdg_edge_connect(struct reduct *reduct, reduct_rvsdg_origin_t *origin, reduct_rvsdg_user_t *user)
Connects an origin to a user via an edge.
REDUCT_API void reduct_rvsdg_origin_redirect_users(struct reduct_rvsdg_origin *origin, struct reduct_rvsdg_origin *newOrigin)
Redirect all users of a origin to a new origin.
REDUCT_API reduct_rvsdg_region_t * reduct_rvsdg_region_new(struct reduct *reduct)
Allocate a new IR region.
REDUCT_API struct reduct_rvsdg_user * reduct_rvsdg_node_get_input(reduct_rvsdg_node_t *node, uint16_t index)
Get an input port of a node by index.
REDUCT_API bool reduct_rvsdg_node_is_identical(struct reduct *reduct, reduct_rvsdg_node_t *nodeA, reduct_rvsdg_node_t *nodeB)
Check if two nodes are structurally identical.
REDUCT_API void reduct_rvsdg_node_remove_input(reduct_rvsdg_user_t *user)
Remove an input port from a node.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_simple_binary(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_opcode_t opcode, struct reduct_rvsdg_origin *left, struct reduct_rvsdg_origin *right)
Create a simple binary opcode node.
REDUCT_API bool reduct_rvsdg_region_is_ancestor_or_same(reduct_rvsdg_region_t *region, reduct_rvsdg_region_t *ancestor)
Check if a region is an ancestor of another, or if they are the same.
REDUCT_API void reduct_rvsdg_edge_redirect(reduct_rvsdg_edge_t *edge, reduct_rvsdg_origin_t *newOrigin)
Redirect an existing edge from its current origin to a new origin.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_simple_constant(struct reduct *reduct, reduct_rvsdg_region_t *region, reduct_handle_t constant)
Create a simple constant node.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_lambda(struct reduct *reduct, reduct_rvsdg_region_t *region)
Create a lambda node.
REDUCT_API reduct_rvsdg_origin_t * reduct_rvsdg_resolve_origin(reduct_rvsdg_origin_t *origin)
Resolve an origin to its final source, traversing through ports.
REDUCT_API void reduct_rvsdg_region_remove_argument(reduct_rvsdg_origin_t *origin)
Remove an argument port from a region.
REDUCT_API struct reduct_rvsdg_origin * reduct_rvsdg_node_get_input_origin(reduct_rvsdg_node_t *node, uint16_t index)
Get the output of the node connected to an input node of a node by index.
REDUCT_API void reduct_rvsdg_edge_disconnect(reduct_rvsdg_edge_t *edge)
Disconnect an edge from its origin and user.
uint8_t reduct_rvsdg_node_type_t
Node type.
Definition rvsdg.h:154
REDUCT_API reduct_rvsdg_edge_t * reduct_rvsdg_edge_new(struct reduct *reduct)
Allocate a new IR edge.
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_phi(struct reduct *reduct, reduct_rvsdg_region_t *region)
Create a phi node.
REDUCT_API bool reduct_rvsdg_node_is_recur_origin(reduct_rvsdg_node_t *node, struct reduct_rvsdg_origin *origin)
Check if an origin is a recursion target for a given phi node.
@ REDUCT_RVSDG_OWNER_NODE
Definition rvsdg.h:101
@ REDUCT_RVSDG_OWNER_REGION
Definition rvsdg.h:102
Bytecode instruction format.
Handle type.
Definition defs.h:121
Edge structure representing a data dependency.
Definition rvsdg.h:144
struct reduct_rvsdg_edge * next
The next edge in the list.
Definition rvsdg.h:147
struct reduct_rvsdg_edge * prev
The previous edge in the list.
Definition rvsdg.h:148
struct reduct_rvsdg_origin * origin
The node where the edge originates.
Definition rvsdg.h:145
struct reduct_rvsdg_user * user
The node where the edge ends.
Definition rvsdg.h:146
Information about a node type.
Definition rvsdg.h:174
const char * color
The color of the node type for visualization.
Definition rvsdg.h:176
const char * name
The name of the node type.
Definition rvsdg.h:175
uint8_t dataInputOffset
The index where data inputs begin (skipping control inputs).
Definition rvsdg.h:177
struct reduct_rvsdg_user * firstInput
List of input ports.
Definition rvsdg.h:199
struct reduct_rvsdg_region * parent
The region this node belongs to.
Definition rvsdg.h:202
reduct_rvsdg_node_type_t type
The type of the node.
Definition rvsdg.h:194
uint8_t inputCount
Number of input edges.
Definition rvsdg.h:195
uint8_t regionCount
Number of regions in the node.
Definition rvsdg.h:196
reduct_handle_t constant
The constant value associated with the node.
Definition rvsdg.h:206
reduct_rvsdg_node_flags_t flags
Node flags, interpretation depends on node type.
Definition rvsdg.h:197
struct reduct_rvsdg_node * next
Next node in the region's list.
Definition rvsdg.h:203
struct reduct_rvsdg_region * firstRegion
List of regions in the node.
Definition rvsdg.h:201
reduct_opcode_t opcode
The opcode associated with the node.
Definition rvsdg.h:205
struct reduct_rvsdg_origin * output
The output port.
Definition rvsdg.h:200
Origin of a data dependency edge.
Definition rvsdg.h:110
struct reduct_rvsdg_region * region
The region this origin belongs to.
Definition rvsdg.h:114
struct reduct_rvsdg_origin * map
Used during optimization passes to copy nodes.
Definition rvsdg.h:118
struct reduct_rvsdg_origin * next
Next origin in the node/region list.
Definition rvsdg.h:117
uint16_t index
The index for the associated output/argument.
Definition rvsdg.h:119
uint16_t edgeCount
The number of edges originating from this output/argument.
Definition rvsdg.h:120
struct reduct_rvsdg_node * node
The node this origin belongs to.
Definition rvsdg.h:113
reduct_rvsdg_owner_kind_t ownerKind
The kind of owner (node or region).
Definition rvsdg.h:111
struct reduct_rvsdg_edge * firstEdge
List of edges originating from this output/argument.
Definition rvsdg.h:116
struct reduct_rvsdg_region * next
Next region in the parent node's list.
Definition rvsdg.h:223
uint16_t argumentCount
Number of arguments to the region.
Definition rvsdg.h:216
reduct_rvsdg_origin_t * firstArgument
List of argument ports.
Definition rvsdg.h:218
reduct_rvsdg_user_t * result
The result port.
Definition rvsdg.h:219
struct reduct_rvsdg_node * parent
The node that owns this region.
Definition rvsdg.h:222
struct reduct_rvsdg_node * firstNode
First node in the region.
Definition rvsdg.h:220
struct reduct_rvsdg_node * lastNode
Last node in the region.
Definition rvsdg.h:221
User of a data dependency edge.
Definition rvsdg.h:128
uint16_t index
The index for the associated input/result.
Definition rvsdg.h:134
struct reduct_rvsdg_node * node
The node this user belongs to.
Definition rvsdg.h:131
struct reduct_rvsdg_region * region
The region this user belongs to.
Definition rvsdg.h:132
reduct_rvsdg_owner_kind_t ownerKind
The kind of owner (node or region).
Definition rvsdg.h:129
struct reduct_rvsdg_user * next
Next user in the node/region list.
Definition rvsdg.h:136
struct reduct_rvsdg_edge * edge
The single edge connecting to this input's/result's origin.
Definition rvsdg.h:135