From 2da5b1dedfcbe060affcccc003005b3c4f0d337a Mon Sep 17 00:00:00 2001 From: Sameer Rahmani Date: Sun, 6 Feb 2022 21:15:13 +0000 Subject: [PATCH] Add the context options to the makeSereneContext function --- include/serene/context.h | 38 +++++++++++++++++---------------- src/libserene/context.cpp | 4 ++-- src/libserene/jit/halley.cpp | 1 + src/serene-repl/serene-repl.cpp | 5 ++++- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/include/serene/context.h b/include/serene/context.h index 3486959..5eda08d 100644 --- a/include/serene/context.h +++ b/include/serene/context.h @@ -71,20 +71,21 @@ enum class CompilationPhase { /// Terminates the serene compiler process in a thread safe manner SERENE_EXPORT void terminate(SereneContext &ctx, int exitCode); +struct SERENE_EXPORT Options { + + /// Whether to use colors for the output or not + bool withColors = true; + + // JIT related flags + bool JITenableObjectCache = true; + bool JITenableGDBNotificationListener = true; + bool JITenablePerfNotificationListener = true; + bool JITLazy = false; + + Options() = default; +}; + class SERENE_EXPORT SereneContext { - struct Options { - - /// Whether to use colors for the output or not - bool withColors = true; - - // JIT related flags - bool JITenableObjectCache = true; - bool JITenableGDBNotificationListener = true; - bool JITenablePerfNotificationListener = true; - bool JITLazy = false; - - Options() = default; - }; public: template @@ -151,9 +152,9 @@ public: /// and want to keep it long term (like the JIT). NSPtr getSharedPtrToNS(llvm::StringRef nsName); - SereneContext() + SereneContext(Options &options) : pm(&mlirContext), diagEngine(makeDiagnosticEngine(*this)), - targetPhase(CompilationPhase::NoOptimization) { + opts(options), targetPhase(CompilationPhase::NoOptimization) { mlirContext.getOrLoadDialect(); mlirContext.getOrLoadDialect(); @@ -205,8 +206,8 @@ public: return std::make_unique(); }; - static std::unique_ptr make() { - auto ctx = std::make_unique(); + static std::unique_ptr make(Options &options) { + auto ctx = std::make_unique(options); auto *ns = ctx->getNS(DEFAULT_NS_NAME); assert(ns != nullptr && "Default ns doesn't exit!"); @@ -278,7 +279,8 @@ private: /// Creates a new context object. Contexts are used through out the compilation /// process to store the state -SERENE_EXPORT std::unique_ptr makeSereneContext(); +SERENE_EXPORT std::unique_ptr +makeSereneContext(Options opts = Options()); } // namespace serene diff --git a/src/libserene/context.cpp b/src/libserene/context.cpp index 7df64b9..7c856fc 100644 --- a/src/libserene/context.cpp +++ b/src/libserene/context.cpp @@ -176,8 +176,8 @@ void terminate(SereneContext &ctx, int exitCode) { std::exit(exitCode); } -std::unique_ptr makeSereneContext() { - return SereneContext::make(); +std::unique_ptr makeSereneContext(Options opts) { + return SereneContext::make(opts); }; }; // namespace serene diff --git a/src/libserene/jit/halley.cpp b/src/libserene/jit/halley.cpp index 00d8bee..c4578d1 100644 --- a/src/libserene/jit/halley.cpp +++ b/src/libserene/jit/halley.cpp @@ -418,6 +418,7 @@ MaybeJIT Halley::make(SereneContext &serene_ctx, if (serene_ctx.opts.JITLazy) { // Setup a LLLazyJIT instance to the times that latency is important // for example in a REPL. This way + auto jit = cantFail(llvm::orc::LLLazyJITBuilder() .setCompileFunctionCreator(compileFunctionCreator) diff --git a/src/serene-repl/serene-repl.cpp b/src/serene-repl/serene-repl.cpp index 7eab758..e3d0427 100644 --- a/src/serene-repl/serene-repl.cpp +++ b/src/serene-repl/serene-repl.cpp @@ -52,7 +52,10 @@ int main(int argc, char *argv[]) { llvm::outs() << banner << art; - auto ctx = makeSereneContext(); + serene::Options opts; + opts.JITLazy = true; + + auto ctx = makeSereneContext(opts); applySereneCLOptions(*ctx);