2 * This file implements the node emitter.
22 #include "iredges_t.h"
24 #include "../besched_t.h"
25 #include "../benode_t.h"
27 #include "ia32_emitter.h"
28 #include "gen_ia32_emitter.h"
29 #include "gen_ia32_regalloc_if.h"
30 #include "ia32_nodes_attr.h"
31 #include "ia32_new_nodes.h"
32 #include "ia32_map_regs.h"
34 #ifdef obstack_chunk_alloc
35 # undef obstack_chunk_alloc
36 # define obstack_chunk_alloc xmalloc
38 # define obstack_chunk_alloc xmalloc
39 # define obstack_chunk_free free
42 #define BLOCK_PREFIX(x) ".L" x
44 extern int obstack_printf(struct obstack *obst, char *fmt, ...);
46 #define SNPRINTF_BUF_LEN 128
48 /* global arch_env for lc_printf functions */
49 static const arch_env_t *arch_env = NULL;
51 /*************************************************************
53 * (_) | | / _| | | | |
54 * _ __ _ __ _ _ __ | |_| |_ | |__ ___| |_ __ ___ _ __
55 * | '_ \| '__| | '_ \| __| _| | '_ \ / _ \ | '_ \ / _ \ '__|
56 * | |_) | | | | | | | |_| | | | | | __/ | |_) | __/ |
57 * | .__/|_| |_|_| |_|\__|_| |_| |_|\___|_| .__/ \___|_|
60 *************************************************************/
62 /* We always pass the ir_node which is a pointer. */
63 static int ia32_get_arg_type(const lc_arg_occ_t *occ) {
64 return lc_arg_type_ptr;
69 * Returns the register at in position pos.
71 static const arch_register_t *get_in_reg(const ir_node *irn, int pos) {
73 const arch_register_t *reg = NULL;
75 assert(get_irn_arity(irn) > pos && "Invalid IN position");
77 /* The out register of the operator at position pos is the
78 in register we need. */
79 op = get_irn_n(irn, pos);
81 reg = arch_get_irn_register(arch_env, op);
83 assert(reg && "no in register found");
88 * Returns the register at out position pos.
90 static const arch_register_t *get_out_reg(const ir_node *irn, int pos) {
92 const arch_register_t *reg = NULL;
94 /* 1st case: irn is not of mode_T, so it has only */
95 /* one OUT register -> good */
96 /* 2nd case: irn is of mode_T -> collect all Projs and ask the */
97 /* Proj with the corresponding projnum for the register */
99 if (get_irn_mode(irn) != mode_T) {
100 reg = arch_get_irn_register(arch_env, irn);
102 else if (is_ia32_irn(irn)) {
103 reg = get_ia32_out_reg(irn, pos);
106 const ir_edge_t *edge;
108 foreach_out_edge(irn, edge) {
109 proj = get_edge_src_irn(edge);
110 assert(is_Proj(proj) && "non-Proj from mode_T node");
111 if (get_Proj_proj(proj) == pos) {
112 reg = arch_get_irn_register(arch_env, proj);
118 assert(reg && "no out register found");
128 * Returns the name of the in register at position pos.
130 static const char *get_ia32_reg_name(ir_node *irn, int pos, enum io_direction in_out) {
131 const arch_register_t *reg;
133 static char *buf = NULL;
136 if (in_out == IN_REG) {
137 reg = get_in_reg(irn, pos);
140 /* destination address mode nodes don't have outputs */
141 if (is_ia32_irn(irn) && get_ia32_op_type(irn) == ia32_AddrModeD) {
145 reg = get_out_reg(irn, pos);
148 name = arch_register_get_name(reg);
154 len = strlen(name) + 2;
155 buf = xcalloc(1, len);
157 snprintf(buf, len, "%%%s", name);
163 * Get the register name for a node.
165 static int ia32_get_reg_name(lc_appendable_t *app,
166 const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
169 ir_node *X = arg->v_ptr;
170 int nr = occ->width - 1;
173 return lc_appendable_snadd(app, "(null)", 6);
175 buf = get_ia32_reg_name(X, nr, occ->conversion == 'S' ? IN_REG : OUT_REG);
177 return lc_appendable_snadd(app, buf, strlen(buf));
181 * Get the x87 register name for a node.
183 static int ia32_get_x87_name(lc_appendable_t *app,
184 const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
187 ir_node *X = arg->v_ptr;
188 int nr = occ->width - 1;
192 return lc_appendable_snadd(app, "(null)", 6);
194 attr = get_ia32_attr(X);
195 buf = attr->x87[nr]->name;
196 return lc_appendable_snadd(app, buf, strlen(buf));
200 * Returns the tarval, offset or scale of an ia32 as a string.
202 static int ia32_const_to_str(lc_appendable_t *app,
203 const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
206 ir_node *X = arg->v_ptr;
209 return lc_arg_append(app, occ, "(null)", 6);
211 if (occ->conversion == 'C') {
212 buf = get_ia32_cnst(X);
215 buf = get_ia32_am_offs(X);
218 return buf ? lc_appendable_snadd(app, buf, strlen(buf)) : 0;
222 * Determines the SSE suffix depending on the mode.
224 static int ia32_get_mode_suffix(lc_appendable_t *app,
225 const lc_arg_occ_t *occ, const lc_arg_value_t *arg)
227 ir_node *X = arg->v_ptr;
228 ir_mode *mode = get_irn_mode(X);
230 if (mode == mode_T) {
231 mode = is_ia32_AddrModeS(X) || is_ia32_AddrModeD(X) ? get_ia32_ls_mode(X) : get_ia32_res_mode(X);
235 return lc_arg_append(app, occ, "(null)", 6);
237 if (mode_is_float(mode)) {
238 return lc_appendable_chadd(app, get_mode_size_bits(mode) == 32 ? 's' : 'd');
241 return lc_appendable_chadd(app, mode_is_signed(mode) ? 's' : 'z');
246 * Return the ia32 printf arg environment.
247 * We use the firm environment with some additional handlers.
249 const lc_arg_env_t *ia32_get_arg_env(void) {
250 static lc_arg_env_t *env = NULL;
252 static const lc_arg_handler_t ia32_reg_handler = { ia32_get_arg_type, ia32_get_reg_name };
253 static const lc_arg_handler_t ia32_const_handler = { ia32_get_arg_type, ia32_const_to_str };
254 static const lc_arg_handler_t ia32_mode_handler = { ia32_get_arg_type, ia32_get_mode_suffix };
255 static const lc_arg_handler_t ia32_x87_handler = { ia32_get_arg_type, ia32_get_x87_name };
258 /* extend the firm printer */
259 env = firm_get_arg_env();
261 lc_arg_register(env, "ia32:sreg", 'S', &ia32_reg_handler);
262 lc_arg_register(env, "ia32:dreg", 'D', &ia32_reg_handler);
263 lc_arg_register(env, "ia32:cnst", 'C', &ia32_const_handler);
264 lc_arg_register(env, "ia32:offs", 'O', &ia32_const_handler);
265 lc_arg_register(env, "ia32:mode", 'M', &ia32_mode_handler);
266 lc_arg_register(env, "ia32:x87", 'X', &ia32_x87_handler);
272 static char *ia32_get_reg_name_for_mode(ia32_emit_env_t *env, ir_mode *mode, const arch_register_t *reg) {
273 switch(get_mode_size_bits(mode)) {
275 return ia32_get_mapped_reg_name(env->isa->regs_8bit, reg);
277 return ia32_get_mapped_reg_name(env->isa->regs_16bit, reg);
279 return (char *)arch_register_get_name(reg);
284 * Emits registers and/or address mode of a binary operation.
286 char *ia32_emit_binop(const ir_node *n, ia32_emit_env_t *env) {
287 static char *buf = NULL;
289 /* verify that this function is never called on non-AM supporting operations */
290 //assert(get_ia32_am_support(n) != ia32_am_None && "emit binop expects addressmode support");
292 #define PRODUCES_RESULT(n) \
293 (!(is_ia32_St(n) || \
294 is_ia32_Store8Bit(n) || \
295 is_ia32_CondJmp(n) || \
296 is_ia32_fCondJmp(n) || \
297 is_ia32_SwitchJmp(n)))
300 buf = xcalloc(1, SNPRINTF_BUF_LEN);
303 memset(buf, 0, SNPRINTF_BUF_LEN);
306 switch(get_ia32_op_type(n)) {
308 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
309 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%3S, %s", n, get_ia32_cnst(n));
312 const arch_register_t *in1 = get_in_reg(n, 2);
313 const arch_register_t *in2 = get_in_reg(n, 3);
314 const arch_register_t *out = PRODUCES_RESULT(n) ? get_out_reg(n, 0) : NULL;
315 const arch_register_t *in;
317 in = out ? (REGS_ARE_EQUAL(out, in2) ? in1 : in2) : in2;
318 out = out ? out : in1;
320 snprintf(buf, SNPRINTF_BUF_LEN, "%%%s, %%%s", \
321 arch_register_get_name(out), arch_register_get_name(in));
325 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
326 assert(! PRODUCES_RESULT(n) && "Source AM with Const must not produce result");
327 snprintf(buf, SNPRINTF_BUF_LEN, "%s, %s", get_ia32_cnst(n), ia32_emit_am(n, env));
330 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%4S, %s", n, ia32_emit_am(n, env));
334 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
335 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%s,%s%s",
336 ia32_emit_am(n, env),
337 is_ia32_ImmSymConst(n) ? " OFFSET FLAT:" : " ", /* In case of a symconst we must add OFFSET to */
338 get_ia32_cnst(n)); /* tell the assembler to store it's address. */
341 const arch_register_t *in1 = get_in_reg(n, 2);
342 ir_mode *mode = get_ia32_res_mode(n);
344 mode = mode ? mode : get_ia32_ls_mode(n);
345 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%s, %%%s",
346 ia32_emit_am(n, env), ia32_get_reg_name_for_mode(env, mode, in1));
350 assert(0 && "unsupported op type");
353 #undef PRODUCES_RESULT
359 * Emits registers and/or address mode of a unary operation.
361 char *ia32_emit_unop(const ir_node *n, ia32_emit_env_t *env) {
362 static char *buf = NULL;
365 buf = xcalloc(1, SNPRINTF_BUF_LEN);
368 memset(buf, 0, SNPRINTF_BUF_LEN);
371 switch(get_ia32_op_type(n)) {
373 if (is_ia32_ImmConst(n) || is_ia32_ImmSymConst(n)) {
374 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%C", n);
377 lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%1D", n);
381 snprintf(buf, SNPRINTF_BUF_LEN, ia32_emit_am(n, env));
384 assert(0 && "unsupported op type");
391 * Emits address mode.
393 char *ia32_emit_am(const ir_node *n, ia32_emit_env_t *env) {
394 ia32_am_flavour_t am_flav = get_ia32_am_flavour(n);
398 static struct obstack *obst = NULL;
399 ir_mode *mode = get_ia32_ls_mode(n);
401 if (! is_ia32_Lea(n))
402 assert(mode && "AM node must have ls_mode attribute set.");
405 obst = xcalloc(1, sizeof(*obst));
408 obstack_free(obst, NULL);
411 /* obstack_free with NULL results in an uninitialized obstack */
415 switch (get_mode_size_bits(mode)) {
417 obstack_printf(obst, "BYTE PTR ");
420 obstack_printf(obst, "WORD PTR ");
423 obstack_printf(obst, "DWORD PTR ");
430 obstack_printf(obst, "[");
432 if (am_flav & ia32_B) {
433 lc_eoprintf(ia32_get_arg_env(), obst, "%1S", n);
437 if (am_flav & ia32_I) {
439 obstack_printf(obst, "+");
442 lc_eoprintf(ia32_get_arg_env(), obst, "%2S", n);
444 if (am_flav & ia32_S) {
445 obstack_printf(obst, "*%d", 1 << get_ia32_am_scale(n));
451 if (am_flav & ia32_O) {
452 s = get_ia32_am_offs(n);
454 /* omit explicit + if there was no base or index */
455 if (! had_output && s[0] == '+')
458 obstack_printf(obst, s);
461 obstack_printf(obst, "] ");
463 size = obstack_object_size(obst);
464 s = obstack_finish(obst);
473 * Formated print of commands and comments.
475 static void ia32_fprintf_format(FILE *F, const ir_node *irn, char *cmd_buf, char *cmnt_buf) {
477 const char *name = irn ? be_retrieve_dbg_info(get_irn_dbg_info((ir_node *)irn), &lineno) : NULL;
480 fprintf(F, "\t%-35s %-60s /* %s:%u */\n", cmd_buf, cmnt_buf, name, lineno);
482 fprintf(F, "\t%-35s %-60s\n", cmd_buf, cmnt_buf);
488 * Add a number to a prefix. This number will not be used a second time.
490 static char *get_unique_label(char *buf, size_t buflen, const char *prefix) {
491 static unsigned long id = 0;
492 snprintf(buf, buflen, "%s%lu", prefix, ++id);
498 /*************************************************
501 * ___ _ __ ___ _| |_ ___ ___ _ __ __| |
502 * / _ \ '_ ` _ \| | __| / __/ _ \| '_ \ / _` |
503 * | __/ | | | | | | |_ | (_| (_) | | | | (_| |
504 * \___|_| |_| |_|_|\__| \___\___/|_| |_|\__,_|
506 *************************************************/
509 #define IA32_DO_EMIT(irn) ia32_fprintf_format(F, irn, cmd_buf, cmnt_buf)
512 * coding of conditions
514 struct cmp2conditon_t {
520 * positive conditions for signed compares
522 static const struct cmp2conditon_t cmp2condition_s[] = {
523 { NULL, pn_Cmp_False }, /* always false */
524 { "e", pn_Cmp_Eq }, /* == */
525 { "l", pn_Cmp_Lt }, /* < */
526 { "le", pn_Cmp_Le }, /* <= */
527 { "g", pn_Cmp_Gt }, /* > */
528 { "ge", pn_Cmp_Ge }, /* >= */
529 { "ne", pn_Cmp_Lg }, /* != */
530 { "ordered", pn_Cmp_Leg }, /* Floating point: ordered */
531 { "unordered", pn_Cmp_Uo }, /* FLoting point: unordered */
532 { "unordered or ==", pn_Cmp_Ue }, /* Floating point: unordered or == */
533 { "unordered or <", pn_Cmp_Ul }, /* Floating point: unordered or < */
534 { "unordered or <=", pn_Cmp_Ule }, /* Floating point: unordered or <= */
535 { "unordered or >", pn_Cmp_Ug }, /* Floating point: unordered or > */
536 { "unordered or >=", pn_Cmp_Uge }, /* Floating point: unordered or >= */
537 { "unordered or !=", pn_Cmp_Ne }, /* Floating point: unordered or != */
538 { NULL, pn_Cmp_True }, /* always true */
542 * positive conditions for unsigned compares
544 static const struct cmp2conditon_t cmp2condition_u[] = {
545 { NULL, pn_Cmp_False }, /* always false */
546 { "e", pn_Cmp_Eq }, /* == */
547 { "b", pn_Cmp_Lt }, /* < */
548 { "be", pn_Cmp_Le }, /* <= */
549 { "a", pn_Cmp_Gt }, /* > */
550 { "ae", pn_Cmp_Ge }, /* >= */
551 { "ne", pn_Cmp_Lg }, /* != */
552 { "ordered", pn_Cmp_Leg }, /* Floating point: ordered */
553 { "unordered", pn_Cmp_Uo }, /* FLoting point: unordered */
554 { "unordered or ==", pn_Cmp_Ue }, /* Floating point: unordered or == */
555 { "unordered or <", pn_Cmp_Ul }, /* Floating point: unordered or < */
556 { "unordered or <=", pn_Cmp_Ule }, /* Floating point: unordered or <= */
557 { "unordered or >", pn_Cmp_Ug }, /* Floating point: unordered or > */
558 { "unordered or >=", pn_Cmp_Uge }, /* Floating point: unordered or >= */
559 { "unordered or !=", pn_Cmp_Ne }, /* Floating point: unordered or != */
560 { NULL, pn_Cmp_True }, /* always true */
564 * returns the condition code
566 static const char *get_cmp_suffix(int cmp_code, int unsigned_cmp)
568 assert(cmp2condition_s[cmp_code].num == cmp_code);
569 assert(cmp2condition_u[cmp_code].num == cmp_code);
571 return unsigned_cmp ? cmp2condition_u[cmp_code & 7].name : cmp2condition_s[cmp_code & 7].name;
575 * Returns the target block for a control flow node.
577 static ir_node *get_cfop_target_block(const ir_node *irn) {
578 return get_irn_link(irn);
582 * Returns the target label for a control flow node.
584 static char *get_cfop_target(const ir_node *irn, char *buf) {
585 ir_node *bl = get_cfop_target_block(irn);
587 snprintf(buf, SNPRINTF_BUF_LEN, BLOCK_PREFIX("%ld"), get_irn_node_nr(bl));
591 /** Return the next block in Block schedule */
592 static ir_node *next_blk_sched(const ir_node *block) {
593 return get_irn_link(block);
597 * Emits the jump sequence for a conditional jump (cmp + jmp_true + jmp_false)
599 static void finish_CondJmp(FILE *F, const ir_node *irn, ir_mode *mode) {
600 const ir_node *proj1, *proj2 = NULL;
601 const ir_node *block, *next_bl = NULL;
602 const ir_edge_t *edge;
603 char buf[SNPRINTF_BUF_LEN];
604 char cmd_buf[SNPRINTF_BUF_LEN];
605 char cmnt_buf[SNPRINTF_BUF_LEN];
607 /* get both Proj's */
608 edge = get_irn_out_edge_first(irn);
609 proj1 = get_edge_src_irn(edge);
610 assert(is_Proj(proj1) && "CondJmp with a non-Proj");
612 edge = get_irn_out_edge_next(irn, edge);
614 proj2 = get_edge_src_irn(edge);
615 assert(is_Proj(proj2) && "CondJmp with a non-Proj");
618 /* for now, the code works for scheduled and non-schedules blocks */
619 block = get_nodes_block(irn);
621 /* we have a block schedule */
622 next_bl = next_blk_sched(block);
624 if (get_cfop_target_block(proj1) == next_bl) {
625 /* exchange both proj's so the second one can be omitted */
626 const ir_node *t = proj1;
632 /* the first Proj must always be created */
633 if (get_Proj_proj(proj1) == pn_Cond_true) {
634 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "j%s %s",
635 get_cmp_suffix(get_ia32_pncode(irn), !mode_is_signed(get_irn_mode(get_irn_n(irn, 0)))),
636 get_cfop_target(proj1, buf));
637 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* cmp(a, b) == TRUE */");
640 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "j%s %s",
641 get_cmp_suffix(get_negated_pnc(get_ia32_pncode(irn), mode),
642 !mode_is_signed(get_irn_mode(get_irn_n(irn, 0)))),
643 get_cfop_target(proj1, buf));
644 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* cmp(a, b) == FALSE */");
648 /* the second Proj might be a fallthrough */
650 if (get_cfop_target_block(proj2) != next_bl) {
651 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(proj2, buf));
652 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* otherwise */");
656 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* fallthrogh %s */", get_cfop_target(proj2, buf));
663 * Emits code for conditional jump.
665 static void CondJmp_emitter(const ir_node *irn, ia32_emit_env_t *env) {
667 char cmd_buf[SNPRINTF_BUF_LEN];
668 char cmnt_buf[SNPRINTF_BUF_LEN];
670 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "cmp %s", ia32_emit_binop(irn, env));
671 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F */", irn);
673 finish_CondJmp(F, irn, get_irn_mode(get_irn_n(irn, 2)));
677 * Emits code for conditional jump with two variables.
679 static void emit_ia32_CondJmp(const ir_node *irn, ia32_emit_env_t *env) {
680 CondJmp_emitter(irn, env);
684 * Emits code for conditional jump with immediate.
686 static void emit_ia32_CondJmp_i(const ir_node *irn, ia32_emit_env_t *env) {
687 CondJmp_emitter(irn, env);
691 * Emits code for conditional test and jump.
693 static void TestJmp_emitter(const ir_node *irn, ia32_emit_env_t *env) {
695 #define IA32_IS_IMMOP (is_ia32_ImmConst(irn) || is_ia32_ImmSymConst(irn))
698 const char *op1 = arch_register_get_name(get_in_reg(irn, 0));
699 const char *op2 = IA32_IS_IMMOP ? get_ia32_cnst(irn) : NULL;
700 char cmd_buf[SNPRINTF_BUF_LEN];
701 char cmnt_buf[SNPRINTF_BUF_LEN];
704 op2 = arch_register_get_name(get_in_reg(irn, 1));
706 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "test %%%s,%s%s ", op1, IA32_IS_IMMOP ? " " : " %", op2);
707 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F */", irn);
710 finish_CondJmp(F, irn, get_irn_mode(get_irn_n(irn, 0)));
716 * Emits code for conditional test and jump with two variables.
718 static void emit_ia32_TestJmp(const ir_node *irn, ia32_emit_env_t *env) {
719 TestJmp_emitter(irn, env);
722 static void emit_ia32_CJmp(const ir_node *irn, ia32_emit_env_t *env) {
724 char cmd_buf[SNPRINTF_BUF_LEN];
725 char cmnt_buf[SNPRINTF_BUF_LEN];
727 snprintf(cmd_buf, SNPRINTF_BUF_LEN, " ");
728 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F omitted redundant test/cmp */", irn);
730 finish_CondJmp(F, irn, get_irn_mode(get_irn_n(irn, 0)));
733 static void emit_ia32_CJmpAM(const ir_node *irn, ia32_emit_env_t *env) {
735 char cmd_buf[SNPRINTF_BUF_LEN];
736 char cmnt_buf[SNPRINTF_BUF_LEN];
738 snprintf(cmd_buf, SNPRINTF_BUF_LEN, " ");
739 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F omitted redundant test/cmp */", irn);
741 finish_CondJmp(F, irn, get_irn_mode(get_irn_n(irn, 2)));
744 /*********************************************************
747 * ___ _ __ ___ _| |_ _ _ _ _ __ ___ _ __ ___
748 * / _ \ '_ ` _ \| | __| | | | | | '_ ` _ \| '_ \/ __|
749 * | __/ | | | | | | |_ | | |_| | | | | | | |_) \__ \
750 * \___|_| |_| |_|_|\__| | |\__,_|_| |_| |_| .__/|___/
753 *********************************************************/
755 /* jump table entry (target and corresponding number) */
756 typedef struct _branch_t {
761 /* jump table for switch generation */
762 typedef struct _jmp_tbl_t {
763 ir_node *defProj; /**< default target */
764 int min_value; /**< smallest switch case */
765 int max_value; /**< largest switch case */
766 int num_branches; /**< number of jumps */
767 char *label; /**< label of the jump table */
768 branch_t *branches; /**< jump array */
772 * Compare two variables of type branch_t. Used to sort all switch cases
774 static int ia32_cmp_branch_t(const void *a, const void *b) {
775 branch_t *b1 = (branch_t *)a;
776 branch_t *b2 = (branch_t *)b;
778 if (b1->value <= b2->value)
785 * Emits code for a SwitchJmp (creates a jump table if
786 * possible otherwise a cmp-jmp cascade). Port from
789 static void emit_ia32_SwitchJmp(const ir_node *irn, ia32_emit_env_t *emit_env) {
790 unsigned long interval;
791 char buf[SNPRINTF_BUF_LEN];
792 int last_value, i, pn, do_jmp_tbl = 1;
795 const ir_edge_t *edge;
796 const lc_arg_env_t *env = ia32_get_arg_env();
797 FILE *F = emit_env->out;
798 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
800 /* fill the table structure */
801 tbl.label = xmalloc(SNPRINTF_BUF_LEN);
802 tbl.label = get_unique_label(tbl.label, SNPRINTF_BUF_LEN, "JMPTBL_");
804 tbl.num_branches = get_irn_n_edges(irn);
805 tbl.branches = xcalloc(tbl.num_branches, sizeof(tbl.branches[0]));
806 tbl.min_value = INT_MAX;
807 tbl.max_value = INT_MIN;
810 /* go over all proj's and collect them */
811 foreach_out_edge(irn, edge) {
812 proj = get_edge_src_irn(edge);
813 assert(is_Proj(proj) && "Only proj allowed at SwitchJmp");
815 pn = get_Proj_proj(proj);
817 /* create branch entry */
818 tbl.branches[i].target = proj;
819 tbl.branches[i].value = pn;
821 tbl.min_value = pn < tbl.min_value ? pn : tbl.min_value;
822 tbl.max_value = pn > tbl.max_value ? pn : tbl.max_value;
824 /* check for default proj */
825 if (pn == get_ia32_pncode(irn)) {
826 assert(tbl.defProj == NULL && "found two defProjs at SwitchJmp");
833 /* sort the branches by their number */
834 qsort(tbl.branches, tbl.num_branches, sizeof(tbl.branches[0]), ia32_cmp_branch_t);
836 /* two-complement's magic make this work without overflow */
837 interval = tbl.max_value - tbl.min_value;
839 /* check value interval */
840 if (interval > 16 * 1024) {
844 /* check ratio of value interval to number of branches */
845 if ((float)(interval + 1) / (float)tbl.num_branches > 8.0) {
851 if (tbl.min_value != 0) {
852 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "cmpl %lu, -%d(%1S)",
853 interval, tbl.min_value, irn);
854 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* first switch value is not 0 */");
859 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "cmpl %lu, %1S", interval, irn);
860 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* compare for switch */");
865 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "ja %s", get_cfop_target(tbl.defProj, buf));
866 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* default jump if out of range */");
869 if (tbl.num_branches > 1) {
872 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "jmp [%1S*4+%s]", irn, tbl.label);
873 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* get jump table entry as target */");
876 fprintf(F, "\t.section\t.rodata\n");
877 fprintf(F, "\t.align 4\n");
879 fprintf(F, "%s:\n", tbl.label);
881 snprintf(cmd_buf, SNPRINTF_BUF_LEN, ".long %s", get_cfop_target(tbl.branches[0].target, buf));
882 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* case %d */\n", tbl.branches[0].value);
885 last_value = tbl.branches[0].value;
886 for (i = 1; i < tbl.num_branches; ++i) {
887 while (++last_value < tbl.branches[i].value) {
888 snprintf(cmd_buf, SNPRINTF_BUF_LEN, ".long %s", get_cfop_target(tbl.defProj, buf));
889 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* default case */");
892 snprintf(cmd_buf, SNPRINTF_BUF_LEN, ".long %s", get_cfop_target(tbl.branches[i].target, buf));
893 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* case %d */", last_value);
897 fprintf(F, "\t.text");
900 /* one jump is enough */
901 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(tbl.branches[0].target, buf));
902 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* only one case given */");
906 else { // no jump table
907 for (i = 0; i < tbl.num_branches; ++i) {
908 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "cmpl %d, %1S", tbl.branches[i].value, irn);
909 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* case %d */", i);
911 fprintf(F, "\tje %s\n", get_cfop_target(tbl.branches[i].target, buf));
914 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(tbl.defProj, buf));
915 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* default case */");
926 * Emits code for a unconditional jump.
928 static void emit_Jmp(const ir_node *irn, ia32_emit_env_t *env) {
929 ir_node *block, *next_bl;
931 char buf[SNPRINTF_BUF_LEN], cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
933 /* for now, the code works for scheduled and non-schedules blocks */
934 block = get_nodes_block(irn);
936 /* we have a block schedule */
937 next_bl = next_blk_sched(block);
938 if (get_cfop_target_block(irn) != next_bl) {
939 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(irn, buf));
940 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F(%+F) */", irn, get_cfop_target_block(irn));
944 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* fallthrough %s */", get_cfop_target(irn, buf));
949 /****************************
952 * _ __ _ __ ___ _ ___
953 * | '_ \| '__/ _ \| |/ __|
954 * | |_) | | | (_) | |\__ \
955 * | .__/|_| \___/| ||___/
958 ****************************/
961 * Emits code for a proj -> node
963 static void emit_Proj(const ir_node *irn, ia32_emit_env_t *env) {
964 ir_node *pred = get_Proj_pred(irn);
966 if (get_irn_op(pred) == op_Start) {
967 switch(get_Proj_proj(irn)) {
968 case pn_Start_X_initial_exec:
977 /**********************************
980 * | | ___ _ __ _ _| |_) |
981 * | | / _ \| '_ \| | | | _ <
982 * | |___| (_) | |_) | |_| | |_) |
983 * \_____\___/| .__/ \__, |____/
986 **********************************/
989 * Emit movsb/w instructions to make mov count divideable by 4
991 static void emit_CopyB_prolog(FILE *F, int rem, int size) {
992 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
994 fprintf(F, "\t/* memcopy %d bytes*/\n", size);
996 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "cld");
997 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* copy direction forward*/");
1002 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "movsb");
1003 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy remainder 1 */");
1006 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "movsw");
1007 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy remainder 2 */");
1010 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "movsb");
1011 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy remainder 3 */");
1013 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "movsw");
1014 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy remainder 3 */");
1022 * Emit rep movsd instruction for memcopy.
1024 static void emit_ia32_CopyB(const ir_node *irn, ia32_emit_env_t *emit_env) {
1025 FILE *F = emit_env->out;
1026 tarval *tv = get_ia32_Immop_tarval(irn);
1027 int rem = get_tarval_long(tv);
1028 int size = get_tarval_long(get_ia32_Immop_tarval(get_irn_n(irn, 2)));
1029 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1031 emit_CopyB_prolog(F, rem, size);
1033 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "rep movsd");
1034 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy */");
1039 * Emits unrolled memcopy.
1041 static void emit_ia32_CopyB_i(const ir_node *irn, ia32_emit_env_t *emit_env) {
1042 tarval *tv = get_ia32_Immop_tarval(irn);
1043 int size = get_tarval_long(tv);
1044 FILE *F = emit_env->out;
1045 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1047 emit_CopyB_prolog(F, size & 0x3, size);
1051 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "movsd");
1052 snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* memcopy unrolled */");
1059 /***************************
1063 * | | / _ \| '_ \ \ / /
1064 * | |___| (_) | | | \ V /
1065 * \_____\___/|_| |_|\_/
1067 ***************************/
1070 * Emit code for conversions (I, FP), (FP, I) and (FP, FP).
1072 static void emit_ia32_Conv_with_FP(const ir_node *irn, ia32_emit_env_t *emit_env) {
1073 FILE *F = emit_env->out;
1074 const lc_arg_env_t *env = ia32_get_arg_env();
1075 char *from, *to, buf[64];
1076 ir_mode *src_mode, *tgt_mode;
1077 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1079 src_mode = is_ia32_AddrModeS(irn) ? get_ia32_ls_mode(irn) : get_irn_mode(get_irn_n(irn, 2));
1080 tgt_mode = get_ia32_res_mode(irn);
1082 from = mode_is_float(src_mode) ? (get_mode_size_bits(src_mode) == 32 ? "ss" : "sd") : "si";
1083 to = mode_is_float(tgt_mode) ? (get_mode_size_bits(tgt_mode) == 32 ? "ss" : "sd") : "si";
1085 switch(get_ia32_op_type(irn)) {
1087 lc_esnprintf(env, buf, sizeof(buf), "%1D, %3S", irn, irn);
1089 case ia32_AddrModeS:
1090 lc_esnprintf(env, buf, sizeof(buf), "%1D, %s", irn, ia32_emit_am(irn, emit_env));
1093 assert(0 && "unsupported op type for Conv");
1096 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "cvt%s2%s %s", from, to, buf);
1097 lc_esnprintf(env, cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F(%+F, %+F) */", irn, src_mode, tgt_mode);
1101 static void emit_ia32_Conv_I2FP(const ir_node *irn, ia32_emit_env_t *emit_env) {
1102 emit_ia32_Conv_with_FP(irn, emit_env);
1105 static void emit_ia32_Conv_FP2I(const ir_node *irn, ia32_emit_env_t *emit_env) {
1106 emit_ia32_Conv_with_FP(irn, emit_env);
1109 static void emit_ia32_Conv_FP2FP(const ir_node *irn, ia32_emit_env_t *emit_env) {
1110 emit_ia32_Conv_with_FP(irn, emit_env);
1114 * Emits code for an Int conversion.
1116 static void emit_ia32_Conv_I2I(const ir_node *irn, ia32_emit_env_t *emit_env) {
1117 FILE *F = emit_env->out;
1118 const lc_arg_env_t *env = ia32_get_arg_env();
1119 char *move_cmd, *conv_cmd;
1120 ir_mode *src_mode, *tgt_mode;
1122 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1123 const arch_register_t *in_reg, *out_reg;
1125 src_mode = is_ia32_AddrModeS(irn) ? get_ia32_ls_mode(irn) : get_irn_mode(get_irn_n(irn, 2));
1126 tgt_mode = get_ia32_res_mode(irn);
1128 n = get_mode_size_bits(src_mode);
1129 m = get_mode_size_bits(tgt_mode);
1131 if (mode_is_signed(n < m ? src_mode : tgt_mode)) {
1133 if (n == 8 || m == 8)
1135 else if (n == 16 || m == 16)
1138 assert(0 && "unsupported Conv_I2I");
1145 switch(get_ia32_op_type(irn)) {
1147 in_reg = get_in_reg(irn, 2);
1148 out_reg = get_out_reg(irn, 0);
1150 if (REGS_ARE_EQUAL(in_reg, &ia32_gp_regs[REG_EAX]) &&
1151 REGS_ARE_EQUAL(out_reg, in_reg) &&
1152 mode_is_signed(n < m ? src_mode : tgt_mode))
1154 /* argument and result are both in EAX and */
1155 /* signedness is ok: -> use converts */
1156 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "%s", conv_cmd);
1158 else if (REGS_ARE_EQUAL(out_reg, in_reg) &&
1159 ! mode_is_signed(n < m ? src_mode : tgt_mode))
1161 /* argument and result are in the same register */
1162 /* and signedness is ok: -> use and with mask */
1163 int mask = (1 << (n < m ? n : m)) - 1;
1164 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "and %1D, 0x%x", irn, mask);
1167 /* use move w/o sign extension */
1168 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "%s %1D, %%%s",
1169 move_cmd, irn, ia32_get_reg_name_for_mode(emit_env, n < m ? src_mode : tgt_mode, in_reg));
1173 case ia32_AddrModeS:
1174 lc_esnprintf(env, cmd_buf, SNPRINTF_BUF_LEN, "%s %1D, %s",
1175 move_cmd, irn, ia32_emit_am(irn, emit_env));
1178 assert(0 && "unsupported op type for Conv");
1181 lc_esnprintf(env, cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F(%d Bit mode_%F -> %d Bit mode_%F) */",
1182 irn, n, src_mode, m, tgt_mode);
1188 * Emits code for an 8Bit Int conversion.
1190 void emit_ia32_Conv_I2I8Bit(const ir_node *irn, ia32_emit_env_t *emit_env) {
1191 emit_ia32_Conv_I2I(irn, emit_env);
1195 /*******************************************
1198 * | |__ ___ _ __ ___ __| | ___ ___
1199 * | '_ \ / _ \ '_ \ / _ \ / _` |/ _ \/ __|
1200 * | |_) | __/ | | | (_) | (_| | __/\__ \
1201 * |_.__/ \___|_| |_|\___/ \__,_|\___||___/
1203 *******************************************/
1206 * Emits a backend call
1208 static void emit_be_Call(const ir_node *irn, ia32_emit_env_t *emit_env) {
1209 FILE *F = emit_env->out;
1210 entity *ent = be_Call_get_entity(irn);
1211 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1214 snprintf(cmd_buf, SNPRINTF_BUF_LEN, "call %s", get_entity_name(ent));
1217 lc_esnprintf(ia32_get_arg_env(), cmd_buf, SNPRINTF_BUF_LEN, "%1D", get_irn_n(irn, be_pos_Call_ptr));
1220 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F (be_Call) */", irn);
1226 * Emits code to increase stack pointer.
1228 static void emit_be_IncSP(const ir_node *irn, ia32_emit_env_t *emit_env) {
1229 FILE *F = emit_env->out;
1230 unsigned offs = be_get_IncSP_offset(irn);
1231 be_stack_dir_t dir = be_get_IncSP_direction(irn);
1232 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1235 lc_esnprintf(ia32_get_arg_env(), cmd_buf, SNPRINTF_BUF_LEN, "add %1S,%s%u", irn,
1236 (dir == be_stack_dir_expand) ? " -" : " ", offs);
1237 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F (IncSP) */", irn);
1240 snprintf(cmd_buf, SNPRINTF_BUF_LEN, " ");
1241 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* omitted %+F (IncSP) with 0 */", irn);
1248 * Emits code to set stack pointer.
1250 static void emit_be_SetSP(const ir_node *irn, ia32_emit_env_t *emit_env) {
1251 FILE *F = emit_env->out;
1252 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1254 lc_esnprintf(ia32_get_arg_env(), cmd_buf, SNPRINTF_BUF_LEN, "mov %1D, %3S", irn, irn);
1255 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F (restore SP) */", irn);
1260 * Emits code for Copy.
1262 static void emit_be_Copy(const ir_node *irn, ia32_emit_env_t *emit_env) {
1263 FILE *F = emit_env->out;
1264 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1266 lc_esnprintf(ia32_get_arg_env(), cmd_buf, SNPRINTF_BUF_LEN, "mov %1D, %1S", irn, irn);
1267 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F */", irn);
1272 * Emits code for exchange.
1274 static void emit_be_Perm(const ir_node *irn, ia32_emit_env_t *emit_env) {
1275 FILE *F = emit_env->out;
1276 char cmd_buf[SNPRINTF_BUF_LEN], cmnt_buf[SNPRINTF_BUF_LEN];
1278 lc_esnprintf(ia32_get_arg_env(), cmd_buf, SNPRINTF_BUF_LEN, "xchg %1S, %2S", irn, irn);
1279 lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F(%1A, %2A) */", irn, irn, irn);
1283 /***********************************************************************************
1286 * _ __ ___ __ _ _ _ __ | |_ _ __ __ _ _ __ ___ _____ _____ _ __| | __
1287 * | '_ ` _ \ / _` | | '_ \ | _| '__/ _` | '_ ` _ \ / _ \ \ /\ / / _ \| '__| |/ /
1288 * | | | | | | (_| | | | | | | | | | | (_| | | | | | | __/\ V V / (_) | | | <
1289 * |_| |_| |_|\__,_|_|_| |_| |_| |_| \__,_|_| |_| |_|\___| \_/\_/ \___/|_| |_|\_\
1291 ***********************************************************************************/
1294 * Enters the emitter functions for handled nodes into the generic
1295 * pointer of an opcode.
1297 static void ia32_register_emitters(void) {
1299 #define IA32_EMIT(a) op_ia32_##a->ops.generic = (op_func)emit_ia32_##a
1300 #define EMIT(a) op_##a->ops.generic = (op_func)emit_##a
1301 #define BE_EMIT(a) op_be_##a->ops.generic = (op_func)emit_be_##a
1303 /* first clear the generic function pointer for all ops */
1304 clear_irp_opcodes_generic_func();
1306 /* register all emitter functions defined in spec */
1307 ia32_register_spec_emitters();
1309 /* other ia32 emitter functions */
1314 IA32_EMIT(SwitchJmp);
1317 IA32_EMIT(Conv_I2FP);
1318 IA32_EMIT(Conv_FP2I);
1319 IA32_EMIT(Conv_FP2FP);
1320 IA32_EMIT(Conv_I2I);
1321 IA32_EMIT(Conv_I2I8Bit);
1323 /* benode emitter */
1340 * Emits code for a node.
1342 static void ia32_emit_node(const ir_node *irn, void *env) {
1343 ia32_emit_env_t *emit_env = env;
1344 firm_dbg_module_t *mod = emit_env->mod;
1345 FILE *F = emit_env->out;
1346 ir_op *op = get_irn_op(irn);
1348 DBG((mod, LEVEL_1, "emitting code for %+F\n", irn));
1350 if (op->ops.generic) {
1351 void (*emit)(const ir_node *, void *) = (void (*)(const ir_node *, void *))op->ops.generic;
1355 ir_fprintf(F, "\t%35s /* %+F (%+G) */\n", " ", irn, irn);
1360 * Walks over the nodes in a block connected by scheduling edges
1361 * and emits code for each node.
1363 static void ia32_gen_block(ir_node *block, void *env) {
1366 if (! is_Block(block))
1369 fprintf(((ia32_emit_env_t *)env)->out, BLOCK_PREFIX("%ld:\n"), get_irn_node_nr(block));
1370 sched_foreach(block, irn) {
1371 ia32_emit_node(irn, env);
1376 * Emits code for function start.
1378 static void ia32_emit_func_prolog(FILE *F, ir_graph *irg) {
1379 entity *irg_ent = get_irg_entity(irg);
1380 const char *irg_name = get_entity_name(irg_ent);
1382 fprintf(F, "\t.text\n");
1383 if (get_entity_visibility(irg_ent) == visibility_external_visible) {
1384 fprintf(F, ".globl %s\n", irg_name);
1386 fprintf(F, "\t.type\t%s, @function\n", irg_name);
1387 fprintf(F, "%s:\n", irg_name);
1391 * Emits code for function end
1393 static void ia32_emit_func_epilog(FILE *F, ir_graph *irg) {
1394 const char *irg_name = get_entity_name(get_irg_entity(irg));
1396 fprintf(F, "\tret\n");
1397 fprintf(F, "\t.size\t%s, .-%s\n\n", irg_name, irg_name);
1402 * Sets labels for control flow nodes (jump target)
1403 * TODO: Jump optimization
1405 static void ia32_gen_labels(ir_node *block, void *env) {
1407 int n = get_Block_n_cfgpreds(block);
1409 for (n--; n >= 0; n--) {
1410 pred = get_Block_cfgpred(block, n);
1411 set_irn_link(pred, block);
1416 * Main driver. Emits the code for one routine.
1418 void ia32_gen_routine(FILE *F, ir_graph *irg, const ia32_code_gen_t *cg) {
1419 ia32_emit_env_t emit_env;
1422 emit_env.mod = firm_dbg_register("firm.be.ia32.emitter");
1424 emit_env.arch_env = cg->arch_env;
1426 emit_env.isa = (ia32_isa_t *)cg->arch_env->isa;
1428 /* set the global arch_env (needed by print hooks) */
1429 arch_env = cg->arch_env;
1431 ia32_register_emitters();
1433 ia32_emit_func_prolog(F, irg);
1434 irg_block_walk_graph(irg, ia32_gen_labels, NULL, &emit_env);
1436 if (cg->opt.extbb && cg->blk_sched) {
1437 int i, n = ARR_LEN(cg->blk_sched);
1439 for (i = 0; i < n;) {
1442 block = cg->blk_sched[i];
1444 next_bl = i < n ? cg->blk_sched[i] : NULL;
1446 /* set here the link. the emitter expects to find the next block here */
1447 set_irn_link(block, next_bl);
1448 ia32_gen_block(block, &emit_env);
1452 /* "normal" block schedule: Note the get_next_block() returns the NUMBER of the block
1453 in the block schedule. As this number should NEVER be equal the next block,
1454 we does not need a clear block link here. */
1455 irg_walk_blkwise_graph(irg, NULL, ia32_gen_block, &emit_env);
1458 ia32_emit_func_epilog(F, irg);