]> Nishi Git Mirror - gwion.git/commitdiff
:fire: Remove optimize folder and keep TCO
authorfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 20 Jun 2019 15:16:13 +0000 (17:16 +0200)
committerfennecdjay <astor.jeremie@wanadoo.fr>
Thu, 20 Jun 2019 15:16:49 +0000 (17:16 +0200)
config.mk.orig
opt/constant.c [deleted file]
opt/fold.c [deleted file]
opt/optim.c [deleted file]
src/emit/emit.c
src/lib/instr.c

index fc6be789c0b399d9c59c60887f3f7872e6a667e8..18e565d7633013afdba96d78b20bc28f2b283450 100644 (file)
@@ -3,10 +3,6 @@ PRG ?=gwion
 PREFIX ?=/usr/local
 CFLAGS += -Iutil/include -Iast/include -D_GNU_SOURCE
 
-# handle boolean options
-USE_OPTIMIZE  ?= 0
-USE_NOMEMOIZE ?= 0
-
 # base plugin directories
 GWPLUG_DIR   ?= $(shell echo ~/.gwplug)
 
diff --git a/opt/constant.c b/opt/constant.c
deleted file mode 100644 (file)
index f996c30..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "oo.h"
-#include "env.h"
-#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); \
-}
-describe_constant_xxx(int,   num,  t_int)
-describe_constant_xxx(float, float, t_float)
diff --git a/opt/fold.c b/opt/fold.c
deleted file mode 100644 (file)
index 8ceea72..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "oo.h"
-#include "env.h"
-#include "vm.h"
-#include "instr.h"
-#include "emit.h"
-#include "type.h"
-#include "optim.h"
-#include "constant.h"
-#include "traverse.h"
-#include "parse.h"
-
-ANN static void fold_exp(MemPool mp, const Exp_Binary* bin) {
-  const Exp n = exp_self(bin)->next;
-  const Exp e = exp_self(bin);
-  free_exp(mp, bin->lhs);
-  free_exp(mp, bin->rhs);
-  e->exp_type = ae_exp_primary;
-  e->next = n;
-}
-
-#define describe_xxx_exp(name, type, etype, target)            \
-ANN static inline void name##_exp(const Exp e, const type t) { \
-  e->d.exp_primary.primary_type = ae_primary_##etype;          \
-  e->d.exp_primary.d.target = t;                               \
-}
-describe_xxx_exp(int,   m_int,   num,   num)
-describe_xxx_exp(float, m_float, float, fnum)
-
-#define CASE(op_op, l, op, r) case op_##op_op: ret = l op r; break;
-
-#define DIV_BY_ZERO(l, op, r) if(r) ret = l op r; else \
-         ERR_B(bin->rhs->pos, _("Division by zero"))
-
-#define COMMON_CASE(l, r)                     \
-    CASE(add, l, +, r)                        \
-    CASE(sub, l, -, r)                        \
-    CASE(mul, l, /, r)                        \
-    case op_div: DIV_BY_ZERO(l, / , r) break;
-
-#define describe_fold_xxx(name, type, _l, _r, etype, opt)             \
-ANN static m_bool fold_##name(const Env env, const Exp_Binary* bin) { \
-  MemPool mp = env->gwion->mp;                                         \
-  const union exp_primary_data *l = &bin->lhs->d.exp_primary.d;       \
-  const union exp_primary_data *r = &bin->rhs->d.exp_primary.d;       \
-  type ret = 0;                                                       \
-  switch(bin->op) {                                                   \
-    COMMON_CASE(l->_l, r->_r)                                         \
-    opt                                                               \
-    default:                                                          \
-      return GW_OK;                                                   \
-  }                                                                   \
-  const Exp e = exp_self(bin);                                        \
-  fold_exp(mp, bin);                                                  \
-  etype##_exp(e, ret);                                                \
-  return GW_OK;                                                       \
-}
-describe_fold_xxx(ii, m_int, num, num, int,
-  case op_mod: DIV_BY_ZERO(l->num, % , r->num) break;
-  CASE(shl, l->num, >>, r->num) CASE(shr, l->num, <<, r->num))
-describe_fold_xxx(ff, m_float, fnum, fnum, float,)
-describe_fold_xxx(if, m_float,  num, fnum, float,)
-describe_fold_xxx(fi, m_float, fnum,  num, float,)
-
-m_bool constant_folding(const Env env, const Exp_Binary* bin) {
-  if(constant_int(bin->lhs)) {
-    if(constant_int(bin->rhs))
-      CHECK_BB(fold_ii(env, bin))
-    else if(constant_float(bin->rhs))
-      CHECK_BB(fold_if(env, bin))
-  } else if(constant_float(bin->lhs)) {
-    if(constant_float(bin->rhs))
-      CHECK_BB(fold_ff(env, bin))
-    else if(constant_int(bin->rhs))
-      CHECK_BB(fold_fi(env, bin))
-  }
-  return GW_OK;
-}
diff --git a/opt/optim.c b/opt/optim.c
deleted file mode 100644 (file)
index 004af0d..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "gwion_util.h"
-#include "gwion_ast.h"
-#include "oo.h"
-#include "env.h"
-#include "type.h"
-#include "value.h"
-#include "optim.h"
-#include "constant.h"
-
-m_bool optimize_const(const Env env, const Exp_Binary* bin) {
-  return constant_folding(env, bin);
-}
index 741cf27873426dec70e11fd2b1c165654756d0ae..1eabddde96fa006d2ba645e45186701dbee5eb8e 100644 (file)
@@ -1078,30 +1078,24 @@ ANN static m_bool emit_stmt_code(const Emitter emit, const Stmt_Code stmt) {
   return ret;
 }
 
