issue #157: rename GETTABLE_SK and SETTABLE_SK opcodes

pull/159/head
Dibyendu Majumdar 6 years ago
parent 04ca32e8f5
commit eec9a49414

@ -276,9 +276,9 @@ OP_RAVI_SELF_S,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key, known t
a table */
OP_RAVI_GETTABLE_I,/* A B C R(A) := R(B)[RK(C)], integer key, known table */
OP_RAVI_SETTABLE_I,/* A B C R(A)[RK(B)] := RK(C), integer key, known table */
OP_RAVI_GETTABLE_SK, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_GETFIELD, /* A B C R(A) := R(B)[RK(C)], string key */
OP_RAVI_SELF_SK, /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)], string key */
OP_RAVI_SETTABLE_SK, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_SETFIELD, /* A B C R(A)[RK(B)] := RK(C), string key */
OP_RAVI_GETTABUP_SK, /* A B C R(A) := UpValue[B][RK(C)], string key */
} OpCode;

@ -1244,14 +1244,14 @@ class RaviCodeGenerator {
void emit_SETTABLE_I(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETTABLE_SK(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_SETFIELD(RaviFunctionDef *def, int A, int B, int C, int pc);
void emit_GETTABLE(RaviFunctionDef *def, int A, int B, int C, int pc);
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,
void emit_GETFIELD(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);

@ -121,7 +121,7 @@ check(function ()
end,
'LOADNIL',
'MUL',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE_SK', 'POW',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETFIELD', 'POW',
'UNM', 'SETTABLE', 'SETTABLE_I', 'RETURN')
@ -132,7 +132,7 @@ check(function ()
a.x = b
a[b] = 'x'
end,
'LOADNIL', 'SETTABLE_SK', 'SETTABLE_SK', 'SETTABLE', 'RETURN')
'LOADNIL', 'SETFIELD', 'SETFIELD', 'SETTABLE', 'RETURN')
check(function ()
local a,b

@ -111,8 +111,8 @@ opcodes_coverage.GETTABLE_I = 0
opcodes_coverage.GETTABLE_S = 0
opcodes_coverage.SETTABLE_I = 0
opcodes_coverage.SETTABLE_S = 0
opcodes_coverage.SETTABLE_SK = 0
opcodes_coverage.GETTABLE_SK = 0
opcodes_coverage.SETFIELD = 0
opcodes_coverage.GETFIELD = 0
opcodes_coverage.TOTAB = 0
opcodes_coverage.MOVETAB = 0
opcodes_coverage.SETUPVALT = 0
@ -215,7 +215,7 @@ check(function ()
end,
'LOADNIL',
'MUL',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETTABLE_SK', 'POW',
'DIV', 'ADD', 'GETTABLE', 'SUB', 'GETFIELD', 'POW',
'UNM', 'SETTABLE', 'SETTABLE_I', 'RETURN')
-- direct access to constants
@ -230,7 +230,7 @@ check(function ()
a[true] = false
end,
'LOADNIL',
'SETTABLE_SK', 'SETTABLE_SK', 'SETTABLE', 'SUB', 'DIV', 'LOADK',
'SETFIELD', 'SETFIELD', 'SETTABLE', 'SUB', 'DIV', 'LOADK',
'SETTABLE', 'RETURN')
@ -1106,8 +1106,8 @@ function test_tableaccess()
return t.name, t.data.city
end
check(f, 'NEWTABLE', 'SETTABLE_S', 'NEWTABLE',
'SETTABLE_S', 'GETTABLE_S', 'SETTABLE_SK',
'GETTABLE_S', 'GETTABLE_S' , 'GETTABLE_SK',
'SETTABLE_S', 'GETTABLE_S', 'SETFIELD',
'GETTABLE_S', 'GETTABLE_S' , 'GETFIELD',
'RETURN', 'RETURN')
local a,b = f()
assert(a == 'dibyendu')

@ -113,8 +113,8 @@ opcodes_coverage.GETTABLE_I = 0
opcodes_coverage.GETTABLE_S = 0
opcodes_coverage.SETTABLE_I = 0
opcodes_coverage.SETTABLE_S = 0
opcodes_coverage.SETTABLE_SK = 0
opcodes_coverage.GETTABLE_SK = 0
opcodes_coverage.SETFIELD = 0
opcodes_coverage.GETFIELD = 0
opcodes_coverage.TOTAB = 0
opcodes_coverage.MOVETAB = 0
opcodes_coverage.SETUPVALT = 0

@ -276,13 +276,13 @@ Note that if a Lua functions contains a bytecode that cannot be be JITed then th
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_S | YES | R(A) := R(B)[RK(C)], string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_GETTABLE_SK | YES | R(A) := R(B)[RK(C)], string key |
| OP_RAVI_GETFIELD | YES | R(A) := R(B)[RK(C)], string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_I | YES (4) | R(A)[RK(B)] := RK(C), integer key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_S | YES (3) | R(A)[RK(B)] := RK(C), string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_SETTABLE_SK | YES | R(A)[RK(B)] := RK(C), string key |
| OP_RAVI_SETFIELD | YES | R(A)[RK(B)] := RK(C), string key |
+-------------------------+----------+--------------------------------------------------+
| OP_RAVI_TOTAB | YES | R(A) := to_table(R(A)) |
+-------------------------+----------+--------------------------------------------------+

@ -610,7 +610,7 @@ void luaK_dischargevars (FuncState *fs, expdesc *e) {
else if (/* e->ravi_type == RAVI_TTABLE &&*/ e->u.ind.key_ravi_type == RAVI_TNUMINT)
op = OP_RAVI_GETTABLE_I;
else if (e->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, e->u.ind.idx))
op = OP_RAVI_GETTABLE_SK;
op = OP_RAVI_GETFIELD;
else
op = OP_GETTABLE;
if (e->ravi_type == RAVI_TARRAYFLT || e->ravi_type == RAVI_TARRAYINT)
@ -1019,7 +1019,7 @@ void luaK_storevar (FuncState *fs, expdesc *var, expdesc *ex) {
}
else if (var->u.ind.key_ravi_type == RAVI_TSTRING && isshortstr(fs, var->u.ind.idx)) {
/* table with string key */
op = OP_RAVI_SETTABLE_SK;
op = OP_RAVI_SETFIELD;
}
}
int e = luaK_exp2RK(fs, ex);

@ -479,7 +479,7 @@ static const char *getobjname (Proto *p, int lastpc, int reg,
}
case OP_RAVI_GETTABLE_I:
case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_GETFIELD:
case OP_RAVI_GETTABLE_AI:
case OP_RAVI_GETTABLE_AF:
case OP_GETTABUP:
@ -546,12 +546,12 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci,
return "for iterator";
}
/* all other instructions can call only through metamethods */
/* Ravi: added GETTABLE_SK and SELF_SK because the call may be through metamethod rather than table */
/* Ravi: added GETFIELD and SELF_SK because the call may be through metamethod rather than table */
case OP_SELF: case OP_GETTABUP: case OP_GETTABLE:
case OP_RAVI_SELF_SK: case OP_RAVI_GETTABUP_SK: case OP_RAVI_GETTABLE_SK: case OP_RAVI_GETTABLE_I:
case OP_RAVI_SELF_SK: case OP_RAVI_GETTABUP_SK: case OP_RAVI_GETFIELD: case OP_RAVI_GETTABLE_I:
tm = TM_INDEX;
break;
case OP_SETTABUP: case OP_SETTABLE: case OP_RAVI_SETTABLE_SK: case OP_RAVI_SETTABLE_I:
case OP_SETTABUP: case OP_SETTABLE: case OP_RAVI_SETFIELD: case OP_RAVI_SETTABLE_I:
tm = TM_NEWINDEX;
break;
case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD:

@ -159,9 +159,9 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"GETTABLE_I", /* A B C R(A) := R(B)[RK(C)], integer key */
"SETTABLE_I", /* A B C R(A)[RK(B)] := RK(C), integer key */
"GETTABLE_SK", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"GETFIELD", /* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF_SK", /* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE_SK", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"SETFIELD", /*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABUP_SK",
NULL
};
@ -300,9 +300,9 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_I */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_I */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETTABLE_SK */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_GETFIELD */
,opmode(0, 1, OpArgR, OpArgK, iABC) /* OP_RAVI_SELF_SK */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETTABLE_SK */
,opmode(0, 0, OpArgK, OpArgK, iABC) /* OP_RAVI_SETFIELD */
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_GETTABUP_SK */
};
@ -471,7 +471,7 @@ static void PrintCode(const Proto* f)
case OP_RAVI_GETTABLE_AF:
case OP_RAVI_GETTABLE_AI:
case OP_SELF:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_GETFIELD:
case OP_RAVI_SELF_S:
case OP_RAVI_SELF_SK:
if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
@ -479,7 +479,7 @@ static void PrintCode(const Proto* f)
case OP_SETTABLE:
case OP_RAVI_SETTABLE_I:
case OP_RAVI_SETTABLE_S:
case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETFIELD:
case OP_RAVI_SETTABLE_AF:
case OP_RAVI_SETTABLE_AFF:
case OP_RAVI_SETTABLE_AI:

