Skip to content

Commit

Permalink
Merge branch 'release/0.33.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiayang committed Mar 20, 2019
2 parents 67def52 + 59db7b2 commit a5f0e6c
Show file tree
Hide file tree
Showing 40 changed files with 654 additions and 179 deletions.
20 changes: 20 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v1.0
name: flax
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: "main"
task:
jobs:
- name: main
commands:
- checkout
- echo "LLVM 7"
- sudo echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main" | sudo tee -a /etc/apt/sources.list
- sudo echo "deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main" | sudo tee -a /etc/apt/sources.list
- sudo wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
- sudo apt -y update
- sudo apt-get -o Dpkg::Options::="--force-overwrite" --allow-unauthenticated -y install -y llvm-7 llvm-7-dev libllvm7 libmpfr-dev libmpfr6
- CXX=g++-8 CC=gcc-8 LLVM_CONFIG=llvm-config-7 make -j2 test
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ compiler: clang
matrix:
include:
- os: linux
dist: trusty
dist: xenial
sudo: false
- os: osx
osx_image: xcode9.4

addons:
apt:
sources:
- llvm-toolchain-trusty-6.0
- llvm-toolchain-xenial-7
- ubuntu-toolchain-r-test

packages:
- g++-8
- llvm-6.0
- llvm-6.0-dev
- libllvm6.0
- llvm-7
- llvm-7-dev
- libllvm7
- libmpfr-dev
- libmpfr4
homebrew:
packages:
- llvm@6
- llvm@7
update: true

script:
- if [ "$TRAVIS_OS_NAME" == "osx" ];
then PATH="/usr/local/opt/llvm@6/bin:$PATH" LLVM_CONFIG=llvm-config make tester;
else CXX=g++-$GCC_VERSION CC=gcc-$GCC_VERSION make ci;
then PATH="/usr/local/opt/llvm@7/bin:$PATH" LLVM_CONFIG=llvm-config make tester;
else CXX=g++-$GCC_VERSION CC=gcc-$GCC_VERSION LLVM_CONFIG=llvm-config-7 make ci;
fi

notifications:
Expand Down
8 changes: 6 additions & 2 deletions build/run-test.bat
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ IF /I "%1"=="debugopt" (
)


ninja -C %buildDir% && cls && %buildDir%\flaxc.exe -Ox -sysroot build\sysroot -run build\%2.flx
ninja -C %buildDir% && cls && %buildDir%\flaxc.exe -Ox -sysroot build\sysroot -run build\%2.flx %3 %4

ENDLOCAL
IF /I "%1"=="release" (
copy %buildDir%\flaxc.exe build\sysroot\usr\local\bin\ >NUL
)

ENDLOCAL
11 changes: 10 additions & 1 deletion build/supertiny.flx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ import libc as _

// import std::io
// import std::map
import std::opt

@raw union unn {
foo: i64
bar: f64
}

@entry fn main()
{
}
var x: unn
x.bar = 3.14159

printf("x = %.2lf\n", x.bar)
printf("x = %d\n", x.foo)
}


