Browse Source

Remove the AOT_USE_TAILCALL option

In my experiments, the trampoline version proved to be faster than the
tail call version (most of the time -- a few benchmarks were faster
using tail calls). Since the trampoline version works even for older
compilers, and appears to be faster, I'm going to make it the default
and not bother with having an option for the tail call version.
Hugo Musso Gualandi 4 năm trước cách đây
mục cha
commit
fab0f2dbad
4 tập tin đã thay đổi với 1 bổ sung63 xóa
  1. 0 4
      src/lobject.h
  2. 0 21
      src/luaot_gotos.c
  3. 0 21
      src/luaot_switches.c
  4. 1 17
      src/lvm.c

+ 0 - 4
src/lobject.h

@@ -537,11 +537,7 @@ typedef struct AbsLineInfo {
 /*
 /*
 ** AOT implementation
 ** AOT implementation
 */
 */
-#if AOT_USE_TAILCALL
-typedef void (*AotCompiledFunction) (lua_State *L, struct CallInfo *ci);
-#else
 typedef struct CallInfo *(*AotCompiledFunction) (lua_State *L, struct CallInfo *ci);
 typedef struct CallInfo *(*AotCompiledFunction) (lua_State *L, struct CallInfo *ci);
-#endif
 
 
 /*
 /*
 ** Function Prototypes
 ** Function Prototypes

+ 0 - 21
src/luaot_gotos.c

@@ -19,21 +19,12 @@ void println_goto_ret()
 {
 {
     // This is the piece of code that is after the "ret" label.
     // This is the piece of code that is after the "ret" label.
     // It should be used in the places that do "goto ret;"
     // It should be used in the places that do "goto ret;"
-    #if AOT_USE_TAILCALL
-    println("    if (ci->callstatus & CIST_FRESH)");
-    println("        return;  /* end this frame */");
-    println("    else {");
-    println("        ci = ci->previous;");
-    println("        return luaV_execute(L, ci); /* continue running caller in this frame */"); // (!)
-    println("    }");
-    #else
     println("    if (ci->callstatus & CIST_FRESH)");
     println("    if (ci->callstatus & CIST_FRESH)");
     println("        return NULL;  /* end this frame */");
     println("        return NULL;  /* end this frame */");
     println("    else {");
     println("    else {");
     println("        ci = ci->previous;");
     println("        ci = ci->previous;");
     println("        return ci;");
     println("        return ci;");
     println("    }");
     println("    }");
-    #endif
 }
 }
 
 
 static
 static
@@ -49,11 +40,7 @@ void create_function(Proto *f)
     }
     }
 
 
     println("static");
     println("static");
