issue #124 fix LLVM4.0 related issues

gccjit-ravi534
Dibyendu Majumdar 7 years ago
parent 17ba049005
commit a79f4d8a99

@ -2,5 +2,5 @@ mkdir llvm64
cd llvm64
rem pre LLVM 3.9
rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 14 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\LLVM37\share\llvm\cmake ..
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 14 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\d\LLVM39_64\lib\cmake\llvm ..
cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 15 2017 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\d\LLVM40_64\lib\cmake\llvm ..
cd ..

@ -313,9 +313,28 @@ struct UpVal {
} u;
};
/*
** Union of all collectable objects (only for conversions)
*/
union GCUnion {
struct GCObject gc; /* common header */
struct TString ts;
struct Udata u;
union Closure cl;
struct Table h;
struct Proto p;
struct lua_State th; /* thread */
};
#define rttype(o) ((o)->tt_)
#define BIT_ISCOLLECTABLE (1 << 6)
#define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE)
#define upisopen(up) ((up)->v != &(up)->u.value)
#define val_(o) ((o)->value_)
#define cast(t, exp) ((t)(exp))
#define cast_u(o) cast(union GCUnion *, (o))
#define gco2t(o) &((cast_u(o))->h)
#define hvalue(o) gco2t(val_(o).gc)
#endif

@ -0,0 +1,6 @@
#include "lua_hdr.h"
int tablevalue(struct TValue *v)
{
return (hvalue(v))->sizearray;
}

@ -0,0 +1,37 @@
; ModuleID = 'tab.c'
source_filename = "tab.c"
target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc"
%struct.TValue = type { %union.Value, i32 }
%union.Value = type { i64 }
%struct.Table = type { %struct.GCObject*, i8, i8, i8, i8, i32, %struct.TValue*, %struct.Node*, %struct.Node*, %struct.Table*, %struct.GCObject*, %struct.RaviArray, i32 }
%struct.Node = type { %struct.TValue, %union.TKey }
%union.TKey = type { %struct.anon.2 }
%struct.anon.2 = type { %union.Value, i32, i32 }
%struct.GCObject = type { %struct.GCObject*, i8, i8 }
%struct.RaviArray = type { i8*, i32, i32, i32 }
; Function Attrs: norecurse nounwind readonly
define i32 @tablevalue(%struct.TValue* nocapture readonly %v) local_unnamed_addr #0 {
entry:
%0 = bitcast %struct.TValue* %v to %struct.Table**
%1 = load %struct.Table*, %struct.Table** %0, align 8, !tbaa !1
%sizearray = getelementptr inbounds %struct.Table, %struct.Table* %1, i32 0, i32 5
%2 = load i32, i32* %sizearray, align 8, !tbaa !5
ret i32 %2
}
attributes #0 = { norecurse nounwind readonly "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = !{!"clang version 3.9.0 (trunk)"}
!1 = !{!2, !2, i64 0}
!2 = !{!"any pointer", !3, i64 0}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}
!5 = !{!6, !7, i64 8}
!6 = !{!"Table", !2, i64 0, !3, i64 4, !3, i64 5, !3, i64 6, !3, i64 7, !7, i64 8, !2, i64 12, !2, i64 16, !2, i64 20, !2, i64 24, !2, i64 28, !8, i64 32, !7, i64 48}
!7 = !{!"int", !3, i64 0}
!8 = !{!"RaviArray", !2, i64 0, !3, i64 4, !7, i64 8, !7, i64 12}

@ -27,7 +27,7 @@
#include "llvm/Config/llvm-config.h"
#if (LLVM_VERSION_MAJOR != 3 || LLVM_VERSION_MINOR < 5)
#if (LLVM_VERSION_MAJOR < 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 5)
#error Unsupported LLVM version
#endif
@ -46,7 +46,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/IR/Metadata.h"
#if LLVM_VERSION_MINOR < 7
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 7
#include "llvm/PassManager.h"
#else
#include "llvm/IR/LegacyPassManager.h"

