Skip to content

Commit

Permalink
issue #100 generate calls to specialized functions for string keys wh…
Browse files Browse the repository at this point in the history
…en operand of OP_SELF is known to be a short string
  • Loading branch information
Dibyendu Majumdar committed Oct 6, 2016
1 parent 8a43eb5 commit b48a096
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
1 change: 0 additions & 1 deletion include/ltable.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "lobject.h"


#define gnode(t,i) (&(t)->node[i])
#define gval(n) (&(n)->i_val)
#define gnext(n) ((n)->i_key.nk.next)
Expand Down
1 change: 1 addition & 0 deletions include/ravi_llvmcodegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,7 @@ class RaviCodeGenerator {

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

void emit_common_GETTABLE_S(RaviFunctionDef *def, int A, int B, int C,
TString *key);
Expand Down
1 change: 0 additions & 1 deletion src/lcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include "lprefix.h"


#include <math.h>
#include <stdlib.h>

Expand Down
19 changes: 18 additions & 1 deletion src/ravi_llvmcodegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,29 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
int C = GETARG_C(i);
emit_SETLIST(def, A, B, C, pc);
} break;
case OP_RAVI_SELF_SK:
case OP_SELF:
case OP_RAVI_SELF_SK:{
int B = GETARG_B(i);
int C = GETARG_C(i);
/* key must be string */
if (ISK(C)) {
TValue *kv = k + INDEXK(C);
if (ttisshrstring(kv))
emit_SELF_SK(def, A, B, C, pc);
else
emit_SELF(def, A, B, C, pc);
}
else {
emit_SELF(def, A, B, C, pc);
}
} break;
#if 0
case OP_SELF: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SELF(def, A, B, C, pc);
} break;
#endif
case OP_LEN: {
int B = GETARG_B(i);
emit_LEN(def, A, B, pc);
Expand Down
18 changes: 18 additions & 0 deletions src/ravi_llvmtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ void RaviCodeGenerator::emit_SELF(RaviFunctionDef *def, int A, int B, int C,
CreateCall4(def->builder, def->luaV_gettableF, def->L, rb, rc, ra);
}

// R(A+1) := R(B); R(A) := R(B)[RK(C)]
void RaviCodeGenerator::emit_SELF_SK(RaviFunctionDef *def, int A, int B, int C,
int pc) {
// StkId rb = RB(i);
// setobjs2s(L, ra + 1, rb);
// Protect(luaV_gettable(L, rb, RKC(i), ra));
bool traced = emit_debug_trace(def, OP_RAVI_SELF_SK, pc);
// Below may invoke metamethod so we set savedpc
if (!traced) emit_update_savedpc(def, pc);
emit_load_base(def);
llvm::Value *rb = emit_gep_register(def, B);
llvm::Value *ra1 = emit_gep_register(def, A + 1);
emit_assign(def, ra1, rb);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
CreateCall4(def->builder, def->raviV_gettable_sskeyF, def->L, rb, rc, ra);
}

// R(A+1) := R(B); R(A) := R(B)[RK(C)]
void RaviCodeGenerator::emit_SELF_S(RaviFunctionDef *def, int A, int B, int C,
int pc, TString *key) {
Expand Down

0 comments on commit b48a096

Please sign in to comment.