constants can be directly assigned in some cases

pull/81/head
Dibyendu Majumdar 9 years ago
parent 279a6411ea
commit f9fb46f17a

@ -657,6 +657,9 @@ public:
// emit code to obtain address of register or constant at location B
llvm::Value *emit_gep_register_or_constant(RaviFunctionDef *def, int B);
// emit code to obtain address of constant at locatiion B
llvm::Value *emit_gep_constant(RaviFunctionDef *def, int B);
// obtain address of L->top
llvm::Value *emit_gep_L_top(RaviFunctionDef *def);

@ -87,27 +87,35 @@ void ravi_emit_LOADK(ravi_function_def_t *def, int A, int Bx, int pc) {
TValue *Konst = &def->p->k[Bx];
switch (Konst->tt_) {
case LUA_TNUMINT:
ravi_emit_store_reg_i_withtype(
def, gcc_jit_context_new_rvalue_from_int(
def->function_context, def->ravi->types->lua_IntegerT, Konst->value_.i),
dest);
break;
case LUA_TNUMFLT:
ravi_emit_store_reg_n_withtype(
def, gcc_jit_context_new_rvalue_from_double(
def->function_context, def->ravi->types->lua_NumberT, Konst->value_.n),
dest);
break;
default: {
// rb
gcc_jit_rvalue *src = ravi_emit_get_constant(def, Bx);
// *ra = *rb
ravi_emit_struct_assign(def, dest, src);
}
case LUA_TNUMINT:
ravi_emit_store_reg_i_withtype(
def, gcc_jit_context_new_rvalue_from_int(def->function_context,
def->ravi->types->lua_IntegerT,
Konst->value_.i),
dest);
break;
case LUA_TNUMFLT:
ravi_emit_store_reg_n_withtype(def, gcc_jit_context_new_rvalue_from_double(
def->function_context,
def->ravi->types->lua_NumberT,
Konst->value_.n),
dest);
break;
case LUA_TBOOLEAN:
ravi_emit_store_reg_b_withtype(
def,
gcc_jit_context_new_rvalue_from_int(
def->function_context, def->ravi->types->C_intT, Konst->value_.b),
dest);
break;
default: {
// rb
gcc_jit_rvalue *src = ravi_emit_get_constant(def, Bx);
// *ra = *rb
ravi_emit_struct_assign(def, dest, src);
}
}
}
// R(A) := R(B)

@ -156,6 +156,21 @@ llvm::Value *RaviCodeGenerator::emit_gep_register(RaviFunctionDef *def, int A) {
return dest;
}
llvm::Value *RaviCodeGenerator::emit_gep_constant(RaviFunctionDef *def,
int Bx) {
// Load pointer to k
llvm::Value *k_ptr = def->k_ptr;
llvm::Value *src;
if (Bx == 0) {
// If Bx is 0 we can use the base pointer which is &k[0]
src = k_ptr;
} else {
// emit &k[Bx]
src = emit_array_get(def, k_ptr, Bx);
}
return src;
}
llvm::Instruction *RaviCodeGenerator::emit_load_reg_n(RaviFunctionDef *def,
llvm::Value *rb) {
#if RAVI_NAN_TAGGING

@ -356,24 +356,35 @@ void RaviCodeGenerator::emit_LOADK(RaviFunctionDef *def, int A, int Bx) {
// Load pointer to base
emit_load_base(def);
// Load pointer to k
llvm::Value *k_ptr = def->k_ptr;
// LOADK requires a structure assignment
// in LLVM as far as I can tell this requires a call to
// an intrinsic memcpy
llvm::Value *dest = emit_gep_register(def, A);
llvm::Value *src;
if (Bx == 0) {
// If Bx is 0 we can use the base pointer which is &k[0]
src = k_ptr;
} else {
// emit &k[Bx]
src = emit_array_get(def, k_ptr, Bx);
TValue *Konst = &def->p->k[Bx];
switch (Konst->tt_) {
case LUA_TNUMINT:
emit_store_reg_i_withtype(
def, llvm::ConstantInt::get(def->types->lua_IntegerT, Konst->value_.i),
dest);
break;
case LUA_TNUMFLT:
emit_store_reg_n_withtype(
def, llvm::ConstantFP::get(def->types->lua_NumberT, Konst->value_.n),
dest);
break;
case LUA_TBOOLEAN:
emit_store_reg_b_withtype(
def, llvm::ConstantInt::get(def->types->C_intT, Konst->value_.b), dest);
break;
default: {
// rb
llvm::Value *src = emit_gep_constant(def, Bx);
// *ra = *rb
emit_assign(def, dest, src);
}
}
emit_assign(def, dest, src);
}
void RaviCodeGenerator::emit_assign(RaviFunctionDef *def, llvm::Value *dest,

Loading…
Cancel
Save