auto mode heuristics

pull/81/head
Dibyendu Majumdar 9 years ago
parent 78e3501cc4
commit 27637907c8

@ -413,7 +413,9 @@ typedef struct LocVar {
typedef struct RaviJITProto {
lu_byte jit_status; // 0=not compiled, 1=can't compile, 2=compiled, 3=freed
lu_byte jit_status; /* 0=not compiled, 1=can't compile, 2=compiled, 3=freed */
lu_byte jit_flags;
unsigned short execution_count; /* how many times has function been executed */
void *jit_data;
lua_CFunction jit_function;
} RaviJITProto;

@ -80,6 +80,7 @@ struct LuaLLVMTypes {
llvm::Type *C_size_t;
llvm::Type *C_ptrdiff_t;
llvm::Type *C_int64_t;
llvm::Type *C_shortT;
llvm::Type *lua_NumberT;
llvm::PointerType *plua_NumberT;
@ -157,7 +158,6 @@ struct LuaLLVMTypes {
llvm::PointerType *pppLClosureT;
llvm::StructType *RaviJITProtoT;
llvm::PointerType *pRaviJITProtoT;
llvm::StructType *ProtoT;
llvm::PointerType *pProtoT;

@ -121,6 +121,8 @@ Proto *luaF_newproto (lua_State *L) {
f->ravi_jit.jit_data = NULL;
f->ravi_jit.jit_function = NULL;
f->ravi_jit.jit_status = 0; /* not compiled */
f->ravi_jit.jit_flags = 0; /* no loop */
f->ravi_jit.execution_count = 0; /* number of times function execution (capped) */
return f;
}

@ -1763,10 +1763,12 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum, For
checknext(ls, TK_DO);
if (isnum) {
if (info && info->is_constant && info->int_value > 1) {
ls->fs->f->ravi_jit.jit_flags = 1;
forprep_inst = OP_RAVI_FORPREP_IP;
forloop_inst = OP_RAVI_FORLOOP_IP;
}
else if (info && info->is_constant && info->int_value == 1) {
ls->fs->f->ravi_jit.jit_flags = 1;
forprep_inst = OP_RAVI_FORPREP_I1;
forloop_inst = OP_RAVI_FORLOOP_I1;
}

@ -53,6 +53,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
C_int64_t = llvm::Type::getIntNTy(context, sizeof(int64_t) * 8);
C_intT = llvm::Type::getIntNTy(context, sizeof(int) * 8);
C_pintT = llvm::PointerType::get(C_intT, 0);
C_shortT = llvm::Type::getIntNTy(context, sizeof(short) * 8);
static_assert(sizeof(size_t) == sizeof(lu_mem),
"lu_mem size is not same as size_t");
@ -269,7 +270,13 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
pppLClosureT = llvm::PointerType::get(ppLClosureT, 0);
RaviJITProtoT = llvm::StructType::create(context, "ravi.RaviJITProto");
pRaviJITProtoT = llvm::PointerType::get(RaviJITProtoT, 0);
elements.clear();
elements.push_back(lu_byteT); /* jit_status*/
elements.push_back(lu_byteT); /* jit_flags */
elements.push_back(C_shortT); /* execution_count */
elements.push_back(C_pcharT); /* jit_data */
elements.push_back(plua_CFunctionT); /* jit_function */
RaviJITProtoT->setBody(elements);
///*
//** Function Prototypes
@ -328,7 +335,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
elements.push_back(pLClosureT); /* cache */
elements.push_back(pTStringT); /* source */
elements.push_back(pGCObjectT); /* gclist */
elements.push_back(pRaviJITProtoT); /* ravi_jit */
elements.push_back(RaviJITProtoT); /* ravi_jit */
ProtoT->setBody(elements);
///*
@ -1087,6 +1094,8 @@ void LuaLLVMTypes::dump() {
fputs("\n", stdout);
LocVarT->dump();
fputs("\n", stdout);
RaviJITProtoT->dump();
fputs("\n", stdout);
ProtoT->dump();
fputs("\n", stdout);
CClosureT->dump();

@ -267,13 +267,32 @@ void raviV_close(struct lua_State *L) {
// a manual compilation request was made
// Returns true if compilation was successful
int raviV_compile(struct lua_State *L, struct Proto *p, int manual_request) {
if (p->ravi_jit.jit_status == 2)
return true;
global_State *G = G(L);
if (G->ravi_state == NULL)
return 0;
if (!G->ravi_state->jit->is_enabled()) {
return 0;
}
#if 0
if (G->ravi_state->jit->is_auto() || manual_request)
#else
bool doCompile = manual_request != 0;
if (!doCompile && G->ravi_state->jit->is_auto()) {
if (p->ravi_jit.jit_flags != 0) /* loop */
doCompile = true;
else if (p->sizecode > 1)
doCompile = true;
else {
if (p->ravi_jit.execution_count < 50)
p->ravi_jit.execution_count++;
else
doCompile = true;
}
}
if (doCompile)
#endif
G->ravi_state->code_generator->compile(L, p);
return p->ravi_jit.jit_status == 2;
}
@ -289,6 +308,7 @@ void raviV_freeproto(struct lua_State *L, struct Proto *p) {
p->ravi_jit.jit_status = 3;
p->ravi_jit.jit_function = NULL;
p->ravi_jit.jit_data = NULL;
p->ravi_jit.execution_count = 0;
}
}

Loading…
Cancel
Save