Merge branch 'master' into ravi-distro

pull/167/head
Dibyendu Majumdar 5 years ago
commit 4874e85401

@ -44,25 +44,31 @@ To obtain a nice trace of codegen
#include <symbol.h>
/*
Some Implementation Notes
=========================
1. Local variables are modelled as byte strings - the load/store ops
1. Local aggregate variables are modelled as byte strings - the load/store ops
take care of extracting / storing the right type of value
2. Phi values are modelled as temporaries - phisrc is implemented as store
2. Local primitives are modelled as temporaries.
3. Phi values are modelled as temporaries - phisrc is implemented as store
to temporary while phi is a load from temporary.
3. We create all the blocks at the beginning based upon the blocks in
4. We create all the blocks at the beginning based upon the blocks in
Sparse IR - but we have to add an extra block for every CBR instruction
as conditional branches in OMR fall through to the next block
4. Local SymRefs are stored in Sparse Symbol->priv field.
5. Local SymRefs are stored in Sparse Symbol->priv field.
5. Pseudo SymRefs are stored in pseudo->priv2, whereas corresponding load
6. Pseudo SymRefs are stored in pseudo->priv2, whereas corresponding load
is stored in pseudo->priv.
7. If address of a local temporary is taken we need to let the compiler
backend know this as otherwise the backend may not realize that the
locals could change through the pointers. Strictly speaking this is a
problem if the pointers escape (e.g. are passed to a function call)
but we don't optimize for that yet.
*/
/*
@ -576,8 +582,13 @@ static JIT_SymbolRef get_sym_value(struct dmr_C *C, struct function *fn, pseudo_
return NULL;
}
result = build_local(C, fn, sym);
if (!result)
if (!result) {
dmrC_sparse_error(C, sym->initializer->pos,
"unsupported initializer for "
"local variable because zero initialization is not yet done\n");
dmrC_show_expression(C, sym->initializer);
return result;
}
sym->priv = result;
}
}
@ -1691,6 +1702,15 @@ static JIT_NodeRef output_op_sel(struct dmr_C *C, struct function *fn, struct in
case JIT_Int8:
op_code = OP_bternary;
break;
case JIT_Address:
op_code = OP_aternary;
break;
case JIT_Float:
op_code = OP_fternary;
break;
case JIT_Double:
op_code = OP_dternary;
break;
default:
// TODO error message
return NULL;

@ -549,7 +549,9 @@ struct lua_Debug {
LUA_API void (ravi_pushcfastcall)(lua_State *L, void *ptr, int tag);
#define RAVI_TFCF_D_D 1
#define RAVI_TFCF_EXP 1
#define RAVI_TFCF_LOG 2
#define RAVI_TFCF_D_D 3
/* Create an integer array (specialization of Lua table)
* of given size and initialize array with supplied initial value

@ -0,0 +1,19 @@
local function f()
local tm = os.clock()
local o = 0
for j = 1, 1e4 do
local x = 0
for k = 1, 1e5 do
x = x ~ (j + k)
end
o = o | x
end
print(" Result = "..o)
print(" CPU time = "..(os.clock() - tm))
end
print"Benchmarking non-compiled function"
f()
print"Compiling the function"
assert(ravi.compile(f))
print"Benchmarking compiled function"
f()

@ -0,0 +1,19 @@
local function f()
local tm = os.clock()
local o: integer = 0
for j = 1, 10000 do
local x: integer = 0
for k = 1, 100000 do
x = x ~ (j + k)
end
o = o | x
end
print(" Result = "..o)
print(" CPU time = "..(os.clock() - tm))
end
print"Benchmarking non-compiled function"
f()
print"Compiling the function"
assert(ravi.compile(f))
print"Benchmarking compiled function"
f()

@ -1695,6 +1695,16 @@ check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST',
'RETURN', 'RETURN')
print 'Test 74 OK'
function x()
assert(math.exp(2) == ravi.exp(2))
assert(math.log(2) == ravi.ln(2))
assert(math.exp(math.log(2)) == ravi.exp(ravi.ln(2)))
end
x()
compile(x)
x()
print 'Test 75 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

@ -13,9 +13,9 @@ The following api is under development, but is not yet fully functional, and is
Examples
========
An example use of the C parser is `ravi-tests/dmrc_getsymbols.lua <https://github.com/dibyendumajumdar/ravi/blob/master/ravi-tests/dmrc_getsymbols.lua>`_.
For an example of invoking the C compiler with LLVM backend see `ravi-tests/dmrc_testllvm.lua`.
For an example of invoking the C compiler with LLVM backend see `ravi-tests/dmrc_testllvm.lua <https://github.com/dibyendumajumdar/ravi/blob/master/ravi-tests/dmrc_testllvm.lua>`_.
Outstanding issues
==================
* The Eclipse OMR backend cannot automatically access C functions externally defined; these have to be pre-registered. A solution might be to expose the resolution of symbols from dynamic libraries.
* We need to validate that the compiled C function is callable from Lua. This is not as easy to do with Eclipse OMR backend as with the LLVM backend.
* We need to validate that the compiled C function is callable from Lua. This is not as easy to do with Eclipse OMR backend as with the LLVM backend.

@ -13,6 +13,7 @@
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "lua.h"
@ -514,10 +515,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int op_call) {
return 0;
}
case RAVI_TFCF: {
int tt = rttype(func);
int nargs = L->top - func - 1;
int sig = tt >> 8;
int tt = rttype(func);
int sig = tt >> 8; /* Extract the function signature*/
switch (sig) {
case RAVI_TFCF_LOG:
case RAVI_TFCF_EXP:
case RAVI_TFCF_D_D: {
if (nargs == 1) {
TValue *arg1 = func + 1;
@ -529,8 +532,16 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int op_call) {
else
nargs = 0;
if (nargs) {
double (*f)(double) = fcfvalue(func);
double v = f(arg);
double v;
switch (sig) {
case RAVI_TFCF_EXP: v = exp(arg); break;
case RAVI_TFCF_LOG: v = log(arg); break;
default: {
double(*f)(double) = fcfvalue(func);
double v = f(arg);
break;
}
}
setfltvalue(func, v);
L->top = func + 1; /* top points after the last result */
return 1;

@ -272,9 +272,9 @@ static const luaL_Reg ravilib[] = {{"iscompiled", ravi_is_compiled},
LUAMOD_API int raviopen_llvmjit(lua_State *L) {
luaL_newlib(L, ravilib);
/* faster calls some maths functions */
ravi_pushcfastcall(L, (void *)exp, RAVI_TFCF_D_D);
ravi_pushcfastcall(L, NULL, RAVI_TFCF_EXP);
lua_setfield(L, -2, "exp");
ravi_pushcfastcall(L, (void *)log, RAVI_TFCF_D_D);
ravi_pushcfastcall(L, NULL, RAVI_TFCF_LOG);
lua_setfield(L, -2, "ln");
return 1;
}

Loading…
Cancel
Save