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.
23 #include "bechordal_t.h"
24 #include "besched_t.h"
27 #include "iredges_t.h"
38 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
40 /* collect static data about perms */
41 typedef struct _perm_stat_t {
42 const arch_register_class_t *cls; /**< the current register class */
43 int *perm_size_ar; /**< the sizes of all perms in an irg */
44 int *real_perm_size_ar; /**< the sizes of all perms in an irg */
45 int *chain_len_ar; /**< the sizes of all chains for all perms */
46 int *cycle_len_ar; /**< the siyes of all cycles for all perms */
47 int num_perms; /**< number of all perms */
48 int num_real_perms; /**< number of all perms */
49 int num_chains; /**< the number of all chains */
50 int num_cycles; /**< the number of all cycles */
53 /* lowering walker environment */
54 typedef struct _lower_env_t {
55 be_chordal_env_t *chord_env;
60 DEBUG_ONLY(firm_dbg_module_t *dbg_module;)
63 /* holds a perm register pair */
64 typedef struct _reg_pair_t {
65 const arch_register_t *in_reg; /**< a perm IN register */
66 ir_node *in_node; /**< the in node to which the register belongs */
68 const arch_register_t *out_reg; /**< a perm OUT register */
69 ir_node *out_node; /**< the out node to which the register belongs */
71 int checked; /**< indicates whether the pair was check for cycle or not */
74 typedef enum _perm_type_t {
81 /* structure to represent cycles or chains in a perm */
82 typedef struct _perm_cycle_t {
83 const arch_register_t **elems; /**< the registers in the cycle */
84 int n_elems; /**< number of elements in the cycle */
85 perm_type_t type; /**< type (CHAIN or CYCLE) */
88 /* Compare the in registers of two register pairs */
89 static int compare_reg_pair(const void *a, const void *b) {
90 const reg_pair_t *pair_a = a;
91 const reg_pair_t *pair_b = b;
93 if (pair_a->in_reg->index > pair_b->in_reg->index)
99 /* returns the number register pairs marked as checked */
100 static int get_n_checked_pairs(reg_pair_t *pairs, int n) {
101 int i, n_checked = 0;
103 for (i = 0; i < n; i++) {
104 if (pairs[i].checked)
112 * Gets the node corresponding to a register from an array of register pairs.
113 * NOTE: The given registers pairs and the register to look for must belong
114 * to the same register class.
116 * @param pairs The array of register pairs
117 * @param n The number of pairs
118 * @param reg The register to look for
119 * @param in_out 0 == look for IN register, 1 == look for OUT register
120 * @return The corresponding node or NULL if not found
122 static ir_node *get_node_for_register(reg_pair_t *pairs, int n, const arch_register_t *reg, int in_out) {
126 for (i = 0; i < n; i++) {
127 /* out register matches */
128 if (pairs[i].out_reg->index == reg->index)
129 return pairs[i].out_node;
133 for (i = 0; i < n; i++) {
134 /* in register matches */
135 if (pairs[i].in_reg->index == reg->index)
136 return pairs[i].in_node;
144 * Gets the index in the register pair array where the in/out register
145 * corresponds to reg_idx.
147 * @param pairs The array of register pairs
148 * @param n The number of pairs
149 * @param reg The register index to look for
150 * @param in_out 0 == look for IN register, 1 == look for OUT register
151 * @return The corresponding index in pairs or -1 if not found
153 static int get_pairidx_for_regidx(reg_pair_t *pairs, int n, int reg_idx, int in_out) {
157 for (i = 0; i < n; i++) {
158 /* out register matches */
159 if (pairs[i].out_reg->index == reg_idx)
164 for (i = 0; i < n; i++) {
165 /* in register matches */
166 if (pairs[i].in_reg->index == reg_idx)
175 * Gets an array of register pairs and tries to identify a cycle or chain starting
178 * @param cycle Variable to hold the cycle
179 * @param pairs Array of register pairs
180 * @param start Index to start
181 * @return The cycle or chain
183 static perm_cycle_t *get_perm_cycle(perm_cycle_t *cycle, reg_pair_t *pairs, int n, int start) {
184 int head = pairs[start].in_reg->index;
185 int cur_idx = pairs[start].out_reg->index;
186 int cur_pair_idx = start;
187 int n_pairs_done = get_n_checked_pairs(pairs, n);
189 perm_type_t cycle_tp = PERM_CYCLE;
191 /* We could be right in the middle of a chain, so we need to find the start */
192 while (head != cur_idx) {
193 /* goto previous register in cycle or chain */
194 cur_pair_idx = get_pairidx_for_regidx(pairs, n, head, 1);
196 if (cur_pair_idx < 0) {
197 cycle_tp = PERM_CHAIN;
201 head = pairs[cur_pair_idx].in_reg->index;
202 start = cur_pair_idx;
206 /* assume worst case: all remaining pairs build a cycle or chain */
207 cycle->elems = xcalloc((n - n_pairs_done) * 2, sizeof(cycle->elems[0]));
208 cycle->n_elems = 2; /* initial number of elements is 2 */
209 cycle->elems[0] = pairs[start].in_reg;
210 cycle->elems[1] = pairs[start].out_reg;
211 cycle->type = cycle_tp;
212 cur_idx = pairs[start].out_reg->index;
215 /* check for cycle or end of a chain */
216 while (cur_idx != head) {
217 /* goto next register in cycle or chain */
218 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cur_idx, 0);
220 if (cur_pair_idx < 0)
223 cur_idx = pairs[cur_pair_idx].out_reg->index;
225 /* it's not the first element: insert it */
226 if (cur_idx != head) {
227 cycle->elems[idx++] = pairs[cur_pair_idx].out_reg;
231 /* we are there where we started -> CYCLE */
232 cycle->type = PERM_CYCLE;
236 /* mark all pairs having one in/out register with cycle in common as checked */
237 for (idx = 0; idx < cycle->n_elems; idx++) {
238 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cycle->elems[idx]->index, 0);
240 if (cur_pair_idx >= 0)
241 pairs[cur_pair_idx].checked = 1;
243 cur_pair_idx = get_pairidx_for_regidx(pairs, n, cycle->elems[idx]->index, 1);
245 if (cur_pair_idx >= 0)
246 pairs[cur_pair_idx].checked = 1;
253 * Lowers a perm node. Resolves cycles and creates a bunch of
254 * copy and swap operations to permute registers.
255 * Note: The caller of this function has to make sure, that irn
258 * @param irn The perm node
259 * @param block The block the perm node belongs to
260 * @param walk_env The environment
262 static void lower_perm_node(ir_node *irn, void *walk_env) {
263 const arch_register_class_t *reg_class;
264 const arch_env_t *arch_env;
265 lower_env_t *env = walk_env;
266 perm_stat_t **pstat = env->pstat;
269 int n, i, pn, do_copy, j, n_ops;
271 const ir_edge_t *edge;
273 ir_node *sched_point, *block, *in[2];
274 ir_node *arg1, *arg2, *res1, *res2;
275 ir_node *cpyxchg = NULL;
276 DEBUG_ONLY(firm_dbg_module_t *mod;)
278 arch_env = env->chord_env->birg->main_env->arch_env;
279 do_copy = env->do_copy;
280 DEBUG_ONLY(mod = env->dbg_module;)
281 block = get_nodes_block(irn);
284 Get the schedule predecessor node to the perm
285 NOTE: This works with auto-magic. If we insert the
286 new copy/exchange nodes after this node, everything
289 sched_point = sched_prev(irn);
290 DBG((mod, LEVEL_1, "sched point is %+F\n", sched_point));
291 assert(sched_point && "Perm is not scheduled or has no predecessor");
293 n = get_irn_arity(irn);
294 assert(n == get_irn_n_edges(irn) && "perm's in and out numbers different");
296 reg_class = arch_get_irn_register(arch_env, get_irn_n(irn, 0))->reg_class;
297 pairs = alloca(n * sizeof(pairs[0]));
302 /* determine index in statistics */
303 for (i = 0; i < env->pstat_n; i++) {
304 if (strcmp(pstat[i]->cls->name, reg_class->name) == 0) {
309 assert(pstat_idx >= 0 && "could not determine class index for statistics");
311 pstat[pstat_idx]->num_perms++;
312 pstat[pstat_idx]->perm_size_ar[n - 1]++;
315 /* build the list of register pairs (in, out) */
317 foreach_out_edge(irn, edge) {
318 pairs[i].out_node = get_edge_src_irn(edge);
319 pn = get_Proj_proj(pairs[i].out_node);
320 pairs[i].in_node = get_irn_n(irn, pn);
322 pairs[i].in_reg = arch_get_irn_register(arch_env, pairs[i].in_node);
323 pairs[i].out_reg = arch_get_irn_register(arch_env, pairs[i].out_node);
325 pairs[i].checked = 0;
329 /* sort the register pairs by the indices of the in registers */
330 qsort(pairs, n, sizeof(pairs[0]), compare_reg_pair);
332 /* Mark all equal pairs as checked, and exchange the OUT proj with
334 for (i = 0; i < n; i++) {
335 if (pairs[i].in_reg->index == pairs[i].out_reg->index) {
336 DBG((mod, LEVEL_1, "%+F removing equal perm register pair (%+F, %+F, %s)\n",
337 irn, pairs[i].in_node, pairs[i].out_node, pairs[i].out_reg->name));
339 /* We have to check for a special case:
340 The in-node could be a Proj from a Perm. In this case,
341 we need to correct the projnum */
342 if (is_Perm(arch_env, pairs[i].in_node) && is_Proj(pairs[i].in_node)) {
343 set_Proj_proj(pairs[i].out_node, get_Proj_proj(pairs[i].in_node));
346 /* remove the proj from the schedule */
347 sched_remove(pairs[i].out_node);
349 /* reroute the edges from the proj to the argument */
350 edges_reroute(pairs[i].out_node, pairs[i].in_node, env->chord_env->irg);
352 pairs[i].checked = 1;
356 /* Set do_copy to 0 if it's on but we have no free register */
361 if (env->do_stat && get_n_checked_pairs(pairs, n) < n) {
362 pstat[pstat_idx]->num_real_perms++;
363 pstat[pstat_idx]->real_perm_size_ar[n - 1]++;
364 real_size = n - get_n_checked_pairs(pairs, n);
367 hook_be_block_stat_perm(reg_class->name, reg_class->n_regs, irn, block, n, real_size);
369 /* check for cycles and chains */
370 while (get_n_checked_pairs(pairs, n) < n) {
373 /* go to the first not-checked pair */
374 while (pairs[i].checked) i++;
375 cycle = xcalloc(1, sizeof(*cycle));
376 cycle = get_perm_cycle(cycle, pairs, n, i);
378 DB((mod, LEVEL_1, "%+F: following %s created:\n ", irn, cycle->type == PERM_CHAIN ? "chain" : "cycle"));
379 for (j = 0; j < cycle->n_elems; j++) {
380 DB((mod, LEVEL_1, " %s", cycle->elems[j]->name));
382 DB((mod, LEVEL_1, "\n"));
386 int n_idx = cycle->n_elems - 1;
387 if (cycle->type == PERM_CHAIN) {
388 pstat[pstat_idx]->num_chains++;
389 pstat[pstat_idx]->chain_len_ar[n_idx]++;
392 pstat[pstat_idx]->num_cycles++;
393 pstat[pstat_idx]->cycle_len_ar[n_idx]++;
397 /* We don't need to do anything if we have a Perm with two
398 elements which represents a cycle, because those nodes
399 already represent exchange nodes */
400 if (n == 2 && cycle->type == PERM_CYCLE) {
405 //TODO: - iff PERM_CYCLE && do_copy -> determine free temp reg and insert copy to/from it before/after
406 // the copy cascade (this reduces the cycle into a chain)
408 /* build copy/swap nodes from back to front */
409 for (i = cycle->n_elems - 2; i >= 0; i--) {
410 arg1 = get_node_for_register(pairs, n, cycle->elems[i], 0);
411 arg2 = get_node_for_register(pairs, n, cycle->elems[i + 1], 0);
413 res1 = get_node_for_register(pairs, n, cycle->elems[i], 1);
414 res2 = get_node_for_register(pairs, n, cycle->elems[i + 1], 1);
416 If we have a cycle and don't copy: we need to create exchange nodes
417 NOTE: An exchange node is a perm node with 2 INs and 2 OUTs
418 IN_1 = in node with register i
419 IN_2 = in node with register i + 1
420 OUT_1 = out node with register i + 1
421 OUT_2 = out node with register i
423 if (cycle->type == PERM_CYCLE && !do_copy) {
427 /* At this point we have to handle the following problem: */
429 /* If we have a cycle with more than two elements, then */
430 /* this could correspond to the following Perm node: */
432 /* +----+ +----+ +----+ */
433 /* | r1 | | r2 | | r3 | */
434 /* +-+--+ +-+--+ +--+-+ */
437 /* +-+--------+---------+-+ */
439 /* +-+--------+---------+-+ */
442 /* +-+--+ +-+--+ +--+-+ */
443 /* |Proj| |Proj| |Proj| */
444 /* | r2 | | r3 | | r1 | */
445 /* +----+ +----+ +----+ */
447 /* This node is about to be split up into two 2x Perm's */
448 /* for which we need 4 Proj's and the one additional Proj */
449 /* of the first Perm has to be one IN of the second. So in */
450 /* general we need to create one additional Proj for each */
451 /* "middle" Perm and set this to one in node of the successor */
454 DBG((mod, LEVEL_1, "%+F creating exchange node (%+F, %s) and (%+F, %s) with\n",
455 irn, arg1, cycle->elems[i]->name, arg2, cycle->elems[i + 1]->name));
456 DBG((mod, LEVEL_1, "%+F (%+F, %s) and (%+F, %s)\n",
457 irn, res1, cycle->elems[i]->name, res2, cycle->elems[i + 1]->name));
459 cpyxchg = be_new_Perm(reg_class, env->chord_env->irg, block, 2, in);
463 /* cycle is not done yet */
464 int pidx = get_pairidx_for_regidx(pairs, n, cycle->elems[i]->index, 0);
466 /* create intermediate proj */
467 res1 = new_r_Proj(get_irn_irg(irn), block, cpyxchg, get_irn_mode(res1), 0);
469 /* set as in for next Perm */
470 pairs[pidx].in_node = res1;
478 set_Proj_pred(res2, cpyxchg);
479 set_Proj_proj(res2, 0);
480 set_Proj_pred(res1, cpyxchg);
481 set_Proj_proj(res1, 1);
483 sched_add_after(sched_point, res1);
484 sched_add_after(sched_point, res2);
486 arch_set_irn_register(arch_env, res2, cycle->elems[i + 1]);
487 arch_set_irn_register(arch_env, res1, cycle->elems[i]);
489 /* insert the copy/exchange node in schedule after the magic schedule node (see above) */
490 sched_add_after(sched_point, cpyxchg);
492 DBG((mod, LEVEL_1, "replacing %+F with %+F, placed new node after %+F\n", irn, cpyxchg, sched_point));
494 /* set the new scheduling point */
498 DBG((mod, LEVEL_1, "%+F creating copy node (%+F, %s) -> (%+F, %s)\n",
499 irn, arg1, cycle->elems[i]->name, res2, cycle->elems[i + 1]->name));
501 cpyxchg = be_new_Copy(reg_class, env->chord_env->irg, block, arg1);
502 arch_set_irn_register(arch_env, cpyxchg, cycle->elems[i + 1]);
505 /* remove the proj from the schedule */
508 /* exchange copy node and proj */
509 exchange(res2, cpyxchg);
511 /* insert the copy/exchange node in schedule after the magic schedule node (see above) */
512 sched_add_after(sched_point, cpyxchg);
514 /* set the new scheduling point */
515 sched_point = cpyxchg;
520 hook_be_block_stat_permcycle(reg_class->name, irn, block, \
521 cycle->type == PERM_CHAIN, cycle->n_elems, n_ops);
524 free((void *) cycle->elems);
530 /* remove the perm from schedule */
536 static int get_n_out_edges(const ir_node *irn) {
537 const ir_edge_t *edge;
540 foreach_out_edge(irn, edge) {
547 static ir_node *belower_skip_proj(ir_node *irn) {
549 irn = get_Proj_pred(irn);
553 static void fix_in(ir_node *irn, ir_node *old, ir_node *nw) {
556 irn = belower_skip_proj(irn);
557 n = get_irn_arity(irn);
559 for (i = 0; i < n; i++) {
560 if (get_irn_n(irn, i) == old) {
561 set_irn_n(irn, i, nw);
567 static void gen_assure_different_pattern(ir_node *irn, be_irg_t *birg, ir_node *other_different) {
568 const arch_env_t *arch_env = birg->main_env->arch_env;
569 ir_node *in[2], *keep, *cpy, *temp;
570 ir_node *block = get_nodes_block(irn);
571 const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, other_different, -1);
572 FIRM_DBG_REGISTER(firm_dbg_module_t *mod, "firm.be.lower");
574 if (arch_irn_is(arch_env, other_different, ignore) || ! mode_is_datab(get_irn_mode(other_different))) {
575 DBG((mod, LEVEL_1, "ignore constraint for %+F because other_irn is ignore or not a datab node\n", irn));
579 /* Make a not spillable copy of the different node */
580 /* this is needed because the different irn could be */
581 /* in block far far away */
582 /* The copy is optimized later if not needed */
584 temp = new_rd_Unknown(birg->irg, get_irn_mode(other_different));
585 cpy = be_new_Copy(cls, birg->irg, block, temp);
586 be_node_set_flags(cpy, BE_OUT_POS(0), arch_irn_flags_dont_spill);
591 /* Let the irn use the copy instead of the old other_different */
592 fix_in(irn, other_different, cpy);
594 /* Add the Keep resp. CopyKeep and reroute the users */
595 /* of the other_different irn in case of CopyKeep. */
596 if (get_n_out_edges(other_different) == 0) {
597 keep = be_new_Keep(cls, birg->irg, block, 2, in);
600 keep = be_new_CopyKeep_single(cls, birg->irg, block, cpy, irn, get_irn_mode(other_different));
601 be_node_set_reg_class(keep, 1, cls);
602 edges_reroute(other_different, keep, birg->irg);
605 /* after rerouting: let the copy point to the other_different irn */
606 set_irn_n(cpy, 0, other_different);
608 DBG((mod, LEVEL_1, "created %+F for %+F to assure should_be_different\n", keep, irn));
612 * Checks if node has a should_be_different constraint in output
613 * and adds a Keep then to assure the constraint.
615 static void assure_different_constraints(ir_node *irn, be_irg_t *birg) {
616 const arch_env_t *arch_env = birg->main_env->arch_env;
617 const arch_register_req_t *req;
618 arch_register_req_t req_temp;
621 req = arch_get_register_req(arch_env, &req_temp, irn, -1);
624 if (arch_register_req_is(req, should_be_different)) {
625 gen_assure_different_pattern(irn, birg, req->other_different);
627 else if (arch_register_req_is(req, should_be_different_from_all)) {
628 n = get_irn_arity(belower_skip_proj(irn));
629 for (i = 0; i < n; i++) {
630 gen_assure_different_pattern(irn, birg, get_irn_n(belower_skip_proj(irn), i));
639 * Calls the functions to assure register constraints.
641 * @param irn The node to be checked for lowering
642 * @param walk_env The walker environment
644 static void assure_constraints_walker(ir_node *irn, void *walk_env) {
648 if (mode_is_datab(get_irn_mode(irn)))
649 assure_different_constraints(irn, walk_env);
657 * Walks over all nodes to assure register constraints.
659 * @param birg The birg structure containing the irg
661 void assure_constraints(be_irg_t *birg) {
662 irg_walk_blkwise_graph(birg->irg, NULL, assure_constraints_walker, birg);
668 * Calls the corresponding lowering function for the node.
670 * @param irn The node to be checked for lowering
671 * @param walk_env The walker environment
673 static void lower_nodes_after_ra_walker(ir_node *irn, void *walk_env) {
674 lower_env_t *env = walk_env;
675 const arch_env_t *arch_env = env->chord_env->birg->main_env->arch_env;
677 if (!is_Block(irn) && !is_Proj(irn)) {
678 if (is_Perm(arch_env, irn)) {
679 lower_perm_node(irn, walk_env);
686 static void lower_print_perm_stat(lower_env_t *env) {
687 int j, total_len_chain, total_len_cycle, total_size_perm, total_size_real_perm;
690 printf("=== IRG: %s ===\n", get_entity_name(get_irg_entity(env->chord_env->irg)));
691 for (i = 0; i < env->pstat_n; i++) {
692 if (env->pstat[i]->num_perms == 0)
695 printf("CLASS: %s\n", env->pstat[i]->cls->name);
696 printf("# total perms: %d (size:num -> 1:%d", env->pstat[i]->num_perms, env->pstat[i]->perm_size_ar[0]);
698 total_size_perm = env->pstat[i]->perm_size_ar[0];
699 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
700 total_size_perm += (j + 1) * env->pstat[i]->perm_size_ar[j];
701 printf(", %d:%d", j + 1, env->pstat[i]->perm_size_ar[j]);
704 printf("avg perm size: %.2f\n", env->pstat[i]->num_perms ? (float)total_size_perm / (float)env->pstat[i]->num_perms : 0);
706 printf("# real perms: %d (size:num -> 1:%d", env->pstat[i]->num_real_perms, env->pstat[i]->real_perm_size_ar[0]);
708 total_size_real_perm = env->pstat[i]->real_perm_size_ar[0];
709 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
710 total_size_real_perm += (j + 1) * env->pstat[i]->real_perm_size_ar[j];
711 printf(", %d:%d", j + 1, env->pstat[i]->real_perm_size_ar[j]);
714 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);
716 printf("# total chains: %d (lenght:num -> 1:%d", env->pstat[i]->num_chains, env->pstat[i]->chain_len_ar[0]);
718 total_len_chain = env->pstat[i]->chain_len_ar[0];
720 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
721 total_len_chain += (j + 1) * env->pstat[i]->chain_len_ar[j];
722 printf(", %d:%d", j + 1, env->pstat[i]->chain_len_ar[j]);
725 printf("avg chain length: %.2f\n", env->pstat[i]->num_chains ? (float)total_len_chain / (float)env->pstat[i]->num_chains : 0);
726 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);
728 printf("# total cycles: %d (length:num -> 1:%d", env->pstat[i]->num_cycles, env->pstat[i]->cycle_len_ar[0]);
730 total_len_cycle = env->pstat[i]->cycle_len_ar[0];
731 for (j = 1; j < env->pstat[i]->cls->n_regs; j++) {
732 total_len_cycle += (j + 1) * env->pstat[i]->cycle_len_ar[j];
733 printf(", %d:%d", j + 1, env->pstat[i]->cycle_len_ar[j]);
736 printf("avg cycle length: %.2f\n", env->pstat[i]->num_cycles ? (float)total_len_cycle / (float)env->pstat[i]->num_cycles : 0);
737 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);
742 * Walks over all blocks in an irg and performs lowering need to be
743 * done after register allocation (e.g. perm lowering).
745 * @param chord_env The chordal environment containing the irg
746 * @param do_copy 1 == resolve cycles with a free reg if available
748 void lower_nodes_after_ra(be_chordal_env_t *chord_env, int do_copy, int do_stat) {
751 env.chord_env = chord_env;
752 env.do_copy = do_copy;
753 env.do_stat = do_stat;
754 FIRM_DBG_REGISTER(env.dbg_module, "firm.be.lower");
756 /* if we want statistics: allocate memory for the data and initialize with 0 */
758 const arch_isa_t *isa = chord_env->birg->main_env->arch_env->isa;
759 int i, n = arch_isa_get_n_reg_class(isa);
761 env.pstat = alloca(n * sizeof(env.pstat[0]));
764 for (i = 0; i < n; i++) {
765 const arch_register_class_t *cls = arch_isa_get_reg_class(isa, i);
766 int n_regs = cls->n_regs;
768 env.pstat[i] = alloca(sizeof(*(env.pstat[0])));
769 memset(env.pstat[i], 0, sizeof(*(env.pstat[0])));
771 env.pstat[i]->perm_size_ar = alloca(n_regs * sizeof(env.pstat[i]->perm_size_ar[0]));
772 env.pstat[i]->real_perm_size_ar = alloca(n_regs * sizeof(env.pstat[i]->real_perm_size_ar[0]));
773 env.pstat[i]->chain_len_ar = alloca(n_regs * sizeof(env.pstat[i]->chain_len_ar[0]));
774 env.pstat[i]->cycle_len_ar = alloca(n_regs * sizeof(env.pstat[i]->cycle_len_ar[0]));
776 memset(env.pstat[i]->perm_size_ar, 0, n_regs * sizeof(env.pstat[i]->perm_size_ar[0]));
777 memset(env.pstat[i]->real_perm_size_ar, 0, n_regs * sizeof(env.pstat[i]->real_perm_size_ar[0]));
778 memset(env.pstat[i]->chain_len_ar, 0, n_regs * sizeof(env.pstat[i]->chain_len_ar[0]));
779 memset(env.pstat[i]->cycle_len_ar, 0, n_regs * sizeof(env.pstat[i]->cycle_len_ar[0]));
781 env.pstat[i]->cls = cls;
785 irg_walk_blkwise_graph(chord_env->irg, NULL, lower_nodes_after_ra_walker, &env);
788 lower_print_perm_stat(&env);