refactoring

pull/81/head
Dibyendu Majumdar 9 years ago
parent fcb22d1da2
commit b65e5d2fa1

@ -23,7 +23,7 @@ The project was kicked off in January 2015.
JIT Implementation
++++++++++++++++++
Right now (June 2015) I am working on the ``libgccjit`` based JIT implementation.
Right now (July 2015) I am working on the ``libgccjit`` based JIT implementation.
The LLVM JIT compiler is mostly functional. The Lua and Ravi bytecodes currently implemented in LLVM are described in `JIT Status <http://the-ravi-programming-language.readthedocs.org/en/latest/ravi-jit-status.html>`_ page.
@ -33,7 +33,7 @@ For performance benchmarks please visit the `Ravi Performance Benchmarks <http:/
Optional Static Typing
++++++++++++++++++++++
Ravi allows you to annotate local variables with static types. The supported types and the resulting behaviour are as follows:
Ravi allows you to annotate ``local`` variables with static types. The supported types and the resulting behaviour are as follows:
``integer``
denotes an integral value of 64-bits.
@ -44,12 +44,14 @@ Ravi allows you to annotate local variables with static types. The supported typ
``number[]``
denotes an array of numbers
Declaring the types of variables has following advantages.
Declaring the types of ``local`` variables has following advantages.
* Variables declared with above types are automatically initialized to 0
.. attention:: Currently function parameters cannot be decorated with types; this will be added in future.
* Local variables declared with above types are automatically initialized to 0
* Arithmetic operations trigger type specific bytecodes which leads to more efficient JIT compilation
* Specialised operators to get/set from arrays are implemented which makes array access more efficient in JIT mode as the access can be inlined
* Values assigned to typed variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime
* Values assigned to typed variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime (i.e. value is cast to the expected type - this can be exploited to work around the limitation that function parameter types cannot be specified)
* The standard table operations on arrays are checked to ensure that the type is not subverted
* Even if a typed variable is captured in a closure its type must be respected

@ -685,17 +685,23 @@ public:
// emit code to store lua_Number value into register
void emit_store_reg_n(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
void emit_store_reg_n_withtype(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
// emit code to store lua_Integer value into register
void emit_store_reg_i(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
void emit_store_reg_i_withtype(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
// emit code to store bool value into register
void emit_store_reg_b(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
void emit_store_reg_b_withtype(RaviFunctionDef *def, llvm::Value *value,
llvm::Value *dest_ptr);
// emit code to set the type in the register
void emit_store_type(RaviFunctionDef *def, llvm::Value *value, int type);
void emit_store_type_(RaviFunctionDef *def, llvm::Value *value, int type);
// emit code to load the type from a register
llvm::Instruction *emit_load_type(RaviFunctionDef *def, llvm::Value *value);
@ -712,8 +718,7 @@ public:
void emit_assign(RaviFunctionDef *def, llvm::Value *ra, llvm::Value *rb);
// Get &upvals[offset] from LClosure
llvm::Value *emit_gep_upvals(RaviFunctionDef *def, llvm::Value *cl_ptr,
int offset);
llvm::Value *emit_gep_upvals(RaviFunctionDef *def, int offset);
// Load the &upvals[offset] -> result is UpVal*
llvm::Instruction *emit_load_pupval(RaviFunctionDef *def,

@ -23,7 +23,7 @@ The project was kicked off in January 2015.
JIT Implementation
++++++++++++++++++
Right now (June 2015) I am working on the ``libgccjit`` based JIT implementation.
Right now (July 2015) I am working on the ``libgccjit`` based JIT implementation.
The LLVM JIT compiler is mostly functional. The Lua and Ravi bytecodes currently implemented in LLVM are described in `JIT Status <http://the-ravi-programming-language.readthedocs.org/en/latest/ravi-jit-status.html>`_ page.
@ -33,7 +33,7 @@ For performance benchmarks please visit the `Ravi Performance Benchmarks <http:/
Optional Static Typing
++++++++++++++++++++++
Ravi allows you to annotate local variables with static types. The supported types and the resulting behaviour are as follows:
Ravi allows you to annotate ``local`` variables with static types. The supported types and the resulting behaviour are as follows:
``integer``
denotes an integral value of 64-bits.
@ -44,12 +44,14 @@ Ravi allows you to annotate local variables with static types. The supported typ
``number[]``
denotes an array of numbers
Declaring the types of variables has following advantages.
Declaring the types of ``local`` variables has following advantages.
* Variables declared with above types are automatically initialized to 0
.. attention:: Currently function parameters cannot be decorated with types; this will be added in future.
* Local variables declared with above types are automatically initialized to 0
* Arithmetic operations trigger type specific bytecodes which leads to more efficient JIT compilation
* Specialised operators to get/set from arrays are implemented which makes array access more efficient in JIT mode as the access can be inlined
* Values assigned to typed variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime
* Values assigned to typed variables are checked statically unless the values are results from a function call in which case the there is an attempt to convert values at runtime (i.e. value is cast to the expected type - this can be exploited to work around the limitation that function parameter types cannot be specified)
* The standard table operations on arrays are checked to ensure that the type is not subverted
* Even if a typed variable is captured in a closure its type must be respected

@ -35,8 +35,7 @@ void RaviCodeGenerator::emit_UNMF(RaviFunctionDef *def, int A, int B) {
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Value *result = def->builder->CreateFNeg(lhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := -R(B), integer
@ -46,8 +45,7 @@ void RaviCodeGenerator::emit_UNMI(RaviFunctionDef *def, int A, int B) {
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Value *result = def->builder->CreateNeg(lhs, "", false, true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) + C, result is floating
@ -60,8 +58,7 @@ void RaviCodeGenerator::emit_ADDFN(RaviFunctionDef *def, int A, int B, int C) {
lhs,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) + RK(C), all floating
@ -73,8 +70,7 @@ void RaviCodeGenerator::emit_ADDFF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFAdd(lhs, rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) + RK(C), float+int
@ -87,8 +83,7 @@ void RaviCodeGenerator::emit_ADDFI(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateFAdd(
lhs, def->builder->CreateSIToFP(rhs, def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) + RK(C), int+int
@ -101,8 +96,7 @@ void RaviCodeGenerator::emit_ADDII(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateAdd(lhs, rhs, "", false, true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) + C, int+c
@ -114,8 +108,7 @@ void RaviCodeGenerator::emit_ADDIN(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result = def->builder->CreateAdd(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - RK(C), float-float
@ -127,8 +120,7 @@ void RaviCodeGenerator::emit_SUBFF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFSub(lhs, rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) - RK(C), float-int
@ -141,8 +133,7 @@ void RaviCodeGenerator::emit_SUBFI(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateFSub(
lhs, def->builder->CreateSIToFP(rhs, def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) - RK(C), int-float
@ -155,8 +146,7 @@ void RaviCodeGenerator::emit_SUBIF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFSub(
def->builder->CreateSIToFP(lhs, def->types->lua_NumberT), rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) - RK(C), int-int
@ -168,8 +158,7 @@ void RaviCodeGenerator::emit_SUBII(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateSub(lhs, rhs, "", false, true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - C, float - c
@ -182,8 +171,7 @@ void RaviCodeGenerator::emit_SUBFN(RaviFunctionDef *def, int A, int B, int C) {
lhs,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := B - RK(C), b - float
@ -196,8 +184,7 @@ void RaviCodeGenerator::emit_SUBNF(RaviFunctionDef *def, int A, int B, int C) {
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, B),
def->types->lua_NumberT),
rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := B - RK(C), b - int
@ -209,8 +196,7 @@ void RaviCodeGenerator::emit_SUBIN(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result = def->builder->CreateSub(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - C, int - c
@ -222,8 +208,7 @@ void RaviCodeGenerator::emit_SUBNI(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result = def->builder->CreateSub(
llvm::ConstantInt::get(def->types->lua_IntegerT, C), rhs, "", false,
true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) * C, float*c
@ -236,8 +221,7 @@ void RaviCodeGenerator::emit_MULFN(RaviFunctionDef *def, int A, int B, int C) {
lhs,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) * RK(C), float*float
@ -249,8 +233,7 @@ void RaviCodeGenerator::emit_MULFF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFMul(lhs, rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) * RK(C), float*int
@ -263,8 +246,7 @@ void RaviCodeGenerator::emit_MULFI(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateFMul(
lhs, def->builder->CreateSIToFP(rhs, def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) * RK(C), int*int
@ -277,8 +259,7 @@ void RaviCodeGenerator::emit_MULII(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateMul(lhs, rhs, "", false, true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) * C, int*c
@ -290,8 +271,7 @@ void RaviCodeGenerator::emit_MULIN(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result = def->builder->CreateMul(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) / RK(C), float/float
@ -303,8 +283,7 @@ void RaviCodeGenerator::emit_DIVFF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFDiv(lhs, rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) / RK(C), float/int
@ -317,8 +296,7 @@ void RaviCodeGenerator::emit_DIVFI(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateFDiv(
lhs, def->builder->CreateSIToFP(rhs, def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) / RK(C), int/float
@ -331,8 +309,7 @@ void RaviCodeGenerator::emit_DIVIF(RaviFunctionDef *def, int A, int B, int C) {
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFDiv(
def->builder->CreateSIToFP(lhs, def->types->lua_NumberT), rhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) / RK(C), int/int but result is float
@ -346,7 +323,6 @@ void RaviCodeGenerator::emit_DIVII(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result = def->builder->CreateFDiv(
def->builder->CreateSIToFP(lhs, def->types->lua_NumberT),
def->builder->CreateSIToFP(rhs, def->types->lua_NumberT));
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
}
}

@ -96,8 +96,7 @@ void RaviCodeGenerator::emit_ARITH(RaviFunctionDef *def, int A, int B, int C,
lua_assert(0);
}
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
def->builder->CreateBr(done_block);
@ -205,8 +204,7 @@ void RaviCodeGenerator::emit_ARITH(RaviFunctionDef *def, int A, int B, int C,
lua_assert(0);
}
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
def->builder->CreateBr(done_block);
@ -279,8 +277,7 @@ void RaviCodeGenerator::emit_MOD(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result =
CreateCall3(def->builder, def->luaV_modF, def->L, lhs, rhs);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
def->builder->CreateBr(done_block);
@ -400,8 +397,7 @@ void RaviCodeGenerator::emit_MOD(RaviFunctionDef *def, int A, int B, int C) {
lhs = emit_load_local_n(def, nb);
emit_store_reg_n(def, lhs, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, lhs, ra);
def->builder->CreateBr(done_block);
@ -472,8 +468,7 @@ void RaviCodeGenerator::emit_IDIV(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *result =
CreateCall3(def->builder, def->luaV_divF, def->L, lhs, rhs);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
def->builder->CreateBr(done_block);
@ -563,8 +558,7 @@ void RaviCodeGenerator::emit_IDIV(RaviFunctionDef *def, int A, int B, int C) {
result = def->builder->CreateFDiv(lhs, rhs);
llvm::Value *floor_result = def->builder->CreateCall(def->floorFunc, result);
emit_store_reg_n(def, floor_result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, floor_result, ra);
def->builder->CreateBr(done_block);
@ -692,8 +686,7 @@ void RaviCodeGenerator::emit_POW(RaviFunctionDef *def, int A, int B, int C) {
llvm::Value *pow_result = CreateCall2(def->builder, def->powFunc, lhs, rhs);
emit_store_reg_n(def, pow_result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, pow_result, ra);
def->builder->CreateBr(done_block);
@ -755,8 +748,7 @@ void RaviCodeGenerator::emit_UNM(RaviFunctionDef *def, int A, int B) {
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Value *result = def->builder->CreateNeg(lhs, "", false, true);
emit_store_reg_i(def, result, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, result, ra);
def->builder->CreateBr(done_block);
@ -805,8 +797,7 @@ void RaviCodeGenerator::emit_UNM(RaviFunctionDef *def, int A, int B) {
result = def->builder->CreateFNeg(lhs);
emit_store_reg_n(def, result, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, result, ra);
def->builder->CreateBr(done_block);

@ -241,6 +241,13 @@ void RaviCodeGenerator::emit_store_reg_n(RaviFunctionDef *def,
#endif
}
void RaviCodeGenerator::emit_store_reg_n_withtype(RaviFunctionDef *def,
llvm::Value *result,
llvm::Value *dest_ptr) {
emit_store_reg_n(def, result, dest_ptr);
emit_store_type_(def, dest_ptr, LUA_TNUMFLT);
}
void RaviCodeGenerator::emit_store_reg_i(RaviFunctionDef *def,
llvm::Value *result,
llvm::Value *dest_ptr) {
@ -250,6 +257,13 @@ void RaviCodeGenerator::emit_store_reg_i(RaviFunctionDef *def,
store->setMetadata(llvm::LLVMContext::MD_tbaa, def->types->tbaa_TValue_nT);
}
void RaviCodeGenerator::emit_store_reg_i_withtype(RaviFunctionDef *def,
llvm::Value *result,
llvm::Value *dest_ptr) {
emit_store_reg_i(def, result, dest_ptr);
emit_store_type_(def, dest_ptr, LUA_TNUMINT);
}
void RaviCodeGenerator::emit_store_reg_b(RaviFunctionDef *def,
llvm::Value *result,
llvm::Value *dest_ptr) {
@ -259,7 +273,15 @@ void RaviCodeGenerator::emit_store_reg_b(RaviFunctionDef *def,
store->setMetadata(llvm::LLVMContext::MD_tbaa, def->types->tbaa_TValue_nT);
}
void RaviCodeGenerator::emit_store_type(RaviFunctionDef *def,
void RaviCodeGenerator::emit_store_reg_b_withtype(RaviFunctionDef *def,
llvm::Value *result,
llvm::Value *dest_ptr) {
emit_store_reg_b(def, result, dest_ptr);
emit_store_type_(def, dest_ptr, LUA_TBOOLEAN);
}
void RaviCodeGenerator::emit_store_type_(RaviFunctionDef *def,
llvm::Value *value, int type) {
lua_assert(type == LUA_TNUMFLT || type == LUA_TNUMINT ||
type == LUA_TBOOLEAN);
@ -901,9 +923,8 @@ void RaviCodeGenerator::link_block(RaviFunctionDef *def, int pc) {
}
llvm::Value *RaviCodeGenerator::emit_gep_upvals(RaviFunctionDef *def,
llvm::Value *cl_ptr,
int offset) {
return emit_gep(def, "upvals", cl_ptr, 0, 6, offset);
return emit_gep(def, "upvals", def->p_LClosure, 0, 6, offset);
}
llvm::Instruction *RaviCodeGenerator::emit_load_pupval(RaviFunctionDef *def,

@ -202,8 +202,7 @@ void RaviCodeGenerator::emit_NOT(RaviFunctionDef *def, int A, int B) {
llvm::Value *v = emit_boolean_testfalse(def, rb, false);
llvm::Value *result = def->builder->CreateZExt(v, def->types->C_intT, "i");
llvm::Value *ra = emit_gep_register(def, A);
emit_store_reg_b(def, result, ra);
emit_store_type(def, ra, LUA_TBOOLEAN);
emit_store_reg_b_withtype(def, result, ra);
}
void RaviCodeGenerator::emit_TESTSET(RaviFunctionDef *def, int A, int B, int C,

@ -126,8 +126,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, int A, int pc,
// setivalue(ra + 3, idx); /* ...and external index */
idx_int_value = emit_load_local_n(def, idx_int_ptr);
emit_store_reg_i(def, idx_int_value, rvar);
emit_store_type(def, rvar, LUA_TNUMINT);
emit_store_reg_i_withtype(def, idx_int_value, rvar);
// ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
def->builder->CreateBr(def->jmp_targets[pc].jmp1);
@ -193,8 +192,7 @@ void RaviCodeGenerator::emit_FORLOOP2(RaviFunctionDef *def, int A, int pc,
// setfltvalue(ra + 3, idx); /* ...and external index */
idx_double_value = emit_load_local_n(def, idx_double_ptr);
emit_store_reg_n(def, idx_double_value, rvar);
emit_store_type(def, rvar, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, idx_double_value, rvar);
// ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
def->builder->CreateBr(def->jmp_targets[pc].jmp1);
@ -309,8 +307,7 @@ void RaviCodeGenerator::emit_FORLOOP(RaviFunctionDef *def, int A, int pc) {
emit_store_reg_i(def, new_idx, rinit);
// setivalue(ra + 3, idx); /* ...and external index */
emit_store_reg_i(def, new_idx, rvar);
emit_store_type(def, rvar, LUA_TNUMINT);
emit_store_reg_i_withtype(def, new_idx, rvar);
// ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
def->builder->CreateBr(def->jmp_targets[pc].jmp1);
@ -371,8 +368,7 @@ void RaviCodeGenerator::emit_FORLOOP(RaviFunctionDef *def, int A, int pc) {
emit_store_reg_n(def, new_idx, rinit);
// setfltvalue(ra + 3, idx); /* ...and external index */
emit_store_reg_n(def, new_idx, rvar);
emit_store_type(def, rvar, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, new_idx, rvar);
// ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
def->builder->CreateBr(def->jmp_targets[pc].jmp1);
@ -448,8 +444,7 @@ void RaviCodeGenerator::emit_iFORLOOP(RaviFunctionDef *def, int A, int pc, RaviB
// setivalue(ra + 3, idx); /* ...and external index */
idx_int_value = emit_load_local_n(def, idx_int_ptr);
emit_store_reg_i(def, idx_int_value, rvar);
emit_store_type(def, rvar, LUA_TNUMINT);
emit_store_reg_i_withtype(def, idx_int_value, rvar);
// ci->u.l.savedpc += GETARG_sBx(i); /* jump back */
def->builder->CreateBr(def->jmp_targets[pc].jmp1);

@ -525,8 +525,7 @@ void RaviCodeGenerator::emit_FORPREP(RaviFunctionDef *def, int A, int pc) {
// setivalue(plimit, ilimit);
llvm::Instruction *ilimit_val = emit_load_local_n(def, ilimit);
emit_store_reg_i(def, ilimit_val, plimit);
emit_store_type(def, plimit, LUA_TNUMINT);
emit_store_reg_i_withtype(def, ilimit_val, plimit);
// setivalue(init, initv - ivalue(pstep));
// we aleady know init is LUA_TNUMINT

@ -36,10 +36,8 @@ void RaviCodeGenerator::emit_LOADFZ(RaviFunctionDef *def, int A) {
emit_load_base(def);
llvm::Value *dest = emit_gep_register(def, A);
// destvalue->n = 0.0
emit_store_reg_n(def, llvm::ConstantFP::get(def->types->lua_NumberT, 0.0),
emit_store_reg_n_withtype(def, llvm::ConstantFP::get(def->types->lua_NumberT, 0.0),
dest);
// destvalue->type = LUA_TNUMFLT
emit_store_type(def, dest, LUA_TNUMFLT);
}
// R(A) := tointeger(0)
@ -47,9 +45,7 @@ void RaviCodeGenerator::emit_LOADIZ(RaviFunctionDef *def, int A) {
emit_load_base(def);
llvm::Value *dest = emit_gep_register(def, A);
// dest->i = 0
emit_store_reg_i(def, def->types->kluaInteger[0], dest);
// dest->type = LUA_TNUMINT
emit_store_type(def, dest, LUA_TNUMINT);
emit_store_reg_i_withtype(def, def->types->kluaInteger[0], dest);
}
// R(A) := (Bool)B; if (C) pc++
@ -62,9 +58,7 @@ void RaviCodeGenerator::emit_LOADBOOL(RaviFunctionDef *def, int A, int B, int C,
emit_load_base(def);
llvm::Value *dest = emit_gep_register(def, A);
// dest->i = 0
emit_store_reg_b(def, llvm::ConstantInt::get(def->types->C_intT, B), dest);
// dest->type = LUA_TBOOLEAN
emit_store_type(def, dest, LUA_TBOOLEAN);
emit_store_reg_b_withtype(def, llvm::ConstantInt::get(def->types->C_intT, B), dest);
if (C) {
// Skip next instruction if C
def->builder->CreateBr(def->jmp_targets[j].jmp1);
@ -154,8 +148,7 @@ void RaviCodeGenerator::emit_MOVEI(RaviFunctionDef *def, int A, int B) {
def->builder->SetInsertPoint(end1);
auto load_var = emit_load_local_n(def, var);
emit_store_reg_i(def, load_var, dest);
emit_store_type(def, dest, LUA_TNUMINT);
emit_store_reg_i_withtype(def, load_var, dest);
}
void RaviCodeGenerator::emit_MOVEF(RaviFunctionDef *def, int A, int B) {
@ -226,8 +219,7 @@ void RaviCodeGenerator::emit_MOVEF(RaviFunctionDef *def, int A, int B) {
// Set R(A)
auto load_var = emit_load_local_n(def, var);
emit_store_reg_n(def, load_var, dest);
emit_store_type(def, dest, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, load_var, dest);
}
void RaviCodeGenerator::emit_TOINT(RaviFunctionDef *def, int A) {
@ -286,8 +278,7 @@ void RaviCodeGenerator::emit_TOINT(RaviFunctionDef *def, int A) {
def->builder->SetInsertPoint(else2);
auto load_var = emit_load_local_n(def, var);
emit_store_reg_i(def, load_var, dest);
emit_store_type(def, dest, LUA_TNUMINT);
emit_store_reg_i_withtype(def, load_var, dest);
def->builder->CreateBr(end1);
def->f->getBasicBlockList().push_back(end1);
@ -350,8 +341,7 @@ void RaviCodeGenerator::emit_TOFLT(RaviFunctionDef *def, int A) {
def->builder->SetInsertPoint(else2);
auto load_var = emit_load_local_n(def, var);
emit_store_reg_n(def, load_var, dest);
emit_store_type(def, dest, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, load_var, dest);
def->builder->CreateBr(end1);
def->f->getBasicBlockList().push_back(end1);

@ -107,8 +107,7 @@ void RaviCodeGenerator::emit_GETTABLE_AF(RaviFunctionDef *def,int A, int B, int
llvm::Instruction *value = def->builder->CreateLoad(ptr);
value->setMetadata(llvm::LLVMContext::MD_tbaa, def->types->tbaa_pdoubleT);
emit_store_reg_n(def, value, ra);
emit_store_type(def, ra, LUA_TNUMFLT);
emit_store_reg_n_withtype(def, value, ra);
def->builder->CreateBr(end_block);
def->f->getBasicBlockList().push_back(else_block);
@ -162,8 +161,7 @@ void RaviCodeGenerator::emit_GETTABLE_AI(RaviFunctionDef *def, int A, int B, int
llvm::Instruction *value = def->builder->CreateLoad(ptr);
value->setMetadata(llvm::LLVMContext::MD_tbaa, def->types->tbaa_plonglongT);
emit_store_reg_i(def, value, ra);
emit_store_type(def, ra, LUA_TNUMINT);
emit_store_reg_i_withtype(def, value, ra);
def->builder->CreateBr(end_block);
def->f->getBasicBlockList().push_back(else_block);
@ -296,7 +294,7 @@ void RaviCodeGenerator::emit_GETUPVAL(RaviFunctionDef *def, int A, int B) {
// setobj2s(L, ra, cl->upvals[b]->v);
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *upval_ptr = emit_gep_upvals(def, def->p_LClosure, B);
llvm::Value *upval_ptr = emit_gep_upvals(def, B);
llvm::Instruction *upval = emit_load_pupval(def, upval_ptr);
llvm::Value *v = emit_load_upval_v(def, upval);
emit_assign(def, ra, v);
@ -311,7 +309,7 @@ void RaviCodeGenerator::emit_SETUPVAL(RaviFunctionDef *def, int A, int B) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *upval_ptr = emit_gep_upvals(def, def->p_LClosure, B);
llvm::Value *upval_ptr = emit_gep_upvals(def, B);
llvm::Instruction *upval = emit_load_pupval(def, upval_ptr);
llvm::Value *v = emit_load_upval_v(def, upval);
emit_assign(def, v, ra);
@ -350,7 +348,7 @@ void RaviCodeGenerator::emit_GETTABUP(RaviFunctionDef *def, int A, int B, int C)
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
llvm::Value *upval_ptr = emit_gep_upvals(def, def->p_LClosure, B);
llvm::Value *upval_ptr = emit_gep_upvals(def, B);
llvm::Instruction *upval = emit_load_pupval(def, upval_ptr);
llvm::Value *v = emit_load_upval_v(def, upval);
CreateCall4(def->builder, def->luaV_gettableF, def->L, v, rc, ra);
@ -366,7 +364,7 @@ void RaviCodeGenerator::emit_SETTABUP(RaviFunctionDef *def, int A, int B, int C)
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
llvm::Value *upval_ptr = emit_gep_upvals(def, def->p_LClosure, A);
llvm::Value *upval_ptr = emit_gep_upvals(def, A);
llvm::Instruction *upval = emit_load_pupval(def, upval_ptr);
llvm::Value *v = emit_load_upval_v(def, upval);
CreateCall4(def->builder, def->luaV_settableF, def->L, v, rb, rc);

Loading…
Cancel
Save