@ -934,7 +934,7 @@ void luaV_finishOp (lua_State *L) {
case OP_MOD: case OP_POW:
case OP_UNM: case OP_BNOT: case OP_LEN:
case OP_RAVI_GETTABUP_SK:
case OP_RAVI_GETTABLE_SK: case OP_RAVI_GETTABLE_I: case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETFIELD: case OP_RAVI_GETTABLE_I: case OP_RAVI_GETTABLE_S:
case OP_RAVI_SELF_SK: case OP_RAVI_SELF_S:
case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
setobjs2s(L, base + GETARG_A(inst), --L->top);
@ -977,7 +977,7 @@ void luaV_finishOp (lua_State *L) {
L->top = ci->top; /* adjust results */
break;
}
case OP_RAVI_SETTABLE_I: case OP_RAVI_SETTABLE_S: case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETTABLE_I: case OP_RAVI_SETTABLE_S: case OP_RAVI_SETFIELD:
case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
break;
default: lua_assert(0);
@ -1254,9 +1254,9 @@ int luaV_execute (lua_State *L) {
&&vmlabel(OP_RAVI_SELF_S),
&&vmlabel(OP_RAVI_GETTABLE_I),
&&vmlabel(OP_RAVI_SETTABLE_I),
&&vmlabel(OP_RAVI_GETTABLE_SK),
&&vmlabel(OP_RAVI_GETFIELD),
&&vmlabel(OP_RAVI_SELF_SK),
&&vmlabel(OP_RAVI_SETTABLE_SK),
&&vmlabel(OP_RAVI_SETFIELD),
&&vmlabel(OP_RAVI_GETTABUP_SK)
};
#endif
@ -1356,7 +1356,7 @@ int luaV_execute (lua_State *L) {
SETTABLE_INLINE_PROTECTED_I(L, ra, rb, rc);
vmbreak;
}
vmcase(OP_RAVI_SETTABLE_SK)
vmcase(OP_RAVI_SETFIELD)
vmcase(OP_RAVI_SETTABLE_S) {
TValue *rb = RKB(i);
TValue *rc = RKC(i);
@ -2096,7 +2096,7 @@ int luaV_execute (lua_State *L) {
GETTABLE_INLINE_SSKEY_PROTECTED(L, rb, rc, ra);
vmbreak;
}
vmcase(OP_RAVI_GETTABLE_SK) {
vmcase(OP_RAVI_GETFIELD) {
StkId rb = RB(i); /* variable - may not be a table */
lua_assert(ISK(GETARG_C(i)));
/* we know that the key a short string constant */

@ -630,13 +630,13 @@ bool raviJ_cancompile(Proto *p) {
case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETTABLE_AI:
case OP_RAVI_GETTABLE_AF:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_GETFIELD:
case OP_RAVI_GETTABLE_I:
case OP_GETTABLE:
case OP_SELF:
case OP_RAVI_SELF_S:
case OP_RAVI_SELF_SK:
case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETFIELD:
case OP_RAVI_SETTABLE_S:
case OP_RAVI_SETTABLE_I:
case OP_RAVI_SETTABLE_AII:
@ -1194,7 +1194,7 @@ static void emit_op_gettable(struct function *fn, int A, int B, int C, int pc, O
emit_reg(fn, "ra", A);
emit_reg(fn, "rb", B);
emit_reg_or_k(fn, "rc", C);
if (op == OP_RAVI_GETTABLE_SK) {
if (op == OP_RAVI_GETFIELD) {
membuff_add_string(&fn->body, "raviV_gettable_sskey(L, rb, rc, ra);\n"); }
else if (op == OP_RAVI_GETTABLE_I) {
membuff_add_string(&fn->body, "raviV_gettable_i(L, rb, rc, ra);\n");
@ -1233,7 +1233,7 @@ static void emit_op_settable(struct function *fn, int A, int B, int C, int pc, O
emit_reg(fn, "ra", A);
emit_reg_or_k(fn, "rb", B);
emit_reg_or_k(fn, "rc", C);
if (op == OP_RAVI_SETTABLE_SK) {
if (op == OP_RAVI_SETFIELD) {
membuff_add_string(&fn->body, "raviV_settable_sskey(L, ra, rb, rc);\n"); }
else if (op == OP_RAVI_SETTABLE_I) {
membuff_add_string(&fn->body, "raviV_settable_i(L, ra, rb, rc);\n");
@ -1884,7 +1884,7 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p,
emit_op_testset(&fn, A, B, C, j, GETARG_A(i), pc - 1);
} break;
case OP_RAVI_GETTABLE_S:
case OP_RAVI_GETTABLE_SK:
case OP_RAVI_GETFIELD:
case OP_RAVI_GETTABLE_I:
case OP_GETTABLE: {
int B = GETARG_B(i);
@ -1901,7 +1901,7 @@ bool raviJ_codegen(struct lua_State *L, struct Proto *p,
int C = GETARG_C(i);
emit_gettable_af(&fn, A, B, C, options->omit_array_get_range_check, pc);
} break;
case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETFIELD:
case OP_RAVI_SETTABLE_S:
case OP_RAVI_SETTABLE_I:
case OP_SETTABLE: {

@ -1628,11 +1628,11 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
emit_CALL(def, A, B, C, pc);
} break;
case OP_RAVI_SETTABLE_SK:
case OP_RAVI_SETFIELD:
case OP_RAVI_SETTABLE_S: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SETTABLE_SK(def, A, B, C, pc);
emit_SETFIELD(def, A, B, C, pc);
} break;
case OP_RAVI_SETTABLE_I: {
int B = GETARG_B(i);
@ -1668,14 +1668,14 @@ 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_GETFIELD: {
int B = GETARG_B(i);
int C = GETARG_C(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);
emit_GETFIELD(def, A, B, C, pc, key);
} break;
case OP_GETTABLE: {
int B = GETARG_B(i);

@ -121,10 +121,10 @@ void RaviCodeGenerator::emit_SETTABLE(RaviFunctionDef *def, int A, int B, int C,
}
// R(A)[RK(B)] := RK(C)
void RaviCodeGenerator::emit_SETTABLE_SK(RaviFunctionDef *def, int A, int B,
void RaviCodeGenerator::emit_SETFIELD(RaviFunctionDef *def, int A, int B,
int C, int pc) {
// Protect(raviV_settable_sskey(L, ra, RKB(i), RKC(i)));
bool traced = emit_debug_trace(def, OP_RAVI_SETTABLE_SK, pc);
bool traced = emit_debug_trace(def, OP_RAVI_SETFIELD, pc);
// Below may invoke metamethod so we set savedpc
if (!traced) emit_update_savedpc(def, pc);
emit_load_base(def);
@ -149,9 +149,9 @@ void RaviCodeGenerator::emit_GETTABLE(RaviFunctionDef *def, int A, int B, int C,
}
// R(A) := R(B)[RK(C)]
void RaviCodeGenerator::emit_GETTABLE_SK(RaviFunctionDef *def, int A, int B,
void RaviCodeGenerator::emit_GETFIELD(RaviFunctionDef *def, int A, int B,
int C, int pc, TString *key) {
bool traced = emit_debug_trace(def, OP_RAVI_GETTABLE_SK, pc);
bool traced = emit_debug_trace(def, OP_RAVI_GETFIELD, pc);
// Below may invoke metamethod so we set savedpc
if (!traced) emit_update_savedpc(def, pc);
emit_load_base(def);
@ -166,13 +166,13 @@ void RaviCodeGenerator::emit_GETTABLE_SK(RaviFunctionDef *def, int A, int B,
// if table type try fast path
llvm::Value *cmp1 = emit_is_value_of_type(def, type, RAVI__TLTABLE,
"GETTABLE_SK_is_table_type");
"GETFIELD_is_table_type");
llvm::BasicBlock *is_table = llvm::BasicBlock::Create(
def->jitState->context(), "GETTABLE_SK_is_table", def->f);
def->jitState->context(), "GETFIELD_is_table", def->f);
llvm::BasicBlock *not_table = llvm::BasicBlock::Create(
def->jitState->context(), "GETTABLE_SK_is_not_table");
def->jitState->context(), "GETFIELD_is_not_table");
llvm::BasicBlock *done =
llvm::BasicBlock::Create(def->jitState->context(), "GETTABLE_SK_done");
llvm::BasicBlock::Create(def->jitState->context(), "GETFIELD_done");
auto brinst1 = def->builder->CreateCondBr(cmp1, is_table, not_table);
attach_branch_weights(def, brinst1, 100, 0);
def->builder->SetInsertPoint(is_table);
@ -853,7 +853,7 @@ void RaviCodeGenerator::emit_SETTABUP_SK(RaviFunctionDef *def, int A, int B,
// int a = GETARG_A(i);
// Protect(luaV_settable(L, cl->upvals[a]->v, RKB(i), RKC(i)));
bool traced = emit_debug_trace(def, OP_RAVI_SETTABLE_SK, pc);
bool traced = emit_debug_trace(def, OP_RAVI_SETFIELD, pc);
if (!traced) emit_update_savedpc(def, pc);
emit_load_base(def);
llvm::Value *rb = emit_gep_register_or_constant(def, B);

@ -543,11 +543,11 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES + 1] =
"GETTABLE_I", /* A B C R(A) := R(B)[RK(C)], integer key */
"SETTABLE_I", /* A B C R(A)[RK(B)] := RK(C), integer key */
"GETTABLE_SK",
"GETFIELD",
/* _SK */ /* A B C R(A) := R(B)[RK(C)], string key */
"SELF_SK",
/* _SK*/ /* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */
"SETTABLE_SK",
"SETFIELD",
/*_SK */ /* A B C R(A)[RK(B)] := RK(C), string key */
"GETTABUP_SK",
NULL};

Loading…
Cancel
Save