#include <limits.h>
+#include "bitfiddle.h"
#include "xmalloc.h"
#include "tv.h"
#include "iredges.h"
#include "dbginfo.h"
#include "heights.h"
-#include "../besched.h"
-#include "../beblocksched.h"
-#include "../beirg.h"
-#include "../begnuas.h"
-#include "../be_dbgout.h"
-#include "../benode.h"
-#include "../bestack.h"
+#include "besched.h"
+#include "beblocksched.h"
+#include "beirg.h"
+#include "begnuas.h"
+#include "be_dbgout.h"
+#include "benode.h"
+#include "bestack.h"
#include "sparc_emitter.h"
#include "gen_sparc_emitter.h"
static void sparc_emit_node(const ir_node *node);
-/**
- * Returns the register at in position pos.
- */
-static const arch_register_t *get_in_reg(const ir_node *node, int pos)
-{
- ir_node *op;
- const arch_register_t *reg = NULL;
-
- assert(get_irn_arity(node) > pos && "Invalid IN position");
-
- /* The out register of the operator at position pos is the
- in register we need. */
- op = get_irn_n(node, pos);
-
- reg = arch_get_irn_register(op);
-
- assert(reg && "no in register found");
- return reg;
-}
-
-/**
- * Returns the register at out position pos.
- */
-static const arch_register_t *get_out_reg(const ir_node *node, int pos)
-{
- ir_node *proj;
- const arch_register_t *reg = NULL;
-
- /* 1st case: irn is not of mode_T, so it has only */
- /* one OUT register -> good */
- /* 2nd case: irn is of mode_T -> collect all Projs and ask the */
- /* Proj with the corresponding projnum for the register */
-
- if (get_irn_mode(node) != mode_T) {
- reg = arch_get_irn_register(node);
- } else if (is_sparc_irn(node)) {
- reg = arch_irn_get_register(node, pos);
- } else {
- const ir_edge_t *edge;
-
- foreach_out_edge(node, edge) {
- proj = get_edge_src_irn(edge);
- assert(is_Proj(proj) && "non-Proj from mode_T node");
- if (get_Proj_proj(proj) == pos) {
- reg = arch_get_irn_register(proj);
- break;
- }
- }
- }
-
- assert(reg && "no out register found");
- return reg;
-}
-
void sparc_emit_immediate(const ir_node *node)
{
const sparc_attr_t *attr = get_sparc_attr_const(node);
assert(sparc_is_value_imm_encodeable(value));
be_emit_irprintf("%d", value);
} else {
- be_emit_cstring("%lo(");
+ if (get_entity_owner(entity) == get_tls_type()) {
+ be_emit_cstring("%tle_lox10(");
+ } else {
+ be_emit_cstring("%lo(");
+ }
be_gas_emit_entity(entity);
if (attr->immediate_value != 0) {
be_emit_irprintf("%+d", attr->immediate_value);
const sparc_attr_t *attr = get_sparc_attr_const(node);
ir_entity *entity = attr->immediate_value_entity;
- be_emit_cstring("%hi(");
if (entity == NULL) {
uint32_t value = (uint32_t) attr->immediate_value;
- be_emit_irprintf("0x%X", value);
+ be_emit_irprintf("%%hi(0x%X)", value);
} else {
+ if (get_entity_owner(entity) == get_tls_type()) {
+ be_emit_cstring("%tle_hix22(");
+ } else {
+ be_emit_cstring("%hi(");
+ }
be_gas_emit_entity(entity);
if (attr->immediate_value != 0) {
be_emit_irprintf("%+d", attr->immediate_value);
}
+ be_emit_char(')');
}
- be_emit_char(')');
}
void sparc_emit_source_register(const ir_node *node, int pos)
{
- const arch_register_t *reg = get_in_reg(node, pos);
+ const arch_register_t *reg = arch_get_irn_register_in(node, pos);
be_emit_char('%');
be_emit_string(arch_register_get_name(reg));
}
void sparc_emit_dest_register(const ir_node *node, int pos)
{
- const arch_register_t *reg = get_out_reg(node, pos);
+ const arch_register_t *reg = arch_get_irn_register_out(node, pos);
be_emit_char('%');
be_emit_string(arch_register_get_name(reg));
}
*/
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_get_irn_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);
}
}
}
}
-/**
- * emit integer signed/unsigned prefix char
- */
-void sparc_emit_mode_sign_prefix(const ir_node *node)
-{
- ir_mode *mode = get_irn_mode(node);
- bool is_signed = mode_is_signed(mode);
- be_emit_string(is_signed ? "s" : "u");
-}
-
static void emit_fp_suffix(const ir_mode *mode)
{
unsigned bits = get_mode_size_bits(mode);
{
/* copies are nops if src_reg == dest_reg */
if (be_is_Copy(node) || be_is_CopyKeep(node)) {
- const arch_register_t *src_reg = get_in_reg(node, 0);
- const arch_register_t *dest_reg = get_out_reg(node, 0);
+ const arch_register_t *src_reg = arch_get_irn_register_in(node, 0);
+ const arch_register_t *dest_reg = arch_get_irn_register_out(node, 0);
if (src_reg == dest_reg)
return true;
static bool has_delay_slot(const ir_node *node)
{
- if (is_sparc_Ba(node) && ba_is_fallthrough(node))
- return false;
+ if (is_sparc_Ba(node)) {
+ return !ba_is_fallthrough(node);
+ }
- return is_sparc_Bicc(node) || is_sparc_fbfcc(node) || is_sparc_Ba(node)
- || is_sparc_SwitchJmp(node) || is_sparc_Call(node)
- || is_sparc_SDiv(node) || is_sparc_UDiv(node)
- || be_is_Return(node);
+ return arch_get_irn_flags(node) & sparc_arch_irn_flag_has_delay_slot;
}
/** returns true if the emitter for this sparc node can produce more than one
if (has_delay_slot(node))
return true;
- return is_sparc_Mulh(node) || is_sparc_SDiv(node) || is_sparc_UDiv(node)
+ if (is_sparc_Call(node)) {
+ return arch_get_irn_flags(node) & sparc_arch_irn_flag_aggregate_return;
+ }
+
+ return is_sparc_SMulh(node) || is_sparc_UMulh(node)
+ || is_sparc_SDiv(node) || is_sparc_UDiv(node)
|| be_is_MemPerm(node) || be_is_Perm(node);
}
/* the Call also destroys the value of %o7, but since this is currently
* marked as ignore register in the backend, it should never be used by
* the instruction in the delay slot. */
- } else if (be_is_Return(node)) {
+ } else if (is_sparc_Return(node)) {
/* we only have to check the jump destination value */
int arity = get_irn_arity(node);
int i;
if (emits_multiple_instructions(schedpoint))
continue;
+ /* if check and schedpoint are not in the same block, give up. */
+ if (check != NULL
+ && get_nodes_block(check) != get_nodes_block(schedpoint))
+ break;
+
/* allowed for delayslot: any instruction which is not necessary to
* compute an input to the branch. */
if (check != NULL
static void emit_sparc_Mulh(const ir_node *irn)
{
be_emit_cstring("\t");
- sparc_emit_mode_sign_prefix(irn);
+ if (is_sparc_UMulh(irn)) {
+ be_emit_char('u');
+ } else {
+ assert(is_sparc_SMulh(irn));
+ be_emit_char('s');
+ }
be_emit_cstring("mul ");
sparc_emit_source_register(irn, 0);
be_emit_finish_line_gas(node);
fill_delay_slot();
+
+ if (arch_get_irn_flags(node) & sparc_arch_irn_flag_aggregate_return) {
+ be_emit_cstring("\tunimp 8\n");
+ be_emit_write_line();
+ }
}
/**
be_emit_finish_line_gas(irn);
}
-static void emit_be_MemPerm(const ir_node *node)
+/* The stack pointer must always be SPARC_STACK_ALIGNMENT bytes aligned, so get
+ * the next bigger integer that's evenly divisible by it. */
+static unsigned get_aligned_sp_change(const unsigned num_regs)
{
- int i;
- int memperm_arity;
- int sp_change = 0;
- ir_graph *irg = get_irn_irg(node);
- be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
+ const unsigned bytes = num_regs * SPARC_REGISTER_SIZE;
+ return round_up2(bytes, SPARC_STACK_ALIGNMENT);
+}
- /* this implementation only works with frame pointers currently */
- assert(layout->sp_relative == false);
+/* Spill register l0 or both l0 and l1, depending on n_spilled and n_to_spill.*/
+static void memperm_emit_spill_registers(const ir_node *node, int n_spilled,
+ int n_to_spill)
+{
+ assert(n_spilled < n_to_spill);
+
+ if (n_spilled == 0) {
+ /* We always reserve stack space for two registers because during copy
+ * processing we don't know yet if we also need to handle a cycle which
+ * needs two registers. More complicated code in emit_MemPerm would
+ * prevent wasting SPARC_REGISTER_SIZE bytes of stack space but
+ * it is not worth the worse readability of emit_MemPerm. */
+
+ /* Keep stack pointer aligned. */
+ unsigned sp_change = get_aligned_sp_change(2);
+ be_emit_irprintf("\tsub %%sp, %u, %%sp", sp_change);
+ be_emit_finish_line_gas(node);
- /* TODO: this implementation is slower than necessary.
- The longterm goal is however to avoid the memperm node completely */
+ /* Spill register l0. */
+ be_emit_irprintf("\tst %%l0, [%%sp%+d]", SPARC_MIN_STACKSIZE);
+ be_emit_finish_line_gas(node);
+ }
- memperm_arity = be_get_MemPerm_entity_arity(node);
- // we use our local registers - so this is limited to 8 inputs !
- if (memperm_arity > 8)
- panic("memperm with more than 8 inputs not supported yet");
+ if (n_to_spill == 2) {
+ /* Spill register l1. */
+ be_emit_irprintf("\tst %%l1, [%%sp%+d]", SPARC_MIN_STACKSIZE + SPARC_REGISTER_SIZE);
+ be_emit_finish_line_gas(node);
+ }
+}
- be_emit_irprintf("\tsub %%sp, %d, %%sp", memperm_arity*4);
+/* Restore register l0 or both l0 and l1, depending on n_spilled. */
+static void memperm_emit_restore_registers(const ir_node *node, int n_spilled)
+{
+ unsigned sp_change;
+
+ if (n_spilled == 2) {
+ /* Restore register l1. */
+ be_emit_irprintf("\tld [%%sp%+d], %%l1", SPARC_MIN_STACKSIZE + SPARC_REGISTER_SIZE);
+ be_emit_finish_line_gas(node);
+ }
+
+ /* Restore register l0. */
+ be_emit_irprintf("\tld [%%sp%+d], %%l0", SPARC_MIN_STACKSIZE);
be_emit_finish_line_gas(node);
- for (i = 0; i < memperm_arity; ++i) {
- ir_entity *entity = be_get_MemPerm_in_entity(node, i);
- int offset = be_get_stack_entity_offset(layout, entity, 0);
+ /* Restore stack pointer. */
+ sp_change = get_aligned_sp_change(2);
+ be_emit_irprintf("\tadd %%sp, %u, %%sp", sp_change);
+ be_emit_finish_line_gas(node);
+}
- /* spill register */
- be_emit_irprintf("\tst %%l%d, [%%sp%+d]", i, sp_change + SPARC_MIN_STACKSIZE);
- be_emit_finish_line_gas(node);
+/* Emit code to copy in_ent to out_ent. Only uses l0. */
+static void memperm_emit_copy(const ir_node *node, ir_entity *in_ent,
+ ir_entity *out_ent)
+{
+ ir_graph *irg = get_irn_irg(node);
+ be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
+ int off_in = be_get_stack_entity_offset(layout, in_ent, 0);
+ int off_out = be_get_stack_entity_offset(layout, out_ent, 0);
- /* load from entity */
- be_emit_irprintf("\tld [%%fp%+d], %%l%d", offset, i);
- be_emit_finish_line_gas(node);
- sp_change += 4;
+ /* Load from input entity. */
+ be_emit_irprintf("\tld [%%fp%+d], %%l0", off_in);
+ be_emit_finish_line_gas(node);
+
+ /* Store to output entity. */
+ be_emit_irprintf("\tst %%l0, [%%fp%+d]", off_out);
+ be_emit_finish_line_gas(node);
+}
+
+/* Emit code to swap ent1 and ent2. Uses l0 and l1. */
+static void memperm_emit_swap(const ir_node *node, ir_entity *ent1,
+ ir_entity *ent2)
+{
+ ir_graph *irg = get_irn_irg(node);
+ be_stack_layout_t *layout = be_get_irg_stack_layout(irg);
+ int off1 = be_get_stack_entity_offset(layout, ent1, 0);
+ int off2 = be_get_stack_entity_offset(layout, ent2, 0);
+
+ /* Load from first input entity. */
+ be_emit_irprintf("\tld [%%fp%+d], %%l0", off1);
+ be_emit_finish_line_gas(node);
+
+ /* Load from second input entity. */
+ be_emit_irprintf("\tld [%%fp%+d], %%l1", off2);
+ be_emit_finish_line_gas(node);
+
+ /* Store first value to second output entity. */
+ be_emit_irprintf("\tst %%l0, [%%fp%+d]", off2);
+ be_emit_finish_line_gas(node);
+
+ /* Store second value to first output entity. */
+ be_emit_irprintf("\tst %%l1, [%%fp%+d]", off1);
+ be_emit_finish_line_gas(node);
+}
+
+/* Find the index of ent in ents or return -1 if not found. */
+static int get_index(ir_entity **ents, int n, ir_entity *ent)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ if (ents[i] == ent)
+ return i;
+
+ return -1;
+}
+
+/*
+ * Emit code for a MemPerm node.
+ *
+ * Analyze MemPerm for copy chains and cyclic swaps and resolve them using
+ * loads and stores.
+ * This function is conceptually very similar to permute_values in
+ * beprefalloc.c.
+ */
+static void emit_be_MemPerm(const ir_node *node)
+{
+ int memperm_arity = be_get_MemPerm_entity_arity(node);
+ /* Upper limit for the number of participating entities is twice the
+ * arity, e.g., for a simple copying MemPerm node with one input/output. */
+ int max_size = 2 * memperm_arity;
+ ir_entity **entities = ALLOCANZ(ir_entity *, max_size);
+ /* sourceof contains the input entity for each entity. If an entity is
+ * never used as an output, its entry in sourceof is a fix point. */
+ int *sourceof = ALLOCANZ(int, max_size);
+ /* n_users counts how many output entities use this entity as their input.*/
+ int *n_users = ALLOCANZ(int, max_size);
+ /* n_spilled records the number of spilled registers, either 1 or 2. */
+ int n_spilled = 0;
+ int i, n, oidx;
+
+ for (i = 0; i < max_size; ++i) {
+ sourceof[i] = i;
}
- for (i = memperm_arity-1; i >= 0; --i) {
- ir_entity *entity = be_get_MemPerm_out_entity(node, i);
- int offset = be_get_stack_entity_offset(layout, entity, 0);
+ for (i = n = 0; i < memperm_arity; ++i) {
+ ir_entity *out = be_get_MemPerm_out_entity(node, i);
+ ir_entity *in = be_get_MemPerm_in_entity(node, i);
+ int oidx; /* Out index */
+ int iidx; /* In index */
- sp_change -= 4;
+ /* Insert into entities to be able to operate on unique indices. */
+ if (get_index(entities, n, out) == -1)
+ entities[n++] = out;
+ if (get_index(entities, n, in) == -1)
+ entities[n++] = in;
- /* store to new entity */
- be_emit_irprintf("\tst %%l%d, [%%fp%+d]", i, offset);
- be_emit_finish_line_gas(node);
- /* restore register */
- be_emit_irprintf("\tld [%%sp%+d], %%l%d", sp_change + SPARC_MIN_STACKSIZE, i);
- be_emit_finish_line_gas(node);
+ oidx = get_index(entities, n, out);
+ iidx = get_index(entities, n, in);
+
+ sourceof[oidx] = iidx; /* Remember the source. */
+ ++n_users[iidx]; /* Increment number of users of this entity. */
}
- be_emit_irprintf("\tadd %%sp, %d, %%sp", memperm_arity*4);
- be_emit_finish_line_gas(node);
+ /* First do all the copies. */
+ for (oidx = 0; oidx < n; /* empty */) {
+ int iidx = sourceof[oidx];
+
+ /* Nothing to do for fix points.
+ * Also, if entities[oidx] is used as an input by another copy, we
+ * can't overwrite entities[oidx] yet.*/
+ if (iidx == oidx || n_users[oidx] > 0) {
+ ++oidx;
+ continue;
+ }
+
+ /* We found the end of a 'chain', so do the copy. */
+ if (n_spilled == 0) {
+ memperm_emit_spill_registers(node, n_spilled, /*n_to_spill=*/1);
+ n_spilled = 1;
+ }
+ memperm_emit_copy(node, entities[iidx], entities[oidx]);
+
+ /* Mark as done. */
+ sourceof[oidx] = oidx;
+
+ assert(n_users[iidx] > 0);
+ /* Decrementing the number of users might enable us to do another
+ * copy. */
+ --n_users[iidx];
- assert(sp_change == 0);
+ if (iidx < oidx && n_users[iidx] == 0) {
+ oidx = iidx;
+ } else {
+ ++oidx;
+ }
+ }
+
+ /* The rest are cycles. */
+ for (oidx = 0; oidx < n; /* empty */) {
+ int iidx = sourceof[oidx];
+ int tidx;
+
+ /* Nothing to do for fix points. */
+ if (iidx == oidx) {
+ ++oidx;
+ continue;
+ }
+
+ assert(n_users[iidx] == 1);
+
+ /* Swap the two values to resolve the cycle. */
+ if (n_spilled < 2) {
+ memperm_emit_spill_registers(node, n_spilled, /*n_to_spill=*/2);
+ n_spilled = 2;
+ }
+ memperm_emit_swap(node, entities[iidx], entities[oidx]);
+
+ tidx = sourceof[iidx];
+ /* Mark as done. */
+ sourceof[iidx] = iidx;
+
+ /* The source of oidx is now the old source of iidx, because we swapped
+ * the two entities. */
+ sourceof[oidx] = tidx;
+ }
+
+#ifdef DEBUG_libfirm
+ /* Only fix points should remain. */
+ for (i = 0; i < max_size; ++i) {
+ assert(sourceof[i] == i);
+ }
+#endif
+
+ assert(n_spilled > 0 && "Useless MemPerm node");
+
+ memperm_emit_restore_registers(node, n_spilled);
}
-static void emit_be_Return(const ir_node *node)
+static void emit_sparc_Return(const ir_node *node)
{
+ ir_graph *irg = get_irn_irg(node);
+ ir_entity *entity = get_irg_entity(irg);
+ ir_type *type = get_entity_type(entity);
+
const char *destreg = "%o7";
/* hack: we don't explicitely model register changes because of the
}
be_emit_cstring("\tjmp ");
be_emit_string(destreg);
- be_emit_cstring("+8");
+ if (get_method_calling_convention(type) & cc_compound_ret) {
+ be_emit_cstring("+12");
+ } else {
+ be_emit_cstring("+8");
+ }
be_emit_finish_line_gas(node);
fill_delay_slot();
}
static void emit_sparc_fbfcc(const ir_node *node)
{
+ /* if the flags producing node was immediately in front of us, emit
+ * a nop */
+ ir_node *flags = get_irn_n(node, n_sparc_fbfcc_flags);
+ ir_node *prev = sched_prev(node);
+ if (is_Block(prev)) {
+ /* TODO: when the flags come from another block, then we have to do
+ * more complicated tests to see wether the flag producing node is
+ * potentially in front of us (could happen for fallthroughs) */
+ panic("TODO: fbfcc flags come from other block");
+ }
+ if (skip_Proj(flags) == prev) {
+ be_emit_cstring("\tnop\n");
+ }
emit_sparc_branch(node, get_fcc);
}
be_emit_cstring("\t/* fallthrough to ");
sparc_emit_cfop_target(node);
be_emit_cstring(" */");
+ be_emit_finish_line_gas(node);
} else {
be_emit_cstring("\tba ");
sparc_emit_cfop_target(node);
be_emit_finish_line_gas(node);
fill_delay_slot();
}
- 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)
{
ir_mode *mode = get_irn_mode(node);
- const arch_register_t *src_reg = get_in_reg(node, 0);
- const arch_register_t *dst_reg = get_out_reg(node, 0);
+ const arch_register_t *src_reg = arch_get_irn_register_in(node, 0);
+ const arch_register_t *dst_reg = arch_get_irn_register_out(node, 0);
if (src_reg == dst_reg)
return;
set_emitter(op_be_IncSP, emit_be_IncSP);
set_emitter(op_be_MemPerm, emit_be_MemPerm);
set_emitter(op_be_Perm, emit_be_Perm);
- set_emitter(op_be_Return, emit_be_Return);
set_emitter(op_sparc_Ba, emit_sparc_Ba);
set_emitter(op_sparc_Bicc, emit_sparc_Bicc);
set_emitter(op_sparc_Call, emit_sparc_Call);
set_emitter(op_sparc_fbfcc, emit_sparc_fbfcc);
set_emitter(op_sparc_FrameAddr, emit_sparc_FrameAddr);
- set_emitter(op_sparc_Mulh, emit_sparc_Mulh);
+ set_emitter(op_sparc_SMulh, emit_sparc_Mulh);
+ set_emitter(op_sparc_UMulh, emit_sparc_Mulh);
+ set_emitter(op_sparc_Return, emit_sparc_Return);
set_emitter(op_sparc_SDiv, emit_sparc_SDiv);
set_emitter(op_sparc_SwitchJmp, emit_sparc_SwitchJmp);
set_emitter(op_sparc_UDiv, emit_sparc_UDiv);
/* no need to emit anything for the following nodes */
- set_emitter(op_be_Keep, emit_nothing);
- set_emitter(op_be_Start, emit_nothing);
- set_emitter(op_Phi, emit_nothing);
+ set_emitter(op_be_Keep, emit_nothing);
+ set_emitter(op_sparc_Start, emit_nothing);
+ set_emitter(op_Phi, emit_nothing);
}
/**
return schedpoint;
}
+static bool block_needs_label(const ir_node *block, const ir_node *sched_prev)
+{
+ int n_cfgpreds;
+
+ if (has_Block_entity(block))
+ return true;
+
+ n_cfgpreds = get_Block_n_cfgpreds(block);
+ if (n_cfgpreds == 0) {
+ return false;
+ } else if (n_cfgpreds > 1) {
+ return true;
+ } else {
+ ir_node *cfgpred = get_Block_cfgpred(block, 0);
+ ir_node *cfgpred_block = get_nodes_block(cfgpred);
+ if (is_Proj(cfgpred) && is_sparc_SwitchJmp(get_Proj_pred(cfgpred)))
+ return true;
+ return sched_prev != cfgpred_block || get_irn_link(cfgpred) != block;
+ }
+}
+
/**
* Walks over the nodes in a block connected by scheduling edges
* and emits code for each node.
*/
-static void sparc_emit_block(ir_node *block)
+static void sparc_emit_block(ir_node *block, ir_node *prev)
{
ir_node *node;
ir_node *next_delay_slot;
assert(is_Block(block));
- be_gas_emit_block_name(block);
- be_emit_cstring(":\n");
- be_emit_write_line();
+ if (block_needs_label(block, prev)) {
+ be_gas_emit_block_name(block);
+ be_emit_cstring(":\n");
+ be_emit_write_line();
+ }
next_delay_slot = find_next_delay_slot(sched_first(block));
if (next_delay_slot != NULL)
size_t i;
size_t n;
- be_gas_elf_type_char = '#';
- be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF_SPARC;
-
heights = heights_new(irg);
/* register all emitter functions */
for (i = 0; i < n; ++i) {
ir_node *block = block_schedule[i];
+ ir_node *prev = i>=1 ? block_schedule[i-1] : NULL;
if (block == get_irg_end_block(irg))
continue;
- sparc_emit_block(block);
+ sparc_emit_block(block, prev);
}
/* emit function epilog */