issue #128 refactoring

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent 73635d3876
commit 364b221433

@ -165,7 +165,8 @@ endif()
set(LUA_CORE_SRCS src/lapi.c src/lcode.c src/lctype.c src/ldebug.c src/ldo.c src/ldump.c
src/lfunc.c src/lgc.c src/llex.c src/lmem.c src/lobject.c src/lopcodes.c
src/lparser.c src/lstate.c src/lstring.c src/ltable.c src/ltm.c src/lundump.c
src/lvm.c src/lzio.c src/ravijit.cpp src/ltests.c src/ravi_profile.c src/ravi_membuf.c)
src/lvm.c src/lzio.c src/ravijit.cpp src/ltests.c src/ravi_profile.c src/ravi_membuf.c
src/ravi_jitshared.c)
# define the lua lib source files
set(LUA_LIB_SRCS src/lauxlib.c src/lbaselib.c src/lbitlib.c src/lcorolib.c src/ldblib.c src/liolib.c
src/lmathlib.c src/loslib.c src/ltablib.c src/lstrlib.c src/loadlib.c src/linit.c src/lutf8lib.c)

@ -0,0 +1,112 @@
/******************************************************************************
* Copyright (C) 2015-2017 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#ifndef RAVI_JITSHARED_H
#define RAVI_JITSHARED_H
#ifdef __cplusplus
extern "C" {
#endif
// TODO we probably do not need all the headers
// below
#define LUA_CORE
#include "lprefix.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lvm.h"
#include "lauxlib.h"
#include <ravi_membuf.h>
#define RA(i) (base + GETARG_A(i))
/* to be used after possible stack reallocation */
#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base + GETARG_B(i))
#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base + GETARG_C(i))
#define RKB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_B(i)) ? k + INDEXK(GETARG_B(i)) : base + GETARG_B(i))
#define RKC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_C(i)) ? k + INDEXK(GETARG_C(i)) : base + GETARG_C(i))
#define KBx(i) \
(k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
/* RAVI */
#define KB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_B(i)))
#define KC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_C(i)))
enum ravi_codegen_type {
RAVI_CODEGEN_NONE = 0,
RAVI_CODEGEN_HEADER_ONLY = 1,
RAVI_CODEGEN_FUNCTION_ONLY = 2,
RAVI_CODEGEN_ALL = 3,
};
typedef struct ravi_compile_options_t {
/* Is this a manual request? */
int manual_request;
/* Should range check be omitted when compiling array access */
int omit_array_get_range_check;
/* Should the compiler dump generated code ? */
int dump_level;
/* Should the compiler validate the generated code ? */
int verification_level;
enum ravi_codegen_type codegen_type;
} ravi_compile_options_t;
LUAI_FUNC bool raviJ_cancompile(Proto *p);
// Convert a Lua function to C code
// Returns true if compilation was successful
// If successful then buf will be set
LUAI_FUNC bool raviJ_codegen(struct lua_State *L, struct Proto *p,
ravi_compile_options_t *options, const char *fname, membuff_t *buf);
#ifdef __cplusplus
};
#endif
#endif

@ -20,74 +20,45 @@
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
/******************************************************************************
* Copyright (C) 2015-2017 Dibyendu Majumdar
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#ifndef RAVI_NANOJIT_H
#define RAVI_NANOJIT_H
#include <ravi_jitshared.h>
#ifdef USE_NANOJIT
#include "dmr_c.h"
#ifdef __cplusplus
extern "C" {
#endif
// TODO we probably do not need all the headers
// below
#define LUA_CORE
#include "lprefix.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "lvm.h"
typedef enum {
LUA__TNIL = LUA_TNIL,
LUA__TBOOLEAN = LUA_TBOOLEAN,
LUA__TLIGHTUSERDATA = LUA_TLIGHTUSERDATA,
LUA__TNUMBER = LUA_TNUMBER,
LUA__TSTRING = ctb(LUA_TSTRING),
LUA__TTABLE = ctb(LUA_TTABLE),
RAVI__TLTABLE = ctb(LUA_TTABLE),
RAVI__TIARRAY = ctb(RAVI_TIARRAY),
RAVI__TFARRAY = ctb(RAVI_TFARRAY),
LUA__TFUNCTION = ctb(LUA_TFUNCTION),
LUA__TUSERDATA = ctb(LUA_TUSERDATA),
LUA__TTHREAD = ctb(LUA_TTHREAD),
LUA__TLCL = ctb(LUA_TLCL),
LUA__TLCF = LUA_TLCF,
LUA__TCCL = ctb(LUA_TCCL),
LUA__TSHRSTR = ctb(LUA_TSHRSTR),
LUA__TLNGSTR = ctb(LUA_TLNGSTR),
LUA__TNUMFLT = LUA_TNUMFLT,
LUA__TNUMINT = LUA_TNUMINT
} lua_typecode_t;
struct ravi_State {
NJXContextRef jit;
unsigned long long id; // counter to generate function names
};
#ifdef __cplusplus
};
#endif
#endif /* USE_GCCJIT */
#endif /* USE_NANOJIT */
#endif /* RAVI_RAVI_GCCJIT_H */
#endif /* RAVI_NANOJIT_H */