@ -465,7 +465,9 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int op_call) {
callhook(L, ci);
if (L == G(L)->mainthread && p->ravi_jit.jit_status == RAVI_JIT_NOT_COMPILED) {
/* not compiled */
raviV_compile(L, p, NULL);
ravi_compile_options_t options = { 0 };
options.verification_level = 1;
raviV_compile(L, p, &options);
}
if (L == G(L)->mainthread && p->ravi_jit.jit_function) {
/* compiled */

@ -1355,7 +1355,7 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
// This is the function's activation record / stack frame
def->ci_val = builder.CreateLoad(def->L_ci);
def->ci_val->setMetadata(llvm::LLVMContext::MD_tbaa,
def->types->tbaa_CallInfoT);
def->types->tbaa_luaState_ciT);
// Get pointer to function's 'base' stack location
// 'base' is the address relative to which all the
@ -1918,11 +1918,10 @@ bool RaviCodeGenerator::compile(lua_State *L, Proto *p,
}
}
}
doVerify = true;
if (doVerify && llvm::verifyFunction(*f->function(), &llvm::errs())) {
f->dump();
fprintf(stderr, "LLVM Code Verification failed\n");
abort();
exit(1);
}
ravi::RaviJITFunction *llvm_func = f.release();
p->ravi_jit.jit_data = reinterpret_cast<void *>(llvm_func);

