sparc: attempt to fix stack alignment/address for omit-fp again
[libfirm] / ir / be / sparc / bearch_sparc.c
index 6feb3f7..9c2fef4 100644 (file)
 #include "iroptimize.h"
 #include "irtools.h"
 #include "irdump.h"
+#include "iropt_t.h"
 #include "lowering.h"
 #include "lower_dw.h"
+#include "lower_alloc.h"
 #include "lower_builtins.h"
 #include "lower_calls.h"
+#include "lower_mode_b.h"
 #include "lower_softfloat.h"
 
 #include "bitset.h"
 #include "error.h"
 #include "util.h"
 
-#include "../bearch.h"
-#include "../benode.h"
-#include "../belower.h"
-#include "../besched.h"
+#include "bearch.h"
+#include "benode.h"
+#include "belower.h"
+#include "besched.h"
 #include "be.h"
-#include "../bemachine.h"
-#include "../bemodule.h"
-#include "../beirg.h"
-#include "../begnuas.h"
-#include "../belistsched.h"
-#include "../beflags.h"
-#include "../beutil.h"
+#include "bemachine.h"
+#include "bemodule.h"
+#include "beirg.h"
+#include "begnuas.h"
+#include "belistsched.h"
+#include "beflags.h"
+#include "beutil.h"
 
 #include "bearch_sparc_t.h"
 
@@ -356,7 +359,8 @@ static arch_env_t *sparc_init(FILE *outfile)
        isa->constants = pmap_create();
 
        be_gas_elf_type_char      = '#';
-       be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF_SPARC;
+       be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF;
+       be_gas_elf_variant        = ELF_VARIANT_SPARC;
 
        be_emit_init(outfile);
 
@@ -418,7 +422,6 @@ static void sparc_lower_for_target(void)
        lower_mode_b_config_t lower_mode_b_config = {
                mode_Iu,
                sparc_create_set,
-               0,
        };
 
        lower_calls_with_compounds(LF_RETURN_HIDDEN);
@@ -434,31 +437,21 @@ static void sparc_lower_for_target(void)
                ir_graph *irg = get_irp_irg(i);
                ir_lower_mode_b(irg, &lower_mode_b_config);
                lower_switch(irg, 4, 256, false);
+               lower_alloc(irg, SPARC_STACK_ALIGNMENT, false, -SPARC_MIN_STACKSIZE);
        }
 
        for (i = 0; i < n_irgs; ++i) {
                ir_graph *irg = get_irp_irg(i);
                /* Turn all small CopyBs into loads/stores and all bigger CopyBs into
                 * memcpy calls. */
-               lower_CopyB(irg, 31, 32, 4);
+               lower_CopyB(irg, 31, 32, false);
        }
 }
 
 static int sparc_is_mux_allowed(ir_node *sel, ir_node *mux_false,
                                 ir_node *mux_true)
 {
-       ir_graph *irg  = get_irn_irg(sel);
-       ir_mode  *mode = get_irn_mode(mux_true);
-
-       if (get_irg_phase_state(irg) == phase_low)
-               return false;
-
-       if (!mode_is_int(mode) && !mode_is_reference(mode) && mode != mode_b)
-               return false;
-       if (is_Const(mux_true) && is_Const_one(mux_true) &&
-                       is_Const(mux_false) && is_Const_null(mux_false))
-               return true;
-       return false;
+       return ir_is_optimizable_mux(sel, mux_false, mux_true);
 }
 
 /**
@@ -503,15 +496,22 @@ static const backend_params *sparc_get_backend_params(void)
                              irma_twos_complement, 64);
        ir_type *type_unsigned_long_long
                = new_type_primitive(mode_unsigned_long_long);
-       ir_mode *mode_long_double
-               = new_ir_mode("long double", irms_float_number, 128, 1,
-                             irma_ieee754, 0);
-       ir_type *type_long_double = new_type_primitive(mode_long_double);
 
-       set_type_alignment_bytes(type_long_double, 8);
-       p.type_long_double        = type_long_double;
        p.type_long_long          = type_long_long;
        p.type_unsigned_long_long = type_unsigned_long_long;
+
+       if (sparc_isa_template.fpu_arch == SPARC_FPU_ARCH_SOFTFLOAT) {
+               p.mode_float_arithmetic = NULL;
+               p.type_long_double      = NULL;
+       } else {
+               ir_mode *mode_long_double
+                       = new_ir_mode("long double", irms_float_number, 128, 1,
+                                                 irma_ieee754, 0);
+               ir_type *type_long_double = new_type_primitive(mode_long_double);
+
+               set_type_alignment_bytes(type_long_double, 8);
+               p.type_long_double        = type_long_double;
+       }
        return &p;
 }