[svn:parrot] r47191 - branches/constant_unfolding/compilers/imcc
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Mon May 31 04:11:04 UTC 2010
Author: plobsing
Date: Mon May 31 04:11:03 2010
New Revision: 47191
URL: https://trac.parrot.org/parrot/changeset/47191
Log:
add constant unfolding stage to ops selection (try_weaken_const_to_temp)
Modified:
branches/constant_unfolding/compilers/imcc/imc.h
branches/constant_unfolding/compilers/imcc/parser_util.c
Modified: branches/constant_unfolding/compilers/imcc/imc.h
==============================================================================
--- branches/constant_unfolding/compilers/imcc/imc.h Mon May 31 04:10:24 2010 (r47190)
+++ branches/constant_unfolding/compilers/imcc/imc.h Mon May 31 04:11:03 2010 (r47191)
@@ -321,7 +321,22 @@
__attribute__nonnull__(1);
PARROT_WARN_UNUSED_RESULT
-int try_find_op(PARROT_INTERP,
+int try_weaken_const_to_temp(PARROT_INTERP,
+ ARGMOD(IMC_Unit *unit),
+ ARGIN(const char *name),
+ ARGMOD(SymReg **r),
+ int n,
+ int keyvec,
+ int emit)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*unit)
+ FUNC_MODIFIES(*r);
+
+PARROT_WARN_UNUSED_RESULT
+int try_weaken_int_to_num(PARROT_INTERP,
ARGMOD(IMC_Unit *unit),
ARGIN(const char *name),
ARGMOD(SymReg **r),
@@ -393,7 +408,12 @@
, PARROT_ASSERT_ARG(args))
#define ASSERT_ARGS_register_compilers __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
-#define ASSERT_ARGS_try_find_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_try_weaken_const_to_temp __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(unit) \
+ , PARROT_ASSERT_ARG(name) \
+ , PARROT_ASSERT_ARG(r))
+#define ASSERT_ARGS_try_weaken_int_to_num __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(unit) \
, PARROT_ASSERT_ARG(name) \
Modified: branches/constant_unfolding/compilers/imcc/parser_util.c
==============================================================================
--- branches/constant_unfolding/compilers/imcc/parser_util.c Mon May 31 04:10:24 2010 (r47190)
+++ branches/constant_unfolding/compilers/imcc/parser_util.c Mon May 31 04:11:03 2010 (r47191)
@@ -341,9 +341,13 @@
}
}
- /* still wrong, try to find an existing op */
+ /* still wrong, try using temporaries in stead of constants */
if (op < 0)
- op = try_find_op(interp, unit, name, r, n, keyvec, emit);
+ op = try_weaken_const_to_temp(interp, unit, name, r, n, keyvec, emit);
+
+ /* still wrong, try using C<NUMVAL>s in stead of C<INTVAL>s */
+ if (op < 0)
+ op = try_weaken_int_to_num(interp, unit, name, r, n, keyvec, emit);
if (op < 0) {
int ok = 0;
@@ -1001,16 +1005,86 @@
/*
-=item C<int try_find_op(PARROT_INTERP, IMC_Unit *unit, const char *name, SymReg
-**r, int n, int keyvec, int emit)>
+=item C<int try_weaken_const_to_temp(PARROT_INTERP, IMC_Unit *unit, const char
+*name, SymReg **r, int n, int keyvec, int emit)>
+
+Try to find a valid op doing the same operation by storing const values in
+temporaries used by the actual op.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+int
+try_weaken_const_to_temp(PARROT_INTERP, ARGMOD(IMC_Unit *unit),
+ARGIN(const char *name), ARGMOD(SymReg **r), int n, int keyvec, int emit)
+{
+ ASSERT_ARGS(try_weaken_const_to_temp)
+ char fullname[64];
+ SymReg **r_save = (SymReg **)mem_sys_allocate_zeroed(sizeof (SymReg *) * n);
+
+ int op = -1;
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (r[i]->type == VTCONST ||
+ r[i]->type == VT_CONSTP) {
+ r_save[i] = r[i];
+ r[i] = mk_temp_reg(interp, r[i]->set);
+ op_fullname(fullname, name, r, n, keyvec);
+ op = interp->op_lib->op_code(interp, fullname, 1);
+ if (op >= 0)
+ break;
+ }
+ }
+
+ if (op >= 0) {
+ n = i + 1;
+ for (i = 0; i < n; i++) {
+ if (r_save[i]) {
+ SymReg *rr[2];
+ rr[0] = r[i];
+ rr[1] = r_save[i];
+ INS(interp, unit, "set", NULL, rr, 2, 0, 1);
+ /* XXX leak memory ?
+ free_sym(r_save[i]);
+ */
+ }
+ }
+
+ /* need to allocate the temp - run reg_alloc ??? */
+ IMCC_INFO(interp)->optimizer_level |= OPT_PASM;
+ }
+ else {
+ for (i = 0; i < n; i++) {
+ if (r_save[i]) {
+ /* XXX leak memory ?
+ free_sym(r[i]);
+ */
+ r[i] = r_save[i];
+ }
+ }
+ }
+
+ mem_sys_free(r_save);
+
+ return op;
+}
+
+/*
+
+=item C<int try_weaken_int_to_num(PARROT_INTERP, IMC_Unit *unit, const char
+*name, SymReg **r, int n, int keyvec, int emit)>
-Try to find valid op doing the same operation e.g.
+Try to find valid op doing the same operation by changing C<INTVAL> registers
+to C<NUMVAL> registers. eg:
- add_n_i_n => add_n_n_i
+ add_n_i_n => set_n_i ; add_n_n_n
div_n_ic_n => div_n_nc_n
div_n_i_n => set_n_i ; div_n_n_n
ge_n_ic_ic => ge_n_nc_ic
- acos_n_i => acos_n_n
+ acos_n_i => set_n_i ; acos_n_n
=cut
@@ -1018,10 +1092,10 @@
PARROT_WARN_UNUSED_RESULT
int
-try_find_op(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name),
+try_weaken_int_to_num(PARROT_INTERP, ARGMOD(IMC_Unit *unit), ARGIN(const char *name),
ARGMOD(SymReg **r), int n, int keyvec, int emit)
{
- ASSERT_ARGS(try_find_op)
+ ASSERT_ARGS(try_weaken_int_to_num)
char fullname[64];
int changed = 0;
More information about the parrot-commits
mailing list