@ -61,7 +61,7 @@ RaviJITState::RaviJITState()
init++;
}
triple_ = llvm::sys::getProcessTriple();
#if defined(_WIN32) && (!defined(_WIN64) || LLVM_VERSION_MINOR < 7)
#if defined(_WIN32) && (!defined(_WIN64) || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 7)
// On Windows we get compilation error saying incompatible object format
// Reading posts on mailing lists I found that the issue is that COEFF
// format is not supported and therefore we need to set -elf as the object
@ -115,14 +115,14 @@ RaviJITModule::RaviJITModule(RaviJITState *owner)
layout->getTypeAllocSize(owner->types()->lua_StateT));
delete layout;
}
#if defined(_WIN32) && (!defined(_WIN64) || LLVM_VERSION_MINOR < 7)
#if defined(_WIN32) && (!defined(_WIN64) || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 7)
// On Windows we get error saying incompatible object format
// Reading posts on mailing lists I found that the issue is that COEFF
// format is not supported and therefore we need to set
// -elf as the object format; LLVM 3.7 onwards COEFF is supported
module_->setTargetTriple(owner->triple());
#endif
#if LLVM_VERSION_MINOR > 5
#if LLVM_VERSION_MAJOR > 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 5
// LLVM 3.6.0 change
std::unique_ptr<llvm::Module> module(module_);
llvm::EngineBuilder builder(std::move(module));
@ -188,7 +188,7 @@ RaviJITFunction::~RaviJITFunction() {
}
void RaviJITModule::runpasses(bool dumpAsm) {
#if LLVM_VERSION_MINOR >= 7
#if LLVM_VERSION_MAJOR > 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
using llvm::legacy::FunctionPassManager;
using llvm::legacy::PassManager;
#else
@ -212,16 +212,16 @@ void RaviJITModule::runpasses(bool dumpAsm) {
// Set up the optimizer pipeline. Start with registering info about how the
// target lays out data structures.
#if LLVM_VERSION_MINOR == 6
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 6
// LLVM 3.6.0 change
module_->setDataLayout(engine_->getDataLayout());
FPM->add(new llvm::DataLayoutPass());
#elif LLVM_VERSION_MINOR == 5
#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
// LLVM 3.5.0
auto target_layout = engine_->getTargetMachine()->getDataLayout();
module_->setDataLayout(target_layout);
FPM->add(new llvm::DataLayoutPass(*engine_->getDataLayout()));
#elif LLVM_VERSION_MINOR >= 7
#elif LLVM_VERSION_MAJOR > 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7
// Apparently no need to set DataLayout
#else
#error Unsupported LLVM version
@ -241,7 +241,7 @@ void RaviJITModule::runpasses(bool dumpAsm) {
// flush; so we introduce a scope here to ensure destruction
// of the stream
llvm::raw_string_ostream ostream(codestr);
#if LLVM_VERSION_MINOR < 7
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR < 7
llvm::formatted_raw_ostream formatted_stream(ostream);
#else
llvm::buffer_ostream formatted_stream(ostream);
@ -250,9 +250,9 @@ void RaviJITModule::runpasses(bool dumpAsm) {
// Also in 3.7 the pass manager seems to hold on to the stream
// so we need to ensure that the stream outlives the pass manager
std::unique_ptr<PassManager> MPM(new PassManager());
#if LLVM_VERSION_MINOR == 6
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 6
MPM->add(new llvm::DataLayoutPass());
#elif LLVM_VERSION_MINOR == 5
#elif LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 5
MPM->add(new llvm::DataLayoutPass(*engine_->getDataLayout()));
#endif
pmb.populateModulePassManager(*MPM);
@ -272,7 +272,7 @@ void RaviJITModule::runpasses(bool dumpAsm) {
MPM->run(*module_);
// Note that in 3.7 this flus appears to have no effect
#if LLVM_VERSION_MINOR <= 7
#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR <= 7
formatted_stream.flush();
#endif
}

@ -1235,7 +1235,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
tbaa_TValue_nT =
mdbuilder.createTBAAStructTagNode(tbaa_TValueT, tbaa_longlongT, 0);
tbaa_TValue_hT =
mdbuilder.createTBAAStructTagNode(tbaa_TValueT, tbaa_pointerT, 0);
mdbuilder.createTBAAStructTagNode(tbaa_pointerT, tbaa_pointerT, 0);
tbaa_TValue_ttT =
mdbuilder.createTBAAStructTagNode(tbaa_TValueT, tbaa_intT, 8);
@ -1296,7 +1296,7 @@ LuaLLVMTypes::LuaLLVMTypes(llvm::LLVMContext &context) : mdbuilder(context) {
tbaa_Table_lsizenode =
mdbuilder.createTBAAStructTagNode(tbaa_TableT, tbaa_charT, 7);
tbaa_Table_sizearray =
mdbuilder.createTBAAStructTagNode(tbaa_TableT, tbaa_pointerT, 8);
mdbuilder.createTBAAStructTagNode(tbaa_TableT, tbaa_intT, 8);
tbaa_Table_array =
mdbuilder.createTBAAStructTagNode(tbaa_TableT, tbaa_pointerT, 12);
tbaa_Table_node =

@ -92,10 +92,11 @@ static int ravi_compile_n(lua_State *L) {
}
ravi_compile_options_t options = {0};
options.manual_request = 1;
options.verification_level = 1;
if (lua_istable(L, 2)) {
lua_Integer do_dump, do_verify, omit_arrayget_rangecheck;
l_table_get_integer(L, 2, "dump", &do_dump, 0);
l_table_get_integer(L, 2, "verify", &do_verify, 0);
l_table_get_integer(L, 2, "verify", &do_verify, 1);
l_table_get_integer(L, 2, "omitArrayGetRangeCheck",
&omit_arrayget_rangecheck, 0);
options.omit_array_get_range_check = (int)omit_arrayget_rangecheck;

@ -124,7 +124,7 @@ int test1() {
// Lets create the MCJIT engine
std::string errStr;
#if LLVM_VERSION_MINOR > 5
#if LLVM_VERSION_MAJOR > 3 || LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 5
std::unique_ptr<llvm::Module> module_(module);
auto engine = llvm::EngineBuilder(std::move(module_))
.setErrorStr(&errStr)

Loading…
Cancel
Save