/*
- * Project: libFIRM
- * File name: ir/ana/structure.c
- * Purpose: Structure Analysis
- * Author: Michael Beck
- * Modified by:
- * Created: 5.4.2007
- * CVS-ID: $Id: $
- * Copyright: (c) 2007 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
+ * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
+ *
+ * This file is part of libFirm.
+ *
+ * This file may be distributed and/or modified under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation and appearing in the file LICENSE.GPL included in the
+ * packaging of this file.
+ *
+ * Licensees holding valid libFirm Professional Edition licenses may use
+ * this file in accordance with the libFirm Commercial License.
+ * Agreement provided with the Software.
+ *
+ * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+ * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE.
+ */
+
+/**
+ * @file
+ * @brief Structure Analysis
+ * @author Michael Beck
+ * @date 5.4.2007
+ * @version $Id$
*/
-#ifdef HAVE_CONFIG_H
#include "config.h"
-#endif
#include "firm_common.h"
#include "irnode_t.h"
#include "irtools.h"
#include "irgwalk.h"
#include "array.h"
-#include "irphase_t.h"
#include "irdump.h"
#include "debug.h"
};
/* The debug handle. */
-DEBUG_ONLY(firm_dbg_module_t *dbg;)
+DEBUG_ONLY(static firm_dbg_module_t *dbg;)
/**
* Returns the link of a region.
}
/**
- * Return non-if a given firm thing is a region.
+ * Return non-zero if a given firm thing is a region.
*/
int is_region(const void *thing) {
const firm_kind *kind = thing;
}
/**
- * Return the number of predecessors in a region.
+ * Return the number of predecessors of a region.
*/
int get_region_n_preds(const ir_region *reg) {
return ARR_LEN(reg->pred);
/** Walker environment. */
typedef struct walk_env {
- struct obstack *obst; /**< an obstack to allocate from. */
+ struct obstack *obst; /**< An obstack to allocate from. */
ir_region **post; /**< The list of all currently existent top regions. */
- unsigned l_post; /**< length of the allocated regions array. */
+ unsigned l_post; /**< The length of the allocated regions array. */
unsigned premax; /**< maximum pre counter */
unsigned postmax; /**< maximum post counter */
- ir_node *start_block; /**< the start block of the graph. */
- ir_node *end_block; /**< the end block of the graph. */
+ ir_node *start_block; /**< The start block of the graph. */
+ ir_node *end_block; /**< The end block of the graph. */
} walk_env;
/**
ir_region *reg;
/* Allocate a Block wrapper */
- reg = obstack_alloc(env->obst, sizeof(*reg));
+ reg = OALLOC(env->obst, ir_region);
reg->kind = k_ir_region;
reg->type = ir_rk_BasicBlock;
reg->parent = NULL;
} /* wrap_BasicBlocks */
/**
- * Create the pred and succ edges for Block wrapper.
+ * Post-walker: Create the pred and succ edges for Block wrapper.
* Kill edges to the Start and End blocks.
*/
static void update_BasicBlock_regions(ir_node *blk, void *ctx) {
int i, j, len;
if (blk == env->start_block) {
- /* handle Firm's self loop */
+ /* handle Firm's self loop: Start block has no predecessors */
reg->pred = NEW_ARR_D(ir_region *, env->obst, 0);
} else {
len = get_Block_n_cfgpreds(blk);
ARR_SHRINKLEN(reg->succ, j);
} /* update_BasicBlock_regions */
-/** Allocate a new region of a obstack */
+/** Allocate a new region on an obstack */
#define ALLOC_REG(obst, reg, tp) \
do { \
- (reg) = obstack_alloc((obst), sizeof(*(reg))); \
+ (reg) = OALLOC((obst), ir_region); \
(reg)->kind = k_ir_region; \
(reg)->type = tp; \
(reg)->parent = NULL; \
} /* new_NaturalLoop */
/**
- * Return true if a is an ancestor of b in DFS search.
+ * Return true if region a is an ancestor of region b in DFS search.
*/
static int is_ancestor(const ir_region *a, const ir_region *b) {
return (a->prenum <= b->prenum && a->postnum > b->postnum);
}
/**
- * Return true if region pred is a predecessor of region n.
+ * Return true if region pred is a predecessor of region n.
*/
static int pred_of(const ir_region *pred, const ir_region *n) {
int i;
}
/**
- * Return true if region succ is a successor of region n.
+ * Return true if region succ is a successor of region n.
*/
static int succ_of(const ir_region *succ, const ir_region *n) {
int i;
}
/**
- * Reverse linked list.
+ * Reverse a linked list of regions.
*/
static struct ir_region *reverse_list(ir_region *n) {
ir_region *prev = NULL, *next;
}
/**
- * Clear all links on a list. Needed, because we expect cleared links-
+ * Clear all links on a list. Needed, because we expect cleared links.
*/
static void clear_list(ir_region *list) {
ir_region *next;
replace_pred(succ, reg);
}
- /* second third: replace all succs in predessors */
+ /* third step: replace all succs in predessors */
for (i = get_region_n_preds(reg) - 1; i >= 0; --i) {
ir_region *pred = get_region_pred(reg, i);
ir_reg_tree *construct_region_tree(ir_graph *irg) {
walk_env env;
ir_graph *rem = current_ir_graph;
- ir_reg_tree *res = xmalloc(sizeof(*res));
+ ir_reg_tree *res = XMALLOC(ir_reg_tree);
obstack_init(&res->obst);
do {
ir_region *reg, *n = env.post[postctr];
do {
- if (n->parent) {
+ if (n->parent != NULL) {
/* already folded */
break;
}