#include "ia32_nodes_attr.h"
#include "ia32_new_nodes.h"
#include "ia32_map_regs.h"
+#include "bearch_ia32_t.h"
#define BLOCK_PREFIX(x) ".L" x
*/
void ia32_switch_section(FILE *F, section_t sec) {
static section_t curr_sec = NO_SECTION;
- static const char *text[ASM_MAX][SECTION_MAX] = {
+ static const char *text[ASM_MAX][SECTION_MAX] = {
{
".section\t.text", ".section\t.data", ".section\t.rodata", ".section\t.text"
},
reg = &ia32_xmm_regs[REG_XMM0];
else if (REGS_ARE_EQUAL(reg, &ia32_vfp_regs[REG_VFP_UKNWN]))
reg = &ia32_vfp_regs[REG_VF0];
- else if (REGS_ARE_EQUAL(reg, &ia32_st_regs[REG_ST_UKNWN]))
- reg = &ia32_st_regs[REG_ST0];
return reg;
}
ir_mode *mode = get_irn_mode(X);
if (mode == mode_T) {
- mode = is_ia32_AddrModeS(X) || is_ia32_AddrModeD(X) ? get_ia32_ls_mode(X) : get_ia32_res_mode(X);
+ mode = (is_ia32_Ld(X) || is_ia32_St(X)) ? get_ia32_ls_mode(X) : get_ia32_res_mode(X);
}
if (!X)
lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%1D, %s", n, ia32_emit_am(n, env));
}
else {
- lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%4S, %s", n, ia32_emit_am(n, env));
+ lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%3S, %s", n, ia32_emit_am(n, env));
}
}
break;
lc_esnprintf(ia32_get_arg_env(), buf, SNPRINTF_BUF_LEN, "%1D", n);
}
break;
- case ia32_am_Dest:
- snprintf(buf, SNPRINTF_BUF_LEN, ia32_emit_am(n, env));
+ case ia32_AddrModeD:
+ snprintf(buf, SNPRINTF_BUF_LEN, "%s", ia32_emit_am(n, env));
break;
default:
assert(0 && "unsupported op type");
static char *get_cfop_target(const ir_node *irn, char *buf) {
ir_node *bl = get_cfop_target_block(irn);
- snprintf(buf, SNPRINTF_BUF_LEN, BLOCK_PREFIX("%ld"), get_irn_idx(bl));
+ snprintf(buf, SNPRINTF_BUF_LEN, BLOCK_PREFIX("%ld"), get_irn_node_nr(bl));
return buf;
}
return get_irn_link(block);
}
+/**
+ * Returns the Proj with projection number proj and NOT mode_M
+ */
+static ir_node *get_proj(const ir_node *irn, long proj) {
+ const ir_edge_t *edge;
+ ir_node *src;
+
+ assert(get_irn_mode(irn) == mode_T && "expected mode_T node");
+
+ foreach_out_edge(irn, edge) {
+ src = get_edge_src_irn(edge);
+
+ assert(is_Proj(src) && "Proj expected");
+ if (get_irn_mode(src) == mode_M)
+ continue;
+
+ if (get_Proj_proj(src) == proj)
+ return src;
+ }
+ return NULL;
+}
+
/**
* Emits the jump sequence for a conditional jump (cmp + jmp_true + jmp_false)
*/
static void finish_CondJmp(FILE *F, const ir_node *irn, ir_mode *mode) {
const ir_node *proj1, *proj2 = NULL;
const ir_node *block, *next_bl = NULL;
- const ir_edge_t *edge;
char buf[SNPRINTF_BUF_LEN];
char cmd_buf[SNPRINTF_BUF_LEN];
char cmnt_buf[SNPRINTF_BUF_LEN];
/* get both Proj's */
- edge = get_irn_out_edge_first(irn);
- proj1 = get_edge_src_irn(edge);
- assert(is_Proj(proj1) && "CondJmp with a non-Proj");
+ proj1 = get_proj(irn, pn_Cond_true);
+ assert(proj1 && "CondJmp without true Proj");
- edge = get_irn_out_edge_next(irn, edge);
- if (edge) {
- proj2 = get_edge_src_irn(edge);
- assert(is_Proj(proj2) && "CondJmp with a non-Proj");
- }
+ proj2 = get_proj(irn, pn_Cond_false);
+ assert(proj2 && "CondJmp without false Proj");
/* for now, the code works for scheduled and non-schedules blocks */
block = get_nodes_block(irn);
- if (proj2) {
- /* we have a block schedule */
- next_bl = next_blk_sched(block);
-
- if (get_cfop_target_block(proj1) == next_bl) {
- /* exchange both proj's so the second one can be omitted */
- const ir_node *t = proj1;
- proj1 = proj2;
- proj2 = t;
- }
+
+ /* we have a block schedule */
+ next_bl = next_blk_sched(block);
+
+ if (get_cfop_target_block(proj1) == next_bl) {
+ /* exchange both proj's so the second one can be omitted */
+ const ir_node *t = proj1;
+ proj1 = proj2;
+ proj2 = t;
}
/* the first Proj must always be created */
IA32_DO_EMIT(irn);
/* the second Proj might be a fallthrough */
- if (proj2) {
- if (get_cfop_target_block(proj2) != next_bl) {
- snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(proj2, buf));
- snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* otherwise */");
- }
- else {
- cmd_buf[0] = '\0';
- snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* fallthrogh %s */", get_cfop_target(proj2, buf));
- }
- IA32_DO_EMIT(irn);
+ if (get_cfop_target_block(proj2) != next_bl) {
+ snprintf(cmd_buf, SNPRINTF_BUF_LEN, "jmp %s", get_cfop_target(proj2, buf));
+ snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* otherwise */");
+ }
+ else {
+ cmd_buf[0] = '\0';
+ snprintf(cmnt_buf, SNPRINTF_BUF_LEN, "/* fallthrough %s */", get_cfop_target(proj2, buf));
}
+ IA32_DO_EMIT(irn);
}
/**
/**
* Emits code for conditional x87 floating point jump with two variables.
*/
-static void emit_ia32_x87CondJmp(const ir_node *irn, ia32_emit_env_t *env) {
+static void emit_ia32_x87CondJmp(ir_node *irn, ia32_emit_env_t *env) {
FILE *F = env->out;
char cmd_buf[SNPRINTF_BUF_LEN];
char cmnt_buf[SNPRINTF_BUF_LEN];
}
if (reverse)
- set_ia32_pncode(irn, get_negated_pnc(get_ia32_pncode(irn), mode_Is));
+ set_ia32_pncode(irn, (long)get_negated_pnc(get_ia32_pncode(irn), mode_Is));
snprintf(cmd_buf, SNPRINTF_BUF_LEN, "%s %s", instr, reg);
lc_esnprintf(ia32_get_arg_env(), cmnt_buf, SNPRINTF_BUF_LEN, "/* %+F */", irn);
}
}
+/**
+ * Emits gas alignment directives
+ */
+static void ia32_emit_alignment(FILE *F, unsigned align, unsigned skip) {
+ fprintf(F, "\t.p2align %u,,%u\n", align, skip);
+}
+
+/**
+ * Emits gas alignment directives for Functions depended on cpu architecture.
+ */
+static void ia32_emit_align_func(FILE *F, cpu_support cpu) {
+ unsigned align; unsigned maximum_skip;
+
+ /* gcc doesn't emit alignment for p4 ?*/
+ if (cpu == arch_pentium_4)
+ return;
+
+ switch (cpu) {
+ case arch_i386:
+ align = 2; maximum_skip = 3;
+ break;
+ case arch_i486:
+ align = 4; maximum_skip = 15;
+ break;
+ case arch_k6:
+ align = 5; maximum_skip = 31;
+ break;
+ default:
+ align = 4; maximum_skip = 15;
+ }
+ ia32_emit_alignment(F, align, maximum_skip);
+}
+
+/**
+ * Emits gas alignment directives for Labels depended on cpu architecture.
+ */
+static void ia32_emit_align_label(FILE *F, cpu_support cpu) {
+ unsigned align; unsigned maximum_skip;
+
+ /* gcc doesn't emit alignment for p4 ?*/
+ if (cpu == arch_pentium_4)
+ return;
+
+ switch (cpu) {
+ case arch_i386:
+ align = 2; maximum_skip = 3;
+ break;
+ case arch_i486:
+ align = 4; maximum_skip = 15;
+ break;
+ case arch_k6:
+ align = 5; maximum_skip = 7;
+ break;
+ default:
+ align = 4; maximum_skip = 7;
+ }
+ ia32_emit_alignment(F, align, maximum_skip);
+}
+
/**
* Walks over the nodes in a block connected by scheduling edges
* and emits code for each node.
need_label = (block == get_extbb_leader(get_nodes_extbb(block)));
}
- if (need_label)
- fprintf(emit_env->out, BLOCK_PREFIX("%ld:\n"), get_irn_idx(block));
+ if (need_label) {
+ ia32_emit_align_label(emit_env->out, emit_env->isa->opt_arch);
+ fprintf(emit_env->out, BLOCK_PREFIX("%ld:\n"), get_irn_node_nr(block));
+ }
+
sched_foreach(block, irn) {
ia32_emit_node(irn, env);
}
/**
* Emits code for function start.
*/
-static void ia32_emit_func_prolog(FILE *F, ir_graph *irg) {
+static void ia32_emit_func_prolog(FILE *F, ir_graph *irg, cpu_support cpu) {
entity *irg_ent = get_irg_entity(irg);
const char *irg_name = get_entity_ld_name(irg_ent);
fprintf(F, "\n");
ia32_switch_section(F, SECTION_TEXT);
+ ia32_emit_align_func(F, cpu);
if (get_entity_visibility(irg_ent) == visibility_external_visible) {
fprintf(F, ".globl %s\n", irg_name);
}
ia32_register_emitters();
- ia32_emit_func_prolog(F, irg);
+ ia32_emit_func_prolog(F, irg, emit_env.isa->opt_arch);
irg_block_walk_graph(irg, ia32_gen_labels, NULL, &emit_env);
if ((cg->opt & IA32_OPT_EXTBB) && cg->blk_sched) {