ia32: Merge Test and Test8Bit.
[libfirm] / ir / tr / entity.c
index 5981e3c..455c16c 100644 (file)
@@ -42,7 +42,6 @@
 #include "irgraph_t.h"
 #include "callgraph.h"
 #include "error.h"
-#include "compound_path.h"
 
 /** The name of the unknown entity. */
 #define UNKNOWN_ENTITY_NAME "unknown_entity"
@@ -72,7 +71,7 @@ static ir_entity *intern_new_entity(ir_type *owner, ir_entity_kind kind,
        res->aligned              = align_is_aligned;
        res->usage                = ir_usage_unknown;
        res->compiler_gen         = 0;
-       res->visibility           = ir_visibility_default;
+       res->visibility           = ir_visibility_external;
        res->offset               = -1;
        res->offset_bit_remainder = 0;
        res->alignment            = 0;
@@ -100,21 +99,18 @@ ir_entity *new_d_entity(ir_type *owner, ident *name, ir_type *type,
        if (is_Method_type(type)) {
                ir_graph *irg = get_const_code_irg();
                symconst_symbol sym;
-               ir_mode *mode = is_Method_type(type) ? mode_P_code : mode_P_data;
                res = intern_new_entity(owner, IR_ENTITY_METHOD, name, type, db);
                sym.entity_p            = res;
-               set_atomic_ent_value(res, new_r_SymConst(irg, mode, sym, symconst_addr_ent));
-               res->linkage            = IR_LINKAGE_CONSTANT;
-               res->attr.mtd_attr.irg_add_properties = mtp_property_inherited;
-               res->attr.mtd_attr.vtable_number      = IR_VTABLE_NUM_NOT_SET;
-               res->attr.mtd_attr.param_access       = NULL;
-               res->attr.mtd_attr.param_weight       = NULL;
-               res->attr.mtd_attr.irg                = NULL;
+               set_atomic_ent_value(res, new_r_SymConst(irg, mode_P_code, sym, symconst_addr_ent));
+               res->linkage                     = IR_LINKAGE_CONSTANT;
+               res->attr.mtd_attr.properties    = get_method_additional_properties(type);
+               res->attr.mtd_attr.vtable_number = IR_VTABLE_NUM_NOT_SET;
+               res->attr.mtd_attr.param_access  = NULL;
+               res->attr.mtd_attr.param_weight  = NULL;
+               res->attr.mtd_attr.irg           = NULL;
        } else if (owner != NULL
                   && (is_compound_type(owner) && !(owner->flags & tf_segment))) {
                res = intern_new_entity(owner, IR_ENTITY_COMPOUND_MEMBER, name, type, db);
-               res->attr.cmpd_attr.values    = NULL;
-               res->attr.cmpd_attr.val_paths = NULL;
        } else {
                res = intern_new_entity(owner, IR_ENTITY_NORMAL, name, type, db);
        }
@@ -186,14 +182,8 @@ static void free_entity_attrs(ir_entity *ent)
 
        if (ent->initializer != NULL) {
                /* TODO: free initializers */
-       } else if (entity_has_compound_ent_values(ent)) {
-               /* can't free compound graph path as it might be used
-                * multiple times */
-               ent->attr.cmpd_attr.val_paths = NULL;
        }
-       if (ent->entity_kind == IR_ENTITY_COMPOUND_MEMBER) {
-               ent->attr.cmpd_attr.values = NULL;
-       } else if (ent->entity_kind == IR_ENTITY_METHOD) {
+       if (ent->entity_kind == IR_ENTITY_METHOD) {
                if (ent->attr.mtd_attr.param_access) {
                        DEL_ARR_F(ent->attr.mtd_attr.param_access);
                        ent->attr.mtd_attr.param_access = NULL;
@@ -215,15 +205,6 @@ static ir_entity *deep_entity_copy(ir_entity *old)
        *newe = *old;
        if (old->initializer != NULL) {
                /* FIXME: the initializers are NOT copied */
-       } else if (entity_has_compound_ent_values(old)) {
-               newe->attr.cmpd_attr.values    = NULL;
-               newe->attr.cmpd_attr.val_paths = NULL;
-               if (old->attr.cmpd_attr.values)
-                       newe->attr.cmpd_attr.values = DUP_ARR_F(ir_node *, old->attr.cmpd_attr.values);
-
-               /* FIXME: the compound graph paths are NOT copied */
-               if (old->attr.cmpd_attr.val_paths)
-                       newe->attr.cmpd_attr.val_paths = DUP_ARR_F(compound_graph_path *, old->attr.cmpd_attr.val_paths);
        } else if (is_method_entity(old)) {
                /* do NOT copy them, reanalyze. This might be the best solution */
                newe->attr.mtd_attr.param_access = NULL;
@@ -433,18 +414,9 @@ ir_label_t get_entity_label(const ir_entity *ent)
        return ent->attr.code_attr.label;
 }
 
-static void verify_visibility(const ir_entity *entity)
-{
-       if (get_entity_visibility(entity) == ir_visibility_external
-                       && !is_method_entity(entity)) {
-               assert(!entity_has_definition(entity));
-       }
-}
-
 void set_entity_visibility(ir_entity *entity, ir_visibility visibility)
 {
        entity->visibility = visibility;
-       verify_visibility(entity);
 }
 
 ir_visibility get_entity_visibility(const ir_entity *entity)
@@ -492,7 +464,7 @@ void (set_entity_usage)(ir_entity *ent, ir_entity_usage flags)
        _set_entity_usage(ent, flags);
 }
 
-ir_node *get_atomic_ent_value(ir_entity *entity)
+ir_node *get_atomic_ent_value(const ir_entity *entity)
 {
        ir_initializer_t *initializer = get_entity_initializer(entity);
 
@@ -518,7 +490,7 @@ ir_node *get_atomic_ent_value(ir_entity *entity)
                panic("compound initializer in atomic entity not allowed (%+F)", entity);
        }
 
-       panic("invalid initializer kind in get_atomic_ent_value(%+F)", entity);
+       panic("invalid initializer kind (%+F)", entity);
 }
 
 void set_atomic_ent_value(ir_entity *entity, ir_node *val)
@@ -610,10 +582,18 @@ ir_node *copy_const_value(dbg_info *dbg, ir_node *n, ir_node *block)
                nn = new_rd_Conv(dbg, block,
                                 copy_const_value(dbg, get_Conv_op(n), block), m);
                break;
+       case iro_Minus:
+               nn = new_rd_Minus(dbg, block,
+                                 copy_const_value(dbg, get_Minus_op(n), block), m);
+               break;
+       case iro_Not:
+               nn = new_rd_Not(dbg, block,
+                               copy_const_value(dbg, get_Not_op(n), block), m);
+               break;
        case iro_Unknown:
                nn = new_r_Unknown(irg, m); break;
        default:
-               panic("opcode invalid or not implemented");
+               panic("opcode invalid or not implemented %+F", n);
        }
        return nn;
 }
@@ -993,59 +973,28 @@ int (entity_not_visited)(const ir_entity *ent)
 
 mtp_additional_properties get_entity_additional_properties(const ir_entity *ent)
 {
-       ir_graph *irg;
-
        assert(is_method_entity(ent));
-
-       /* first check, if the graph has additional properties */
-       irg = get_entity_irg(ent);
-
-       if (irg)
-               return get_irg_additional_properties(irg);
-
-       if (ent->attr.mtd_attr.irg_add_properties & mtp_property_inherited)
-               return get_method_additional_properties(get_entity_type(ent));
-
-       return ent->attr.mtd_attr.irg_add_properties;
+       return ent->attr.mtd_attr.properties;
 }
 
 void set_entity_additional_properties(ir_entity *ent, mtp_additional_properties property_mask)
 {
-       ir_graph *irg;
-
        assert(is_method_entity(ent));
+       /* you mustn't set less properties than the entities type */
+       assert((get_method_additional_properties(get_entity_type(ent)) & ~property_mask) == 0);
 
-       /* first check, if the graph exists */
-       irg = get_entity_irg(ent);
-       if (irg)
-               set_irg_additional_properties(irg, property_mask);
-       else {
-               /* do not allow to set the mtp_property_inherited flag or
-                * the automatic inheritance of flags will not work */
-               ent->attr.mtd_attr.irg_add_properties = property_mask & ~mtp_property_inherited;
-       }
+       /* do not allow to set the mtp_property_inherited flag or
+        * the automatic inheritance of flags will not work */
+       ent->attr.mtd_attr.properties = property_mask;
 }
 
 void add_entity_additional_properties(ir_entity *ent, mtp_additional_properties properties)
 {
-       ir_graph *irg;
-
        assert(is_method_entity(ent));
 
-       /* first check, if the graph exists */
-       irg = get_entity_irg(ent);
-       if (irg)
-               add_irg_additional_properties(irg, properties);
-       else {
-               mtp_additional_properties mask = ent->attr.mtd_attr.irg_add_properties;
-
-               if (mask & mtp_property_inherited)
-                       mask = get_method_additional_properties(get_entity_type(ent));
-
-               /* do not allow to set the mtp_property_inherited flag or
-                * the automatic inheritance of flags will not work */
-               ent->attr.mtd_attr.irg_add_properties = mask | (properties & ~mtp_property_inherited);
-       }
+       /* do not allow to set the mtp_property_inherited flag or
+        * the automatic inheritance of flags will not work */
+       ent->attr.mtd_attr.properties |= properties;
 }
 
 ir_type *(get_entity_repr_class)(const ir_entity *ent)
@@ -1071,9 +1020,12 @@ int entity_is_externally_visible(const ir_entity *entity)
 
 int entity_has_definition(const ir_entity *entity)
 {
-       return entity->initializer != NULL
-               || get_entity_irg(entity) != NULL
-               || entity_has_compound_ent_values(entity);
+       if (is_method_entity(entity)) {
+               return get_entity_irg(entity) != NULL
+                   && (get_entity_linkage(entity) & IR_LINKAGE_NO_CODEGEN) == 0;
+       } else {
+               return entity->initializer != NULL;
+       }
 }
 
 void ir_init_entity(ir_prog *irp)