From ffa0611cea1b0ea0a866f9c88be09852bc3f23c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Minisini?= Date: Tue, 3 Jan 2023 14:25:00 +0100 Subject: [PATCH] Factorize exception management in JIT code. [GB.JIT] * OPT: Factorize exception management in JIT code. --- main/lib/jit/gb.jit/.src/CCompilation.class | 2 +- main/lib/jit/gb.jit/.src/Jit.module | 14 ++++++++------ main/lib/jit/gb.jit/jit.h | 1 - main/lib/jit/gb.jit/jit_after.h | 21 +++++++++++++++++++++ main/lib/jit/jit_body.c | 19 +++---------------- 5 files changed, 33 insertions(+), 24 deletions(-) create mode 100644 main/lib/jit/gb.jit/jit_after.h diff --git a/main/lib/jit/gb.jit/.src/CCompilation.class b/main/lib/jit/gb.jit/.src/CCompilation.class index bb159f1de..5c9ef62eb 100644 --- a/main/lib/jit/gb.jit/.src/CCompilation.class +++ b/main/lib/jit/gb.jit/.src/CCompilation.class @@ -28,7 +28,7 @@ Static Public Sub Init() If Not $sCompiler Then Error.Raise("Compiler not found") sFlag = Env["GB_JIT_CFLAGS"] - If Not sFlag Then sFlag = "-O3 -march=native -mtune=native" + If Not sFlag Then sFlag = "-O2 -march=native -mtune=native" $aFlags = Split(sFlag, " ") diff --git a/main/lib/jit/gb.jit/.src/Jit.module b/main/lib/jit/gb.jit/.src/Jit.module index 8b4e50e50..1c79f1392 100644 --- a/main/lib/jit/gb.jit/.src/Jit.module +++ b/main/lib/jit/gb.jit/.src/Jit.module @@ -57,17 +57,19 @@ Public Sub _Compile(sArch As String) As Boolean Print #hFile, "#define NO_CONFIG_H" - Print #hFile, File.Load("gambas.h"); - Print #hFile, File.Load("gb_overflow.h"); - Print #hFile, File.Load("jit.h"); - Print #hFile, File.Load("gb.jit.h"); - + Print #hFile, File.Load("gambas.h") + Print #hFile, File.Load("gb_overflow.h") + Print #hFile, File.Load("jit.h") + Print #hFile, File.Load("gb.jit.h") + Print #hFile, "GB_INTERFACE * GB_PTR;" Print #hFile, "#define GB (*GB_PTR)" Print #hFile, "JIT_INTERFACE * JIT_PTR;" Print #hFile, "#define JIT (*JIT_PTR)" + + Print #hFile, File.Load("gb_error_common.h") - Print #hFile, File.Load("gb_error_common.h"); + Print #hFile, File.Load("jit_after.h") Close #hFile diff --git a/main/lib/jit/gb.jit/jit.h b/main/lib/jit/gb.jit/jit.h index 7f5f83365..4404b1a19 100644 --- a/main/lib/jit/gb.jit/jit.h +++ b/main/lib/jit/gb.jit/jit.h @@ -682,4 +682,3 @@ enum }) #endif - diff --git a/main/lib/jit/gb.jit/jit_after.h b/main/lib/jit/gb.jit/jit_after.h new file mode 100644 index 000000000..424014d2d --- /dev/null +++ b/main/lib/jit/gb.jit/jit_after.h @@ -0,0 +1,21 @@ +static VALUE *_jit_print_catch(VALUE **psp, VALUE *sp, VALUE *ssp, void *cp, void *fp, bool has_catch_finally) +{ + CP = cp; + FP = fp; + if (has_catch_finally) + JIT.error_set_last(FALSE); + if (SP > sp) sp = SP; else SP = sp; + LEAVE_SUPER(); + if (sp > ssp) { JIT.release_many(sp, sp - ssp); SP = sp = ssp; } + return sp; +} + +static VALUE *_jit_end_try(VALUE **psp, VALUE *sp) +{ + if (SP > sp) sp = SP; else SP = sp; + LEAVE_SUPER(); + if (sp > EP) { JIT.release_many(sp, sp - EP); SP = sp = EP; } + *JIT.got_error = 1; + JIT.error_set_last(FALSE); + return sp; +} \ No newline at end of file diff --git a/main/lib/jit/jit_body.c b/main/lib/jit/jit_body.c index cda6e734c..a9bbe4d7b 100644 --- a/main/lib/jit/jit_body.c +++ b/main/lib/jit/jit_body.c @@ -163,16 +163,8 @@ static void enter_function(FUNCTION *func, int index) static void print_catch(void) { JIT_print("\n } CATCH {\n\n"); - JIT_print(" CP = (void *)%p;\n", JIT_class); - JIT_print(" FP = (void *)%p;\n", _func); - if (_has_catch || _has_finally) - JIT_print(" JIT.error_set_last(FALSE); \n"); - //JIT_print(" fprintf(stderr, \"EP = %%p SP = %%p sp = %%p\\n\", EP, SP, sp);\n"); - JIT_print(" if (SP > sp) sp = SP; else SP = sp;\n"); - JIT_print(" LEAVE_SUPER();\n"); - //JIT_print(" if (sp > bp) { fprintf(stderr, \"sp = %%p bp = %%p release %%d\\n\", sp, bp, sp - bp); JIT.release_many(sp, sp - bp); SP = sp = bp; }\n"); - JIT_print(" if (sp > ssp) { JIT.release_many(sp, sp - ssp); SP = sp = ssp; }\n"); - //JIT_print(" PP = SP;\n"); + + JIT_print(" sp = _jit_print_catch(psp, sp, ssp, (void *)%p, (void *)%p, %d);\n", JIT_class, _func, _has_catch || _has_finally); JIT_print(" error = TRUE;\n"); JIT_print("\n } END_TRY\n\n"); JIT_print("__FINALLY:;\n"); @@ -3710,12 +3702,7 @@ _END_TRY: JIT_print(" *JIT.got_error = 0;\n"); JIT_print(" } CATCH {\n"); - JIT_print(" if (SP > sp) sp = SP; else SP = sp;\n"); - JIT_print(" LEAVE_SUPER();\n"); - //JIT_print(" if (sp > EP) { fprintf(stderr, \"release try %%d\\n\", sp - EP); JIT.release_many(sp, sp - EP); SP = sp = EP; }\n"); - JIT_print(" if (sp > EP) { JIT.release_many(sp, sp - EP); SP = sp = EP; }\n"); - JIT_print(" *JIT.got_error = 1;\n"); - JIT_print(" JIT.error_set_last(FALSE);\n"); + JIT_print(" sp = _jit_end_try(psp, sp);\n"); JIT_print(" } END_TRY }\n"); JIT_print(" EP = tp;\n"); goto _MAIN;