/**
* @file
* @brief emit assembler for a backend graph
+ * @author Hannes Rapp, Matthias Braun
* @version $Id$
*/
#include "config.h"
return reg;
}
-static bool is_valid_immediate(int32_t value)
-{
- return -4096 <= value && value < 4096;
-}
-
void sparc_emit_immediate(const ir_node *node)
{
const sparc_attr_t *attr = get_sparc_attr_const(node);
if (entity == NULL) {
int32_t value = attr->immediate_value;
- assert(is_valid_immediate(value));
+ assert(sparc_is_value_imm_encodeable(value));
be_emit_irprintf("%d", value);
} else {
be_emit_cstring("%lo(");
*/
void sparc_emit_reg_or_imm(const ir_node *node, int pos)
{
- if (get_irn_arity(node) > pos) {
- // we have reg input
- sparc_emit_source_register(node, pos);
- } else {
+ if (arch_irn_get_flags(node) & ((arch_irn_flags_t)sparc_arch_irn_flag_immediate_form)) {
// we have a imm input
sparc_emit_immediate(node);
+ } else {
+ // we have reg input
+ sparc_emit_source_register(node, pos);
}
}
-static bool is_stack_pointer_relative(const ir_node *node)
-{
- const arch_register_t *sp = &sparc_registers[REG_SP];
- return (is_sparc_St(node) && get_in_reg(node, n_sparc_St_ptr) == sp)
- || (is_sparc_Ld(node) && get_in_reg(node, n_sparc_Ld_ptr) == sp);
-}
-
/**
* emit SP offset
*/
sparc_emit_source_register(node, offset_node_pos);
} else if (attr->is_frame_entity) {
int32_t offset = attr->base.immediate_value;
- /* bad hack: the real stack stuff is behind the always-there spill
- * space for the register window and stack */
- if (is_stack_pointer_relative(node))
- offset += SPARC_MIN_STACKSIZE;
if (offset != 0) {
- assert(is_valid_immediate(offset));
+ assert(sparc_is_value_imm_encodeable(offset));
be_emit_irprintf("%+ld", offset);
}
} else if (attr->base.immediate_value != 0
*/
static void emit_be_IncSP(const ir_node *irn)
{
- int offs = -be_get_IncSP_offset(irn);
+ int offset = be_get_IncSP_offset(irn);
- if (offs == 0)
+ if (offset == 0)
return;
/* SPARC stack grows downwards */
- if (offs < 0) {
+ if (offset < 0) {
be_emit_cstring("\tsub ");
- offs = -offs;
+ offset = -offset;
} else {
be_emit_cstring("\tadd ");
}
sparc_emit_source_register(irn, 0);
- be_emit_irprintf(", %d", offs);
+ be_emit_irprintf(", %d", -offset);
be_emit_cstring(", ");
sparc_emit_dest_register(irn, 0);
be_emit_finish_line_gas(irn);
static void emit_sparc_FrameAddr(const ir_node *node)
{
- const sparc_attr_t *attr = get_sparc_attr_const(node);
+ const sparc_attr_t *attr = get_sparc_attr_const(node);
+ int32_t offset = attr->immediate_value;
- // no need to fix offset as we are adressing via the framepointer
- if (attr->immediate_value >= 0) {
+ if (offset < 0) {
be_emit_cstring("\tadd ");
sparc_emit_source_register(node, 0);
be_emit_cstring(", ");
- be_emit_irprintf("%ld", attr->immediate_value);
+ assert(sparc_is_value_imm_encodeable(offset));
+ be_emit_irprintf("%ld", offset);
} else {
be_emit_cstring("\tsub ");
sparc_emit_source_register(node, 0);
be_emit_cstring(", ");
- be_emit_irprintf("%ld", -attr->immediate_value);
+ assert(sparc_is_value_imm_encodeable(-offset));
+ be_emit_irprintf("%ld", -offset);
}
be_emit_cstring(", ");
be_emit_finish_line_gas(node);
}
-static void emit_jump_table(const ir_node *node)
+static void emit_sparc_SwitchJmp(const ir_node *node)
{
const sparc_switch_jmp_attr_t *attr = get_sparc_switch_jmp_attr_const(node);
- long switch_max = LONG_MIN;
- long default_pn = attr->default_proj_num;
- ir_entity *entity = attr->jump_table;
- ir_node *default_block = NULL;
- unsigned long length;
- const ir_edge_t *edge;
- unsigned i;
- ir_node **table;
- /* go over all proj's and collect them */
- foreach_out_edge(node, edge) {
- ir_node *proj = get_edge_src_irn(edge);
- long pn = get_Proj_proj(proj);
-
- /* check for default proj */
- if (pn == default_pn) {
- assert(default_block == NULL); /* more than 1 default_pn? */
- default_block = get_jump_target(proj);
- } else {
- switch_max = pn > switch_max ? pn : switch_max;
- }
- }
- assert(switch_max > LONG_MIN);
-
- length = (unsigned long) switch_max + 1;
- /* the 16000 isn't a real limit of the architecture. But should protect us
- * from seamingly endless compiler runs */
- if (length > 16000) {
- /* switch lowerer should have broken this monster to pieces... */
- panic("too large switch encountered");
- }
-
- table = XMALLOCNZ(ir_node*, length);
- foreach_out_edge(node, edge) {
- ir_node *proj = get_edge_src_irn(edge);
- long pn = get_Proj_proj(proj);
- if (pn == default_pn)
- continue;
-
- table[pn] = get_jump_target(proj);
- }
-
- /* emit table */
- be_gas_emit_switch_section(GAS_SECTION_RODATA);
- be_emit_cstring("\t.align 4\n");
- be_gas_emit_entity(entity);
- be_emit_cstring(":\n");
- for (i = 0; i < length; ++i) {
- ir_node *block = table[i];
- if (block == NULL)
- block = default_block;
- be_emit_cstring("\t.long ");
- be_gas_emit_block_name(block);
- be_emit_char('\n');
- be_emit_write_line();
- }
- be_gas_emit_switch_section(GAS_SECTION_TEXT);
-
- xfree(table);
-}
-
-static void emit_sparc_SwitchJmp(const ir_node *node)
-{
be_emit_cstring("\tjmp ");
sparc_emit_source_register(node, 0);
be_emit_finish_line_gas(node);
fill_delay_slot();
- emit_jump_table(node);
+ emit_jump_table(node, attr->default_proj_num, attr->jump_table,
+ get_jump_target);
}
static void emit_fmov(const ir_node *node, const arch_register_t *src_reg,
static const arch_register_t *get_next_fp_reg(const arch_register_t *reg)
{
- unsigned index = reg->global_index;
- assert(reg == &sparc_registers[index]);
- index++;
- assert(index - REG_F0 < N_sparc_fp_REGS);
- return &sparc_registers[index];
+ unsigned idx = reg->global_index;
+ assert(reg == &sparc_registers[idx]);
+ idx++;
+ assert(idx - REG_F0 < N_sparc_fp_REGS);
+ return &sparc_registers[idx];
}
static void emit_be_Copy(const ir_node *node)