]> Nishi Git Mirror - gwion.git/commitdiff
:fire: Remove broken constprop
authorfennecdjay <astor.jeremie@wanadoo.fr>
Sat, 16 Feb 2019 10:31:23 +0000 (11:31 +0100)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Sat, 16 Feb 2019 10:31:23 +0000 (11:31 +0100)
include/instr.h
include/optim.h
opt/constant.c
opt/optim.c
src/emit/emit.c
src/lib/instr.c
src/lib/opfunc.c
src/oo/value.c

index de356a805751bda94a564bc606375e71615959c2..e13236f8ec3f9d94d4171e1e4df7854a38e67f8a 100644 (file)
@@ -72,8 +72,6 @@ INSTR(DotTmpl);
 // optimizations
 #ifdef OPTIMIZE
 INSTR(PutArgsInMem);
-INSTR(ConstPropSet);
-INSTR(ConstPropGet);
 #endif
 #include "opcode.h"
 #endif
index 0cbd2a3b0bf8e5e1589abefd4306524f0703418e..2e1987e4d87570d920b1ca15f2ece263d2b94ccb 100644 (file)
@@ -1,17 +1,10 @@
 #ifndef __OPTIM
 #define __OPTIM
 #ifdef OPTIMIZE
-#define OPTIMIZE_DEFAULT default: break;
 #define OPTIMIZE_CONST(a) CHECK_BO(optimize_const(a))
 ANN m_bool optimize_const(const Exp_Binary*);
 ANN2(1) void constprop_prim(const Exp_Primary* p, m_uint* ptr);
-#define OPTIMIZE_PRIM_CONST(a, b)      \
-else if(GET_FLAG(v, ae_flag_constprop)) \
-  constprop_prim(a,b);
 #else
-#define OPTIMIZE_DEFAULT
-#define OPTIMIZE_CONST(a)
-#define OPTIMIZE_PRIM_CONST(a, b)
 #endif
 m_bool constant_folding(const Exp_Binary* bin);
 #endif
index 66868402641100f9bac587098b6a5ac67cfaf401..f996c3020be3f8d7d506c57bcccec8e81fb42e0f 100644 (file)
@@ -5,11 +5,10 @@
 #include "type.h"
 #include "constant.h"
 
