LLVM  9.0.0svn
CompileUtils.h
Go to the documentation of this file.
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.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
14 #define LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
15 
17 #include <memory>
18 
19 namespace llvm {
20 
21 class JITTargetMachineBuilder;
22 class MCContext;
23 class MemoryBuffer;
24 class Module;
25 class ObjectCache;
26 class TargetMachine;
27 
28 namespace orc {
29 
30 /// Simple compile functor: Takes a single IR module and returns an ObjectFile.
31 /// This compiler supports a single compilation thread and LLVMContext only.
32 /// For multithreaded compilation, use ConcurrentIRCompiler below.
34 public:
35  using CompileResult = std::unique_ptr<MemoryBuffer>;
36 
37  /// Construct a simple compile functor with the given target.
38  SimpleCompiler(TargetMachine &TM, ObjectCache *ObjCache = nullptr)
39  : TM(TM), ObjCache(ObjCache) {}
40 
41  /// Set an ObjectCache to query before compiling.
42  void setObjectCache(ObjectCache *NewCache) { ObjCache = NewCache; }
43 
44  /// Compile a Module to an ObjectFile.
46 
47 private:
48  CompileResult tryToLoadFromObjectCache(const Module &M);
49  void notifyObjectCompiled(const Module &M, const MemoryBuffer &ObjBuffer);
50 
51  TargetMachine &TM;
52  ObjectCache *ObjCache = nullptr;
53 };
54 
55 /// A thread-safe version of SimpleCompiler.
56 ///
57 /// This class creates a new TargetMachine and SimpleCompiler instance for each
58 /// compile.
60 public:
62  ObjectCache *ObjCache = nullptr);
63 
64  void setObjectCache(ObjectCache *ObjCache) { this->ObjCache = ObjCache; }
65 
66  std::unique_ptr<MemoryBuffer> operator()(Module &M);
67 
68 private:
70  ObjectCache *ObjCache = nullptr;
71 };
72 
73 } // end namespace orc
74 
75 } // end namespace llvm
76 
77 #endif // LLVM_EXECUTIONENGINE_ORC_COMPILEUTILS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
void setObjectCache(ObjectCache *ObjCache)
Definition: CompileUtils.h:64
A thread-safe version of SimpleCompiler.
Definition: CompileUtils.h:59
Simple compile functor: Takes a single IR module and returns an ObjectFile.
Definition: CompileUtils.h:33
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
void setObjectCache(ObjectCache *NewCache)
Set an ObjectCache to query before compiling.
Definition: CompileUtils.h:42
This is the base ObjectCache type which can be provided to an ExecutionEngine for the purpose of avoi...
Definition: ObjectCache.h:22
std::unique_ptr< MemoryBuffer > CompileResult
Definition: CompileUtils.h:35
CompileResult operator()(Module &M)
Compile a Module to an ObjectFile.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:65
SimpleCompiler(TargetMachine &TM, ObjectCache *ObjCache=nullptr)
Construct a simple compile functor with the given target.
Definition: CompileUtils.h:38
A utility class for building TargetMachines for JITs.