issue #144 change the size of TValue.tt to byte

pull/167/head
Dibyendu Majumdar 6 years ago
parent 55dc69d4c4
commit a97f974db5

@ -110,7 +110,7 @@ typedef union Value {
} Value;
#define TValuefields Value value_; int tt_
#define TValuefields Value value_; lu_byte tt_
typedef struct lua_TValue {
@ -282,7 +282,8 @@ typedef struct lua_TValue {
#define setobj(L,obj1,obj2) \
{ TValue *io1=(obj1); *io1 = *(obj2); \
{ TValue *io1=(obj1); const TValue *io2=(obj2); \
io1->value_ = io2->value_; io1->tt_ = io2->tt_; \
(void)L; checkliveness(L,io1); }

@ -296,7 +296,7 @@ struct LuaLLVMTypes {
std::array<llvm::Constant *, 256> kInt;
std::array<llvm::Constant *, 21> kluaInteger;
std::array<llvm::Constant *, 10> kByte;
std::array<llvm::Constant *, 256> kByte;
llvm::Constant *kFalse;
@ -462,7 +462,7 @@ class RaviJITState {
size_t allocated_modules_;
// flag to help avoid recursion
bool compiling_;
int compiling_;
public:
RaviJITState();
@ -517,8 +517,13 @@ class RaviJITState {
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; }
int get_compiling_flag() const { return compiling_ > 0; }
void set_compiling_flag(bool value) {
if (value)
compiling_++;
else
compiling_--;
}
};
// A wrapper for LLVM Module
@ -905,9 +910,10 @@ class RaviCodeGenerator {
// emit code for (LClosure *)ci->func->value_.gc
llvm::Instruction *emit_gep_ci_func_value_gc_asLClosure(RaviFunctionDef *def);
llvm::Value *emit_gep(RaviFunctionDef *def, const char *name, llvm::Value *s,
int arg1);
llvm::Value *emit_gep(RaviFunctionDef *def, const char *name, llvm::Value *s,
int arg1, int arg2);
llvm::Value *emit_gep(RaviFunctionDef *def, const char *name, llvm::Value *s,
int arg1, int arg2, int arg3);
llvm::Value *emit_gep(RaviFunctionDef *def, const char *name,

@ -694,6 +694,7 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) {
CallInfo *ci = L->ci;
const char *msg;
va_list argp;
luaC_checkGC(L); /* error message uses memory */
va_start(argp, fmt);
msg = luaO_pushvfstring(L, fmt, argp); /* format message */
va_end(argp);

@ -100,7 +100,7 @@ static const char Lua_header[] = ""
" lua_Integer i;\n"
" lua_Number n;\n"
"} Value;\n"
"#define TValuefields Value value_; int tt_\n"
"#define TValuefields Value value_; lu_byte tt_\n"
"typedef struct lua_TValue {\n"
" TValuefields;\n"
"} TValue;\n"

@ -121,6 +121,13 @@ void RaviCodeGenerator::attach_branch_weights(RaviFunctionDef *def,
#endif
}
llvm::Value *RaviCodeGenerator::emit_gep(RaviFunctionDef *def, const char *name,
llvm::Value *s, int arg1) {
llvm::SmallVector<llvm::Value *, 1> values;
values.push_back(def->types->kInt[arg1]);
return def->builder->CreateInBoundsGEP(s, values, name);
}
llvm::Value *RaviCodeGenerator::emit_gep(RaviFunctionDef *def, const char *name,
llvm::Value *s, int arg1, int arg2) {
llvm::SmallVector<llvm::Value *, 2> values;
@ -532,7 +539,7 @@ void RaviCodeGenerator::emit_store_type_(RaviFunctionDef *def,
type == LUA_TBOOLEAN || type == LUA_TNIL);
llvm::Value *desttype = emit_gep(def, "dest.tt", value, 0, 1);
llvm::Instruction *store =
def->builder->CreateStore(def->types->kInt[type], desttype);
def->builder->CreateStore(def->types->kByte[type], desttype);
store->setMetadata(llvm::LLVMContext::MD_tbaa, def->types->tbaa_TValue_ttT);
}
@ -548,14 +555,14 @@ llvm::Value *RaviCodeGenerator::emit_is_value_of_type(RaviFunctionDef *def,
llvm::Value *value_type,
LuaTypeCode lua_type,
const char *varname) {
return def->builder->CreateICmpEQ(value_type, def->types->kInt[int(lua_type)],
return def->builder->CreateICmpEQ(value_type, def->types->kByte[int(lua_type)],
varname);
}
llvm::Value *RaviCodeGenerator::emit_is_not_value_of_type(
RaviFunctionDef *def, llvm::Value *value_type, LuaTypeCode lua_type,
const char *varname) {
return def->builder->CreateICmpNE(value_type, def->types->kInt[int(lua_type)],
return def->builder->CreateICmpNE(value_type, def->types->kByte[int(lua_type)],
varname);
}
@ -564,9 +571,9 @@ llvm::Value *RaviCodeGenerator::emit_is_not_value_of_type_class(
RaviFunctionDef *def, llvm::Value *value_type, int lua_type,
const char *varname) {
llvm::Value *novariant_type =
def->builder->CreateAnd(value_type, def->types->kInt[0x0F]);
def->builder->CreateAnd(value_type, def->types->kByte[0x0F]);
return def->builder->CreateICmpNE(novariant_type,
def->types->kInt[int(lua_type)], varname);
def->types->kByte[int(lua_type)], varname);
}
llvm::Instruction *RaviCodeGenerator::emit_load_ravi_arraytype(

@ -685,10 +685,11 @@ 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_function) return true;
if (p->ravi_jit.jit_function) return 1;
global_State *G = G(L);
if (G->ravi_state == NULL) return 0;
if (!G->ravi_state->jit->is_enabled()) { return 0; }
if (G->ravi_state->jit->get_compiling_flag()) { return 0; }
bool doCompile = (bool)(options && options->manual_request != 0);
if (!doCompile && G->ravi_state->jit->is_auto()) {
if (p->ravi_jit.jit_flags ==
@ -725,6 +726,8 @@ int raviV_compile_n(struct lua_State *L, struct Proto *p[], int n,
ravi_compile_options_t *options) {
global_State *G = G(L);
int count = 0;
if (G->ravi_state->jit->get_compiling_flag())
return 0;
auto module = std::make_shared<ravi::RaviJITModule>(G->ravi_state->jit);
for (int i = 0; i < n; i++) {
if (G->ravi_state->code_generator->compile(L, p[i], module, options))

@ -766,12 +766,12 @@ void RaviCodeGenerator::emit_SETUPVAL(RaviFunctionDef *def, int A, int B,
llvm::Value *type = emit_load_type(def, v);
llvm::Value *is_collectible =
def->builder->CreateAnd(type, def->types->kInt[BIT_ISCOLLECTABLE]);
def->builder->CreateAnd(type, def->types->kByte[BIT_ISCOLLECTABLE]);
llvm::Value *value = emit_gep_upval_value(def, upval);
llvm::Value *cmp = def->builder->CreateICmpNE(v, value, "v.ne.value");
llvm::Value *tobool = def->builder->CreateICmpEQ(
is_collectible, def->types->kInt[0], "not.collectible");
is_collectible, def->types->kByte[0], "not.collectible");
llvm::Value *orcond =
def->builder->CreateOr(cmp, tobool, "v.ne.value.or.not.collectible");

@ -171,12 +171,12 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
// NOTE: Following structure changes when NaN tagging is enabled
// struct TValue {
// union Value value_;
// int tt_;
// lu_byte tt_;
// };
TValueT = llvm::StructType::create(context, "struct.TValue");
elements.clear();
elements.push_back(ValueT);
elements.push_back(C_intT);
elements.push_back(lu_byteT);
TValueT->setBody(elements);
pTValueT = llvm::PointerType::get(TValueT, 0);
@ -429,7 +429,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
TKeyT = llvm::StructType::create(context, "struct.TKey");
elements.clear();
elements.push_back(ValueT);
elements.push_back(C_intT);
elements.push_back(lu_byteT);
elements.push_back(C_intT); /* next */
TKeyT->setBody(elements);
pTKeyT = llvm::PointerType::get(TKeyT, 0);
@ -1243,7 +1243,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
nodes.clear();
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_longlongT, 0));
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_intT, 8));
nodes.push_back(std::pair<llvm::MDNode *, uint64_t>(tbaa_charT, 8));
tbaa_TValueT = mdbuilder.createTBAAStructTypeNode("TValue", nodes);
tbaa_TValue_nT =
@ -1251,7 +1251,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
tbaa_TValue_hT =
mdbuilder.createTBAAStructTagNode(tbaa_pointerT, tbaa_pointerT, 0);
tbaa_TValue_ttT =
mdbuilder.createTBAAStructTagNode(tbaa_TValueT, tbaa_intT, 8);
mdbuilder.createTBAAStructTagNode(tbaa_TValueT, tbaa_charT, 8);
tbaa_luaState_topT =
mdbuilder.createTBAAStructTagNode(tbaa_luaStateT, tbaa_pointerT, 8);

Loading…
Cancel
Save