2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Loop datastructure and access functions -- private stuff.
9 * @author Goetz Lindenmaier
12 #ifndef FIRM_ANA_IRLOOP_T_H
13 #define FIRM_ANA_IRLOOP_T_H
15 #include "firm_common.h"
16 #include "irgraph_t.h"
21 * The loops data structure.
23 * The loops data structure represents circles in the intermediate
24 * representation. It does not represent loops in the terms of a
26 * Each ir_graph can contain one outermost loop data structure.
27 * loop is the entry point to the nested loops.
28 * The loop data structure contains a field indicating the depth of
29 * the loop within the nesting. Further it contains a list of the
30 * loops with nesting depth -1. Finally it contains a list of all
34 firm_kind kind; /**< A type tag, set to k_ir_loop. */
35 unsigned depth; /**< Nesting depth */
36 struct ir_loop *outer_loop; /**< The outer loop */
37 loop_element *children; /**< Mixed flexible array: Contains sons and loop_nodes */
38 void *link; /**< link field. */
40 long loop_nr; /**< A unique node number for each loop node to make output
46 * Allocates a new loop as son of father on the given obstack.
47 * If father is equal NULL, a new root loop is created.
49 ir_loop *alloc_loop(ir_loop *father, struct obstack *obst);
51 /** Add a son loop to a father loop. */
52 void add_loop_son(ir_loop *loop, ir_loop *son);
54 /** Add a node to a loop. */
55 void add_loop_node(ir_loop *loop, ir_node *n);
57 /** Add an IR graph to a loop. */
58 void add_loop_irg(ir_loop *loop, ir_graph *irg);
60 /** Sets the loop a node belonging to. */
61 void set_irn_loop(ir_node *n, ir_loop *loop);
64 * Mature all loops by removing the flexible arrays of a loop tree
65 * and putting them on the given obstack.
67 void mature_loops(ir_loop *loop, struct obstack *obst);
69 /* -------- inline functions -------- */
71 static inline int _is_ir_loop(const void *thing)
73 return get_kind(thing) == k_ir_loop;
76 static inline void _set_irg_loop(ir_graph *irg, ir_loop *loop)
82 static inline ir_loop *_get_irg_loop(const ir_graph *irg)
88 static inline ir_loop *_get_loop_outer_loop(const ir_loop *loop)
90 assert(_is_ir_loop(loop));
91 return loop->outer_loop;
94 static inline unsigned _get_loop_depth(const ir_loop *loop)
96 assert(_is_ir_loop(loop));
100 /* Uses temporary information to get the loop */
101 static inline ir_loop *_get_irn_loop(const ir_node *n)
106 #define is_ir_loop(thing) _is_ir_loop(thing)
107 #define set_irg_loop(irg, loop) _set_irg_loop(irg, loop)
108 #define get_irg_loop(irg) _get_irg_loop(irg)
109 #define get_loop_outer_loop(loop) _get_loop_outer_loop(loop)
110 #define get_loop_depth(loop) _get_loop_depth(loop)
111 #define get_irn_loop(n) _get_irn_loop(n)