X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fbe%2Fia32%2Fia32_emitter.c;h=bffb6db84af90bd832aaa9bb61dbf952314ef21d;hb=176b5852057f4136da61a7118d8ae54b185412da;hp=c6a7ec268d537e73d10119f2d8bb07aa62b2aa30;hpb=8d75fa23ea7b6e9ee36c41dc1b2ca13ce965c15d;p=libfirm diff --git a/ir/be/ia32/ia32_emitter.c b/ir/be/ia32/ia32_emitter.c index c6a7ec268..bffb6db84 100644 --- a/ir/be/ia32/ia32_emitter.c +++ b/ir/be/ia32/ia32_emitter.c @@ -79,6 +79,7 @@ static ir_node *get_prev_block_sched(const ir_node *block) return get_irn_link(block); } +/** Checks if the current block is a fall-through target. */ static int is_fallthrough(const ir_node *cfgpred) { ir_node *pred; @@ -92,6 +93,10 @@ static int is_fallthrough(const ir_node *cfgpred) return 1; } +/** + * returns non-zero if the given block needs a label + * because of being a jump-target (and not a fall-through) + */ static int block_needs_label(const ir_node *block) { int need_label = 1; @@ -206,6 +211,9 @@ static char *get_unique_label(char *buf, size_t buflen, const char *prefix) * |_| |_| *************************************************************/ +/** + * Emit the name of the 8bit low register + */ static void emit_8bit_register(const arch_register_t *reg) { const char *reg_name = arch_register_get_name(reg); @@ -215,6 +223,18 @@ static void emit_8bit_register(const arch_register_t *reg) be_emit_char('l'); } +/** + * Emit the name of the 8bit high register + */ +static void emit_8bit_register_high(const arch_register_t *reg) +{ + const char *reg_name = arch_register_get_name(reg); + + be_emit_char('%'); + be_emit_char(reg_name[1]); + be_emit_char('h'); +} + static void emit_16bit_register(const arch_register_t *reg) { const char *reg_name = ia32_get_mapped_reg_name(isa->regs_16bit, reg); @@ -223,6 +243,12 @@ static void emit_16bit_register(const arch_register_t *reg) be_emit_string(reg_name); } +/** + * emit a register, possible shortened by a mode + * + * @param reg the register + * @param mode the mode of the register or NULL for full register + */ static void emit_register(const arch_register_t *reg, const ir_mode *mode) { const char *reg_name; @@ -299,7 +325,7 @@ static void emit_ia32_Immediate(const ir_node *node) void ia32_emit_8bit_source_register_or_immediate(const ir_node *node, int pos) { const arch_register_t *reg; - ir_node *in = get_irn_n(node, pos); + const ir_node *in = get_irn_n(node, pos); if (is_ia32_Immediate(in)) { emit_ia32_Immediate(in); return; @@ -309,6 +335,25 @@ void ia32_emit_8bit_source_register_or_immediate(const ir_node *node, int pos) emit_8bit_register(reg); } +void ia32_emit_8bit_high_source_register(const ir_node *node, int pos) +{ + const arch_register_t *reg = get_in_reg(node, pos); + emit_8bit_register_high(reg); +} + +void ia32_emit_16bit_source_register_or_immediate(const ir_node *node, int pos) +{ + const arch_register_t *reg; + const ir_node *in = get_irn_n(node, pos); + if (is_ia32_Immediate(in)) { + emit_ia32_Immediate(in); + return; + } + + reg = get_in_reg(node, pos); + emit_16bit_register(reg); +} + void ia32_emit_dest_register(const ir_node *node, int pos) { const arch_register_t *reg = get_out_reg(node, pos); @@ -316,6 +361,13 @@ void ia32_emit_dest_register(const ir_node *node, int pos) emit_register(reg, NULL); } +void ia32_emit_dest_register_size(const ir_node *node, int pos) +{ + const arch_register_t *reg = get_out_reg(node, pos); + + emit_register(reg, get_ia32_ls_mode(node)); +} + void ia32_emit_8bit_dest_register(const ir_node *node, int pos) { const arch_register_t *reg = get_out_reg(node, pos); @@ -411,11 +463,13 @@ void ia32_emit_xmm_mode_suffix_s(const ir_node *node) be_emit_char(get_xmm_mode_suffix(mode)); } -void ia32_emit_extend_suffix(const ir_mode *mode) +void ia32_emit_extend_suffix(const ir_node *node) { + ir_mode *mode = get_ia32_ls_mode(node); if (get_mode_size_bits(mode) == 32) return; be_emit_char(mode_is_signed(mode) ? 's' : 'z'); + ia32_emit_mode_suffix_mode(mode); } void ia32_emit_source_register_or_immediate(const ir_node *node, int pos) @@ -490,10 +544,17 @@ static const char *const cmp2condition_u[] = { NULL /* always true */ }; +/** + * Emit the suffix for a compare instruction. + */ static void ia32_emit_cmp_suffix(int pnc) { const char *str; + if (pnc == ia32_pn_Cmp_parity) { + be_emit_char('p'); + return; + } if (pnc & ia32_pn_Cmp_float || pnc & ia32_pn_Cmp_unsigned) { str = cmp2condition_u[pnc & 7]; } else { @@ -505,7 +566,8 @@ static void ia32_emit_cmp_suffix(int pnc) typedef enum ia32_emit_mod_t { EMIT_RESPECT_LS = 1U << 0, - EMIT_ALTERNATE_AM = 1U << 1 + EMIT_ALTERNATE_AM = 1U << 1, + EMIT_LONG = 1U << 2 } ia32_emit_mod_t; /** @@ -524,10 +586,12 @@ typedef enum ia32_emit_mod_t { * %Sx source register x * %s const char* string * %u unsigned int unsigned int + * %d signed int signed int * * x starts at 0 * # modifier for %ASx, %D and %S uses ls mode of node to alter register width * * modifier does not prefix immediates with $, but AM with * + * l modifier for %lu and %ld */ static void ia32_emitf(const ir_node *node, const char *fmt, ...) { @@ -566,6 +630,11 @@ static void ia32_emitf(const ir_node *node, const char *fmt, ...) ++fmt; } + if (*fmt == 'l') { + mod |= EMIT_LONG; + ++fmt; + } + switch (*fmt++) { case '%': be_emit_char('%'); @@ -679,15 +748,29 @@ emit_S: break; } - case 'u': { - unsigned num = va_arg(ap, unsigned); - be_emit_irprintf("%u", num); + case 'u': + if (mod & EMIT_LONG) { + unsigned long num = va_arg(ap, unsigned long); + be_emit_irprintf("%lu", num); + } else { + unsigned num = va_arg(ap, unsigned); + be_emit_irprintf("%u", num); + } + break; + + case 'd': + if (mod & EMIT_LONG) { + long num = va_arg(ap, long); + be_emit_irprintf("%ld", num); + } else { + int num = va_arg(ap, int); + be_emit_irprintf("%d", num); + } break; - } default: unknown: - panic("unknown conversion"); + panic("unknown format conversion in ia32_emitf()"); } } @@ -1710,6 +1793,18 @@ static void emit_ia32_GetEIP(const ir_node *node) ia32_emitf(node, "\tpopl %D0\n"); } +static void emit_ia32_ClimbFrame(const ir_node *node) +{ + const ia32_climbframe_attr_t *attr = get_ia32_climbframe_attr_const(node); + + ia32_emitf(node, "\tmovl %S0, %D0\n"); + ia32_emitf(node, "\tmovl $%u, %S1\n", attr->count); + ia32_emitf(NULL, BLOCK_PREFIX "%ld:\n", get_irn_node_nr(node)); + ia32_emitf(node, "\tmovl (%D0), %D0\n"); + ia32_emitf(node, "\tdec %S1\n"); + ia32_emitf(node, "\tjnz " BLOCK_PREFIX "%ld\n", get_irn_node_nr(node)); +} + static void emit_be_Return(const ir_node *node) { unsigned pop = be_Return_get_pop(node); @@ -1774,6 +1869,7 @@ static void ia32_register_emitters(void) IA32_EMIT(LdTls); IA32_EMIT(Minus64Bit); IA32_EMIT(SwitchJmp); + IA32_EMIT(ClimbFrame); /* benode emitter */ BE_EMIT(Copy); @@ -1932,7 +2028,7 @@ static void ia32_emit_block_header(ir_node *block) int i, arity; ir_exec_freq *exec_freq = cg->birg->exec_freq; - if (block == get_irg_end_block(irg) || block == get_irg_start_block(irg)) + if (block == get_irg_end_block(irg)) return; if (ia32_cg_config.label_alignment > 0) { @@ -1977,12 +2073,16 @@ static void ia32_emit_block_header(ir_node *block) /* emit list of pred blocks in comment */ arity = get_irn_arity(block); - for (i = 0; i < arity; ++i) { - ir_node *predblock = get_Block_cfgpred_block(block, i); - be_emit_irprintf(" %d", get_irn_node_nr(predblock)); + if (arity <= 0) { + be_emit_cstring(" none"); + } else { + for (i = 0; i < arity; ++i) { + ir_node *predblock = get_Block_cfgpred_block(block, i); + be_emit_irprintf(" %d", get_irn_node_nr(predblock)); + } } if (exec_freq != NULL) { - be_emit_irprintf(" freq: %f", + be_emit_irprintf(", freq: %f", get_block_execfreq(exec_freq, block)); } be_emit_cstring(" */\n");