issue #131 more fixes

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent daa4f8e89e
commit 99abdf633f

@ -446,6 +446,10 @@ class RaviJITState {
// Enable extra validation such as IR verification
// May slow down compilation
unsigned int validation_ : 1;
// Flag to control calls to GCSTEP
// For some tests we need to disable these calls
unsigned int gcstep_ : 1;
// min code size for compilation
int min_code_size_;
@ -456,6 +460,9 @@ class RaviJITState {
// Count of modules allocated
// Used to debug module deallocation
size_t allocated_modules_;
// flag to help avoid recursion
bool compiling_;
public:
RaviJITState();
@ -501,11 +508,15 @@ class RaviJITState {
}
int get_validation() const { return validation_; }
void set_validation(bool value) { validation_ = value; }
int get_gcstep() const { return gcstep_; }
void set_gcstep(bool value) { gcstep_ = value; }
bool is_tracehook_enabled() const { return tracehook_enabled_; }
void set_tracehook_enabled(bool value) { tracehook_enabled_ = value; }
void incr_allocated_modules() { allocated_modules_++; }
void decr_allocated_modules() { allocated_modules_--; }
size_t allocated_modules() const { return allocated_modules_; }
int get_compiling_flag() const { return compiling_; }
void set_compiling_flag(bool value) { compiling_ = value; }
};
// A wrapper for LLVM Module

@ -79,6 +79,10 @@ int raviV_getminexeccount(struct lua_State *L);
/* Enable IR / codegen validations */
void raviV_setvalidation(struct lua_State *L, int enabled);
int raviV_getvalidation(struct lua_State *L);
/* Enable calls to GCSTEP */
void raviV_setgcstep(struct lua_State *L, int enabled);
int raviV_getgcstep(struct lua_State *L);
/* Enable or disable trace hook */
void raviV_settraceenabled(struct lua_State *L, int enabled);

@ -150,7 +150,9 @@ end
report"gc.lua"
local f = assert(loadfile('gc.lua'))
if ravi then ravi.gcstep(false) end
f()
if ravi then ravi.gcstep(true) end
if not ravi or not ravi.auto() or ravi.tracehook() then
-- in JIT mode we need tracehook enabled
dofile('db.lua')

@ -250,6 +250,15 @@ int raviV_getverbosity(lua_State *L) {
return 0;
}
void raviV_setgcstep(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getgcstep(lua_State *L) {
(void)L;
return 0;
}
// Turn on/off the JIT compiler
void raviV_settraceenabled(lua_State *L, int value) {
(void)L;

@ -1296,7 +1296,11 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
std::shared_ptr<RaviJITModule> module,
ravi_compile_options_t *options) {
if (p->ravi_jit.jit_status == RAVI_JIT_COMPILED) return true;
// Avoid recursive calls
if (module->owner()->get_compiling_flag())
return false;
bool doVerify = module->owner()->get_validation() != 0;
bool omitArrayGetRangeCheck =
options ? options->omit_array_get_range_check != 0 : 0;
@ -1317,6 +1321,9 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
p->ravi_jit.jit_status = RAVI_JIT_CANT_COMPILE; // can't compile
return false;
}
// Set flag so we can avoid recursive calls
module->owner()->set_compiling_flag(true);
// The functions constants
TValue *k = p->k;
@ -1905,7 +1912,7 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
llvm::verifyFunction(*f->function(), &llvm::errs())) {
f->dump();
fprintf(stderr, "LLVM Code Verification failed\n");
exit(1);
exit(1);
}
// The Lua GC doesn't know about memory allocated by the JIT
// compiler; this means that if lots of functions are being compiled
@ -1914,11 +1921,21 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
// To workaround this issue we tell the GC that we increased
// memory usage by approximately n kbytes where n is the
// number of bytecodes in the function compiled
lua_gc(L, LUA_GCSTEP, n); // nKbytes?
if (module->owner()->get_gcstep()) {
// The unlock/lock sequence below is to satisfy ltests
// If the lock allowed recursion then this would not be
// required. In real code the locking is no-op.
lua_unlock(L);
lua_gc(L, LUA_GCSTEP, n); // nKbytes?
lua_lock(L);
}
ravi::RaviJITFunction *llvm_func = f.release();
p->ravi_jit.jit_data = reinterpret_cast<void *>(llvm_func);
p->ravi_jit.jit_function = nullptr;
p->ravi_jit.jit_status = RAVI_JIT_COMPILED;
module->owner()->set_compiling_flag(false);
return llvm_func != nullptr;
}

