Skip to content

Commit

Permalink
issue #100 add JIT compilation for GETTABLE_SK opcode
Browse files Browse the repository at this point in the history
  • Loading branch information
Dibyendu Majumdar committed Sep 25, 2016
1 parent 437c6b3 commit 30ed0bd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions include/ravi_llvmcodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ class RaviCodeGenerator {
void emit_GETTABLE_S(RaviFunctionDef *def, int A, int B, int C, int pc,
TString *key);

void emit_GETTABLE_SK(RaviFunctionDef *def, int A, int B, int C, int pc,
TString *key);

void emit_GETTABLE_I(RaviFunctionDef *def, int A, int B, int C, int pc);

void emit_finish_GETTABLE(RaviFunctionDef *def, llvm::Value *phi,
Expand Down
11 changes: 10 additions & 1 deletion src/ravi_llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,15 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
lua_assert(key->tt == LUA_TSHRSTR);
emit_GETTABLE_S(def, A, B, C, pc, key);
} break;
case OP_RAVI_GETTABLE_SK: {
int C = GETARG_C(i);
int B = GETARG_B(i);
lua_assert(ISK(C));
TValue *kv = k + INDEXK(C);
TString *key = tsvalue(kv);
lua_assert(key->tt == LUA_TSHRSTR);
emit_GETTABLE_SK(def, A, B, C, pc, key);
} break;
case OP_RAVI_SELF_S: {
int C = GETARG_C(i);
int B = GETARG_B(i);
Expand All @@ -1668,7 +1677,7 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
int C = GETARG_C(i);
emit_GETTABLE_I(def, A, B, C, pc);
} break;
case OP_RAVI_GETTABLE_SK:
//case OP_RAVI_GETTABLE_SK:
case OP_GETTABLE: {
int B = GETARG_B(i);
int C = GETARG_C(i);
Expand Down
43 changes: 43 additions & 0 deletions src/ravi_llvmtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,49 @@ void RaviCodeGenerator::emit_GETTABLE_S(RaviFunctionDef *def, int A, int B,
emit_common_GETTABLE_S(def, A, B, C, key);
}

void RaviCodeGenerator::emit_GETTABLE_SK(RaviFunctionDef *def, int A, int B,
int C, int pc, TString *key) {
emit_debug_trace(def, OP_RAVI_GETTABLE_SK, pc);
emit_load_base(def);
llvm::Value *rb = emit_gep_register(def, B);
llvm::Instruction *type = emit_load_type(def, rb);

// if not table
// call luaV_gettable
// else
// do GETTABLE_S

// type != LUA_TTABLE ?
llvm::Value *cmp1 =
emit_is_not_value_of_type(def, type, LUA__TTABLE, "is_not_table");

llvm::BasicBlock *not_table = llvm::BasicBlock::Create(
def->jitState->context(), "GETTABLE_SK_if_not_table", def->f);
llvm::BasicBlock *else_not_table =
llvm::BasicBlock::Create(def->jitState->context(), "GETTABLE_SK_if_table");
llvm::BasicBlock *done =
llvm::BasicBlock::Create(def->jitState->context(), "GETTABLE_SK_done");
def->builder->CreateCondBr(cmp1, not_table, else_not_table);
def->builder->SetInsertPoint(not_table);

llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
CreateCall4(def->builder, def->luaV_gettableF, def->L, rb, rc, ra);

def->builder->CreateBr(done);

def->f->getBasicBlockList().push_back(else_not_table);
def->builder->SetInsertPoint(else_not_table);

emit_common_GETTABLE_S(def, A, B, C, key);

def->builder->CreateBr(done);

def->f->getBasicBlockList().push_back(done);
def->builder->SetInsertPoint(done);
}


void RaviCodeGenerator::emit_GETTABLE_AF(RaviFunctionDef *def, int A, int B,
int C, bool omitArrayGetRangeCheck,
int pc) {
Expand Down

0 comments on commit 30ed0bd

Please sign in to comment.