浏览代码

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 年之前
父节点
当前提交
fab0f2dbad
共有 4 个文件被更改,包括 1 次插入63 次删除
  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
 */
-#if AOT_USE_TAILCALL
-typedef void (*AotCompiledFunction) (lua_State *L, struct CallInfo *ci);
-#else
 typedef struct CallInfo *(*AotCompiledFunction) (lua_State *L, struct CallInfo *ci);
-#endif
 
 /*
 ** 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.
     // 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("        return NULL;  /* end this frame */");
     println("    else {");
     println("        ci = ci->previous;");
     println("        return ci;");
     println("    }");
-    #endif
 }
 
 static
@@ -49,11 +40,7 @@ void create_function(Proto *f)
     }
 
     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);
-#endif
     println("{");
     println("  LClosure *cl;");
     println("  TValue *k;");
@@ -587,11 +574,7 @@ void create_function(Proto *f)
                 println("    else {");
                 println("        ci = newci;");
                 println("        ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
-                #if AOT_USE_TAILCALL
-                println("        return luaV_execute(L, ci);"); // (!!!)
-                #else
                 println("        return ci;");
-                #endif
                 println("    }");
                 break;
             }
@@ -626,11 +609,7 @@ void create_function(Proto *f)
                 println("    }");
                 println("    ci->func -= delta;  /* restore 'func' (if vararg) */");
                 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;");
-                #endif
                 break;
             }
             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.
     // 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("        return NULL;  /* end this frame */");
     println("    else {");
     println("        ci = ci->previous;");
     println("        return ci;");
     println("    }");
-    #endif
 }
 
 static
@@ -41,11 +32,7 @@ void create_function(Proto *f)
     }
 
     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);
-#endif
     println("{");
     println("  LClosure *cl;");
     println("  TValue *k;");
@@ -656,11 +643,7 @@ void create_function(Proto *f)
                 println("        else {");
                 println("            ci = newci;");
                 println("            ci->callstatus = 0;  /* call re-uses 'luaV_execute' */");
-                #if AOT_USE_TAILCALL
-                println("            return luaV_execute(L, ci);"); // (!!!)
-                #else
                 println("            return ci;");
-                #endif
                 println("        }");
                 // FALLTHROUGH
                 break;
@@ -696,11 +679,7 @@ void create_function(Proto *f)
                 println("        }");
                 println("        ci->func -= delta;  /* restore 'func' (if vararg) */");
                 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;");
-                #endif
                 // FALLTHROUGH
                 break;
             }

+ 1 - 17
src/lvm.c

@@ -1162,11 +1162,7 @@ void luaV_finishOp (lua_State *L) {
 #define vmcase(l)	case l:
 #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)
-#endif
 {
   LClosure *cl;
   TValue *k;
@@ -1182,11 +1178,7 @@ static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
   cl = clLvalue(s2v(ci->func));
 #if LUAOT
   if (cl->p->aot_implementation) {
-      #if AOT_USE_TAILCALL
-          return cl->p->aot_implementation(L, ci);
-      #else
-          return ci;
-      #endif
+      return ci;
   }
 #endif
   k = cl->p->k;
@@ -1770,11 +1762,7 @@ static CallInfo *luaV_execute_(lua_State *L, CallInfo *ci)
         }
        ret:  /* return from a Lua function */
         if (ci->callstatus & CIST_FRESH)
-      #if AOT_USE_TAILCALL
-          return;  /* end this frame */
-      #else
           return NULL;  /* end this frame */
-      #endif
         else {
           ci = ci->previous;
           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
 void luaV_execute (lua_State *L, CallInfo *ci) {
-#if AOT_USE_TAILCALL
-    return luaV_execute_(L, ci);
-#else
     do {
         LClosure *cl = clLvalue(s2v(ci->func));
         if (cl->p->aot_implementation) {
@@ -1900,7 +1885,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
             ci = luaV_execute_(L, ci);
         }
     } while (ci);
-#endif
 }
 #endif