pull/81/head
Dibyendu Majumdar 9 years ago
parent a86e9660a8
commit 5491d88c1f

@ -423,6 +423,17 @@ typedef struct LocVar {
ravitype_t ravi_type; /* RAVI type of the variable - RAVI_TANY if unknown */
} LocVar;
typedef enum {
RAVI_JIT_NOT_COMPILED = 0,
RAVI_JIT_CANT_COMPILE = 1,
RAVI_JIT_COMPILED = 2,
RAVI_JIT_FREED = 3
} ravi_jit_status_t;
typedef enum {
RAVI_JIT_FLAG_NONE = 0,
RAVI_JIT_FLAG_HASFORLOOP = 1
} ravi_jit_flag_t;
typedef struct RaviJITProto {
lu_byte jit_status; /* 0=not compiled, 1=can't compile, 2=compiled, 3=freed */

@ -27,7 +27,7 @@
#ifdef USE_LLVM
#include "ravijit.h"
#include "ravillvm.h"
#include "ravi_llvm.h"
#ifdef __cplusplus
extern "C" {
@ -515,7 +515,7 @@ struct RaviFunctionDef {
llvm::Function *raviV_op_shrF;
llvm::Function *raviV_op_shlF;
// array setters
// array setters
llvm::Function *raviH_set_intF;
llvm::Function *raviH_set_floatF;
@ -764,19 +764,16 @@ public:
void debug_printf(RaviFunctionDef *def, const char *str);
void debug_printf1(RaviFunctionDef *def, const char *str,
llvm::Value *arg1);
void debug_printf1(RaviFunctionDef *def, const char *str, llvm::Value *arg1);
void debug_printf2(RaviFunctionDef *def, const char *str,
llvm::Value *arg1, llvm::Value *arg2);
void debug_printf2(RaviFunctionDef *def, const char *str, llvm::Value *arg1,
llvm::Value *arg2);
void debug_printf3(RaviFunctionDef *def, const char *str,
llvm::Value *arg1, llvm::Value *arg2,
llvm::Value *arg3);
void debug_printf3(RaviFunctionDef *def, const char *str, llvm::Value *arg1,
llvm::Value *arg2, llvm::Value *arg3);
void debug_printf4(RaviFunctionDef *def, const char *str,
llvm::Value *arg1, llvm::Value *arg2,
llvm::Value *arg3, llvm::Value *arg4);
void debug_printf4(RaviFunctionDef *def, const char *str, llvm::Value *arg1,
llvm::Value *arg2, llvm::Value *arg3, llvm::Value *arg4);
// Look for Lua bytecodes that are jump targets and allocate
// a BasicBlock for each such target in def->jump_targets.
@ -932,9 +929,11 @@ public:
void emit_TFORLOOP(RaviFunctionDef *def, int A, int j);
void emit_GETTABLE_AF(RaviFunctionDef *def, int A, int B, int C, bool omitArrayGetRangeCheck = false);
void emit_GETTABLE_AF(RaviFunctionDef *def, int A, int B, int C,
bool omitArrayGetRangeCheck = false);
void emit_GETTABLE_AI(RaviFunctionDef *def, int A, int B, int C, bool omitArrayGetRangeCheck = false);
void emit_GETTABLE_AI(RaviFunctionDef *def, int A, int B, int C,
bool omitArrayGetRangeCheck = false);
void emit_SETTABLE_AF(RaviFunctionDef *def, int A, int B, int C,
bool known_int);
@ -968,4 +967,4 @@ private:
#endif
#endif
#endif

@ -468,7 +468,7 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
static const char *getfuncname (lua_State *L, CallInfo *ci, const char **name) {
TMS tm = (TMS)0; /* to avoid warnings */
Proto *p = ci_func(ci)->p; /* calling function */
if (p->ravi_jit.jit_status == 2) {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) {
*name = "?";
return "compiled";
}

@ -370,11 +370,11 @@ int luaD_precall (lua_State *L, StkId func, int nresults) {
L->top = ci->top;
if (L->hookmask & LUA_MASKCALL)
callhook(L, ci);
if (L == G(L)->mainthread && p->ravi_jit.jit_status == 0) {
if (L == G(L)->mainthread && p->ravi_jit.jit_status == RAVI_JIT_NOT_COMPILED) {
/* not compiled */
raviV_compile(L, p, NULL);
}
if (L == G(L)->mainthread && p->ravi_jit.jit_status == 2) {
if (L == G(L)->mainthread && p->ravi_jit.jit_status == RAVI_JIT_COMPILED) {
/* compiled */
lua_assert(p->ravi_jit.jit_function != NULL);
ci->jitstatus = 1;

@ -120,8 +120,8 @@ Proto *luaF_newproto (lua_State *L) {
f->source = NULL;
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.jit_status = RAVI_JIT_NOT_COMPILED; /* not compiled */
f->ravi_jit.jit_flags = RAVI_JIT_FLAG_NONE; /* no loop */
f->ravi_jit.execution_count = 0; /* number of times function execution (capped) */
return f;
}

@ -1823,7 +1823,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum, For
adjustlocalvars(ls, 3); /* control variables */
checknext(ls, TK_DO);
if (isnum) {
ls->fs->f->ravi_jit.jit_flags = 1;
ls->fs->f->ravi_jit.jit_flags = RAVI_JIT_FLAG_HASFORLOOP;
if (info && info->is_constant && info->int_value > 1) {
forprep_inst = OP_RAVI_FORPREP_IP;
forloop_inst = OP_RAVI_FORLOOP_IP;

@ -579,10 +579,10 @@ llvm::Value *RaviCodeGenerator::emit_num_stack_elements(RaviFunctionDef *def,
// Check if we can compile
// The cases we can compile will increase over time
bool RaviCodeGenerator::canCompile(Proto *p) {
if (p->ravi_jit.jit_status == 1)
if (p->ravi_jit.jit_status == RAVI_JIT_CANT_COMPILE)
return false;
if (jitState_ == nullptr) {
p->ravi_jit.jit_status = 1;
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE;
return false;
}
const Instruction *code = p->code;
@ -987,7 +987,7 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p, ravi_compile_options_t *
bool doVerify = options ? options->verification_level != 0: 0;
bool omitArrayGetRangeCheck = options ? options->omit_array_get_range_check != 0: 0;
if (p->ravi_jit.jit_status != 0 || !canCompile(p))
if (p->ravi_jit.jit_status != RAVI_JIT_NOT_COMPILED || !canCompile(p))
return;
llvm::LLVMContext &context = jitState_->context();
@ -1002,7 +1002,7 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p, ravi_compile_options_t *
// printf("compiling function\n");
auto f = create_function(builder, def);
if (!f) {
p->ravi_jit.jit_status = 1; // can't compile
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE; // can't compile
return;
}
// Add extern declarations for Lua functions we need to call
@ -1493,11 +1493,11 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p, ravi_compile_options_t *
p->ravi_jit.jit_function = (lua_CFunction)llvm_func->compile(doDump);
lua_assert(p->ravi_jit.jit_function);
if (p->ravi_jit.jit_function == nullptr) {
p->ravi_jit.jit_status = 1; // can't compile
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE; // can't compile
delete llvm_func;
p->ravi_jit.jit_data = NULL;
} else {
p->ravi_jit.jit_status = 2;
p->ravi_jit.jit_status = RAVI_JIT_COMPILED;
}
// printf("compiled function\n");
}

@ -421,7 +421,7 @@ void raviV_close(struct lua_State *L) {
// Returns true if compilation was successful
int raviV_compile(struct lua_State *L, struct Proto *p,
ravi_compile_options_t *options) {
if (p->ravi_jit.jit_status == 2)
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED)
return true;
global_State *G = G(L);
if (G->ravi_state == NULL)
@ -431,7 +431,7 @@ int raviV_compile(struct lua_State *L, struct Proto *p,
}
bool doCompile = (bool)(options && options->manual_request != 0);
if (!doCompile && G->ravi_state->jit->is_auto()) {
if (p->ravi_jit.jit_flags != 0) /* function has fornum loop, so compile */
if (p->ravi_jit.jit_flags == RAVI_JIT_FLAG_HASFORLOOP) /* function has fornum loop, so compile */
doCompile = true;
else if (p->sizecode >
G->ravi_state->jit
@ -449,18 +449,18 @@ int raviV_compile(struct lua_State *L, struct Proto *p,
}
if (doCompile)
G->ravi_state->code_generator->compile(L, p, options);
return p->ravi_jit.jit_status == 2;
return p->ravi_jit.jit_status == RAVI_JIT_COMPILED;
}
// Free the JIT compiled function
// Note that this is called by the garbage collector
void raviV_freeproto(struct lua_State *L, struct Proto *p) {
if (p->ravi_jit.jit_status == 2) /* compiled */ {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) /* compiled */ {
ravi::RaviJITFunction *f =
reinterpret_cast<ravi::RaviJITFunction *>(p->ravi_jit.jit_data);
if (f)
delete f;
p->ravi_jit.jit_status = 3;
p->ravi_jit.jit_status = RAVI_JIT_FREED;
p->ravi_jit.jit_function = NULL;
p->ravi_jit.jit_data = NULL;
p->ravi_jit.execution_count = 0;
@ -469,7 +469,7 @@ void raviV_freeproto(struct lua_State *L, struct Proto *p) {
// Dump the LLVM IR
void raviV_dumpIR(struct lua_State *L, struct Proto *p) {
if (p->ravi_jit.jit_status == 2) /* compiled */ {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) /* compiled */ {
ravi::RaviJITFunction *f =
reinterpret_cast<ravi::RaviJITFunction *>(p->ravi_jit.jit_data);
if (f)
@ -479,7 +479,7 @@ void raviV_dumpIR(struct lua_State *L, struct Proto *p) {
// Dump the LLVM ASM
void raviV_dumpASM(struct lua_State *L, struct Proto *p) {
if (p->ravi_jit.jit_status == 2) /* compiled */ {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) /* compiled */ {
ravi::RaviJITFunction *f =
reinterpret_cast<ravi::RaviJITFunction *>(p->ravi_jit.jit_data);
if (f)

@ -1,4 +1,4 @@
#include "ravillvm.h"
#include "ravi_llvm.h"
#include <iostream>

Loading…
Cancel
Save