From 7fb2125c4b4a0500b0b03cee3b7b2597de505092 Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Tue, 25 Jul 2023 22:23:37 +0100 Subject: [PATCH] Move triples to the Options class --- .clang-format | 2 +- .pre-commit-config.yaml | 15 ++++++++--- serene/src/commands/commands.cpp | 2 +- serene/src/jit/jit.cpp | 45 +++++++++++++++++++++++++------- serene/src/jit/jit.h | 22 +++------------- serene/src/options.h | 16 ++++++++++++ serene/src/serene.cpp | 4 +-- 7 files changed, 70 insertions(+), 36 deletions(-) diff --git a/.clang-format b/.clang-format index be520e2..95be247 100644 --- a/.clang-format +++ b/.clang-format @@ -16,7 +16,7 @@ AlignEscapedNewlines: Left AlwaysBreakTemplateDeclarations: Yes IncludeBlocks: Regroup IncludeCategories: - - Regex: '^"(serene)/' + - Regex: '^"' Priority: 1 SortPriority: 1 CaseSensitive: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2c26d8..ba177b3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,12 +18,19 @@ repos: - id: trailing-whitespace - id: mixed-line-ending + # - repo: local + # hooks: + # - id: include-fixer + # name: Fixing 'serene' includes + # language: script + # entry: ./scripts/include-fixer.sh + # files: ".*.(h|cpp)" - repo: local hooks: - - id: include-fixer - name: Fixing 'serene' includes - language: script - entry: ./scripts/include-fixer.sh + - id: include-fixer py + name: Fixing local includes + language: python + entry: ./scripts/include-fixer.py files: ".*.(h|cpp)" - repo: https://github.com/pocc/pre-commit-hooks diff --git a/serene/src/commands/commands.cpp b/serene/src/commands/commands.cpp index 3556431..8deb439 100644 --- a/serene/src/commands/commands.cpp +++ b/serene/src/commands/commands.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ -#include +#include "commands/commands.h" #include diff --git a/serene/src/jit/jit.cpp b/serene/src/jit/jit.cpp index 5f88524..cbb45ff 100644 --- a/serene/src/jit/jit.cpp +++ b/serene/src/jit/jit.cpp @@ -16,22 +16,36 @@ * along with this program. If not, see . */ -#include -#include // for error_code +#include "jit/jit.h" -#include // for StringMapEntry -#include // for iterator_facade_base -#include // for JITEventListener -#include // IWYU pragma: keep +#include "options.h" // for Options + +#include <__type_traits/remove_reference.h> // for remov... +#include <__utility/move.h> // for move +#include // for error_code + +#include // for StringMapEntry +#include // for iterator_facade_base +#include // for JITEventListener +#include // for TMOwn... +#include // for JITDy... +#include // for opera... +#include // for Dynam... +#include // for IRCom... +#include // IWYU pragma: keep +#include // for Objec... #include +#include // for Threa... #include +#include // for DataL... +#include // for LLVMC... #include // for Module #include // for OpenFlags #include // for ToolOutputFile +#include // for Triple -#include // for assert -#include // for Options -#include // for operator+, char_t... +#include // for assert +#include // for operator+, char_t... namespace serene::jit { @@ -213,7 +227,7 @@ MaybeJIT JIT::make(llvm::orc::JITTargetMachineBuilder &&jtmb, // exported symbol visibility. // cf llvm/lib/ExecutionEngine/Orc/LLJIT.cpp // LLJIT::createObjectLinkingLayer - if (jitEngine->hostTriple.isOSBinFormatCOFF()) { + if (jitEngine->options->hostTriple.isOSBinFormatCOFF()) { objectLayer->setOverrideObjectFlagsWithResponsibilityFlags(true); objectLayer->setAutoClaimResponsibilityForObjectSymbols(true); } @@ -278,4 +292,15 @@ MaybeJIT JIT::make(llvm::orc::JITTargetMachineBuilder &&jtmb, return MaybeJIT(std::move(jitEngine)); }; + +MaybeJIT makeJIT(std::unique_ptr opts) { + llvm::orc::JITTargetMachineBuilder jtmb(opts->hostTriple); + auto maybeJIT = JIT::make(std::move(jtmb), std::move(opts)); + + if (!maybeJIT) { + return maybeJIT.takeError(); + } + + return maybeJIT; +}; } // namespace serene::jit diff --git a/serene/src/jit/jit.h b/serene/src/jit/jit.h index 824ac66..5170049 100644 --- a/serene/src/jit/jit.h +++ b/serene/src/jit/jit.h @@ -26,6 +26,8 @@ #ifndef JIT_JIT_H #define JIT_JIT_H +#include "options.h" + #include <__memory/unique_ptr.h> #include @@ -43,6 +45,7 @@ #include #include #include +#include namespace llvm { class JITEventListener; @@ -55,9 +58,6 @@ class JITDylib; class LLJIT; class LLLazyJIT; } // namespace llvm::orc -namespace serene { -struct Options; -} // namespace serene #define MAIN_PROCESS_JD_NAME "*main*" #define HALLEY_LOG(...) \ @@ -130,20 +130,6 @@ class JIT { llvm::Error createCurrentProcessJD(); public: - // We will use this triple to generate code that will endup in the binary - // for the target platform. If we're not cross compiling, `targetTriple` - // will be the same as `hostTriple`. - const llvm::Triple targetTriple; - - // This triple will be used in code generation for the host platform in - // complie time. For example any function that will be called during - // the compile time has to run on the host. So we need to generate - // appropriate code for the host. If the same function has to be part - // of the runtime, then we use `targetTriple` again to generate the code - // for the target platform. So, we might end up with two version of the - // same function - const llvm::Triple hostTriple; - JIT(llvm::orc::JITTargetMachineBuilder &&jtmb, std::unique_ptr opts); static MaybeJIT make(llvm::orc::JITTargetMachineBuilder &&jtmb, std::unique_ptr opts); @@ -177,6 +163,6 @@ public: llvm::ArrayRef getLoadPaths() { return loadPaths; }; }; -MaybeJIT makeJIT(); +MaybeJIT makeJIT(std::unique_ptr opts); } // namespace serene::jit #endif diff --git a/serene/src/options.h b/serene/src/options.h index 42af54a..7fcbc1e 100644 --- a/serene/src/options.h +++ b/serene/src/options.h @@ -19,6 +19,8 @@ #ifndef OPTIONS_H #define OPTIONS_H +#include // for Triple + namespace serene { /// This enum describes the different operational phases for the compiler /// in order. Anything below `NoOptimization` is considered only for debugging @@ -50,6 +52,20 @@ struct Options { bool JITenablePerfNotificationListener = true; bool JITLazy = false; + // We will use this triple to generate code that will endup in the binary + // for the target platform. If we're not cross compiling, `targetTriple` + // will be the same as `hostTriple`. + const llvm::Triple targetTriple; + + // This triple will be used in code generation for the host platform in + // complie time. For example any function that will be called during + // the compile time has to run on the host. So we need to generate + // appropriate code for the host. If the same function has to be part + // of the runtime, then we use `targetTriple` again to generate the code + // for the target platform. So, we might end up with two version of the + // same function + const llvm::Triple hostTriple; + CompilationPhase compilationPhase = CompilationPhase::NoOptimization; }; diff --git a/serene/src/serene.cpp b/serene/src/serene.cpp index c1b575b..b091cb6 100644 --- a/serene/src/serene.cpp +++ b/serene/src/serene.cpp @@ -16,9 +16,9 @@ * along with this program. If not, see . */ -#include "serene/config.h" // for SERENE_VERSION - #include "commands/commands.h" // for cc, run +#include "serene/config.h" // for SERENE_VERSION + // #include <__fwd/string.h> // for string #include // for StringRef