becopyopt: Use the set of admissible registers from bechordal.
[libfirm] / ir / be / sparc / bearch_sparc.c
index 2b7d769..5da59e5 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2010 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
 #include "array_t.h"
 #include "error.h"
 #include "util.h"
-
+#include "be_t.h"
 #include "bearch.h"
 #include "benode.h"
 #include "belower.h"
 #include "besched.h"
-#include "be.h"
 #include "bemodule.h"
-#include "beirg.h"
 #include "begnuas.h"
 #include "belistsched.h"
 #include "beflags.h"
@@ -125,7 +109,6 @@ const arch_irn_ops_t sparc_irn_ops = {
        sparc_get_frame_entity,
        sparc_set_frame_offset,
        sparc_get_sp_bias,
-       NULL,    /* get_inverse             */
        NULL,    /* get_op_estimated_cost   */
        NULL,    /* possible_memory_operand */
        NULL,    /* perform_memory_operand  */
@@ -142,12 +125,22 @@ static void sparc_prepare_graph(ir_graph *irg)
 
 static bool sparc_modifies_flags(const ir_node *node)
 {
-       return arch_get_irn_flags(node) & sparc_arch_irn_flag_modifies_flags;
+       be_foreach_out(node, o) {
+               const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
+               if (req->cls == &sparc_reg_classes[CLASS_sparc_flags_class])
+                       return true;
+       }
+       return false;
 }
 
 static bool sparc_modifies_fp_flags(const ir_node *node)
 {
-       return arch_get_irn_flags(node) & sparc_arch_irn_flag_modifies_fp_flags;
+       be_foreach_out(node, o) {
+               const arch_register_req_t *req = arch_get_irn_register_req_out(node, o);
+               if (req->cls == &sparc_reg_classes[CLASS_sparc_fpflags_class])
+                       return true;
+       }
+       return false;
 }
 
 static void sparc_before_ra(ir_graph *irg)
@@ -159,31 +152,24 @@ static void sparc_before_ra(ir_graph *irg)
                           NULL, sparc_modifies_fp_flags);
 }
 
