alernative way to reset L->top after calling luaV_execute() in JITed OP_CALL

pull/81/head
Dibyendu Majumdar 9 years ago
parent 65dd836d4a
commit 527fdccd1f

@ -59,7 +59,7 @@ LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
StkId val);
LUAI_FUNC void luaV_finishOp (lua_State *L);
LUAI_FUNC void luaV_execute (lua_State *L);
LUAI_FUNC int luaV_execute (lua_State *L);
LUAI_FUNC void luaV_concat (lua_State *L, int total);
LUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y);
LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);

@ -392,10 +392,14 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
* yield
*/
L->nny++;
n = (*p->ravi_jit.jit_function)(L);
int b = (*p->ravi_jit.jit_function)(L);
L->nny--;
L->nCcalls--;
lua_assert(L->ci == prevci);
if (b && isLua(L->ci))
/* b is the value returned by luaD_poscall()
*/
L->top = L->ci->top;
/* Return a different value from 1 to
* allow luaV_execute() to distinguish between
* JITed function and true C function

@ -815,7 +815,7 @@ void luaV_finishOp (lua_State *L) {
#define vmcasenb(l,b) case l: {b} /* nb = no break */
void luaV_execute (lua_State *L) {
int luaV_execute (lua_State *L) {
CallInfo *ci = L->ci;
LClosure *cl;
TValue *k;
@ -1199,10 +1199,10 @@ newframe: /* reentry point when frame changes (call/return) */
* via OP_CALL always takes the other branch but in JIT mode
* this branch is taken.
*/
if (b && isLua(L->ci)) {
L->top = L->ci->top;
}
return; /* external invocation: return */
//if (b && isLua(L->ci)) {
// L->top = L->ci->top;
//}
return b; /* external invocation: return */
}
else { /* invocation via reentry: continue execution */
ci = L->ci;

@ -94,7 +94,9 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int
llvm::Value *precall_result =
CreateCall3(def->builder, def->luaD_precallF, def->L, ra,
llvm::ConstantInt::get(def->types->C_intT, nresults));
llvm::Value *precall_bool =
// If luaD_precall() returns 0 then we need to interpret the
// Lua function
llvm::Value *do_Lua_interp =
def->builder->CreateICmpEQ(precall_result, def->types->kInt[0]);
llvm::BasicBlock *then_block = llvm::BasicBlock::Create(
@ -103,12 +105,25 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int
llvm::BasicBlock::Create(def->jitState->context(), "if.not.lua.function");
llvm::BasicBlock *end_block =
llvm::BasicBlock::Create(def->jitState->context(), "op_call.done");
def->builder->CreateCondBr(precall_bool, then_block, else_block);
def->builder->CreateCondBr(do_Lua_interp, then_block, else_block);
def->builder->SetInsertPoint(then_block);
// Lua function, not compiled, so call luaV_execute
def->builder->CreateCall(def->luaV_executeF, def->L);
llvm::Value *b = def->builder->CreateCall(def->luaV_executeF, def->L);
// If the return value is non zero then we need to refresh L->top = ci->top
llvm::Value *b_not_zero =
def->builder->CreateICmpNE(b, def->types->kInt[0]);
llvm::BasicBlock *if_b_block = llvm::BasicBlock::Create(
def->jitState->context(), "if.b", def->f);
def->builder->CreateCondBr(b_not_zero, if_b_block, end_block);
def->builder->SetInsertPoint(if_b_block);
emit_refresh_L_top(def, def->ci_val);
def->builder->CreateBr(end_block);
// Handle the C or JIT case
def->f->getBasicBlockList().push_back(else_block);
def->builder->SetInsertPoint(else_block);
@ -126,12 +141,9 @@ void RaviCodeGenerator::emit_CALL(RaviFunctionDef *def, int A, int B, int C, int
def->builder->SetInsertPoint(then1_block);
emit_refresh_L_top(def, def->ci_val);
//emit_dump_stack(def, "POST L->top = register");
}
def->builder->CreateBr(end_block);
def->f->getBasicBlockList().push_back(end_block);
def->builder->SetInsertPoint(end_block);
//emit_dump_stacktop(def, "JIT OP_CALL after function call");
}
}

@ -92,6 +92,7 @@ void RaviCodeGenerator::emit_RETURN(RaviFunctionDef *def, int A, int B, int pc)
llvm::Value *b =
CreateCall3(def->builder, def->luaD_poscallF, def->L, ra_ptr, nresults);
#if 0
// Reload L->ci (as L->ci would have been updated by luaD_poscall()
llvm::Value *ci_val = emit_load_ci(def);
@ -128,5 +129,8 @@ void RaviCodeGenerator::emit_RETURN(RaviFunctionDef *def, int A, int B, int pc)
// emit_dump_stack(def, "<-- Function exit");
def->builder->CreateRet(nresults);
#endif
def->builder->CreateRet(b);
}
}

@ -704,11 +704,11 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
luaD_callT =
llvm::FunctionType::get(llvm::Type::getVoidTy(context), elements, false);
// void luaV_execute(lua_State L);
// int luaV_execute(lua_State L);
elements.clear();
elements.push_back(plua_StateT);
luaV_executeT =
llvm::FunctionType::get(llvm::Type::getVoidTy(context), elements, false);
llvm::FunctionType::get(C_intT, elements, false);
// void luaF_close (lua_State *L, StkId level)
elements.clear();

Loading…
Cancel
Save