LLVM  7.0.0
Layer.h
Go to the documentation of this file.
1 //===---------------- Layer.h -- Layer interfaces --------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Layer interfaces.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_EXECUTIONENGINE_ORC_LAYER_H
15 #define LLVM_EXECUTIONENGINE_ORC_LAYER_H
16 
18 #include "llvm/IR/Module.h"
19 
20 namespace llvm {
21 namespace orc {
22 
23 /// Interface for layers that accept LLVM IR.
24 class IRLayer {
25 public:
27  virtual ~IRLayer();
28 
29  /// Returns the ExecutionSession for this layer.
31 
32  /// Adds a MaterializationUnit representing the given IR to the given VSO.
33  virtual Error add(VSO &V, VModuleKey K, std::unique_ptr<Module> M);
34 
35  /// Emit should materialize the given IR.
37  std::unique_ptr<Module> M) = 0;
38 
39 private:
40  ExecutionSession &ES;
41 };
42 
43 /// IRMaterializationUnit is a convenient base class for MaterializationUnits
44 /// wrapping LLVM IR. Represents materialization responsibility for all symbols
45 /// in the given module. If symbols are overridden by other definitions, then
46 /// their linkage is changed to available-externally.
48 public:
49  using SymbolNameToDefinitionMap = std::map<SymbolStringPtr, GlobalValue *>;
50 
51  /// Create an IRMaterializationLayer. Scans the module to build the
52  /// SymbolFlags and SymbolToDefinition maps.
53  IRMaterializationUnit(ExecutionSession &ES, std::unique_ptr<Module> M);
54 
55  /// Create an IRMaterializationLayer from a module, and pre-existing
56  /// SymbolFlags and SymbolToDefinition maps. The maps must provide
57  /// entries for each definition in M.
58  /// This constructor is useful for delegating work from one
59  /// IRMaterializationUnit to another.
60  IRMaterializationUnit(std::unique_ptr<Module> M, SymbolFlagsMap SymbolFlags,
61  SymbolNameToDefinitionMap SymbolToDefinition);
62 
63 protected:
64  std::unique_ptr<Module> M;
66 
67 private:
68  void discard(const VSO &V, SymbolStringPtr Name) override;
69 };
70 
71 /// MaterializationUnit that materializes modules by calling the 'emit' method
72 /// on the given IRLayer.
74 public:
76  std::unique_ptr<Module> M);
77 private:
78 
79  void materialize(MaterializationResponsibility R) override;
80 
81  IRLayer &L;
82  VModuleKey K;
83 };
84 
85 /// Interface for Layers that accept object files.
86 class ObjectLayer {
87 public:
89  virtual ~ObjectLayer();
90 
91  /// Returns the execution session for this layer.
93 
94  /// Adds a MaterializationUnit representing the given IR to the given VSO.
95  virtual Error add(VSO &V, VModuleKey K, std::unique_ptr<MemoryBuffer> O);
96 
97  /// Emit should materialize the given IR.
99  std::unique_ptr<MemoryBuffer> O) = 0;
100 
101 private:
102  ExecutionSession &ES;
103 };
104 
105 /// Materializes the given object file (represented by a MemoryBuffer
106 /// instance) by calling 'emit' on the given ObjectLayer.
108 public:
109 
110 
111  /// The MemoryBuffer should represent a valid object file.
112  /// If there is any chance that the file is invalid it should be validated
113  /// prior to constructing a BasicObjectLayerMaterializationUnit.
115  std::unique_ptr<MemoryBuffer> O);
116 
117 private:
118  void materialize(MaterializationResponsibility R) override;
119  void discard(const VSO &V, SymbolStringPtr Name) override;
120 
121  ObjectLayer &L;
122  VModuleKey K;
123  std::unique_ptr<MemoryBuffer> O;
124 };
125 
126 } // End namespace orc
127 } // End namespace llvm
128 
129 #endif // LLVM_EXECUTIONENGINE_ORC_LAYER_H
IRLayer(ExecutionSession &ES)
Definition: Layer.cpp:17
virtual Error add(VSO &V, VModuleKey K, std::unique_ptr< Module > M)
Adds a MaterializationUnit representing the given IR to the given VSO.
Definition: Layer.cpp:20
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A symbol table that supports asynchoronous symbol queries.
Definition: Core.h:544
SymbolNameToDefinitionMap SymbolToDefinition
Definition: Layer.h:65
std::unique_ptr< Module > M
Definition: Layer.h:64
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
Definition: Core.h:40
Materializes the given object file (represented by a MemoryBuffer instance) by calling &#39;emit&#39; on the ...
Definition: Layer.h:107
std::map< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
Definition: Core.h:57
std::map< SymbolStringPtr, GlobalValue * > SymbolNameToDefinitionMap
Definition: Layer.h:49
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:124
virtual void emit(MaterializationResponsibility R, VModuleKey K, std::unique_ptr< Module > M)=0
Emit should materialize the given IR.
IRMaterializationUnit is a convenient base class for MaterializationUnits wrapping LLVM IR...
Definition: Layer.h:47
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
Definition: Layer.h:92
MaterializationUnit that materializes modules by calling the &#39;emit&#39; method on the given IRLayer...
Definition: Layer.h:73
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this layer.
Definition: Layer.h:30
Pointer to a pooled string representing a symbol name.
Interface for layers that accept LLVM IR.
Definition: Layer.h:24
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
Definition: Core.h:205
Module.h This file contains the declarations for the Module class.
An ExecutionSession represents a running JIT program.
Definition: Core.h:735
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
virtual ~IRLayer()
Definition: Layer.cpp:18
Interface for Layers that accept object files.
Definition: Layer.h:86