Skip to content

Commit

Permalink
issue #169 Add initial support for MIR JIT backend
Browse files Browse the repository at this point in the history
  • Loading branch information
dibyendumajumdar committed Oct 27, 2019
1 parent 41135f3 commit 4e445f4
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 5 deletions.
30 changes: 26 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
# By default JIT is OFF
option(LLVM_JIT "Controls whether LLVM JIT compilation will be enabled, default is OFF" OFF)
option(OMR_JIT "Controls whether NanoJIT compilation will be enabled, default is OFF" OFF)
option(MIR_JIT "Controls whether MIR JIT compilation will be enabled, default is OFF" ON)
option(STATIC_BUILD "Build static version of Ravi, default is OFF" OFF)
option(COMPUTED_GOTO "Controls whether the interpreter switch will use computed gotos on gcc/clang, default is ON" ON)
option(ASM_VM "Controls whether to use the new VM (not ready yet! so don't turn on)" OFF)
option(LTESTS "Controls whether ltests are enabled in Debug mode" ON)

if (LLVM_JIT AND OMR_JIT)
if (LLVM_JIT AND OMR_JIT AND MIR_JIT)
message(FATAL_ERROR
"Both LLVM_JIT and OMR_JIT cannot be set to ON at the same time")
"LLVM_JIT, OMR_JIT and MIR_IT cannot all be set to ON at the same time")
endif ()

if (LLVM_JIT OR OMR_JIT)
if (LLVM_JIT OR OMR_JIT OR MIR_JIT)
# ASM VM is in development and not compatible with anything yet
set(ASM_VM OFF)
endif ()

if (MIR_JIT)
set(LLVM_JIT OFF)
set(OMR_JIT OFF)
endif()

if (ASM_VM)
# For now we switch to static build
# TODO A fix is needed to ensure that in shared library the asm functions are resolved
Expand All @@ -35,6 +41,7 @@ if (ASM_VM)
set(LTESTS OFF)
set(LLVM_JIT OFF)
set(OMR_JIT OFF)
set(MIR_JIT OFF)
endif ()

if (STATIC_BUILD)
Expand Down Expand Up @@ -63,6 +70,12 @@ if (OMR_JIT)
add_definitions(-DUSE_OMRJIT)
endif ()

if (MIR_JIT)
find_package(MIRJIT REQUIRED)
include_directories(${MIRJIT_INCLUDE_DIRS})
add_definitions(-DUSE_MIRJIT)
endif ()

message(STATUS "Computed goto ${COMPUTED_GOTO}")
if (COMPUTED_GOTO AND MSVC)
message(WARNING "Computed goto is not available with MSVC")
Expand Down Expand Up @@ -187,6 +200,8 @@ if (LLVM_JIT)
src/ravi_llvmluaapi.cpp)
elseif (OMR_JIT)
set(OMR_JIT_SRCS src/ravi_omrjit.c src/ravi_omrjitapi.c)
elseif (MIR_JIT)
set(MIR_JIT_SRCS src/ravi_mirjit.c)
else ()
set(NO_JIT_SRCS src/ravi_nojit.c)
endif ()
Expand Down Expand Up @@ -371,6 +386,9 @@ if (LLVM_JIT)
set(LIBRAVI_NAME libravillvm)
elseif (OMR_JIT)
set(LIBRAVI_NAME libravilomr)
elseif (MIR_JIT)
set(LIBRAVI_NAME libravimir)
set(LIBRAVI_BUILD_TYPE STATIC)
else ()
set(LIBRAVI_NAME libravinojit)
endif ()
Expand All @@ -382,6 +400,7 @@ add_library(${LIBRAVI_NAME} ${LIBRAVI_BUILD_TYPE}
${LUA_CORE_SRCS}
${LLVM_JIT_SRCS}
${OMR_JIT_SRCS}
${MIR_JIT_SRCS}
${NO_JIT_SRCS}
${DMR_C_HEADERS}
${DMR_C_SRCS}
Expand All @@ -404,10 +423,13 @@ endif ()
if (OMR_JIT)
set_target_properties(${LIBRAVI_NAME} PROPERTIES COMPILE_DEFINITIONS "USE_OMRJIT=1")
endif ()
if (MIR_JIT)
set_target_properties(${LIBRAVI_NAME} PROPERTIES COMPILE_DEFINITIONS "USE_MIRJIT=1")
endif ()
if (EMBEDDED_DMRC)
set_target_properties(${LIBRAVI_NAME} PROPERTIES COMPILE_DEFINITIONS "USE_DMR_C=1")
endif ()
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${OMRJIT_LIBRARIES})
target_link_libraries(${LIBRAVI_NAME} ${EXTRA_LIBRARIES} ${LLVM_LIBS} ${OMRJIT_LIBRARIES} ${MIRJIT_LIBRARIES})

# Main Ravi executable
add_executable(ravi src/lua.c)
Expand Down
16 changes: 16 additions & 0 deletions cmake/FindMIRJIT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
find_path(MIRJIT_INCLUDE_DIR c2mir.h
PATHS
c:/Software/mir/include/mir
~/Software/mir/include/mir
NO_DEFAULT_PATH
)

find_library(MIRJIT_LIBRARY
NAMES libc2mir.a
PATHS
c:/Software/mir/lib
~/Software/mir/lib
)

set( MIRJIT_INCLUDE_DIRS "${MIRJIT_INCLUDE_DIR}" )
set( MIRJIT_LIBRARIES "${MIRJIT_LIBRARY}" )
73 changes: 73 additions & 0 deletions include/ravi_mirjit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/******************************************************************************
* 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.
******************************************************************************/
/******************************************************************************
* Copyright (C) 2015-2018 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_OMRJIT_H
#define RAVI_OMRJIT_H

#include <ravi_jitshared.h>

#ifdef USE_MIRJIT
#include "c2mir.h"

struct ravi_State {
void *jit;
unsigned long long id; // counter to generate function names
unsigned int verbosity_ : 3;
unsigned int auto_ : 1; /* Should we auto compile what we can? */
unsigned int enabled_ : 1; /* is JIT enabled */
unsigned int opt_level_ : 3; /* optimization level */
unsigned int tracehook_enabled_ : 1; /* enable calls to luaG_traceexec() at every bytecode, this is expensive ! */
unsigned int validation_ : 1; /* Enable extra validation such as IL verification */
unsigned int compiling_; /* flag to help avoid recursion */
int min_code_size_; /* min code size for compilation */
int min_exec_count_; /* min execution count for compilation */
};

#ifdef __cplusplus
};
#endif

#endif /* USE_MIRJIT */

#endif /* RAVI_MIRJIT_H */
6 changes: 5 additions & 1 deletion src/ravi_jitshared.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
*/

static const char Lua_header[] = ""
"typedef __SIZE_TYPE__ size_t;\n"
//"#ifndef __SIZE_TYPE__\n"
//"#define __SIZE_TYPE__ long long\n"
//"#endif\n"
//"typedef __SIZE_TYPE__ size_t;\n"
"typedef long long size_t;\n"
"typedef long long ptrdiff_t;\n"
"typedef long long intptr_t;\n"
"typedef long long int64_t;\n"
Expand Down
Loading

0 comments on commit 4e445f4

Please sign in to comment.