2 * Author: Christian Wuerdig
4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
8 * Performs lowering of perm nodes and spill/reload optimization.
24 #include "bechordal_t.h"
25 #include "besched_t.h"
28 #include "iredges_t.h"
39 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
41 /* collect static data about perms */
42 typedef struct _perm_stat_t {
43 const arch_register_class_t *cls; /**< the current register class */
44 int *perm_size_ar; /**< the sizes of all perms in an irg */
45 int *real_perm_size_ar; /**< the sizes of all perms in an irg */
46 int *chain_len_ar; /**< the sizes of all chains for all perms */
47 int *cycle_len_ar; /**< the siyes of all cycles for all perms */
48 int num_perms; /**< number of all perms */
49 int num_real_perms; /**< number of all perms */
50 int num_chains; /**< the number of all chains */
51 int num_cycles; /**< the number of all cycles */
54 /* lowering walker environment */
55 typedef struct _lower_env_t {
56 be_chordal_env_t *chord_env;
61 DEBUG_ONLY(firm_dbg_module_t *dbg_module;)
64 /* holds a perm register pair */
65 typedef struct _reg_pair_t {
66 const arch_register_t *in_reg; /**< a perm IN register */
67 ir_node *in_node; /**< the in node to which the register belongs */
69 const arch_register_t *out_reg; /**< a perm OUT register */
70 ir_node *out_node; /**< the out node to which the register belongs */
72 int checked; /**< indicates whether the pair was check for cycle or not */
75 typedef enum _perm_type_t {
82 /* structure to represent cycles or chains in a perm */
83 typedef struct _perm_cycle_t {
84 const arch_register_t **elems; /**< the registers in the cycle */
85 int n_elems; /**< number of elements in the cycle */
86 perm_type_t type; /**< type (CHAIN or CYCLE) */
89 /* Compare the in registers of two register pairs */
90 static int compare_reg_pair(const void *a, const void *b) {
91 const reg_pair_t *pair_a = a;
92 const reg_pair_t *pair_b = b;
94 if (pair_a->in_reg->index > pair_b->in_reg->index)
100 /* returns the number register pairs marked as checked */
101 static int get_n_checked_pairs(reg_pair_t *pairs, int n) {
102 int i, n_checked = 0;
104 for (i = 0; i < n; i++) {
105 if (pairs[i].checked)
113 * Gets the node corresponding to a register from an array of register pairs.
114 * NOTE: The given registers pairs and the register to look for must belong
115 * to the same register class.
117 * @param pairs The array of register pairs
118 * @param n The number of pairs
119 * @param reg The register to look for
120 * @param in_out 0 == look for IN register, 1 == look for OUT register
121 * @return The corresponding node or NULL if not found
123 static ir_node *get_node_for_register(reg_pair_t *pairs, int n, const arch_register_t *reg, int in_out) {
127 for (i = 0; i < n; i++) {
128 /* out register matches */
129 if (pairs[i].out_reg->index == reg->index)
130 return pairs[i].out_node;
134 for (i = 0; i < n; i++) {
135 /* in register matches */
136 if (pairs[i].in_reg->index == reg->index)
137 return pairs[i].in_node;
145 * Gets the index in the register pair array where the in/out register
146 * corresponds to reg_idx.
148 * @param pairs The array of register pairs
149 * @param n The number of pairs
150 * @param reg The register index to look for
151 * @param in_out 0 == look for IN register, 1 == look for OUT register
152 * @return The corresponding index in pairs or -1 if not found
154 static int get_pairidx_for_regidx(reg_pair_t *pairs, int n, int reg_idx, int in_out) {
158 for (i = 0; i < n; i++) {
159 /* out register matches */
160 if (pairs[i].out_reg->index == reg_idx)
165 for (i = 0; i < n; i++) {
166 /* in register matches */
167 if (pairs[i].in_reg->index == reg_idx)
176 * Gets an array of register pairs and tries to identify a cycle or chain starting
179 * @param cycle Variable to hold the cycle
180 * @param pairs Array of register pairs
181 * @param start Index to start
182 * @return The cycle or chain
184 static perm_cycle_t *get_perm_cycle(perm_cycle_t *cycle, reg_pair_t *pairs, int n, int start) {
185 int head = pairs[start].in_reg->index;
186 int cur_idx = pairs[start].out_reg->index;
187 int cur_pair_idx = start;
188 int n_pairs_done = get_n_checked_pairs(pairs, n);
190 perm_type_t cycle_tp = PERM_CYCLE;
192 /* We could be right in the middle of a chain, so we need to find the start */
193 while (head != cur_idx) {
194 /* goto previous register in cycle or chain */
195 cur_pair_idx = get_pairidx_for_regidx(pairs, n, head, 1);
197 if (cur_pair_idx < 0) {
198 cycle_tp = PERM_CHAIN;
202 head = pairs[cur_pair_idx].in_reg->index;
203 start = cur_pair_idx;
207 /* assume worst case: all remaining pairs build a cycle or chain */
208 cycle->elems = xcalloc((n - n_pairs_done) * 2, sizeof(cycle->elems[0]));
209 cycle->n_elems = 2; /* initial number of elements is 2 */
210 cycle->elems[0] = pairs[start].in_reg;
211 cycle->elems[1] = pairs[start].out_reg;
212 cycle->type = cycle_tp;
213 cur_idx = pairs[start].out_reg->index;
216 /* check for cycle or end of a chain */
217 while (cur_idx != head) {
218 /* goto next register in cycle or chain */
219 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cur_idx, 0);
221 if (cur_pair_idx < 0)
224 cur_idx = pairs[cur_pair_idx].out_reg->index;
226 /* it's not the first element: insert it */
227 if (cur_idx != head) {
228 cycle->elems[idx++] = pairs[cur_pair_idx].out_reg;
232 /* we are there where we started -> CYCLE */
233 cycle->type = PERM_CYCLE;
237 /* mark all pairs having one in/out register with cycle in common as checked */
238 for (idx = 0; idx < cycle->n_elems; idx++) {
239 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cycle->elems[idx]->index, 0);
241 if (cur_pair_idx >= 0)
242 pairs[cur_pair_idx].checked = 1;
244 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cycle->elems[idx]->index, 1);
246 if (cur_pair_idx >= 0)
247 pairs[cur_pair_idx].checked = 1;
254 * Lowers a perm node. Resolves cycles and creates a bunch of
255 * copy and swap operations to permute registers.
256 * Note: The caller of this function has to make sure, that irn
259 * @param irn The perm node
260 * @param block The block the perm node belongs to
261 * @param walk_env The environment
263 static void lower_perm_node(ir_node *irn, void *walk_env) {
264 const arch_register_class_t *reg_class;
265 const arch_env_t *arch_env;
266 lower_env_t *env = walk_env;
267 perm_stat_t **pstat = env->pstat;
270 int n, i, pn, do_copy, j, n_ops;
272 const ir_edge_t *edge;
274 ir_node *sched_point, *block, *in[2];
275 ir_node *arg1, *arg2, *res1, *res2;
276 ir_node *cpyxchg = NULL;
277 DEBUG_ONLY(firm_dbg_module_t *mod;)
279 arch_env = env->chord_env->birg->main_env->arch_env;
280 do_copy = env->do_copy;
281 DEBUG_ONLY(mod = env->dbg_module;)
282 block = get_nodes_block(irn);
285 Get the schedule predecessor node to the perm
286 NOTE: This works with auto-magic. If we insert the
287 new copy/exchange nodes after this node, everything
290 sched_point = sched_prev(irn);
291 DBG((mod, LEVEL_1, "sched point is %+F\n", sched_point));
292 assert(sched_point && "Perm is not scheduled or has no predecessor");
294 n = get_irn_arity(irn);
295 assert(n == get_irn_n_edges(irn) && "perm's in and out numbers different");
297 reg_class = arch_get_irn_register(arch_env, get_irn_n(irn, 0))->reg_class;
298 pairs = alloca(n * sizeof(pairs[0]));
303 /* determine index in statistics */
304 for (i = 0; i < env->pstat_n; i++) {
305 if (strcmp(pstat[i]->cls->name, reg_class->name) == 0) {
310 assert(pstat_idx >= 0 && "could not determine class index for statistics");
312 pstat[pstat_idx]->num_perms++;
313 pstat[pstat_idx]->perm_size_ar[n - 1]++;
316 /* build the list of register pairs (in, out) */
318 foreach_out_edge(irn, edge) {
319 pairs[i].out_node = get_edge_src_irn(edge);
320 pn = get_Proj_proj(pairs[i].out_node);
321 pairs[i].in_node = get_irn_n(irn, pn);
323 pairs[i].in_reg = arch_get_irn_register(arch_env, pairs[i].in_node);
324 pairs[i].out_reg = arch_get_irn_register(arch_env, pairs[i].out_node);
326 pairs[i].checked = 0;
330 /* sort the register pairs by the indices of the in registers */
331 qsort(pairs, n, sizeof(pairs[0]), compare_reg_pair);
333 /* Mark all equal pairs as checked, and exchange the OUT proj with
335 for (i = 0; i < n; i++) {
336 if (pairs[i].in_reg->index == pairs[i].out_reg->index) {
337 DBG((mod, LEVEL_1, "%+F removing equal perm register pair (%+F, %+F, %s)\n",
338 irn, pairs[i].in_node, pairs[i].out_node, pairs[i].out_reg->name));
340 /* We have to check for a special case:
341 The in-node could be a Proj from a Perm. In this case,
342 we need to correct the projnum */
343 if (is_Perm(arch_env, pairs[i].in_node) && is_Proj(pairs[i].in_node)) {
344 set_Proj_proj(pairs[i].out_node, get_Proj_proj(pairs[i].in_node));
347 /* remove the proj from the schedule */
348 sched_remove(pairs[i].out_node);
350 /* reroute the edges from the proj to the argument */
351 edges_reroute(pairs[i].out_node, pairs[i].in_node, env->chord_env->irg);
353 pairs[i].checked = 1;
357 /* Set do_copy to 0 if it's on but we have no free register */
362 if (env->do_stat && get_n_checked_pairs(pairs, n) < n) {
363 pstat[pstat_idx]->num_real_perms++;
364 pstat[pstat_idx]->real_perm_size_ar[n - 1]++;
365 real_size = n - get_n_checked_pairs(pairs, n);
368 hook_be_block_stat_perm(reg_class->name, reg_class->n_regs, irn, block, n, real_size);
370 /* check for cycles and chains */
371 while (get_n_checked_pairs(pairs, n) < n) {
374 /* go to the first not-checked pair */
375 while (pairs[i].checked) i++;
376 cycle = xcalloc(1, sizeof(*cycle));
377 cycle = get_perm_cycle(cycle, pairs, n, i);
379 DB((mod, LEVEL_1, "%+F: following %s created:\n ", irn, cycle->type == PERM_CHAIN ? "chain" : "cycle"));
380 for (j = 0; j < cycle->n_elems; j++) {
381 DB((mod, LEVEL_1, " %s", cycle->elems[j]->name));
383 DB((mod, LEVEL_1, "\n"));
387 int n_idx = cycle->n_elems - 1;
388 if (cycle->type == PERM_CHAIN) {
389 pstat[pstat_idx]->num_chains++;
390 pstat[pstat_idx]->chain_len_ar[n_idx]++;
393 pstat[pstat_idx]->num_cycles++;
394 pstat[pstat_idx]->cycle_len_ar[n_idx]++;
398 /* We don't need to do anything if we have a Perm with two
399 elements which represents a cycle, because those nodes
400 already represent exchange nodes */
401 if (n == 2 && cycle->type == PERM_CYCLE) {
406 //TODO: - iff PERM_CYCLE && do_copy -> determine free temp reg and insert copy to/from it before/after
407 // the copy cascade (this reduces the cycle into a chain)
409 /* build copy/swap nodes from back to front */
410 for (i = cycle->n_elems - 2; i >= 0; i--) {
411 arg1 = get_node_for_register(pairs, n, cycle->elems[i], 0);
412 arg2 = get_node_for_register(pairs, n, cycle->elems[i + 1], 0);
414 res1 = get_node_for_register(pairs, n, cycle->elems[i], 1);
415 res2 = get_node_for_register(pairs, n, cycle->elems[i + 1], 1);
419 If we have a cycle and don't copy: we need to create exchange nodes
420 NOTE: An exchange node is a perm node with 2 INs and 2 OUTs
421 IN_1 = in node with register i
422 IN_2 = in node with register i + 1
423 OUT_1 = out node with register i + 1
424 OUT_2 = out node with register i
426 if (cycle->type == PERM_CYCLE && !do_copy) {
430 /* At this point we have to handle the following problem: */
432 /* If we have a cycle with more than two elements, then */
433 /* this could correspond to the following Perm node: */
435 /* +----+ +----+ +----+ */
436 /* | r1 | | r2 | | r3 | */
437 /* +-+--+ +-+--+ +--+-+ */
440 /* +-+--------+---------+-+ */
442 /* +-+--------+---------+-+ */
445 /* +-+--+ +-+--+ +--+-+ */
446 /* |Proj| |Proj| |Proj| */
447 /* | r2 | | r3 | | r1 | */
448 /* +----+ +----+ +----+ */
450 /* This node is about to be split up into two 2x Perm's */
451 /* for which we need 4 Proj's and the one additional Proj */
452 /* of the first Perm has to be one IN of the second. So in */
453 /* general we need to create one additional Proj for each */
454 /* "middle" Perm and set this to one in node of the successor */
457 DBG((mod, LEVEL_1, "%+F creating exchange node (%+F, %s) and (%+F, %s) with\n",
458 irn, arg1, cycle->elems[i]->name, arg2, cycle->elems[i + 1]->name));
459 DBG((mod, LEVEL_1, "%+F (%+F, %s) and (%+F, %s)\n",
460 irn, res1, cycle->elems[i]->name, res2, cycle->elems[i + 1]->name));
462 cpyxchg = be_new_Perm(reg_class, env->chord_env->irg, block, 2, in);
466 /* cycle is not done yet */
467 int pidx = get_pairidx_for_regidx(pairs, n, cycle->elems[i]->index, 0);
469 /* create intermediate proj */
470 res1 = new_r_Proj(get_irn_irg(irn), block, cpyxchg, get_irn_mode(res1), 0);
472 /* set as in for next Perm */
473 pairs[pidx].in_node = res1;
481 set_Proj_pred(res2, cpyxchg);
482 set_Proj_proj(res2, 0);
483 set_Proj_pred(res1, cpyxchg);
484 set_Proj_proj(res1, 1);
486 sched_add_after(sched_point, res1);
487 sched_add_after(sched_point, res2);
489 arch_set_irn_register(arch_env, res2, cycle->elems[i + 1]);
490 arch_set_irn_register(arch_env, res1, cycle->elems[i]);
492 /* insert the copy/exchange node in schedule after the magic schedule node (see above) */
493 sched_add_after(sched_point, cpyxchg);
495 DBG((mod, LEVEL_1, "replacing %+F with %+F, placed new node after %+F\n", irn, cpyxchg, sched_point));
497 /* set the new scheduling point */
501 DBG((mod, LEVEL_1, "%+F creating copy node (%+F, %s) -> (%+F, %s)\n",
502 irn, arg1, cycle->elems[i]->name, res2, cycle->elems[i + 1]->name));
504 cpyxchg = be_new_Copy(reg_class, env->chord_env->irg, block, arg1);
505 arch_set_irn_register(arch_env, cpyxchg, cycle->elems[i + 1]);
508 /* remove the proj from the schedule */
511 /* exchange copy node and proj */
512 exchange(res2, cpyxchg);
514 /* insert the copy/exchange node in schedule after the magic schedule node (see above) */
515 sched_add_after(sched_point, cpyxchg);
517 /* set the new scheduling point */
518 sched_point = cpyxchg;
522 hook_be_block_stat_permcycle(reg_class->name, irn, block, cycle->type == PERM_CHAIN, cycle->n_elems, n_ops);
526 free((void *) cycle->elems);
532 /* remove the perm from schedule */
538 static int get_n_out_edges(const ir_node *irn) {
539 const ir_edge_t *edge;
542 foreach_out_edge(irn, edge) {
549 static ir_node *belower_skip_proj(ir_node *irn) {
551 irn = get_Proj_pred(irn);
555 static void fix_in(ir_node *irn, ir_node *old, ir_node *nw) {
558 irn = belower_skip_proj(irn);
559 n = get_irn_arity(irn);
561 for (i = 0; i < n; i++) {
562 if (get_irn_n(irn, i) == old) {
563 set_irn_n(irn, i, nw);
569 static void gen_assure_different_pattern(ir_node *irn, be_irg_t *birg, ir_node *other_different) {
570 const arch_env_t *arch_env = birg->main_env->arch_env;
571 ir_node *in[2], *keep, *cpy, *temp;
572 ir_node *block = get_nodes_block(irn);
573 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, other_different, -1);
574 FIRM_DBG_REGISTER(firm_dbg_module_t *mod, "firm.be.lower");
576 if (arch_irn_is(arch_env, other_different, ignore) || ! mode_is_datab(get_irn_mode(other_different))) {
577 DBG((mod, LEVEL_1, "ignore constraint for %+F because other_irn is ignore or not a datab node\n", irn));
581 /* Make a not spillable copy of the different node */
582 /* this is needed because the different irn could be */
583 /* in block far far away */
584 /* The copy is optimized later if not needed */
586 temp = new_rd_Unknown(birg->irg, get_irn_mode(other_different));
587 cpy = be_new_Copy(cls, birg->irg, block, temp);
588 be_node_set_flags(cpy, BE_OUT_POS(0), arch_irn_flags_dont_spill);
593 /* Let the irn use the copy instead of the old other_different */
594 fix_in(irn, other_different, cpy);
596 /* Add the Keep resp. CopyKeep and reroute the users */
597 /* of the other_different irn in case of CopyKeep. */
598 if (get_n_out_edges(other_different) == 0) {
599 keep = be_new_Keep(cls, birg->irg, block, 2, in);
602 keep = be_new_CopyKeep_single(cls, birg->irg, block, cpy, irn, get_irn_mode(other_different));
603 be_node_set_reg_class(keep, 1, cls);
604 edges_reroute(other_different, keep, birg->irg);
607 /* after rerouting: let the copy point to the other_different irn */
608 set_irn_n(cpy, 0, other_different);
610 DBG((mod, LEVEL_1, "created %+F for %+F to assure should_be_different\n", keep, irn));
614 * Checks if node has a should_be_different constraint in output
615 * and adds a Keep then to assure the constraint.
617 static void assure_different_constraints(ir_node *irn, be_irg_t *birg) {
618 const arch_env_t *arch_env = birg->main_env->arch_env;
619 const arch_register_req_t *req;
620 arch_register_req_t req_temp;
623 req = arch_get_register_req(arch_env, &req_temp, irn, -1);
626 if (arch_register_req_is(req, should_be_different)) {
627 gen_assure_different_pattern(irn, birg, req->other_different);
629 else if (arch_register_req_is(req, should_be_different_from_all)) {
630 n = get_irn_arity(belower_skip_proj(irn));
631 for (i = 0; i < n; i++) {
632 gen_assure_different_pattern(irn, birg, get_irn_n(belower_skip_proj(irn), i));
641 * Calls the functions to assure register constraints.
643 * @param irn The node to be checked for lowering
644 * @param walk_env The walker environment
646 static void assure_constraints_walker(ir_node *irn, void *walk_env) {
650 if (mode_is_datab(get_irn_mode(irn)))
651 assure_different_constraints(irn, walk_env);
659 * Walks over all nodes to assure register constraints.
661 * @param birg The birg structure containing the irg
663 void assure_constraints(be_irg_t *birg) {
664 irg_walk_blkwise_graph(birg->irg, NULL, assure_constraints_walker, birg);
670 * Calls the corresponding lowering function for the node.
672 * @param irn The node to be checked for lowering
673 * @param walk_env The walker environment
675 static void lower_nodes_after_ra_walker(ir_node *irn, void *walk_env) {
676 lower_env_t *env = walk_env;
677 const arch_env_t *arch_env = env->chord_env->birg->main_env->arch_env;
679 if (!is_Block(irn) && !is_Proj(irn)) {
680 if (is_Perm(arch_env, irn)) {
681 lower_perm_node(irn, walk_env);
688 static void lower_print_perm_stat(lower_env_t *env) {
689 int j, total_len_chain, total_len_cycle, total_size_perm, total_size_real_perm;
692 printf("=== IRG: %s ===\n", get_entity_name(get_irg_entity(env->chord_env->irg)));
693 for (i = 0; i < env->pstat_n; i++) {
694 if (env->pstat[i]->num_perms == 0)
697 printf("CLASS: %s\n", env->pstat[i]->cls->name);
698 printf("# total perms: %d (size:num -> 1:%d", env->pstat[i]->num_perms, env->pstat[i]->perm_size_ar[0]);
700 total_size_perm = env->pstat[i]->perm_size_ar[0];
701 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
702 total_size_perm += (j + 1) * env->pstat[i]->perm_size_ar[j];
703 printf(", %d:%d", j + 1, env->pstat[i]->perm_size_ar[j]);
706 printf("avg perm size: %.2f\n", env->pstat[i]->num_perms ? (float)total_size_perm / (float)env->pstat[i]->num_perms : 0);
708 printf("# real perms: %d (size:num -> 1:%d", env->pstat[i]->num_real_perms, env->pstat[i]->real_perm_size_ar[0]);
710 total_size_real_perm = env->pstat[i]->real_perm_size_ar[0];
711 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
712 total_size_real_perm += (j + 1) * env->pstat[i]->real_perm_size_ar[j];
713 printf(", %d:%d", j + 1, env->pstat[i]->real_perm_size_ar[j]);
716 printf("avg real perm size: %.2f\n", env->pstat[i]->num_real_perms ? (float)total_size_real_perm / (float)env->pstat[i]->num_real_perms : 0);
718 printf("# total chains: %d (lenght:num -> 1:%d", env->pstat[i]->num_chains, env->pstat[i]->chain_len_ar[0]);
720 total_len_chain = env->pstat[i]->chain_len_ar[0];
722 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
723 total_len_chain += (j + 1) * env->pstat[i]->chain_len_ar[j];
724 printf(", %d:%d", j + 1, env->pstat[i]->chain_len_ar[j]);
727 printf("avg chain length: %.2f\n", env->pstat[i]->num_chains ? (float)total_len_chain / (float)env->pstat[i]->num_chains : 0);
728 printf("avg chains/perm: %.2f\n", env->pstat[i]->num_real_perms ? (float)env->pstat[i]->num_chains / (float)env->pstat[i]->num_real_perms : 0);
730 printf("# total cycles: %d (length:num -> 1:%d", env->pstat[i]->num_cycles, env->pstat[i]->cycle_len_ar[0]);
732 total_len_cycle = env->pstat[i]->cycle_len_ar[0];
733 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
734 total_len_cycle += (j + 1) * env->pstat[i]->cycle_len_ar[j];
735 printf(", %d:%d", j + 1, env->pstat[i]->cycle_len_ar[j]);
738 printf("avg cycle length: %.2f\n", env->pstat[i]->num_cycles ? (float)total_len_cycle / (float)env->pstat[i]->num_cycles : 0);
739 printf("avg cycles/perm: %.2f\n", env->pstat[i]->num_real_perms ? (float)env->pstat[i]->num_cycles / (float)env->pstat[i]->num_real_perms : 0);
744 * Walks over all blocks in an irg and performs lowering need to be
745 * done after register allocation (e.g. perm lowering).
747 * @param chord_env The chordal environment containing the irg
748 * @param do_copy 1 == resolve cycles with a free reg if available
750 void lower_nodes_after_ra(be_chordal_env_t *chord_env, int do_copy, int do_stat) {
753 env.chord_env = chord_env;
754 env.do_copy = do_copy;
755 env.do_stat = do_stat;
756 FIRM_DBG_REGISTER(env.dbg_module, "firm.be.lower");
758 /* if we want statistics: allocate memory for the data and initialize with 0 */
760 const arch_isa_t *isa = chord_env->birg->main_env->arch_env->isa;
761 int i, n = arch_isa_get_n_reg_class(isa);
763 env.pstat = alloca(n * sizeof(env.pstat[0]));
766 for (i = 0; i < n; i++) {
767 const arch_register_class_t *cls = arch_isa_get_reg_class(isa, i);
768 int n_regs = cls->n_regs;
770 env.pstat[i] = alloca(sizeof(*(env.pstat[0])));
771 memset(env.pstat[i], 0, sizeof(*(env.pstat[0])));
773 env.pstat[i]->perm_size_ar = alloca(n_regs * sizeof(env.pstat[i]->perm_size_ar[0]));
774 env.pstat[i]->real_perm_size_ar = alloca(n_regs * sizeof(env.pstat[i]->real_perm_size_ar[0]));
775 env.pstat[i]->chain_len_ar = alloca(n_regs * sizeof(env.pstat[i]->chain_len_ar[0]));
776 env.pstat[i]->cycle_len_ar = alloca(n_regs * sizeof(env.pstat[i]->cycle_len_ar[0]));
778 memset(env.pstat[i]->perm_size_ar, 0, n_regs * sizeof(env.pstat[i]->perm_size_ar[0]));
779 memset(env.pstat[i]->real_perm_size_ar, 0, n_regs * sizeof(env.pstat[i]->real_perm_size_ar[0]));
780 memset(env.pstat[i]->chain_len_ar, 0, n_regs * sizeof(env.pstat[i]->chain_len_ar[0]));
781 memset(env.pstat[i]->cycle_len_ar, 0, n_regs * sizeof(env.pstat[i]->cycle_len_ar[0]));
783 env.pstat[i]->cls = cls;
787 irg_walk_blkwise_graph(chord_env->irg, NULL, lower_nodes_after_ra_walker, &env);
790 lower_print_perm_stat(&env);