/**
* @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(");
}
}
-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
if (is_sparc_Ba(node) && ba_is_fallthrough(node))
return true;
- return be_is_Keep(node) || be_is_Barrier(node) || be_is_Start(node)
- || is_Phi(node);
+ return be_is_Keep(node) || be_is_Start(node) || is_Phi(node);
}
static bool has_delay_slot(const ir_node *node)
*/
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 const char *get_icc_unsigned(pn_Cmp pnc)
+static const char *get_icc_unsigned(ir_relation relation)
{
- switch (pnc) {
- case pn_Cmp_False: return "bn";
- case pn_Cmp_Eq: return "be";
- case pn_Cmp_Lt: return "blu";
- case pn_Cmp_Le: return "bleu";
- case pn_Cmp_Gt: return "bgu";
- case pn_Cmp_Ge: return "bgeu";
- case pn_Cmp_Lg: return "bne";
- case pn_Cmp_Leg: return "ba";
- default: panic("Cmp has unsupported pnc");
+ switch (relation & (ir_relation_less_equal_greater)) {
+ case ir_relation_false: return "bn";
+ case ir_relation_equal: return "be";
+ case ir_relation_less: return "blu";
+ case ir_relation_less_equal: return "bleu";
+ case ir_relation_greater: return "bgu";
+ case ir_relation_greater_equal: return "bgeu";
+ case ir_relation_less_greater: return "bne";
+ case ir_relation_less_equal_greater: return "ba";
+ default: panic("Cmp has unsupported relation");
}
}
-static const char *get_icc_signed(pn_Cmp pnc)
+static const char *get_icc_signed(ir_relation relation)
{
- switch (pnc) {
- case pn_Cmp_False: return "bn";
- case pn_Cmp_Eq: return "be";
- case pn_Cmp_Lt: return "bl";
- case pn_Cmp_Le: return "ble";
- case pn_Cmp_Gt: return "bg";
- case pn_Cmp_Ge: return "bge";
- case pn_Cmp_Lg: return "bne";
- case pn_Cmp_Leg: return "ba";
- default: panic("Cmp has unsupported pnc");
+ switch (relation & (ir_relation_less_equal_greater)) {
+ case ir_relation_false: return "bn";
+ case ir_relation_equal: return "be";
+ case ir_relation_less: return "bl";
+ case ir_relation_less_equal: return "ble";
+ case ir_relation_greater: return "bg";
+ case ir_relation_greater_equal: return "bge";
+ case ir_relation_less_greater: return "bne";
+ case ir_relation_less_equal_greater: return "ba";
+ default: panic("Cmp has unsupported relation");
}
}
-static const char *get_fcc(pn_Cmp pnc)
+static const char *get_fcc(ir_relation relation)
{
- switch (pnc) {
- case pn_Cmp_False: return "fbn";
- case pn_Cmp_Eq: return "fbe";
- case pn_Cmp_Lt: return "fbl";
- case pn_Cmp_Le: return "fble";
- case pn_Cmp_Gt: return "fbg";
- case pn_Cmp_Ge: return "fbge";
- case pn_Cmp_Lg: return "fblg";
- case pn_Cmp_Leg: return "fbo";
- case pn_Cmp_Uo: return "fbu";
- case pn_Cmp_Ue: return "fbue";
- case pn_Cmp_Ul: return "fbul";
- case pn_Cmp_Ule: return "fbule";
- case pn_Cmp_Ug: return "fbug";
- case pn_Cmp_Uge: return "fbuge";
- case pn_Cmp_Ne: return "fbne";
- case pn_Cmp_True: return "fba";
- case pn_Cmp_max:
- break;
+ switch (relation) {
+ case ir_relation_false: return "fbn";
+ case ir_relation_equal: return "fbe";
+ case ir_relation_less: return "fbl";
+ case ir_relation_less_equal: return "fble";
+ case ir_relation_greater: return "fbg";
+ case ir_relation_greater_equal: return "fbge";
+ case ir_relation_less_greater: return "fblg";
+ case ir_relation_less_equal_greater: return "fbo";
+ case ir_relation_unordered: return "fbu";
+ case ir_relation_unordered_equal: return "fbue";
+ case ir_relation_unordered_less: return "fbul";
+ case ir_relation_unordered_less_equal: return "fbule";
+ case ir_relation_unordered_greater: return "fbug";
+ case ir_relation_unordered_greater_equal: return "fbuge";
+ case ir_relation_unordered_less_greater: return "fbne";
+ case ir_relation_true: return "fba";
}
- panic("invalid pnc");
+ panic("invalid relation");
}
-typedef const char* (*get_cc_func)(pn_Cmp pnc);
+typedef const char* (*get_cc_func)(ir_relation relation);
static void emit_sparc_branch(const ir_node *node, get_cc_func get_cc)
{
const sparc_jmp_cond_attr_t *attr = get_sparc_jmp_cond_attr_const(node);
- pn_Cmp pnc = attr->pnc;
+ ir_relation relation = attr->relation;
const ir_node *proj_true = NULL;
const ir_node *proj_false = NULL;
const ir_edge_t *edge;
proj_true = proj_false;
proj_false = t;
- if (is_sparc_fbfcc(node)) {
- pnc = get_negated_pnc(pnc, mode_F);
- } else {
- pnc = get_negated_pnc(pnc, mode_Iu);
- }
+ relation = get_negated_relation(relation);
}
/* emit the true proj */
be_emit_cstring("\t");
- be_emit_string(get_cc(pnc));
+ be_emit_string(get_cc(relation));
be_emit_char(' ');
sparc_emit_cfop_target(proj_true);
be_emit_finish_line_gas(proj_true);
static const arch_register_t *get_next_fp_reg(const arch_register_t *reg)
{
- unsigned index = reg->index;
+ unsigned index = reg->global_index;
assert(reg == &sparc_registers[index]);
index++;
assert(index - REG_F0 < N_sparc_fp_REGS);
set_emitter(op_sparc_UDiv, emit_sparc_UDiv);
/* no need to emit anything for the following nodes */
- set_emitter(op_be_Barrier, emit_nothing);
set_emitter(op_be_Keep, emit_nothing);
set_emitter(op_be_Start, emit_nothing);
set_emitter(op_Phi, emit_nothing);
{
ir_entity *entity = get_irg_entity(irg);
ir_node **block_schedule;
- int i;
- int n;
+ size_t i;
+ size_t n;
be_gas_elf_type_char = '#';
be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF_SPARC;