-#define describe_constant_xxx(name, etype, mtype)                  \
-ANN m_bool constant_##name(const Exp e) {                          \
-  return (e->exp_type == ae_exp_primary &&                         \
-    e->d.exp_primary.primary_type == ae_primary_##etype) ||        \
-    (e->exp_type == ae_exp_constprop && isa(e->type , mtype) > 0); \
+#define describe_constant_xxx(name, etype, mtype)         \
+ANN m_bool constant_##name(const Exp e) {                 \
+  return (e->exp_type == ae_exp_primary &&                \
+    e->d.exp_primary.primary_type == ae_primary_##etype); \
 }
 describe_constant_xxx(int,   num,  t_int)
 describe_constant_xxx(float, float, t_float)
index dfed7639e18cdc4089cdb7960fbac2789c8f7068..b5ba915930c5c1fdaa9a3a8abba42fbf2589487a 100644 (file)
@@ -7,83 +7,6 @@
 #include "optim.h"
 #include "constant.h"
 
-void constprop_prim(const Exp_Primary* p, m_uint* ptr) {
-  Exp_Primary* e = (Exp_Primary*)p;
-  e->primary_type = ae_primary_constprop;
-  e->d.num = (m_uint)ptr; // improve me
-}
-
-ANN static m_bool is_constprop_value(const Exp e) {
-  if (e->exp_type == ae_exp_decl
-    && isa(e->d.exp_decl.list->self->value->type, t_int) > 0 &&
-    !e->d.exp_decl.list->self->value->type->array_depth &&
-    !e->d.exp_decl.list->self->value->owner_class &&
-    !GET_FLAG(e->d.exp_decl.list->self->value, arg))
-  return (e->exp_type == ae_exp_primary &&
-    e->d.exp_primary.primary_type == ae_primary_id &&
-    isa(e->type, t_int) > 0 &&
-    !e->d.exp_primary.value->owner_class) ||
-    e->exp_type == ae_exp_constprop2;
-  return 0;
-}
-
-ANN static void constprop_exp(const Exp_Binary* bin, long num) {
-  const Exp e = bin->self, l = bin->lhs, r = bin->rhs;
-  e->exp_type = ae_exp_constprop;
-  e->d.exp_primary.d.num = num;
-  free_exp(l);
-  free_exp(r);
-}
-
-ANN static void constprop_value(const Value v, const long num) {
-  v->d.ptr = (m_uint*)num; //fixme
-  SET_FLAG(v, constprop);
-}
-
-ANN static m_bool constant_propagation(const Exp_Binary* bin) {
-  const Exp l = bin->lhs, r = bin->rhs;
-  switch(bin->op) {
-    case op_chuck:
-      if(isa(r->type, t_function) < 0) {
-        if(is_constprop_value(r)) {
-          if(constant_int(l)) {
-if(r->d.exp_primary.primary_type == ae_primary_num) {
-            constprop_value(r->d.exp_primary.value,
-              l->d.exp_primary.d.num);
-            constprop_exp(bin, l->d.exp_primary.d.num);
-}
-  else if(r->exp_type == ae_exp_decl) {
-    SET_FLAG(r->d.exp_decl.list->self->value, constprop);
-  *(m_uint*)r->d.exp_decl.list->self->value->d.ptr = l->d.exp_primary.d.num;
-  }
-            return GW_OK;
-          }
-        }
-      } /* fallthrough */
-    case op_radd:
-    case op_rsub:
-    case op_rmul:
-    case op_rdiv:
-    case op_rmod:
-    case op_rsl:
-    case op_rsr:
-    case op_rsand:
-    case op_rsor:
-    case op_rsxor:
-    case op_ref:
-    case op_unref:
-    case op_trig:
-    case op_untrig:
-      if(r->exp_type == ae_exp_constprop2) {
-        r->d.exp_primary.value->d.ptr = 0;
-        UNSET_FLAG(r->d.exp_primary.value, constprop);
-      }
-    default: break;
-  }
-  return GW_OK;
-}
-
 m_bool optimize_const(const Exp_Binary* bin) {
-  constant_propagation(bin);
   return constant_folding(bin);
 }
index b23cb43e8e17e444debbc7afcc9f379d9d7b2656..b5856660cd5e6e1d5c6e75eec4a4f460911e274b 100644 (file)
@@ -264,11 +264,11 @@ ANN static m_bool emit_symbol_builtin(const Emitter emit, const Exp_Primary* pri
     const m_uint size = v->type->size;
     const Instr instr = emit_kind(emit, size, prim->self->emit_var, regpushimm);
     if(!prim->self->emit_var && size == SZ_INT) {
-    if(isa(v->type, t_object) > 0) {
-      instr->execute = RegPushImm;
-      instr->m_val = (m_uint)v->d.ptr;
-    } else if(v->d.ptr)
-      instr->m_val = *(m_uint*)v->d.ptr;
+      if(isa(v->type, t_object) > 0) {
+        instr->execute = RegPushImm;
+        instr->m_val = (m_uint)v->d.ptr;
+      } else if(v->d.ptr)
+        instr->m_val = *(m_uint*)v->d.ptr;
     } else if(v->d.ptr)
       memcpy(&instr->m_val, v->d.ptr, v->type->size);
     else
@@ -439,23 +439,10 @@ ANN static m_bool prim_gack(const Emitter emit, const Exp_Primary* primary) {
   return GW_OK;
 }
 
-#ifdef OPTIMIZE
-ANN static m_bool prim_constprop(Emitter emit, const Exp_Primary* prim) {
-  const Instr instr = emit_add_instr(emit, ConstPropSet);
-  instr->m_val = prim->value->offset;
-  instr->m_val2 = prim->d.num;
-  *(m_bool*)instr->ptr = prim->self->emit_var;
-  return GW_OK;
-}
-#endif
-
 static const _exp_func prim_func[] = {
   (_exp_func)prim_id, (_exp_func)prim_num, (_exp_func)prim_float, (_exp_func)prim_str,
   (_exp_func)prim_array, (_exp_func)prim_gack, (_exp_func)prim_vec, (_exp_func)prim_vec,
   (_exp_func)prim_vec, (_exp_func)prim_char, (_exp_func)dummy_func,
-#ifdef OPTIMIZE
-  (_exp_func)prim_constprop
-#endif
 };
 
 ANN static m_bool emit_exp_primary(const Emitter emit, const Exp_Primary* prim) { GWDEBUG_EXE
@@ -881,28 +868,6 @@ ANN static m_bool emit_exp_if(const Emitter emit, const Exp_If* exp_if) { GWDEBU
   return ret;
 }
 
-#ifdef OPTIMIZE
-ANN static void emit_exp_constprop(const Emitter emit, const Exp e) {
-  if(!e->emit_var) {
-    if(e->exp_type == ae_exp_constprop) {
-      const Instr instr = emit_add_instr(emit, RegPushMem);
-      instr->m_val = e->d.exp_primary.value->offset;
-      *(m_uint*)instr->ptr = GET_FLAG(e->d.exp_primary.value, global);
-      return;
-    }
-    const Instr instr = emit_add_instr(emit, ConstPropGet);
-    instr->m_val2 = e->d.exp_primary.value->offset;
-    instr->m_val = e->d.exp_primary.d.num;
-    *(m_uint*)instr->ptr = 1;
-  } else {
-    const Instr instr = emit_add_instr(emit, ConstPropSet);
-    instr->m_val = e->d.exp_primary.value->offset;
-    *(m_bool*)instr->ptr = 1;
-    instr->m_val2 = e->d.exp_primary.d.num;
-  }
-}
-#endif
-
 DECL_EXP_FUNC(emit)
 
 ANN2(1) static m_bool emit_exp(const Emitter emit, Exp exp, const m_bool ref) { GWDEBUG_EXE
index 3702658b8714a316ae4d7d05ce1b9f748230e79e..78214c67cf7011a41e7ebad46c75c2ed38b27aae 100644 (file)
@@ -82,29 +82,6 @@ INSTR(PutArgsInMem) { GWDEBUG_EXE
   POP_REG(shred, instr->m_val)
   memcpy(shred->mem, shred->reg, instr->m_val);
 }
-
-INSTR(ConstPropSet) { GWDEBUG_EXE
-  if(*(m_uint*)instr->ptr >= 2) {
-    *(m_int**)(shred->reg) = (m_int*)(shred->mem + instr->m_val);
-    PUSH_REG(shred, SZ_INT);
-    return;
-  }
-  *(m_int*)(shred->mem + instr->m_val) = instr->m_val2;
-  if(*(m_bool*)instr->ptr)
-    *(m_int**)(shred->reg) = (m_int*)(shred->mem + instr->m_val);
-  else
-    *(m_int*)(shred->reg) = instr->m_val2;
-  PUSH_REG(shred, SZ_INT);
-  *(m_uint*)instr->ptr = 2 + *(m_uint*)instr->ptr;
-}
-
-INSTR(ConstPropGet) { GWDEBUG_EXE
-  if(!*(m_uint*)instr->ptr)
-    memcpy(REG(0), MEM(instr->m_val2), SZ_INT);
-  else
-    memcpy(REG(0), &instr->m_val, SZ_INT);
-  PUSH_REG(shred, SZ_INT);
-}
 #endif
 
 Type_List tmpl_tl(const Env env, const m_str name) {
index d4cde019c0f2c0adcfc07cfb593f6e2d4951853e..4af00e9983c4e251da3cd218cba0056a0692970f 100644 (file)
@@ -50,15 +50,6 @@ OP_CHECK(opck_rassign) {
 OP_CHECK(opck_unary_meta) {
   const Exp_Unary* unary = (Exp_Unary*)data;
   unary->self->meta = ae_meta_value;
-#ifdef OPTIMIZE
-  if(unary->exp->exp_type == ae_exp_constprop2) {
-    unary->exp->exp_type =ae_exp_primary;
-    unary->exp->d.exp_primary.primary_type = ae_primary_id;
-    unary->exp->d.exp_primary.d.num = (m_uint)unary->exp->d.exp_primary.value->d.ptr;
-    UNSET_FLAG(unary->exp->d.exp_primary.value, constprop);
-    unary->exp->d.exp_primary.value->d.ptr = 0;
-  }
-#endif
   return unary->exp->type;
 }
 
@@ -70,21 +61,6 @@ OP_CHECK(opck_unary) {
           op2str(unary->op), access(unary->exp->meta))
   unary->exp->emit_var = 1;
   unary->self->meta = ae_meta_value;
-#ifdef OPTIMIZE
-if(unary->exp->exp_type == ae_exp_primary &&
-    GET_FLAG(unary->exp->d.exp_primary.value, constprop)) {
-    UNSET_FLAG(unary->exp->d.exp_primary.value, constprop);
-    unary->exp->d.exp_primary.value->d.ptr = 0;
-  return unary->exp->type;
-}
-  if(unary->exp->exp_type == ae_exp_constprop) {
-    unary->exp->exp_type = ae_exp_primary;
-    unary->exp->d.exp_primary.primary_type = ae_primary_constprop;
-    unary->exp->d.exp_primary.d.num = (m_uint)unary->exp->d.exp_primary.value->d.ptr;
-    UNSET_FLAG(unary->exp->d.exp_primary.value, constprop);
-    unary->exp->d.exp_primary.value->d.ptr = 0;
-  }
-#endif
   return unary->exp->type;
 }
 
@@ -95,28 +71,6 @@ OP_CHECK(opck_post) {
           op2str(post->op), access(post->exp->meta))
   post->exp->emit_var = 1;
   post->self->meta = ae_meta_value;
-#ifdef OPTIMIZE
-if(post->exp->exp_type == ae_exp_primary &&
-    GET_FLAG(post->exp->d.exp_primary.value, constprop)) {
-    UNSET_FLAG(post->exp->d.exp_primary.value, constprop);
-    post->exp->d.exp_primary.value->d.ptr = 0;
-  return post->exp->type;
-}
-  if(post->exp->exp_type == ae_exp_constprop2) {exit(3);
-    post->exp->exp_type =ae_exp_primary;
-    post->exp->d.exp_primary.primary_type = ae_primary_constprop;
-    post->exp->d.exp_primary.d.num = (m_uint)post->exp->d.exp_primary.value->d.ptr;
-    UNSET_FLAG(post->exp->d.exp_primary.value, constprop);
-    post->exp->d.exp_primary.value->d.ptr = 0;
-}
-  if(post->exp->exp_type == ae_exp_constprop) {exit(2);
-    post->exp->exp_type =ae_exp_primary;
-    post->exp->d.exp_primary.primary_type = ae_primary_constprop;
-    post->exp->d.exp_primary.d.num = (m_uint)post->exp->d.exp_primary.value->d.ptr;
-    UNSET_FLAG(post->exp->d.exp_primary.value, constprop);
-    post->exp->d.exp_primary.value->d.ptr = 0;
-}
-#endif
   return post->exp->type;
 }
 
index c06b0795cfe001c44aff547fdd6377c724869e96..ae39b9e69d05db65381ad73c1d42226a8c930611 100644 (file)
@@ -7,8 +7,7 @@
 #include "type.h"
 
 ANN static void free_value(Value a) {
-//  if(!GET_FLAG(a, func) && !GET_FLAG(a, constprop) && a->d.ptr && isa(a->type, t_object) < 0)
-  if(!GET_FLAG(a, func) && !GET_FLAG(a, constprop) && a->d.ptr &&
+  if(!GET_FLAG(a, func) && a->d.ptr &&
 !(GET_FLAG(a, enum) && GET_FLAG(a, builtin) && a->owner_class)
 && isa(a->type, t_object) < 0)
     _mp_free(a->type->size, a->d.ptr);