annotate include/llvm/ExecutionEngine/Orc/IRTransformLayer.h @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1 //===- IRTransformLayer.h - Run all IR through a functor --------*- C++ -*-===//
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // Run all IR passed in through a user supplied functor.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #ifndef LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #define LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
17 #include "llvm/ExecutionEngine/JITSymbol.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
18 #include <memory>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
19 #include <string>
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 namespace llvm {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
22 class Module;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 namespace orc {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 /// @brief IR mutating layer.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 ///
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
27 /// This layer applies a user supplied transform to each module that is added,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
28 /// then adds the transformed module to the layer below.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 template <typename BaseLayerT, typename TransformFtor>
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 class IRTransformLayer {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 public:
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
32
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 /// @brief Handle to a set of added modules.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
34 using ModuleHandleT = typename BaseLayerT::ModuleHandleT;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 /// @brief Construct an IRTransformLayer with the given BaseLayer
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 IRTransformLayer(BaseLayerT &BaseLayer,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 TransformFtor Transform = TransformFtor())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 : BaseLayer(BaseLayer), Transform(std::move(Transform)) {}
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
41 /// @brief Apply the transform functor to the module, then add the module to
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
42 /// the layer below, along with the memory manager and symbol resolver.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 /// @return A handle for the added modules.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
45 Expected<ModuleHandleT>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
46 addModule(std::shared_ptr<Module> M,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
47 std::shared_ptr<JITSymbolResolver> Resolver) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
48 return BaseLayer.addModule(Transform(std::move(M)), std::move(Resolver));
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
51 /// @brief Remove the module associated with the handle H.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
52 Error removeModule(ModuleHandleT H) { return BaseLayer.removeModule(H); }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 /// @brief Search for the given named symbol.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 /// @param Name The name of the symbol to search for.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 /// @param ExportedSymbolsOnly If true, search only for exported symbols.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 /// @return A handle for the given named symbol, if it exists.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 JITSymbol findSymbol(const std::string &Name, bool ExportedSymbolsOnly) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 return BaseLayer.findSymbol(Name, ExportedSymbolsOnly);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
62 /// @brief Get the address of the given symbol in the context of the module
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
63 /// represented by the handle H. This call is forwarded to the base
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
64 /// layer's implementation.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
65 /// @param H The handle for the module to search in.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 /// @param Name The name of the symbol to search for.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /// @param ExportedSymbolsOnly If true, search only for exported symbols.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 /// @return A handle for the given named symbol, if it is found in the
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
69 /// given module.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
70 JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name,
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 bool ExportedSymbolsOnly) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return BaseLayer.findSymbolIn(H, Name, ExportedSymbolsOnly);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
75 /// @brief Immediately emit and finalize the module represented by the given
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
76 /// handle.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
77 /// @param H Handle for module to emit/finalize.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
78 Error emitAndFinalize(ModuleHandleT H) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
79 return BaseLayer.emitAndFinalize(H);
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 /// @brief Access the transform functor directly.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 TransformFtor& getTransform() { return Transform; }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 /// @brief Access the mumate functor directly.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 const TransformFtor& getTransform() const { return Transform; }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 private:
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 BaseLayerT &BaseLayer;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 TransformFtor Transform;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
93 } // end namespace orc
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
94 } // end namespace llvm
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 #endif // LLVM_EXECUTIONENGINE_ORC_IRTRANSFORMLAYER_H