summaryrefslogtreecommitdiffhomepage
path: root/ir/be/betranshlp.c
diff options
context:
space:
mode:
authorChristoph Mallon <mallon@cs.uni-saarland.de>2015-06-22 08:49:52 +0200
committerChristoph Mallon <mallon@cs.uni-saarland.de>2015-06-26 23:40:47 +0200
commitd8fb534de0740baa44800b82c99d68861c56f03c (patch)
tree5b8b340dafc6d3941ec1598491698470664fd85e /ir/be/betranshlp.c
parent5f4cf6e027fe4f96450ef5a3c5c5f834253a2264 (diff)
be: Simplify process_ops_in_block().
Use a flexible array, so we can iterate over the linked list only once instead of twice.
Diffstat (limited to 'ir/be/betranshlp.c')
-rw-r--r--ir/be/betranshlp.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/ir/be/betranshlp.c b/ir/be/betranshlp.c
index 8252919..e0be216 100644
--- a/ir/be/betranshlp.c
+++ b/ir/be/betranshlp.c
@@ -661,34 +661,27 @@ static int cmp_call_dependency(const void *c1, const void *c2)
*/
static void process_ops_in_block(ir_node *block, void *data)
{
- ir_nodemap *map = (ir_nodemap*)data;
- unsigned n_nodes = 0;
- for (ir_node *node = (ir_node*)get_irn_link(block); node != NULL;
- node = (ir_node*)get_irn_link(node)) {
- ++n_nodes;
- }
- if (n_nodes == 0)
- return;
+ ir_nodemap *const map = (ir_nodemap*)data;
- ir_node **nodes = XMALLOCN(ir_node*, n_nodes);
- unsigned n = 0;
- for (ir_node *node = (ir_node*)get_irn_link(block); node != NULL;
- node = (ir_node*)get_irn_link(node)) {
- nodes[n++] = node;
+ ir_node **nodes = NEW_ARR_F(ir_node*, 0);
+ for (ir_node *node = block; (node = (ir_node*)get_irn_link(node));) {
+ ARR_APP1(ir_node*, nodes, node);
}
- assert(n == n_nodes);
-
- /* order nodes according to their data dependencies */
- QSORT(nodes, n_nodes, cmp_call_dependency);
- /* remember the calculated dependency into a phase */
- for (n = n_nodes-1; n > 0; --n) {
- ir_node *node = nodes[n];
- ir_node *pred = nodes[n-1];
+ unsigned const n_nodes = ARR_LEN(nodes);
+ if (n_nodes != 0) {
+ /* order nodes according to their data dependencies */
+ QSORT(nodes, n_nodes, cmp_call_dependency);
- ir_nodemap_insert(map, node, pred);
+ /* remember the calculated dependency into a phase */
+ for (unsigned n = n_nodes - 1; n > 0; --n) {
+ ir_node *const node = nodes[n];
+ ir_node *const pred = nodes[n - 1];
+ ir_nodemap_insert(map, node, pred);
+ }
}
- free(nodes);
+
+ DEL_ARR_F(nodes);
}
struct be_stackorder_t {