simplify confusing entity/owner interfaces. There is no public way anymore to add...
[libfirm] / ir / opt / opt_polymorphy.c
index a268136..fd5c953 100644 (file)
  * @brief   Optimize polymorphic Sel and Load nodes.
  * @author  Goetz Lindenmaier, Michael Beck
  * @version $Id$
- * @summary
+ * @brief
  *  This file subsumes optimization code from cgana.
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
+#include "opt_polymorphy.h"
 #include "iroptimize.h"
 #include "irprog_t.h"
 #include "entity_t.h"
@@ -47,7 +46,8 @@
  *
  * The default implementation hecks for Alloc nodes only.
  */
-ir_type *default_firm_get_Alloc(ir_node *n) {
+static ir_type *default_firm_get_Alloc(ir_node *n)
+{
        n = skip_Proj(n);
        if (is_Alloc(n)) {
                return get_Alloc_type(n);
@@ -55,13 +55,12 @@ ir_type *default_firm_get_Alloc(ir_node *n) {
        return NULL;
 }
 
-typedef ir_type *(*get_Alloc_func)(ir_node *n);
-
 /** The get_Alloc function */
 static get_Alloc_func firm_get_Alloc = default_firm_get_Alloc;
 
 /** Set a new get_Alloc_func and returns the old one. */
-get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf) {
+get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf)
+{
        get_Alloc_func old = firm_get_Alloc;
        firm_get_Alloc = newf;
        return old;
@@ -76,7 +75,8 @@ get_Alloc_func firm_set_Alloc_func(get_Alloc_func newf) {
  * If we find a dynamic type this means that the pointer always points
  * to an object of this type during runtime.   We resolved polymorphy.
  */
-static ir_type *get_dynamic_type(ir_node *ptr) {
+static ir_type *get_dynamic_type(ir_node *ptr)
+{
        ir_type *tp;
 
        /* skip Cast and Confirm nodes */
@@ -102,7 +102,8 @@ static ir_type *get_dynamic_type(ir_node *ptr) {
 /**
  * Check, if an entity is final, i.e. is not anymore overridden.
  */
-static int is_final_ent(ir_entity *ent) {
+static int is_final_ent(ir_entity *ent)
+{
        if (is_entity_final(ent)) {
                /* not possible to override this entity. */
                return 1;
@@ -118,7 +119,8 @@ static int is_final_ent(ir_entity *ent) {
 /*
  * Transform Sel[method] to SymC[method] if possible.
  */
-ir_node *transform_node_Sel(ir_node *node) {
+ir_node *transform_node_Sel(ir_node *node)
+{
        ir_node   *new_node, *ptr;
        ir_type   *dyn_tp;
        ir_entity *ent = get_Sel_entity(node);
@@ -159,8 +161,6 @@ ir_node *transform_node_Sel(ir_node *node) {
 
                /* We know which method will be called, no dispatch necessary. */
                called_ent = resolve_ent_polymorphy(dyn_tp, ent);
-               /* called_ent may not be description: has no Address/Const to Call! */
-               assert(get_entity_peculiarity(called_ent) != peculiarity_description);
 
                rem_block = get_cur_block();
                set_cur_block(get_nodes_block(node));
@@ -182,7 +182,8 @@ ir_node *transform_node_Sel(ir_node *node) {
  *  a tuple, or replace the Projs of the load.
  *  Therefore we call this optimization in ldstopt().
  */
-ir_node *transform_polymorph_Load(ir_node *load) {
+ir_node *transform_polymorph_Load(ir_node *load)
+{
        ir_node *new_node = NULL;
        ir_node *field_ptr, *ptr;
        ir_entity *ent;
@@ -196,8 +197,7 @@ ir_node *transform_polymorph_Load(ir_node *load) {
        if (! is_Sel(field_ptr)) return load;
 
        ent = get_Sel_entity(field_ptr);
-       if ((get_entity_allocation(ent) != allocation_static)    ||
-               (get_entity_variability(ent) != variability_constant)  )
+       if ( !(get_entity_linkage(ent) & IR_LINKAGE_CONSTANT) )
                return load;
 
        /* If the entity is a leave in the inheritance tree,
@@ -214,8 +214,6 @@ ir_node *transform_polymorph_Load(ir_node *load) {
 
                        /* We know which method will be called, no dispatch necessary. */
                        loaded_ent = resolve_ent_polymorphy(dyn_tp, ent);
-                       /* called_ent may not be description: has no Address/Const to Call! */
-                       assert(get_entity_peculiarity(loaded_ent) != peculiarity_description);
                        new_node = get_atomic_ent_value(loaded_ent);
                }
        }