-ir_loop *new_loop (void) {
- ir_loop *father, *son;
-
- father = current_loop;
-
- son = (ir_loop *) obstack_alloc (outermost_ir_graph->obst, sizeof (ir_loop));
- memset (son, 0, sizeof (ir_loop));
- son->kind = k_ir_loop;
- son->children = NEW_ARR_F (loop_element, 0);
- son->n_nodes = 0;
- son->n_sons=0;
- if (father) {
- son->outer_loop = father;
- add_loop_son(father, son);
- son->depth = father->depth+1;
- if (son->depth > max_loop_depth) max_loop_depth = son->depth;
- } else { /* The root loop */
- son->outer_loop = son;
- son->depth = 0;
- }
-
-#ifdef DEBUG_libfirm
- son->loop_nr = get_irp_new_node_nr();
- son->link = NULL;
-#endif
-
- current_loop = son;
- return father;
-}
-
-#if 0
-/* Finishes the datastructures, copies the arrays to the obstack
- of current_ir_graph.
- A. Schoesser: Caution: loop -> sons is gone. */
-static void mature_loop (ir_loop *loop) {
- ir_loop **new_sons;
-
- new_sons = NEW_ARR_D (ir_loop *, current_ir_graph->obst, ARR_LEN(loop->sons));
- memcpy (new_sons, loop->sons, sizeof (ir_loop *) * ARR_LEN(loop->sons));
- DEL_ARR_F(loop->sons);
- loop->sons = new_sons;
-}
-#endif
-
-/* Returns outer loop, itself if outermost. */
-ir_loop *(get_loop_outer_loop)(const ir_loop *loop) {
- return _get_loop_outer_loop(loop);
-}
-
-/* Returns nesting depth of this loop */
-int (get_loop_depth)(const ir_loop *loop) {
- return _get_loop_depth(loop);
-}
-
-/* Returns the number of inner loops */
-int (get_loop_n_sons)(const ir_loop *loop) {
- return _get_loop_n_sons(loop);
-}
-
-/* Returns the pos`th loop_node-child *
- * TODO: This method isn`t very efficient ! *
- * Returns NULL if there isn`t a pos`th loop_node */
-ir_loop *get_loop_son (ir_loop *loop, int pos) {
- int child_nr = 0, loop_nr = -1;
-
- assert(loop && loop->kind == k_ir_loop);
- while(child_nr < ARR_LEN(loop->children))
- {
- if(*(loop -> children[child_nr].kind) == k_ir_loop)
- loop_nr++;
- if(loop_nr == pos)
- return(loop -> children[child_nr].son);
- child_nr++;
- }
- return NULL;
-}
-
-/* Use EXCLUSIVELY this function to add sons, otherwise the loop->n_sons
- is invalid! */
-
-void
-add_loop_son(ir_loop *loop, ir_loop *son) {
- loop_element lson;
- lson.son = son;
- assert(loop && loop->kind == k_ir_loop);
- assert(get_kind(son) == k_ir_loop);
- ARR_APP1 (loop_element, loop->children, lson);
- loop -> n_sons++;
-}
-
-/* Returns the number of nodes in the loop */
-int get_loop_n_nodes (ir_loop *loop) {
- assert(loop); assert(loop->kind == k_ir_loop);
- return loop -> n_nodes;
-/* return ARR_LEN(loop->nodes); */
-}
-
-/* Returns the pos`th ir_node-child *
- * TODO: This method isn`t very efficient ! *
- * Returns NULL if there isn`t a pos`th ir_node */
-ir_node *get_loop_node (ir_loop *loop, int pos) {
- int child_nr, node_nr = -1;
-
- assert(loop && loop->kind == k_ir_loop);
- assert(pos < get_loop_n_nodes(loop));
-
- for (child_nr = 0; child_nr < ARR_LEN(loop->children); child_nr++) {
- if(*(loop -> children[child_nr].kind) == k_ir_node)
- node_nr++;
- if(node_nr == pos)
- return(loop -> children[child_nr].node);
- }
-
- assert(0 && "no child at pos found");
- return NULL;
-}
-
-/* Use EXCLUSIVELY this function to add nodes, otherwise the loop->n_nodes
- is invalid! */
-
-void
-add_loop_node(ir_loop *loop, ir_node *n) {
- loop_element ln;
- ln.node = n;
- assert(loop && loop->kind == k_ir_loop);
- assert(get_kind(n) == k_ir_node || get_kind(n) == k_ir_graph); /* used in callgraph.c */
- ARR_APP1 (loop_element, loop->children, ln);
- loop->n_nodes++;
-}
-
-/* Returns the number of elements contained in loop. */
-int get_loop_n_elements (const ir_loop *loop) {
- assert(loop && loop->kind == k_ir_loop);
- return(ARR_LEN(loop->children));
-}
-
-/*
- Returns the pos`th loop element.
- This may be a loop_node or a ir_node. The caller of this function has
- to check the *(loop_element.kind) field for "k_ir_node" or "k_ir_loop"
- and then select the appropriate "loop_element.node" or "loop_element.son".
-*/
-
-loop_element get_loop_element(const ir_loop *loop, int pos) {
- assert(loop && loop->kind == k_ir_loop && pos < ARR_LEN(loop->children));
- return(loop -> children[pos]);
-}
-
-int get_loop_element_pos(const ir_loop *loop, void *le) {
- int i, n;
- assert(loop && loop->kind == k_ir_loop);
-
- n = get_loop_n_elements(loop);
- for (i = 0; i < n; i++)
- if (get_loop_element(loop, i).node == le) return i;
- return -1;
-}
-
-int get_loop_loop_nr(const ir_loop *loop) {
- assert(loop && loop->kind == k_ir_loop);
-#ifdef DEBUG_libfirm
- return loop->loop_nr;
-#else
- return (int)loop;
-#endif
-}
-
-
-/** A field to connect additional information to a loop. Only valid
- if libfirm_debug is set. */
-void set_loop_link (ir_loop *loop, void *link) {
- assert(loop && loop->kind == k_ir_loop);
- loop->link = link;
-}
-void *get_loop_link (const ir_loop *loop) {
- assert(loop && loop->kind == k_ir_loop);
- return loop->link;
-}
-
-int (is_ir_loop)(const void *thing) {
- return _is_ir_loop(thing);
-}
-
-/* The outermost loop is remarked in the surrounding graph. */
-void (set_irg_loop)(ir_graph *irg, ir_loop *loop) {
- _set_irg_loop(irg, loop);
-}