From: fennecdjay Date: Thu, 20 Jun 2019 15:16:13 +0000 (+0200) Subject: :fire: Remove optimize folder and keep TCO X-Git-Tag: nightly~2419 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=004706844dbb255ac41d2a598c0fcbe28f48622f;p=gwion.git :fire: Remove optimize folder and keep TCO --- diff --git a/config.mk.orig b/config.mk.orig index fc6be789..18e565d7 100644 --- a/config.mk.orig +++ b/config.mk.orig @@ -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 index f996c302..00000000 --- a/opt/constant.c +++ /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 index 8ceea72c..00000000 --- a/opt/fold.c +++ /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 index 004af0da..00000000 --- a/opt/optim.c +++ /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); -} diff --git a/src/emit/emit.c b/src/emit/emit.c index 741cf278..1eabddde 100644 --- a/src/emit/emit.c +++ b/src/emit/emit.c @@ -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); diff --git a/src/lib/instr.c b/src/lib/instr.c index e9342d21..c75b63c6 100644 --- a/src/lib/instr.c +++ b/src/lib/instr.c @@ -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"