-static void sparc_init_graph(ir_graph *irg)
-{
-       (void) irg;
-}
-
 extern const arch_isa_if_t sparc_isa_if;
 static sparc_isa_t sparc_isa_template = {
        {
-               &sparc_isa_if,                      /* isa interface implementation */
+               &sparc_isa_if,                       /* isa interface implementation */
                N_SPARC_REGISTERS,
                sparc_registers,
                N_SPARC_CLASSES,
                sparc_reg_classes,
-               &sparc_registers[REG_SP],           /* stack pointer register */
-               &sparc_registers[REG_FRAME_POINTER],/* base pointer register */
-               &sparc_reg_classes[CLASS_sparc_gp], /* link pointer register class */
-               3,                                  /* power of two stack alignment
-                                                      for calls */
-               NULL,                               /* main environment */
-               7,                                  /* costs for a spill instruction */
-               5,                                  /* costs for a reload instruction */
-               true,                               /* custom abi handling */
+               &sparc_registers[REG_SP],            /* stack pointer register */
+               &sparc_registers[REG_FRAME_POINTER], /* base pointer register */
+               3,                                   /* power of two stack alignment
+                                                       for calls */
+               7,                                   /* costs for a spill instruction */
+               5,                                   /* costs for a reload instruction */
+               true,                                /* custom abi handling */
        },
-       NULL,               /* constants */
-       SPARC_FPU_ARCH_FPU, /* FPU architecture */
+       NULL,                                  /* constants */
+       SPARC_FPU_ARCH_FPU,                    /* FPU architecture */
 };
 
 /**
@@ -291,13 +277,13 @@ static void rewrite_float_unsigned_Conv(ir_node *node)
                ir_node   *sub         = new_rd_Sub(dbgi, true_block, float_x, limitc,
                                                    mode_f);
                ir_node   *sub_conv    = new_rd_Conv(dbgi, true_block, sub, mode_s);
-               ir_node   *xor         = new_rd_Eor(dbgi, true_block, sub_conv, c_const,
+               ir_node   *xorn        = new_rd_Eor(dbgi, true_block, sub_conv, c_const,
                                                    mode_s);
 
                ir_node   *converted   = new_rd_Conv(dbgi, false_block, float_x,mode_s);
 
                ir_node  *lower_in[2] = { true_jmp, false_jmp };
-               ir_node  *phi_in[2]   = { xor, converted };
+               ir_node  *phi_in[2]   = { xorn, converted };
                ir_node  *phi;
                ir_node  *res_conv;
 
@@ -423,18 +409,14 @@ static void sparc_finish(void)
        sparc_free_opcodes();
 }
 
-static arch_env_t *sparc_begin_codegeneration(const be_main_env_t *env)
+static arch_env_t *sparc_begin_codegeneration(void)
 {
        sparc_isa_t *isa = XMALLOC(sparc_isa_t);
        *isa = sparc_isa_template;
        isa->constants = pmap_create();
 
-       be_gas_elf_type_char      = '#';
-       be_gas_object_file_format = OBJECT_FILE_FORMAT_ELF;
-       be_gas_elf_variant        = ELF_VARIANT_SPARC;
-
-       be_emit_init(env->file_handle);
-       be_gas_begin_compilation_unit(env);
+       be_gas_elf_type_char = '#';
+       be_gas_elf_variant   = ELF_VARIANT_SPARC;
 
        return &isa->base;
 }
@@ -445,17 +427,13 @@ static arch_env_t *sparc_begin_codegeneration(const be_main_env_t *env)
 static void sparc_end_codegeneration(void *self)
 {
        sparc_isa_t *isa = (sparc_isa_t*)self;
-
-       /* emit now all global declarations */
-       be_gas_end_compilation_unit(isa->base.main_env);
-
        pmap_destroy(isa->constants);
-       be_emit_exit();
        free(isa);
 }
 
 static void sparc_lower_for_target(void)
 {
+       ir_mode *mode_gp = sparc_reg_classes[CLASS_sparc_gp].mode;
        size_t i, n_irgs = get_irp_n_irgs();
 
        lower_calls_with_compounds(LF_RETURN_HIDDEN);
@@ -477,8 +455,10 @@ static void sparc_lower_for_target(void)
        for (i = 0; i < n_irgs; ++i) {
                ir_graph *irg = get_irp_irg(i);
                ir_lower_mode_b(irg, mode_Iu);
-               lower_switch(irg, 4, 256, false);
-               lower_alloc(irg, SPARC_STACK_ALIGNMENT, false, SPARC_MIN_STACKSIZE);
+               lower_switch(irg, 4, 256, mode_gp);
+               /* TODO: Pass SPARC_MIN_STACKSIZE as addr_delta as soon as
+                * Alloc nodes are implemented more efficiently. */
+               lower_alloc(irg, SPARC_STACK_ALIGNMENT, true, 0);
        }
 }
 
@@ -532,16 +512,11 @@ static const backend_params *sparc_get_backend_params(void)
        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_type *type_long_double = new_type_primitive(mode_Q);
+       ir_type *type_long_double = new_type_primitive(mode_Q);
 
-               set_type_alignment_bytes(type_long_double, 8);
-               set_type_size_bytes(type_long_double, 16);
-               p.type_long_double = type_long_double;
-       }
+       set_type_alignment_bytes(type_long_double, 8);
+       set_type_size_bytes(type_long_double, 16);
+       p.type_long_double = type_long_double;
        return &p;
 }
 
@@ -625,7 +600,7 @@ const arch_isa_if_t sparc_isa_if = {
 
        sparc_begin_codegeneration,
        sparc_end_codegeneration,
-       sparc_init_graph,
+       NULL,
        NULL,                /* get call abi */
        NULL,                /* mark remat */
        NULL,                /* get_pic_base */