@ -29,20 +29,7 @@ extern "C" {
struct lua_State;
struct Proto;
typedef struct {
/* Is this a manual request? */
int manual_request;
/* Should range check be omitted when compiling array access */
int omit_array_get_range_check;
/* Should the compiler dump generated code ? */
int dump_level;
/* Should the compiler validate the generated code ? */
int verification_level;
} ravi_compile_options_t;
typedef struct ravi_compile_options_t ravi_compile_options_t;
/* Initialise the JIT engine */
int raviV_initjit(struct lua_State *L);

@ -33,6 +33,7 @@
#include "lvm.h"
#include "lzio.h"
#include "ravijit.h"
#include "ravi_jitshared.h"
#define errorstatus(s) ((s) > LUA_YIELD)

@ -23,6 +23,7 @@
#include <ravi_gccjit.h>
#include <ravijit.h>
#include <ravi_jitshared.h>
#include <assert.h>
// Create a unique function name in the context
@ -218,24 +219,6 @@ static void free_function_def(ravi_function_def_t *def) {
}
}
#define RA(i) (base + GETARG_A(i))
/* to be used after possible stack reallocation */
#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base + GETARG_B(i))
#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base + GETARG_C(i))
#define RKB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_B(i)) ? k + INDEXK(GETARG_B(i)) : base + GETARG_B(i))
#define RKC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_C(i)) ? k + INDEXK(GETARG_C(i)) : base + GETARG_C(i))
#define KBx(i) \
(k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
/* RAVI */
#define KB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_B(i)))
#define KC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_C(i)))
/* Scan the Lua bytecode to identify the jump targets and pre-create
* basic blocks for each target. The blocks are saved in an array
* def->jmp_targets

@ -118,17 +118,7 @@ bool ravi_jit_has_errored(ravi_gcc_context_t *ravi) {
return false;
}
// TODO we probably do not need all the headers
// below
#define LUA_CORE
#include "lua.h"
#include "lobject.h"
#include "lstate.h"
#include "lauxlib.h"
#include "ravi_gccjit.h"
#include <ravi_jitshared.h>
// Initialize the JIT State and attach it to the
// Global Lua State

File diff suppressed because it is too large Load Diff

@ -21,7 +21,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include <ravijit.h>
#include "ravi_llvmcodegen.h"
#include <ravi_llvmcodegen.h>
#include <ravi_jitshared.h>
namespace ravi {
@ -1210,24 +1211,6 @@ void RaviCodeGenerator::emit_extern_declarations(RaviFunctionDef *def) {
#endif
}
#define RA(i) (base + GETARG_A(i))
/* to be used after possible stack reallocation */
#define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base + GETARG_B(i))
#define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base + GETARG_C(i))
#define RKB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_B(i)) ? k + INDEXK(GETARG_B(i)) : base + GETARG_B(i))
#define RKC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
ISK(GETARG_C(i)) ? k + INDEXK(GETARG_C(i)) : base + GETARG_C(i))
#define KBx(i) \
(k + (GETARG_Bx(i) != 0 ? GETARG_Bx(i) - 1 : GETARG_Ax(*ci->u.l.savedpc++)))
/* RAVI */
#define KB(i) \
check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_B(i)))
#define KC(i) \
check_exp(getCMode(GET_OPCODE(i)) == OpArgK, k + INDEXK(GETARG_C(i)))
void RaviCodeGenerator::link_block(RaviFunctionDef *def, int pc) {
// If we are on a jump target then check if this is a forloop
// target. Forloop targets are special as they use computed goto

@ -21,7 +21,8 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include <ravijit.h>
#include "ravi_llvmcodegen.h"
#include <ravi_llvmcodegen.h>
#include <ravi_jitshared.h>
/*
* Implementation Notes:

File diff suppressed because it is too large Load Diff

@ -22,6 +22,7 @@
******************************************************************************/
#include <ravijit.h>
#include <ravi_jitshared.h>
int raviV_compile(struct lua_State *L, struct Proto *p,
ravi_compile_options_t *options) {
@ -61,8 +62,19 @@ void raviV_close(struct lua_State *L) {
// Dump the LLVM IR
void raviV_dumpIR(struct lua_State *L, struct Proto *p) {
(void)L;
(void)p;
membuff_t buf;
membuff_init(&buf, 4096);
// TODO enhance this to allow user to specify name
// and also whether to dump header or body or both
char fname[30];
snprintf(fname, sizeof fname, "jitfunction");
ravi_compile_options_t options = { 0 };
options.codegen_type = RAVI_CODEGEN_ALL;
if (raviJ_codegen(L, p, &options, fname, &buf)) {
printf(buf.buf);
}
membuff_free(&buf);
}
// Dump the LLVM ASM

@ -21,6 +21,7 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/
#include <ravijit.h>
#include <ravi_jitshared.h>
#ifdef __cplusplus
extern "C" {

Loading…
Cancel
Save