Reduct  v4.0.5-1-g4851deb
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 region get passed as the outputs of the node (details depend on node type, see below).
46 * - The output of the node can then connect to other nodes or be returned as results of the parent region.
47 *
48 * ## Node Types
49 *
50 * A node can either be simple or structural, a simple node represents a primitive operation such as addition or
51 * subtraction. Structural nodes contain regions and represent more complex logic such as function calls, loops or
52 * conditionals.
53 *
54 * There are multiple types of structural node which defines how it passes data to and from the regions it might
55 * contain. Included below is a list of all such types.
56 *
57 * @note Since Reduct is immutable and does not have traditional global variables, some node types, for example
58 * delta nodes, will not be used. Omega nodes are also replaced with lambda nodes.
59 *
60 * ### Gamma Nodes
61 *
62 * A gamma node represents a branch or decision point. The first input to a gamma node is a predicate, which should
63 * evaluate to a positive integer representing the index of the region to execute. The remaining inputs are passed as
64 * arguments to the corresponding region with that regions outputs mapped to the gamma nodes outputs.
65 *
66 * ### Lambda Nodes
67 *
68 * A lambda node represents a function and contains a single region representing a function's body. The inputs are not
69 * the arguments to the lambda but instead captured variables. The single output is the function itself, not the result
70 * of the function.
71 *
72 * @note The paper describes an "apply" node to represent a function invocation. For simplicity, this is represented as
73 * simple `REDUCT_OPCODE_CALL` or `REDUCT_OPCODE_CALL_CONST` node.
74 *
75 * ### Phi Nodes
76 *
77 * A phi node allows a function to recursively call itself. It contains a single region containing a lambda
78 * node, the output of the lambda node should be connected to the result of this region with the arguments
79 * of this region connected to the inputs of the lambda node. The phi node itself only takes inputs for captured
80 * variables and a outputs the lambda.
81 *
82 * @note The paper describes a phi node as being able to contain multiple lambda nodes for mutual recursion. This will
83 * not be needed within Reduct.
84 *
85 * @see https://arxiv.org/abs/1912.05036 "RVSDG: An Intermediate Representation for Optimizing Compilers" (Nico
86 * Reissmann et al., 2020)
87 *
88 * @{
89 */
90
91/**
92 * @brief Owner of a data dependency origin or user.
93 * @enum reduct_rvsdg_owner_kind_t
94 */
100
101/**
102 * @brief Origin of a data dependency edge.
103 * @struct reduct_rvsdg_origin_t
104 */
105typedef struct reduct_rvsdg_origin
106{
107 reduct_rvsdg_owner_kind_t ownerKind; ///< The kind of owner (node or region).
108 union {
109 struct reduct_rvsdg_node* node; ///< The node this origin belongs to.
110 struct reduct_rvsdg_region* region; ///< The region this origin belongs to.
111 };
112 uint16_t index; ///< The index for the associated output/argument.
113 uint16_t useCount; ///< Length of the `uses` list.
114 struct reduct_rvsdg_edge* edges; ///< List of edges originating from this output/argument.
115 struct reduct_rvsdg_origin* next; ///< Next origin in the node/region list.
117
118/**
119 * @brief User of a data dependency edge.
120 * @struct reduct_rvsdg_user_t
121 */
122typedef struct reduct_rvsdg_user
123{
124 reduct_rvsdg_owner_kind_t ownerKind; ///< The kind of owner (node or region).
125 union {
126 struct reduct_rvsdg_node* node; ///< The node this user belongs to.
127 struct reduct_rvsdg_region* region; ///< The region this user belongs to.
128 };
129 uint16_t index; ///< The index for the associated input/result.
130 struct reduct_rvsdg_edge* edge; ///< The single edge connecting to this input's/result's origin.
131 struct reduct_rvsdg_user* next; ///< Next user in the node/region list.
133
134/**
135 * @brief Edge structure representing a data dependency.
136 * @struct reduct_rvsdg_edge_t
137 */
138typedef struct reduct_rvsdg_edge
139{
140 struct reduct_rvsdg_origin* origin; ///< The node where the edge originates.
141 struct reduct_rvsdg_user* user; ///< The node where the edge ends.
142 struct reduct_rvsdg_edge* next; ///< The next edge in the list.
143 struct reduct_rvsdg_edge* prev; ///< The previous edge in the list.
145
146/**
147 * @brief Node type.
148 */
150#define REDUCT_RVSDG_NODE_TYPE_INVALID 0 ///< Invalid node type.
151#define REDUCT_RVSDG_NODE_TYPE_SIMPLE_OPCODE 1 ///< Represents a primitive operation (opcode).
152#define REDUCT_RVSDG_NODE_TYPE_SIMPLE_CONST 2 ///< Represents a constant.
153#define REDUCT_RVSDG_NODE_TYPE_GAMMA 3 ///< Represents a branch or decision point.
154#define REDUCT_RVSDG_NODE_TYPE_LAMBDA 4 ///< Represents a function.
155#define REDUCT_RVSDG_NODE_TYPE_PHI 5 ///< Represents a phi node.
156
157/**
158 * @brief Node flags.
159 */
161#define REDUCT_RVSDG_NODE_FLAGS_NONE 0 ///< No flags.
162#define REDUCT_RVSDG_NODE_FLAGS_LAMBDA_VARIADIC (1 << 0) ///< Lambda node is variadic.
163
164/**
165 * @brief Information about a node type.
166 * @struct reduct_rvsdg_node_info_t
167 */
168typedef struct reduct_rvsdg_node_info
169{
170 const char* name; ///< The name of the node type.
171 const char* color; ///< The color of the node type for visualization.
172 uint8_t dataInputOffset; ///< The index where data inputs begin (skipping control inputs).
174
175/**
176 * @brief Get information about a node type.
177 *
178 * @param type The node type.
179 * @return Pointer to the node info structure.
180 */
182
183/**
184 * @brief A node in the RVSDG.
185 * @enum reduct_rvsdg_node_t
186 */
187typedef struct reduct_rvsdg_node
188{
189 reduct_rvsdg_node_type_t type; ///< The type of the node.
190 uint8_t inputCount; ///< Number of input edges.
191 uint8_t regionCount; ///< Number of regions in the node.
192 reduct_rvsdg_node_flags_t flags; ///< Node flags, interpretation depends on node type.
193 uint8_t _reserved[4];
194 struct reduct_rvsdg_user* firstInput; ///< List of input ports.
195 struct reduct_rvsdg_origin* output; ///< The output port.
196 struct reduct_rvsdg_region* firstRegion; ///< List of regions in the node.
197 struct reduct_rvsdg_region* parent; ///< The region this node belongs to.
198 struct reduct_rvsdg_node* next; ///< Next node in the region's list.
199 union {
200 reduct_opcode_t opcode; ///< The opcode associated with the node.
201 reduct_handle_t constant; ///< The constant value associated with the node.
202 };
204
205/**
206 * @brief Represents a computation.
207 * @enum reduct_rvsdg_region_t
208 */
209typedef struct reduct_rvsdg_region
210{
211 uint16_t argumentCount; ///< Number of arguments to the region.
212 uint8_t _reserved[6];
213 reduct_rvsdg_origin_t* firstArgument; ///< List of argument ports.
214 reduct_rvsdg_user_t* result; ///< The result port.
215 struct reduct_rvsdg_node* firstNode; ///< First node in the region.
216 struct reduct_rvsdg_node* lastNode; ///< Last node in the region.
217 struct reduct_rvsdg_node* parent; ///< The node that owns this region.
218 struct reduct_rvsdg_region* next; ///< Next region in the parent node's list.
220
221/**
222 * @brief Allocate a new IR edge.
223 *
224 * @param reduct Pointer to the Reduct structure.
225 * @return The newly allocated edge.
226 */
228
229/**
230 * @brief Connects an origin to a user via an edge.
231 *
232 * @param reduct Pointer to the Reduct structure.
233 * @param origin Pointer to the origin port.
234 * @param user Pointer to the user port.
235 */
237 reduct_rvsdg_user_t* user);
238
239/**
240 * @brief Disconnect an edge from its origin and user.
241 *
242 * @param edge Pointer to the edge to disconnect.
243 */
245
246/**
247 * @brief Allocate a new IR node.
248 *
249 * @param reduct Pointer to the Reduct structure.
250 * @return The newly allocated node.
251 */
253
254/**
255 * @brief Create a simple opcode node.
256 *
257 * @param reduct Pointer to the Reduct structure.
258 * @param region The region to add the node to, or NULL.
259 * @param opcode The opcode to use.
260 * @return The newly allocated node.
261 */
263 reduct_rvsdg_region_t* region, reduct_opcode_t opcode);
264
265/**
266 * @brief Create a simple constant node.
267 *
268 * @param reduct Pointer to the Reduct structure.
269 * @param region The region to add the node to, or NULL.
270 * @param constant The constant to use.
271 * @return The newly allocated node.
272 */
274 reduct_rvsdg_region_t* region, reduct_handle_t constant);
275
276/**
277 * @brief Create a simple unary opcode node.
278 *
279 * @param reduct Pointer to the Reduct structure.
280 * @param region The region to add the node to, or NULL.
281 * @param opcode The opcode to use.
282 * @param input The origin of the input.
283 * @return The newly allocated node.
284 */
286 reduct_opcode_t opcode, struct reduct_rvsdg_origin* input);
287
288/**
289 * @brief Create a simple binary opcode node.
290 *
291 * @param reduct Pointer to the Reduct structure.
292 * @param region The region to add the node to, or NULL.
293 * @param opcode The opcode to use.
294 * @param left The origin of the left input.
295 * @param right The origin of the right input.
296 * @return The newly allocated node.
297 */
299 reduct_rvsdg_region_t* region, reduct_opcode_t opcode, struct reduct_rvsdg_origin* left,
300 struct reduct_rvsdg_origin* right);
301
302/**
303 * @brief Create a simple ternary opcode node.
304 *
305 * @param reduct Pointer to the Reduct structure.
306 * @param region The region to add the node to, or NULL.
307 * @param opcode The opcode to use.
308 * @param a The origin of the first input.
309 * @param b The origin of the second input.
310 * @param c The origin of the third input.
311 * @return The newly allocated node.
312 */
314 reduct_rvsdg_region_t* region, reduct_opcode_t opcode, struct reduct_rvsdg_origin* a, struct reduct_rvsdg_origin* b,
315 struct reduct_rvsdg_origin* c);
316
317/**
318 * @brief Create a lambda node.
319 *
320 * @param reduct Pointer to the Reduct structure.
321 * @param region The region to add the node to, or NULL.
322 * @return The newly allocated node.
323 */
325
326/**
327 * @brief Create a phi node.
328 *
329 * @param reduct Pointer to the Reduct structure.
330 * @param region The region to add the node to, or NULL.
331 * @return The newly allocated node.
332 */
334
335/**
336 * @brief Create a gamma node.
337 *
338 * @param reduct Pointer to the Reduct structure.
339 * @param region The region to add the node to, or NULL.
340 * @param regionCount The number of regions (branches) to create.
341 * @return The newly allocated node.
342 */
344 uint8_t regionCount);
345
346/**
347 * @brief Get an input port of a node by index.
348 *
349 * @param node The node to search.
350 * @param index The index of the input port.
351 * @return The user port, or NULL if not found.
352 */
353REDUCT_API struct reduct_rvsdg_user* reduct_rvsdg_node_get_input(reduct_rvsdg_node_t* node, uint16_t index);
354
355/**
356 * @brief Get the output of the node connected to an input node of a node by index.
357 *
358 * @param node The node to search.
359 * @param index The index of the input port.
360 * @return The origin port, or NULL if not found or not connected.
361 */
362REDUCT_API struct reduct_rvsdg_origin* reduct_rvsdg_node_get_input_origin(reduct_rvsdg_node_t* node, uint16_t index);
363
364/**
365 * @brief Get the node connected to an input node of a node by index.
366 *
367 * @param node The node to search.
368 * @param index The index of the input port.
369 * @return The input node, or NULL if not found or the port is not connected to a node.
370 */
371REDUCT_API struct reduct_rvsdg_node* reduct_rvsdg_node_get_input_node(reduct_rvsdg_node_t* node, uint16_t index);
372
373/**
374 * @brief Redirect all users of a origin to a new origin.
375 *
376 * @param origin The current origin.
377 * @param newOrigin The new origin to redirect users to.
378 */
379REDUCT_API void reduct_rvsdg_origin_redirect_users(struct reduct_rvsdg_origin* origin,
380 struct reduct_rvsdg_origin* newOrigin);
381
382/**
383 * @brief Get an argument port of a region by index.
384 *
385 * @param region The region to search.
386 * @param index The index of the argument port.
387 * @return The origin port, or NULL if not found.
388 */
389REDUCT_API struct reduct_rvsdg_origin* reduct_rvsdg_region_get_argument(reduct_rvsdg_region_t* region, uint16_t index);
390
391/**
392 * @brief Check if a region is an ancestor of another, or if they are the same.
393 *
394 * @param region The region to start from.
395 * @param ancestor The potential ancestor region.
396 * @return true if `ancestor` is an ancestor of (or the same as) `region`.
397 */
399
400/**
401 * @brief Redirect an existing edge from its current origin to a new origin.
402 *
403 * @param edge The edge to redirect.
404 * @param newOrigin The new origin to connect the edge to.
405 */
407
408/**
409 * @brief Wrap a lambda node in a phi node for recursive calls.
410 *
411 * @param reduct Pointer to the Reduct structure.
412 * @param lambda The lambda node to wrap.
413 */
415
416/**
417 * @brief Check if a nodes grandparent is a phi node.
418 *
419 * @param node The node to check.
420 * @return true if the node is nested inside a phi node's region.
421 */
423
424/**
425 * @brief Create a CALL opcode node and connect a callable as its first input.
426 *
427 * @param reduct Pointer to the Reduct structure.
428 * @param region The region to add the call node to.
429 * @param callable The origin representing the function to call.
430 * @return The newly created call node.
431 */
433 reduct_rvsdg_origin_t* callable);
434
435/**
436 * @brief Map a node input index to a region argument index.
437 *
438 * @param node The parent node.
439 * @param region The target region.
440 * @param inputIndex The input index on the node.
441 * @param outArgIndex Pointer to store the mapped argument index.
442 * @return true if the input is mapped to an argument.
443 */
444REDUCT_API bool reduct_rvsdg_node_map_input_to_argument(reduct_rvsdg_node_t* node, struct reduct_rvsdg_region* region,
445 uint16_t inputIndex, uint16_t* outArgIndex);
446
447/**
448 * @brief Map a region argument index to an input index of the parent node.
449 *
450 * @param node The parent node.
451 * @param region The region containing the argument.
452 * @param argIndex The argument index within the region.
453 * @param outInputIndex Pointer to store the mapped input index.
454 * @return true if the argument is mapped from an input.
455 */
456REDUCT_API bool reduct_rvsdg_node_map_argument_to_input(reduct_rvsdg_node_t* node, struct reduct_rvsdg_region* region,
457 uint16_t argIndex, uint16_t* outInputIndex);
458
459/**
460 * @brief Check if an origin is a recursion target for a given phi node.
461 *
462 * @param node The phi node.
463 * @param origin The origin to check.
464 * @return true if the origin is a recursion target.
465 */
466REDUCT_API bool reduct_rvsdg_node_is_recur_origin(reduct_rvsdg_node_t* node, struct reduct_rvsdg_origin* origin);
467
468/**
469 * @brief Allocate a new IR region.
470 *
471 * @param reduct Pointer to the Reduct structure.
472 * @return The newly allocated region.
473 */
475
476/**
477 * @brief Allocate a new IR user port.
478 *
479 * @param reduct Pointer to the Reduct structure.
480 * @return The newly allocated user port.
481 */
483
484/**
485 * @brief Allocate a new IR origin port.
486 *
487 * @param reduct Pointer to the Reduct structure.
488 * @return The newly allocated origin port.
489 */
491
492/**
493 * @brief Add a new input port to a node.
494 *
495 * @param reduct Pointer to the Reduct structure.
496 * @param node The node to add the input to.
497 * @return The newly created user port.
498 */
500
501/**
502 * @brief Add a new region to a node.
503 *
504 * @param reduct Pointer to the Reduct structure.
505 * @param node The node to add the region to.
506 * @return The newly created region.
507 */
509
510/**
511 * @brief Add a new argument port to a region.
512 *
513 * @param reduct Pointer to the Reduct structure.
514 * @param region The region to add the argument to.
515 * @return The newly created origin port.
516 */
518 reduct_rvsdg_region_t* region);
519
520/**
521 * @brief Adds a node to a region.
522 *
523 * @param region Pointer to the region to add the node to.
524 * @param node Pointer to the node to add.
525 */
527
528/**
529 * @brief Removes a node from its region.
530 *
531 * @param node Pointer to the node to remove.
532 */
534
535/**
536 * @brief Removes from the region and disconnects from any connections a node and any nodes connected to its input.
537 *
538 * @param reduct Pointer to the Reduct structure.
539 * @param node Pointer to the node to delete.
540 */
541REDUCT_API void reduct_rvsdg_node_delete(struct reduct* reduct, reduct_rvsdg_node_t* node);
542
543/**
544 * @brief Check if two nodes are structurally identical.
545 *
546 * @param reduct Pointer to the Reduct structure.
547 * @param nodeA First node.
548 * @param nodeB Second node.
549 * @return true if the nodes are identical, false otherwise.
550 */
552 reduct_rvsdg_node_t* nodeB);
553
554/**
555 * @brief Lift an origin from an outer region to an inner region, creating a new argument in the inner region and
556 * connecting it to the outer origin.
557 *
558 * @param reduct Pointer to the Reduct structure.
559 * @param region The inner region to lift the origin into.
560 * @param outerValue The origin in the outer region to lift.
561 * @return The new origin in the inner region representing the lifted value.
562 */
564 reduct_rvsdg_origin_t* outerValue);
565
566/**
567 * @brief Recursively copy a node.
568 *
569 * @param reduct Pointer to the Reduct structure.
570 * @param region The region to add the copy to, or NULL.
571 * @param node The node to copy.
572 * @return The newly copied node.
573 */
574REDUCT_API struct reduct_rvsdg_node* reduct_rvsdg_node_copy(struct reduct* reduct, reduct_rvsdg_region_t* region,
575 struct reduct_rvsdg_node* node);
576
577/** @} */
578
579#endif
#define REDUCT_API
Definition defs.h:24
reduct_opcode_t
Opcode enumeration.
Definition opcode.h:50
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 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 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:160
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 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:96
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 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 bool reduct_rvsdg_node_map_argument_to_input(reduct_rvsdg_node_t *node, 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_node * reduct_rvsdg_node_copy(struct reduct *reduct, reduct_rvsdg_region_t *region, struct reduct_rvsdg_node *node)
Recursively copy a node.
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:149
REDUCT_API reduct_rvsdg_node_t * reduct_rvsdg_node_new_gamma(struct reduct *reduct, reduct_rvsdg_region_t *region, uint8_t regionCount)
Create a gamma node.
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:97
@ REDUCT_RVSDG_OWNER_REGION
Definition rvsdg.h:98
Bytecode instruction format.
Handle type.
Definition defs.h:119
Edge structure representing a data dependency.
Definition rvsdg.h:139
struct reduct_rvsdg_edge * next
The next edge in the list.
Definition rvsdg.h:142
struct reduct_rvsdg_edge * prev
The previous edge in the list.
Definition rvsdg.h:143
struct reduct_rvsdg_origin * origin
The node where the edge originates.
Definition rvsdg.h:140
struct reduct_rvsdg_user * user
The node where the edge ends.
Definition rvsdg.h:141
Information about a node type.
Definition rvsdg.h:169
const char * color
The color of the node type for visualization.
Definition rvsdg.h:171
const char * name
The name of the node type.
Definition rvsdg.h:170
uint8_t dataInputOffset
The index where data inputs begin (skipping control inputs).
Definition rvsdg.h:172
struct reduct_rvsdg_user * firstInput
List of input ports.
Definition rvsdg.h:194
struct reduct_rvsdg_region * parent
The region this node belongs to.
Definition rvsdg.h:197
reduct_rvsdg_node_type_t type
The type of the node.
Definition rvsdg.h:189
uint8_t inputCount
Number of input edges.
Definition rvsdg.h:190
uint8_t regionCount
Number of regions in the node.
Definition rvsdg.h:191
reduct_handle_t constant
The constant value associated with the node.
Definition rvsdg.h:201
reduct_rvsdg_node_flags_t flags
Node flags, interpretation depends on node type.
Definition rvsdg.h:192
struct reduct_rvsdg_node * next
Next node in the region's list.
Definition rvsdg.h:198
struct reduct_rvsdg_region * firstRegion
List of regions in the node.
Definition rvsdg.h:196
reduct_opcode_t opcode
The opcode associated with the node.
Definition rvsdg.h:200
struct reduct_rvsdg_origin * output
The output port.
Definition rvsdg.h:195
Origin of a data dependency edge.
Definition rvsdg.h:106
struct reduct_rvsdg_region * region
The region this origin belongs to.
Definition rvsdg.h:110
uint16_t useCount
Length of the uses list.
Definition rvsdg.h:113
struct reduct_rvsdg_origin * next
Next origin in the node/region list.
Definition rvsdg.h:115
struct reduct_rvsdg_edge * edges
List of edges originating from this output/argument.
Definition rvsdg.h:114
uint16_t index
The index for the associated output/argument.
Definition rvsdg.h:112
struct reduct_rvsdg_node * node
The node this origin belongs to.
Definition rvsdg.h:109
reduct_rvsdg_owner_kind_t ownerKind
The kind of owner (node or region).
Definition rvsdg.h:107
struct reduct_rvsdg_region * next
Next region in the parent node's list.
Definition rvsdg.h:218
uint16_t argumentCount
Number of arguments to the region.
Definition rvsdg.h:211
reduct_rvsdg_origin_t * firstArgument
List of argument ports.
Definition rvsdg.h:213
reduct_rvsdg_user_t * result
The result port.
Definition rvsdg.h:214
struct reduct_rvsdg_node * parent
The node that owns this region.
Definition rvsdg.h:217
struct reduct_rvsdg_node * firstNode
First node in the region.
Definition rvsdg.h:215
struct reduct_rvsdg_node * lastNode
Last node in the region.
Definition rvsdg.h:216
User of a data dependency edge.
Definition rvsdg.h:123
uint16_t index
The index for the associated input/result.
Definition rvsdg.h:129
struct reduct_rvsdg_node * node
The node this user belongs to.
Definition rvsdg.h:126
struct reduct_rvsdg_region * region
The region this user belongs to.
Definition rvsdg.h:127
reduct_rvsdg_owner_kind_t ownerKind
The kind of owner (node or region).
Definition rvsdg.h:124
struct reduct_rvsdg_user * next
Next user in the node/region list.
Definition rvsdg.h:131
struct reduct_rvsdg_edge * edge
The single edge connecting to this input's/result's origin.
Definition rvsdg.h:130