Add the context options to the makeSereneContext function

This commit is contained in:
Sameer Rahmani 2022-02-06 21:15:13 +00:00
parent 008ba402f0
commit 2da5b1dedf
4 changed files with 27 additions and 21 deletions

View File

@ -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 <typename T>
@ -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<serene::slir::SereneDialect>();
mlirContext.getOrLoadDialect<mlir::StandardOpsDialect>();
@ -205,8 +206,8 @@ public:
return std::make_unique<llvm::LLVMContext>();
};
static std::unique_ptr<SereneContext> make() {
auto ctx = std::make_unique<SereneContext>();
static std::unique_ptr<SereneContext> make(Options &options) {
auto ctx = std::make_unique<SereneContext>(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<SereneContext> makeSereneContext();
SERENE_EXPORT std::unique_ptr<SereneContext>
makeSereneContext(Options opts = Options());
} // namespace serene

View File

@ -176,8 +176,8 @@ void terminate(SereneContext &ctx, int exitCode) {
std::exit(exitCode);
}
std::unique_ptr<SereneContext> makeSereneContext() {
return SereneContext::make();
std::unique_ptr<SereneContext> makeSereneContext(Options opts) {
return SereneContext::make(opts);
};
}; // namespace serene

View File

@ -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)

View File

@ -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);