diff --git a/LICENSE b/LICENSE index fb54fa4f11..15b29c704e 100644 --- a/LICENSE +++ b/LICENSE @@ -23,6 +23,9 @@ Libraries (lib/ and import/ in binary packages): Phobos (runtime/phobos), is distributed under the terms of the Boost Software License. See the individual source files for author information. + - The jit runtime library is distributed under the terms of the Boost + Software License. + - The profile-rt runtime library (runtime/profile-rt) is a copy of LLVM's compiler-rt/profile library with a small D source addition. It is dual licensed under the University of Illinois Open Source License and under the diff --git a/gen/runtimecompile.cpp b/gen/runtimecompile.cpp index ab5c2634bc..02f005c4fc 100644 --- a/gen/runtimecompile.cpp +++ b/gen/runtimecompile.cpp @@ -1,4 +1,13 @@ -#include "runtimecompile.h" +//===-- runtimecompile.cpp ------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the BSD-style LDC license. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// + +#include "gen/runtimecompile.h" #if defined(LDC_RUNTIME_COMPILE) @@ -797,6 +806,7 @@ void addRuntimeCompiledVar(IRState *irs, IrGlobal *var) { } #else // defined(LDC_RUNTIME_COMPILE) + void generateBitcodeForRuntimeCompile(IRState *) { // nothing } diff --git a/gen/runtimecompile.h b/gen/runtimecompile.h index bc1fe23245..d63d2ea4ea 100644 --- a/gen/runtimecompile.h +++ b/gen/runtimecompile.h @@ -1,5 +1,18 @@ -#ifndef RUNTIMECOMPILE_H -#define RUNTIMECOMPILE_H +//===-- gen/runtimecompile.h - jit support ----------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the BSD-style LDC license. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit routines. +// +//===----------------------------------------------------------------------===// + +#ifndef LDC_GEN_RUNTIMECOMPILE_H +#define LDC_GEN_RUNTIMECOMPILE_H struct IRState; struct IrFunction; @@ -10,4 +23,4 @@ void declareRuntimeCompiledFunction(IRState *irs, IrFunction *func); void defineRuntimeCompiledFunction(IRState *irs, IrFunction *func); void addRuntimeCompiledVar(IRState *irs, IrGlobal *var); -#endif // RUNTIMECOMPILE_H +#endif // LDC_GEN_RUNTIMECOMPILE_H diff --git a/runtime/jit-rt/cpp-so/callback_ostream.cpp b/runtime/jit-rt/cpp-so/callback_ostream.cpp index d0ada3f5f3..197da8de1c 100644 --- a/runtime/jit-rt/cpp-so/callback_ostream.cpp +++ b/runtime/jit-rt/cpp-so/callback_ostream.cpp @@ -1,3 +1,11 @@ +//===-- callback_ostream.cpp ----------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// #include "callback_ostream.h" diff --git a/runtime/jit-rt/cpp-so/callback_ostream.h b/runtime/jit-rt/cpp-so/callback_ostream.h index 312f4b65bf..0b2ca747ed 100644 --- a/runtime/jit-rt/cpp-so/callback_ostream.h +++ b/runtime/jit-rt/cpp-so/callback_ostream.h @@ -1,3 +1,17 @@ +//===-- callback_ostream.h - jit support ------------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Simple llvm::raw_ostream implementation which sink all input to provided +// callback. It uses llvm::function_ref so user must ensure callback lifetime. +// +//===----------------------------------------------------------------------===// + #ifndef CALLBACK_OSTREAM_H #define CALLBACK_OSTREAM_H @@ -9,7 +23,6 @@ class CallbackOstream : public llvm::raw_ostream { CallbackT callback; uint64_t currentPos = 0; - /// See raw_ostream::write_impl. void write_impl(const char *Ptr, size_t Size) override; uint64_t current_pos() const override; diff --git a/runtime/jit-rt/cpp-so/compile.cpp b/runtime/jit-rt/cpp-so/compile.cpp index ed6e2eb970..8a40b3198b 100644 --- a/runtime/jit-rt/cpp-so/compile.cpp +++ b/runtime/jit-rt/cpp-so/compile.cpp @@ -1,3 +1,16 @@ +//===-- compile.cpp -------------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit runtime - shared library part. +// Defines jit runtime entry point and main compilation routines. +// +//===----------------------------------------------------------------------===// #include #include @@ -266,33 +279,34 @@ void dumpModule(const Context &context, const llvm::Module &module, } } -void dumpModuleAsm(const Context &context, const llvm::Module &module, - llvm::TargetMachine &TM) { - if (nullptr != context.dumpHandler) { - auto callback = [&](const char *str, size_t len) { - context.dumpHandler(context.dumpHandlerData, DumpStage::FinalAsm, str, - len); - }; +// Asm dump is disabled for now +// void dumpModuleAsm(const Context &context, const llvm::Module &module, +// llvm::TargetMachine &TM) { +// if (nullptr != context.dumpHandler) { +// auto callback = [&](const char *str, size_t len) { +// context.dumpHandler(context.dumpHandlerData, DumpStage::FinalAsm, str, +// len); +// }; - // TODO: I am not sure if passes added by addPassesToEmitFile can modify - // module, so clone source module to be sure, also, it allow preserve - // constness - auto newModule = llvm::CloneModule(&module); +// // TODO: I am not sure if passes added by addPassesToEmitFile can modify +// // module, so clone source module to be sure, also, it allow preserve +// // constness +// auto newModule = llvm::CloneModule(&module); - llvm::legacy::PassManager PM; +// llvm::legacy::PassManager PM; - llvm::SmallVector asmBufferSV; - llvm::raw_svector_ostream asmStream(asmBufferSV); +// llvm::SmallVector asmBufferSV; +// llvm::raw_svector_ostream asmStream(asmBufferSV); - if (TM.addPassesToEmitFile(PM, asmStream, - llvm::TargetMachine::CGFT_AssemblyFile)) { - fatal(context, "Target does not support asm emission."); - } - PM.run(*newModule); +// if (TM.addPassesToEmitFile(PM, asmStream, +// llvm::TargetMachine::CGFT_AssemblyFile)) { +// fatal(context, "Target does not support asm emission."); +// } +// PM.run(*newModule); - callback(asmBufferSV.data(), asmBufferSV.size()); - } -} +// callback(asmBufferSV.data(), asmBufferSV.size()); +// } +//} void setFunctionsTarget(llvm::Module &module, llvm::TargetMachine &TM) { // Set function target cpu to host if it wasn't set explicitly @@ -396,7 +410,7 @@ void rtCompileProcessImplSoInternal(const RtCompileModuleList *modlist_head, verifyModule(context, *finalModule); dumpModule(context, *finalModule, DumpStage::OptimizedModule); -// dumpModuleAsm(context, *finalModule, myJit.getTargetMachine()); + // dumpModuleAsm(context, *finalModule, myJit.getTargetMachine()); interruptPoint(context, "Codegen final module"); if (myJit.addModule(std::move(finalModule), symMap)) { diff --git a/runtime/jit-rt/cpp-so/context.h b/runtime/jit-rt/cpp-so/context.h index c75d45731c..06d2331b0b 100644 --- a/runtime/jit-rt/cpp-so/context.h +++ b/runtime/jit-rt/cpp-so/context.h @@ -1,9 +1,21 @@ +//===-- context.h - jit support ---------------------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit compilation context, must be in sync with runtimecompile.d. +// +//===----------------------------------------------------------------------===// + #ifndef CONTEXT_H #define CONTEXT_H #include //size_t -// must be synchronized with D source enum class DumpStage : int { OriginalModule = 0, MergedModule = 1, diff --git a/runtime/jit-rt/cpp-so/optimizer.cpp b/runtime/jit-rt/cpp-so/optimizer.cpp index a44b6651d0..23ef8517a6 100644 --- a/runtime/jit-rt/cpp-so/optimizer.cpp +++ b/runtime/jit-rt/cpp-so/optimizer.cpp @@ -1,3 +1,12 @@ +//===-- optimizer.cpp -----------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// + #include "optimizer.h" #include "llvm/Target/TargetMachine.h" diff --git a/runtime/jit-rt/cpp-so/optimizer.h b/runtime/jit-rt/cpp-so/optimizer.h index 65dfec342b..1ab5e2d201 100644 --- a/runtime/jit-rt/cpp-so/optimizer.h +++ b/runtime/jit-rt/cpp-so/optimizer.h @@ -1,3 +1,16 @@ +//===-- optimizer.h - jit support -------------------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit runtime - jit optimizer. +// +//===----------------------------------------------------------------------===// + #ifndef OPTIMIZER_HPP #define OPTIMIZER_HPP diff --git a/runtime/jit-rt/cpp-so/utils.cpp b/runtime/jit-rt/cpp-so/utils.cpp index 9d398e9e09..041340a3fb 100644 --- a/runtime/jit-rt/cpp-so/utils.cpp +++ b/runtime/jit-rt/cpp-so/utils.cpp @@ -1,3 +1,12 @@ +//===-- utils.cpp ---------------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// + #include "utils.h" #include diff --git a/runtime/jit-rt/cpp-so/utils.h b/runtime/jit-rt/cpp-so/utils.h index 8a6e57c635..1ba2bdd153 100644 --- a/runtime/jit-rt/cpp-so/utils.h +++ b/runtime/jit-rt/cpp-so/utils.h @@ -1,3 +1,16 @@ +//===-- utils.h - jit support -----------------------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit runtime - misc routines. +// +//===----------------------------------------------------------------------===// + #ifndef UTILS_HPP #define UTILS_HPP diff --git a/runtime/jit-rt/cpp-so/valueparser.cpp b/runtime/jit-rt/cpp-so/valueparser.cpp index e1ad55cc34..331702b8b7 100644 --- a/runtime/jit-rt/cpp-so/valueparser.cpp +++ b/runtime/jit-rt/cpp-so/valueparser.cpp @@ -1,3 +1,12 @@ +//===-- valueparser.cpp ---------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// + #include "valueparser.h" #include diff --git a/runtime/jit-rt/cpp-so/valueparser.h b/runtime/jit-rt/cpp-so/valueparser.h index 6d486ada27..83400af0c8 100644 --- a/runtime/jit-rt/cpp-so/valueparser.h +++ b/runtime/jit-rt/cpp-so/valueparser.h @@ -1,3 +1,18 @@ +//===-- valueparser.h - jit support -----------------------------*- C++ -*-===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit runtime - value parser. +// Reads data from host process and generates llvm::Constant suitable +// as initializer. +// +//===----------------------------------------------------------------------===// + #ifndef VALUEPARSER_H #define VALUEPARSER_H diff --git a/runtime/jit-rt/cpp/compile.cpp b/runtime/jit-rt/cpp/compile.cpp index bda4fac4f0..7668eaa7c7 100644 --- a/runtime/jit-rt/cpp/compile.cpp +++ b/runtime/jit-rt/cpp/compile.cpp @@ -1,4 +1,18 @@ -#include +//===-- compile.cpp -------------------------------------------------------===// +// +// LDC – the LLVM D compiler +// +// This file is distributed under the Boost Software License. See the LICENSE +// file for details. +// +//===----------------------------------------------------------------------===// +// +// Jit runtime - executable part. +// Defines jit modules list head and and access jit shared library entry point. +// +//===----------------------------------------------------------------------===// + +#include // size_t struct Context; diff --git a/runtime/jit-rt/d/ldc/runtimecompile.d b/runtime/jit-rt/d/ldc/runtimecompile.d index 88918fb28c..699437b31f 100644 --- a/runtime/jit-rt/d/ldc/runtimecompile.d +++ b/runtime/jit-rt/d/ldc/runtimecompile.d @@ -1,3 +1,10 @@ +/** + * Contains jit API. + * + * Copyright: Authors 2017 + * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) + */ + module ldc.runtimecompile; version(LDC_RuntimeCompilation):