-#if AOT_USE_TAILCALL
-    println("void magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
-#else
     println("CallInfo *magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
     println("CallInfo *magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
-#endif
     println("{");
     println("{");
     println("  LClosure *cl;");
     println("  LClosure *cl;");
     println("  TValue *k;");
     println("  TValue *k;");
@@ -587,11 +574,7 @@ void create_function(Proto *f)
                 println("    else {");
                 println("    else {");
                 println("        ci = newci;");
                 println("        ci = newci;");
                 println("        ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
                 println("        ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
-                #if AOT_USE_TAILCALL
-                println("        return luaV_execute(L, ci);"); // (!!!)
-                #else
                 println("        return ci;");
                 println("        return ci;");
-                #endif
                 println("    }");
                 println("    }");
                 break;
                 break;
             }
             }
@@ -626,11 +609,7 @@ void create_function(Proto *f)
                 println("    }");
                 println("    }");
                 println("    ci->func -= delta;  /* restore 'func' (if vararg) */");
                 println("    ci->func -= delta;  /* restore 'func' (if vararg) */");
                 println("    luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */");
                 println("    luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */");
-                #if AOT_USE_TAILCALL
-                println("    return luaV_execute(L, ci); /* execute the callee */"); // (!)
-                #else
                 println("    return ci;");
                 println("    return ci;");
-                #endif
                 break;
                 break;
             }
             }
             case OP_RETURN: {
             case OP_RETURN: {

+ 0 - 21
src/luaot_switches.c

@@ -11,21 +11,12 @@ void println_goto_ret()
 {
 {
     // This is the piece of code that is after the "ret" label.
     // This is the piece of code that is after the "ret" label.
     // It should be used in the places that do "goto ret;"
     // It should be used in the places that do "goto ret;"
-    #if AOT_USE_TAILCALL
-    println("        if (ci->callstatus & CIST_FRESH)");
-    println("            return;  /* end this frame */");
-    println("        else {");
-    println("            ci = ci->previous;");
-    println("            return luaV_execute(L, ci); /* continue running caller in this frame */"); // (!)
-    println("        }");
-    #else
     println("    if (ci->callstatus & CIST_FRESH)");
     println("    if (ci->callstatus & CIST_FRESH)");
     println("        return NULL;  /* end this frame */");
     println("        return NULL;  /* end this frame */");
     println("    else {");
     println("    else {");
     println("        ci = ci->previous;");
     println("        ci = ci->previous;");
     println("        return ci;");
     println("        return ci;");
     println("    }");
     println("    }");
-    #endif
 }
 }
 
 
 static
 static
@@ -41,11 +32,7 @@ void create_function(Proto *f)
     }
     }
 
 
     println("static");
     println("static");
-#if AOT_USE_TAILCALL
-    println("void magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
-#else
     println("CallInfo *magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
     println("CallInfo *magic_implementation_%02d(lua_State *L, CallInfo *ci)", func_id);
-#endif
     println("{");
     println("{");
     println("  LClosure *cl;");
     println("  LClosure *cl;");
     println("  TValue *k;");
     println("  TValue *k;");
@@ -656,11 +643,7 @@ void create_function(Proto *f)
                 println("        else {");
                 println("        else {");
                 println("            ci = newci;");
                 println("            ci = newci;");
                 println("            ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
                 println("            ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
-                #if AOT_USE_TAILCALL
-                println("            return luaV_execute(L, ci);"); // (!!!)
-                #else
                 println("            return ci;");
                 println("            return ci;");
-                #endif
                 println("        }");
                 println("        }");
                 // FALLTHROUGH
                 // FALLTHROUGH
                 break;
                 break;
@@ -696,11 +679,7 @@ void create_function(Proto *f)
                 println("        }");
                 println("        }");
                 println("        ci->func -= delta;  /* restore 'func' (if vararg) */");
                 println("        ci->func -= delta;  /* restore 'func' (if vararg) */");
                 println("        luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */");
                 println("        luaD_pretailcall(L, ci, ra, b);  /* prepare call frame */");
-                #if AOT_USE_TAILCALL
-                println("        return luaV_execute(L, ci); /* execute the callee */"); // (!)
-                #else
                 println("        return ci;");
                 println("        return ci;");
-                #endif
                 // FALLTHROUGH
                 // FALLTHROUGH
                 break;
                 break;
             }
             }

+ 1 - 17
src/lvm.c

@@ -1162,11 +1162,7 @@ void luaV_finishOp (lua_State *L) {
 #define vmcase(l)	case l:
 #define vmcase(l)	case l:
 #define vmbreak		break
 #define vmbreak		break
 
 
-#if AOT_USE_TAILCALL
-static void luaV_execute_(lua_State *L, CallInfo *ci)
-#else
 static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
 static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
-#endif
 {
 {
   LClosure *cl;
   LClosure *cl;
   TValue *k;
   TValue *k;
@@ -1182,11 +1178,7 @@ static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
   cl = clLvalue(s2v(ci->func));
   cl = clLvalue(s2v(ci->func));
 #if LUAOT
 #if LUAOT
   if (cl->p->aot_implementation) {
   if (cl->p->aot_implementation) {
-      #if AOT_USE_TAILCALL
-          return cl->p->aot_implementation(L, ci);
-      #else
-          return ci;
-      #endif
+      return ci;
   }
   }
 #endif
 #endif
   k = cl->p->k;
   k = cl->p->k;
@@ -1770,11 +1762,7 @@ static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
         }
         }
        ret:  /* return from a Lua function */
        ret:  /* return from a Lua function */
         if (ci->callstatus & CIST_FRESH)
         if (ci->callstatus & CIST_FRESH)
-      #if AOT_USE_TAILCALL
-          return;  /* end this frame */
-      #else
           return NULL;  /* end this frame */
           return NULL;  /* end this frame */
-      #endif
         else {
         else {
           ci = ci->previous;
           ci = ci->previous;
           goto returning;  /* continue running caller in this frame */
           goto returning;  /* continue running caller in this frame */
@@ -1889,9 +1877,6 @@ static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
 
 
 #ifndef LUAOT_IS_MODULE
 #ifndef LUAOT_IS_MODULE
 void luaV_execute (lua_State *L, CallInfo *ci) {
 void luaV_execute (lua_State *L, CallInfo *ci) {
-#if AOT_USE_TAILCALL
-    return luaV_execute_(L, ci);
-#else
     do {
     do {
         LClosure *cl = clLvalue(s2v(ci->func));
         LClosure *cl = clLvalue(s2v(ci->func));
         if (cl->p->aot_implementation) {
         if (cl->p->aot_implementation) {
@@ -1900,7 +1885,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
             ci = luaV_execute_(L, ci);
             ci = luaV_execute_(L, ci);
         }
         }
     } while (ci);
     } while (ci);
-#endif
 }
 }
 #endif
 #endif