[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / ExecutionEngine / Orc / CompileUtils.h
blobeb6d84e8cbb405ed17f45abf587c110ccb56590c
1 //===- CompileUtils.h - Utilities for compiling IR in the JIT ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Contains utilities for compiling IR to object files.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
14 #define LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
16 #include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
17 #include <memory>
19 namespace llvm {
21 class MCContext;
22 class MemoryBuffer;
23 class Module;
24 class ObjectCache;
25 class TargetMachine;
27 namespace orc {
29 class JITTargetMachineBuilder;
31 /// Simple compile functor: Takes a single IR module and returns an ObjectFile.
32 /// This compiler supports a single compilation thread and LLVMContext only.
33 /// For multithreaded compilation, use ConcurrentIRCompiler below.
34 class SimpleCompiler {
35 public:
36 using CompileResult = std::unique_ptr<MemoryBuffer>;
38 /// Construct a simple compile functor with the given target.
39 SimpleCompiler(TargetMachine &TM, ObjectCache *ObjCache = nullptr)
40 : TM(TM), ObjCache(ObjCache) {}
42 /// Set an ObjectCache to query before compiling.
43 void setObjectCache(ObjectCache *NewCache) { ObjCache = NewCache; }
45 /// Compile a Module to an ObjectFile.
46 CompileResult operator()(Module &M);
48 private:
49 CompileResult tryToLoadFromObjectCache(const Module &M);
50 void notifyObjectCompiled(const Module &M, const MemoryBuffer &ObjBuffer);
52 TargetMachine &TM;
53 ObjectCache *ObjCache = nullptr;
56 /// A SimpleCompiler that owns its TargetMachine.
57 ///
58 /// This convenient for clients who don't want to own their TargetMachines,
59 /// e.g. LLJIT.
60 class TMOwningSimpleCompiler : public SimpleCompiler {
61 public:
62 TMOwningSimpleCompiler(std::unique_ptr<TargetMachine> TM,
63 ObjectCache *ObjCache = nullptr)
64 : SimpleCompiler(*TM, ObjCache), TM(std::move(TM)) {}
66 private:
67 // FIXME: shared because std::functions (and consequently
68 // IRCompileLayer::CompileFunction) are not moveable.
69 std::shared_ptr<llvm::TargetMachine> TM;
72 /// A thread-safe version of SimpleCompiler.
73 ///
74 /// This class creates a new TargetMachine and SimpleCompiler instance for each
75 /// compile.
76 class ConcurrentIRCompiler {
77 public:
78 ConcurrentIRCompiler(JITTargetMachineBuilder JTMB,
79 ObjectCache *ObjCache = nullptr);
81 void setObjectCache(ObjectCache *ObjCache) { this->ObjCache = ObjCache; }
83 std::unique_ptr<MemoryBuffer> operator()(Module &M);
85 private:
86 JITTargetMachineBuilder JTMB;
87 ObjectCache *ObjCache = nullptr;
90 } // end namespace orc
92 } // end namespace llvm
94 #endif // LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H