use is_Psi()
[libfirm] / ir / lower / lower_hl.c
index 6ebc35a..38d1e4b 100644 (file)
  * @file
  * @brief   Lower some High-level constructs, moved from the firmlower.
  * @author  Boris Boesler, Goetz Lindenmaier, Michael Beck
- * @version $Id$
+ * @version $Id$
  */
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
+#include "lowering.h"
 #include "irmode_t.h"
 #include "irnode_t.h"
 #include "entity_t.h"
-#include "type.h"
+#include "typerep.h"
 #include "irprog_t.h"
 #include "ircons.h"
-#include "lower_hl.h"
 #include "irhooks.h"
 #include "irgmod.h"
 #include "irgwalk.h"
 
 /**
- * Lower a Sel node. Do not touch Sels accessing entities on teh frame type.
+ * Lower a Sel node. Do not touch Sels accessing entities on the frame type.
  */
 static void lower_sel(ir_node *sel) {
        ir_graph *irg = current_ir_graph;
@@ -307,7 +307,10 @@ static void lower_symconst(ir_node *symc) {
                /* run the hooks */
                hook_lower(symc);
                exchange(symc, newn);
-       break;
+               break;
+       case symconst_label:
+               /* leave */
+               break;
 
        default:
                assert(!"unknown SymConst kind");
@@ -349,21 +352,26 @@ static void lower_bitfields_loads(ir_node *proj, ir_node *load) {
        ent     = get_Sel_entity(sel);
        bf_type = get_entity_type(ent);
 
+       /* must be a bitfield type */
+       if (!is_Primitive_type(bf_type) || get_primitive_base_type(bf_type) == NULL)
+               return;
+
        /* We have a bitfield access, if either a bit offset is given, or
           the size is not integral. */
        bf_mode = get_type_mode(bf_type);
        if (! bf_mode)
                return;
 
+       mode       = get_irn_mode(proj);
+       block      = get_nodes_block(proj);
        bf_bits    = get_mode_size_bits(bf_mode);
        bit_offset = get_entity_offset_bits_remainder(ent);
-       if (bit_offset == 0 && is_integral_size(bf_bits))
+
+       if (bit_offset == 0 && is_integral_size(bf_bits) && bf_mode == get_Load_mode(load))
                return;
 
-       mode   = get_irn_mode(proj);
        bits   = get_mode_size_bits(mode);
        offset = get_entity_offset(ent);
-       block  = get_nodes_block(proj);
 
        /*
         * ok, here we are: now convert the Proj_mode_bf(Load) into And(Shr(Proj_mode(Load)) for unsigned
@@ -437,26 +445,30 @@ static void lower_bitfields_stores(ir_node *store) {
        ent     = get_Sel_entity(sel);
        bf_type = get_entity_type(ent);
 
+       /* must be a bitfield type */
+       if (!is_Primitive_type(bf_type) || get_primitive_base_type(bf_type) == NULL)
+               return;
+
        /* We have a bitfield access, if either a bit offset is given, or
           the size is not integral. */
        bf_mode = get_type_mode(bf_type);
        if (! bf_mode)
                return;
 
+       value      = get_Store_value(store);
+       mode       = get_irn_mode(value);
+       block      = get_nodes_block(store);
+
        bf_bits    = get_mode_size_bits(bf_mode);
        bit_offset = get_entity_offset_bits_remainder(ent);
-       if (bit_offset == 0 && is_integral_size(bf_bits))
-               return;
 
-       value = get_Store_value(store);
-       mode  = get_irn_mode(value);
+       if (bit_offset == 0 && is_integral_size(bf_bits) && bf_mode == get_irn_mode(value))
+               return;
 
        /*
         * ok, here we are: now convert the Store(Sel(), value) into Or(And(Load(Sel),c), And(Value,c))
         */
        mem        = get_Store_mem(store);
-       block      = get_nodes_block(store);
-       bit_offset = get_entity_offset_bits_remainder(ent);
        offset     = get_entity_offset(ent);
 
        bits_mask = get_mode_size_bits(mode) - bf_bits;
@@ -494,10 +506,25 @@ static void lower_bitfields_stores(ir_node *store) {
        set_Store_ptr(store, ptr);
 }  /* lower_bitfields_stores */
 
+/**
+ * Lowers unaligned Loads.
+ */
+static void lower_unaligned_Load(ir_node *load) {
+       /* NYI */
+}
+
+/**
+ * Lowers unaligned Stores
+ */
+static void lower_unaligned_Store(ir_node *store) {
+       /* NYI */
+}
+
 /**
  * lowers IR-nodes, called from walker
  */
 static void lower_irnode(ir_node *irn, void *env) {
+       (void) env;
        switch (get_irn_opcode(irn)) {
        case iro_Sel:
                lower_sel(irn);
@@ -505,6 +532,14 @@ static void lower_irnode(ir_node *irn, void *env) {
        case iro_SymConst:
                lower_symconst(irn);
                break;
+       case iro_Load:
+               if (env != NULL && get_Load_align(irn) == align_non_aligned)
+                       lower_unaligned_Load(irn);
+               break;
+       case iro_Store:
+               if (env != NULL && get_Store_align(irn) == align_non_aligned)
+                       lower_unaligned_Store(irn);
+               break;
        default:
                break;
        }
@@ -514,6 +549,7 @@ static void lower_irnode(ir_node *irn, void *env) {
  * Walker: lowers IR-nodes for bitfield access
  */
 static void lower_bf_access(ir_node *irn, void *env) {
+       (void) env;
        switch (get_irn_opcode(irn)) {
        case iro_Proj:
        {
@@ -547,10 +583,10 @@ void lower_highlevel(void) {
                ir_graph *irg = get_irp_irg(i);
 
                /* First step: lower bitfield access: must be run as long as Sels still exists. */
-               irg_walk_graph(irg, lower_bf_access, NULL, NULL);
+               irg_walk_graph(irg, NULL, lower_bf_access, NULL);
 
-               /* Finally: lower SymConst-Size and Sel nodes. */
-               irg_walk_graph(irg, lower_irnode, NULL, NULL);
+               /* Finally: lower SymConst-Size and Sel nodes, unaligned Load/Stores. */
+               irg_walk_graph(irg, NULL, lower_irnode, NULL);
 
                set_irg_phase_low(irg);
        }