@ -124,9 +124,11 @@ RaviJITState::RaviJITState()
verbosity_(0),
tracehook_enabled_(false),
validation_(false),
gcstep_(true),
min_code_size_(150),
min_exec_count_(50),
allocated_modules_(0) {
allocated_modules_(0),
compiling_(false) {
// LLVM needs to be initialized else
// ExecutionEngine cannot be created
// This needs to be an atomic check although LLVM docs
@ -195,10 +197,8 @@ std::shared_ptr<llvm::Module> RaviJITState::optimizeModule(
using llvm::PassManager;
#endif
#if !defined(NDEBUG)
if (get_verbosity() >= 1)
M->dump();
#endif
M->print(&llvm::errs, NULL, false, true);
if (get_verbosity() >= 3)
TM->Options.PrintMachineCode = 1;
else
@ -636,7 +636,7 @@ llvm::Function *RaviJITModule::addExternFunction(llvm::FunctionType *type,
}
void RaviJITModule::dump() {
#if !defined(NDEBUG)
#if LLVM_VERSION_MAJOR < 5
if (module_) module_->dump();
#endif
}
@ -856,6 +856,17 @@ int raviV_getvalidation(lua_State *L) {
return G->ravi_state->jit->get_validation();
}
void raviV_setgcstep(lua_State *L, int value) {
global_State *G = G(L);
if (!G->ravi_state) return;
G->ravi_state->jit->set_gcstep(value != 0);
}
int raviV_getgcstep(lua_State *L) {
global_State *G = G(L);
if (!G->ravi_state) return 0;
return G->ravi_state->jit->get_gcstep();
}
// Turn on/off the JIT compiler
void raviV_settraceenabled(lua_State *L, int value) {
global_State *G = G(L);

@ -552,7 +552,7 @@ static llvm::Value *get_value(lua_State *L, int idx) {
Dump an LLVM object
*/
static int dump_content(lua_State *L) {
#if !defined(NDEBUG)
#if LLVM_VERSION_MAJOR < 5
TypeHolder *th = nullptr;
StructTypeHolder *sth = nullptr;
PointerTypeHolder *ph = nullptr;

@ -1324,7 +1324,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
}
void LuaLLVMTypes::dump() {
#if !defined(NDEBUG)
#if LLVM_VERSION_MAJOR < 5
GCObjectT->dump();
fputs("\n", stdout);
TValueT->dump();

@ -302,6 +302,15 @@ int raviV_getverbosity(lua_State *L) {
return 0;
}
void raviV_setgcstep(lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getgcstep(lua_State *L) {
(void)L;
return 0;
}
// Turn on/off the JIT compiler
void raviV_settraceenabled(lua_State *L, int value) {
(void)L;

@ -156,6 +156,15 @@ int raviV_getgcstep(struct lua_State *L) {
return 0;
}
void raviV_setvalidation(struct lua_State *L, int value) {
(void)L;
(void)value;
}
int raviV_getvalidation(struct lua_State *L) {
(void)L;
return 0;
}
// Turn on/off the JIT compiler
void raviV_settraceenabled(struct lua_State *L, int value) {
(void)L;

@ -191,7 +191,7 @@ static int ravi_sizelevel(lua_State *L) {
return 1;
}
// Set GC step when JIT compiling
// Set validation when JIT compiling
static int ravi_validation(lua_State *L) {
int n = lua_gettop(L);
int oldvalue = raviV_getvalidation(L);
@ -203,6 +203,18 @@ static int ravi_validation(lua_State *L) {
return 1;
}
// Set GC step when JIT compiling
static int ravi_gcstep(lua_State *L) {
int n = lua_gettop(L);
int oldvalue = raviV_getgcstep(L);
if (n == 1) {
int value = lua_tointeger(L, 1);
raviV_setgcstep(L, value);
}
lua_pushboolean(L, oldvalue);
return 1;
}
// Turn on/off the trace hook
static int ravi_traceenable(lua_State *L) {
int n = lua_gettop(L);
@ -246,6 +258,7 @@ static const luaL_Reg ravilib[] = {{"iscompiled", ravi_is_compiled},
{"sizelevel", ravi_sizelevel},
{"verbosity", ravi_verbosity},
{"validation", ravi_validation},
{"gcstep", ravi_gcstep},
{"tracehook", ravi_traceenable},
{"listcode", ravi_listcode},
{"limits", ravi_get_limits},

Loading…
Cancel
Save