/*
Expand Down
21 changes: 10 additions & 11 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@



WARNINGS := -Wno-unused-parameter -Wno-sign-conversion -Wno-padded -Wno-conversion -Wno-shadow -Wno-missing-noreturn -Wno-unused-macros -Wno-switch-enum -Wno-deprecated -Wno-format-nonliteral -Wno-trigraphs -Wno-unused-const-variable
WARNINGS := -Wno-unused-parameter -Wno-sign-conversion -Wno-padded -Wno-conversion -Wno-shadow -Wno-missing-noreturn -Wno-unused-macros -Wno-switch-enum -Wno-deprecated -Wno-format-nonliteral -Wno-trigraphs -Wno-unused-const-variable -Wno-deprecated-declarations


CLANGWARNINGS := -Wno-undefined-func-template -Wno-comma -Wno-nullability-completeness -Wno-redundant-move -Wno-nested-anon-types -Wno-gnu-anonymous-struct -Wno-reserved-id-macro -Wno-extra-semi -Wno-gnu-zero-variadic-macro-arguments -Wno-shift-sign-overflow -Wno-exit-time-destructors -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-documentation-unknown-command -Wno-weak-vtables -Wno-c++98-compat
Expand Down Expand Up @@ -38,12 +38,11 @@ CXXDEPS := $(CXXSRC:.cpp=.cpp.d)

NUMFILES := $$(($(words $(CXXSRC)) + $(words $(CSRC))))



DEFINES := -D__USE_MINGW_ANSI_STDIO=1
SANITISE :=

CXXFLAGS += -std=c++1z -O0 -g -c -Wall -frtti -fexceptions -fno-omit-frame-pointer -Wno-old-style-cast $(SANITISE)
CFLAGS += -std=c11 -O0 -g -c -Wall -fno-omit-frame-pointer -Wno-overlength-strings $(SANITISE)
CXXFLAGS += -std=c++1z -O0 -g -c -Wall -frtti -fexceptions -fno-omit-frame-pointer -Wno-old-style-cast $(SANITISE) $(DEFINES)
CFLAGS += -std=c11 -O0 -g -c -Wall -fno-omit-frame-pointer -Wno-overlength-strings $(SANITISE) $(DEFINES)

LDFLAGS += $(SANITISE)

Expand Down Expand Up @@ -78,15 +77,15 @@ osxflags:

osx: prep jit osxflags

satest: prep osxflags build
satest: osxflags build
@$(OUTPUT) $(FLXFLAGS) -run build/standalone.flx

tester: prep osxflags build
tester: osxflags build
@$(OUTPUT) $(FLXFLAGS) -run build/tester.flx

ci: prep test
ci: test

linux: prep jit
linux: jit

jit: build
@$(OUTPUT) $(FLXFLAGS) -run -o $(SUPERTINYBIN) $(SUPERTINYSRC)
Expand All @@ -100,7 +99,7 @@ test: build
gltest: build
@$(OUTPUT) $(FLXFLAGS) -run -framework GLUT -framework OpenGL -lsdl2 -o $(GLTESTBIN) $(GLTESTSRC)

build: $(OUTPUT) copylibs
build: $(OUTPUT) prep copylibs
# built

build/%.flx: build
Expand All @@ -117,7 +116,7 @@ copylibs: $(FLXSRC)

$(OUTPUT): $(PRECOMP_GCH) $(CXXOBJ) $(COBJ)
@printf "# linking\n"
@$(CXX) -o $@ $(CXXOBJ) $(COBJ) $(shell $(LLVM_CONFIG) --cxxflags --ldflags --system-libs --libs core engine native linker bitwriter lto vectorize all-targets object) -lmpfr -lgmp $(LDFLAGS) -lpthread
@$(CXX) -o $@ $(CXXOBJ) $(COBJ) $(shell $(LLVM_CONFIG) --cxxflags --ldflags --system-libs --libs core engine native linker bitwriter lto vectorize all-targets object orcjit) -lmpfr -lgmp $(LDFLAGS) -lpthread


%.cpp.o: %.cpp
Expand Down
9 changes: 4 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ the_compiler = meson.get_compiler('c')
# buildKind = get_option('buildtype')
# message('build type is ' + buildKind)

# libKind = 'DebugNoSyms'

if get_option('buildtype') == 'debug'
libKind = 'DebugNoSyms'
libKind = 'Debug'
else
libKind = 'Release'
endif

mpir_root_dir = 'D:/Projects/lib/mpir'
mpfr_root_dir = 'D:/Projects/lib/mpfr'
llvm_root_dir = 'D:/Projects/lib/llvm'
llvm_root_dir = 'D:/Projects/lib/llvm/7.0.1/'

mpir_hdr_dir = mpir_root_dir + '/' + libKind + '/include/'
mpfr_hdr_dir = mpfr_root_dir + '/' + libKind + '/include/'
Expand Down Expand Up @@ -164,6 +162,7 @@ source_files = files([
'source/fir/Types/ArraySliceType.cpp',
'source/fir/Types/PrimitiveType.cpp',
'source/fir/Types/FunctionType.cpp',
'source/fir/Types/RawUnionType.cpp',
'source/fir/Types/PointerType.cpp',
'source/fir/Types/SingleTypes.cpp',
'source/fir/Types/StructType.cpp',
Expand Down Expand Up @@ -206,7 +205,7 @@ mpir_dep = declare_dependency(version: '3.0.0', include_directories: include_dir
mpfr_dep = declare_dependency(version: '4.0.0', include_directories: include_directories(mpfr_hdr_dir),
dependencies: the_compiler.find_library('mpfr', dirs: mpfr_lib_dir))

llvm_dep = declare_dependency(version: '6.0.0', include_directories: include_directories(llvm_hdr_dir),
llvm_dep = declare_dependency(version: '7.0.1', include_directories: include_directories(llvm_hdr_dir),
dependencies: [ mpfr_dep, mpir_dep,
# the_compiler.find_library('LLVM_all', dirs: llvm_lib_dir),
the_compiler.find_library('LLVMMC', dirs: llvm_lib_dir),
Expand Down
40 changes: 20 additions & 20 deletions source/backend/llvm/jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@
namespace backend
{
LLVMJit::LLVMJit(llvm::TargetMachine* tm) :
objectLayer([]() -> auto { return std::make_shared<llvm::SectionMemoryManager>(); }),
compileLayer(this->objectLayer, llvm::orc::SimpleCompiler(*tm))
{
this->targetMachine = std::unique_ptr<llvm::TargetMachine>(tm);
targetMachine(tm),
symbolResolver(llvm::orc::createLegacyLookupResolver(this->execSession, [&](const std::string& name) -> llvm::JITSymbol {
if(auto sym = this->compileLayer.findSymbol(name, false)) return sym;
else if(auto err = sym.takeError()) return std::move(err);

if(auto symaddr = llvm::RTDyldMemoryManager::getSymbolAddressInProcess(name))
return llvm::JITSymbol(symaddr, llvm::JITSymbolFlags::Exported);
else
return llvm::JITSymbol(nullptr);
}, [](llvm::Error err) { llvm::cantFail(std::move(err), "lookupFlags failed"); })),
dataLayout(this->targetMachine->createDataLayout()),
objectLayer(this->execSession, [this](llvm::orc::VModuleKey) -> auto {
return llvm::orc::RTDyldObjectLinkingLayer::Resources {
std::make_shared<llvm::SectionMemoryManager>(), this->symbolResolver }; }),
compileLayer(this->objectLayer, llvm::orc::SimpleCompiler(*this->targetMachine.get()))
{
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}

Expand All @@ -20,23 +31,12 @@ namespace backend
return this->targetMachine.get();
}

LLVMJit::ModuleHandle_t LLVMJit::addModule(std::shared_ptr<llvm::Module> mod)
LLVMJit::ModuleHandle_t LLVMJit::addModule(std::unique_ptr<llvm::Module> mod)
{
auto resolver = llvm::orc::createLambdaResolver([&](const std::string& name) -> auto {
if(auto sym = this->compileLayer.findSymbol(name, false))
return sym;

else
return llvm::JITSymbol(nullptr);
}, [](const std::string& name) -> auto {
if(auto symaddr = llvm::RTDyldMemoryManager::getSymbolAddressInProcess(name))
return llvm::JITSymbol(symaddr, llvm::JITSymbolFlags::Exported);

else
return llvm::JITSymbol(nullptr);
});
auto vmod = this->execSession.allocateVModule();
llvm::cantFail(this->compileLayer.addModule(vmod, std::move(mod)));

return llvm::cantFail(this->compileLayer.addModule(mod, std::move(resolver)));
return vmod;
}

void LLVMJit::removeModule(LLVMJit::ModuleHandle_t mod)
Expand All @@ -48,7 +48,7 @@ namespace backend
{
std::string mangledName;
llvm::raw_string_ostream out(mangledName);
llvm::Mangler::getNameWithPrefix(out, name, this->targetMachine->createDataLayout());
llvm::Mangler::getNameWithPrefix(out, name, this->dataLayout);

return this->compileLayer.findSymbol(out.str(), false);
}
Expand Down
13 changes: 7 additions & 6 deletions source/backend/llvm/linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "llvm/Transforms/IPO.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
Expand All @@ -37,6 +38,7 @@
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"

#ifdef _MSC_VER
Expand Down Expand Up @@ -103,7 +105,7 @@ namespace backend
this->entryFunction = mainModule->getFunction(this->compiledData.module->getEntryFunction()->getName().mangled());


this->linkedModule = std::shared_ptr<llvm::Module>(mainModule);
this->linkedModule = std::unique_ptr<llvm::Module>(mainModule);
this->finaliseGlobalConstructors();

// ok, move some shit into here because llvm is fucking retarded
Expand Down Expand Up @@ -160,7 +162,6 @@ namespace backend
fpm.add(llvm::createFlattenCFGPass());
fpm.add(llvm::createScalarizerPass());
fpm.add(llvm::createSinkingPass());
fpm.add(llvm::createInstructionSimplifierPass());
fpm.add(llvm::createDeadStoreEliminationPass());
fpm.add(llvm::createMemCpyOptPass());

Expand Down Expand Up @@ -221,7 +222,7 @@ namespace backend
llvm::sys::fs::OpenFlags of = (llvm::sys::fs::OpenFlags) 0;
llvm::raw_fd_ostream rso(oname.c_str(), e, of);

llvm::WriteBitcodeToFile(this->linkedModule.get(), rso);
llvm::WriteBitcodeToFile(*this->linkedModule.get(), rso);
rso.close();

_printTiming(ts, "writing bitcode file");
Expand Down Expand Up @@ -441,7 +442,7 @@ namespace backend
{
// auto p = prof::Profile(PROFGROUP_LLVM, "llvm_emit_object");
llvm::legacy::PassManager pm = llvm::legacy::PassManager();
targetMachine->addPassesToEmitFile(pm, *rawStream, llvm::TargetMachine::CodeGenFileType::CGFT_ObjectFile);
targetMachine->addPassesToEmitFile(pm, *rawStream, rawStream, llvm::TargetMachine::CodeGenFileType::CGFT_ObjectFile);
pm.run(*this->linkedModule);
}

Expand Down Expand Up @@ -583,11 +584,11 @@ namespace backend
if(this->entryFunction)
{
#if 1
auto name = this->entryFunction->getName().str();

this->jitInstance = new LLVMJit(this->targetMachine);
this->jitInstance->addModule(this->linkedModule);
this->jitInstance->addModule(std::move(this->linkedModule));

auto name = this->entryFunction->getName().str();
auto entryaddr = this->jitInstance->getSymbolAddress(name);
ret = (int (*)(int, const char**)) entryaddr;

Expand Down
Loading

0 comments on commit a5f0e6c

Please sign in to comment.