-#ifdef OPTIMIZE
 ANN static m_bool optimize_taill_call(const Emitter emit, const Exp_Call* e) {
   Exp arg = e->args;
   if(arg)
     CHECK_BB(emit_exp(emit, e->args, 0))
-  const Instr instr = emit_add_instr(emit, PutArgsInMem);
-  while(arg) {
-    instr->m_val += arg->type->size;
-    arg = arg->next;
+  regpop(emit, SZ_INT);
+  for(m_uint i = 0; i < e->m_func->def->stack_depth; i += SZ_INT) {
+    const Instr instr = emit_add_instr(emit, Reg2Mem);
+    instr->m_val = instr->m_val2 = i;
   }
   emit_add_instr(emit, Goto);
   return GW_OK;
 }
-#define OPTIMIZE_TCO\
-  if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func)\
-    return optimize_taill_call(emit, &stmt->val->d.exp_call);
-#else
-#define OPTIMIZE_TCO
-#endif
 
 
 ANN static m_bool emit_stmt_return(const Emitter emit, const Stmt_Exp stmt) {
   if(stmt->val) {
-    OPTIMIZE_TCO
+    if(stmt->val->exp_type == ae_exp_call && emit->env->func == stmt->val->d.exp_call.m_func)
+      return optimize_taill_call(emit, &stmt->val->d.exp_call);
     CHECK_BB(emit_exp(emit, stmt->val, 0))
     if(isa(stmt->val->type, t_object) > 0 && isa(stmt->val->type , t_shred) < 0) // beware shred
       emit_add_instr(emit, RegAddRef);
index e9342d21fb87db2f7a4e06f341b2f038e219132e..c75b63c6635a8a2bc687d42045570f7d77b174d8 100644 (file)
@@ -36,14 +36,6 @@ INSTR(SwitchBranch) {
   shred->pc = map_get(map, *(m_uint*)REG(0)) ?: instr->m_val;
 }
 
-#ifdef OPTIMIZE
-INSTR(PutArgsInMem) {
-  POP_REG(shred, instr->m_val)
-  for(m_uint i = 0; i < instr->m_val; i += SZ_INT)
-    *(m_uint*)(shred->mem + i) = *(m_uint*)(shred->reg + i);
-}
-#endif
-
 #include "gwion.h"
 #include "emit.h"
 #include "value.h"