...
[libfirm] / ir / opt / ldstopt.c
index 5afd5ed..0ea39e8 100644 (file)
@@ -222,7 +222,9 @@ static int optimize_load(ir_node *load)
      * throw an exception when the previous Store was quiet.
      */
     if (! info->projs[pn_Load_X_except] || get_nodes_block(load) == get_nodes_block(pred)) {
+      DBG_OPT_RAW(pred, load);
       exchange( info->projs[pn_Load_res], get_Store_value(pred) );
+
       if (info->projs[pn_Load_M])
        exchange(info->projs[pn_Load_M], mem);
 
@@ -243,6 +245,8 @@ static int optimize_load(ir_node *load)
     if (! info->projs[pn_Load_X_except] || get_nodes_block(load) == get_nodes_block(pred)) {
       ldst_info_t *pred_info = get_irn_link(pred);
 
+      DBG_OPT_RAR(pred, load);
+
       if (pred_info->projs[pn_Load_res]) {
        /* we need a data proj from the previous load for this optimization */
        exchange( info->projs[pn_Load_res], pred_info->projs[pn_Load_res] );
@@ -310,6 +314,7 @@ static int optimize_store(ir_node *store)
      * TODO: What, if both have the same exception handler ???
      */
     if (get_Store_volatility(pred) != volatility_is_volatile && !pred_info->projs[pn_Store_X_except]) {
+      DBG_OPT_WAW(pred, store);
       exchange( pred_info->projs[pn_Store_M], get_Store_mem(pred) );
       res = 1;
     }
@@ -321,6 +326,7 @@ static int optimize_store(ir_node *store)
      * We may remove the second Store, if it does not have an exception handler.
      */
     if (! info->projs[pn_Store_X_except]) {
+      DBG_OPT_WAR(pred, store);
       exchange( info->projs[pn_Store_M], mem );
       res = 1;
     }
@@ -345,10 +351,11 @@ static int optimize_store(ir_node *store)
  *
  * Is only allowed if the predecessor blocks have only one successor.
  */
-static int optimize_phi(ir_node *phi)
+static int optimize_phi(ir_node *phi, void *env)
 {
+  walk_env_t *wenv = env;
   int i, n;
-  ir_node *store, *ptr, *block, *phiM, *phiD, *exc;
+  ir_node *store, *ptr, *block, *phiM, *phiD, *exc, *projM;
   ir_mode *mode;
   ir_node **inM, **inD;
   int *idx;
@@ -448,11 +455,19 @@ static int optimize_phi(ir_node *phi)
 
   /* fourth step: create the Store */
   store = new_rd_Store(db, current_ir_graph, block, phiM, ptr, phiD);
+  projM = new_rd_Proj(NULL, current_ir_graph, block, store, mode_M, pn_Store_M);
+
+  info = get_ldst_info(store, wenv);
+  info->projs[pn_Store_M] = projM;
 
   /* fifths step: repair exception flow */
   if (exc) {
     ir_node *projX = new_rd_Proj(NULL, current_ir_graph, block, store, mode_X, pn_Store_X_except);
 
+    info->projs[pn_Store_X_except] = projX;
+    info->exc_block                = exc;
+    info->exc_idx                  = idx[0];
+
     for (i = 0; i < n; ++i) {
       set_Block_cfgpred(exc, idx[i], projX);
     }
@@ -463,7 +478,7 @@ static int optimize_phi(ir_node *phi)
   }
 
   /* sixt step: replace old Phi */
-  exchange(phi, new_rd_Proj(NULL, current_ir_graph, block, store, mode_M, pn_Store_M));
+  exchange(phi, projM);
 
   return 1;
 }
@@ -485,8 +500,8 @@ static void do_load_store_optimize(ir_node *n, void *env)
     wenv->changes |= optimize_store(n);
     break;
 
-//  case iro_Phi:
-//    wenv->changes |= optimize_phi(n);
+  case iro_Phi:
+    wenv->changes |= optimize_phi(n, env);
 
   default:
     ;