Skip to content

Commit 56ebd61

Browse files
author
Zak Kent
committed
[Immediate] Add documentation for new JIT stacks
1 parent 5181270 commit 56ebd61

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

include/swift/Immediate/SwiftMaterializationUnit.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace swift {
3535

3636
class CompilerInstance;
3737

38+
/// A JIT stack able to lazily JIT Swift programs
3839
class SwiftJIT {
3940
public:
4041
SwiftJIT(const SwiftJIT &) = delete;
@@ -49,23 +50,33 @@ class SwiftJIT {
4950

5051
~SwiftJIT();
5152

53+
/// Get the dylib associated with the main program
5254
llvm::orc::JITDylib &getMainJITDylib();
5355

5456
/// Register a the materialization unit `MU` with the `JITDylib``JD` and
5557
/// create lazy reexports for all functions defined in the interface of `MU`
5658
llvm::Error addSwift(llvm::orc::JITDylib &JD,
5759
std::unique_ptr<llvm::orc::MaterializationUnit> MU);
5860

61+
/// Return a linker-mangled version of `Name`
5962
std::string mangle(llvm::StringRef Name);
6063

61-
llvm::orc::SymbolStringPtr mangleAndIntern(llvm::StringRef Name);
62-
64+
/// Add a symbol name to the underlying `SymbolStringPool` and return
65+
/// a pointer to it
6366
llvm::orc::SymbolStringPtr intern(llvm::StringRef Name);
6467

68+
/// Return a linker-mangled version of `Name` and intern the result
69+
llvm::orc::SymbolStringPtr mangleAndIntern(llvm::StringRef Name);
70+
71+
/// Get the `IRCompileLayer` associated with this `SwiftJIT`
6572
llvm::orc::IRCompileLayer &getIRCompileLayer();
6673

74+
/// Get the `ObjectTransformLayer` associated with this `SwiftJIT`
6775
llvm::orc::ObjectTransformLayer &getObjTransformLayer();
6876

77+
/// Initialize the main `JITDylib`, lookup the main symbol, execute it,
78+
/// deinitialize the main `JITDylib`, and return the exit code of the
79+
/// JIT'd program
6980
llvm::Expected<int> runMain(llvm::ArrayRef<std::string> Args);
7081

7182
private:
@@ -100,10 +111,15 @@ class SwiftJIT {
100111
std::unique_ptr<llvm::orc::IndirectStubsManager> ISM;
101112
};
102113

114+
/// Lazily JITs a Swift AST using function at a time compilation
103115
class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
104116
public:
117+
118+
/// Create a new `LazySwiftMaterializationUnit` with the associated
119+
/// JIT stack `JIT` and compiler instance `CI`
105120
static std::unique_ptr<LazySwiftMaterializationUnit>
106121
Create(SwiftJIT &JIT, CompilerInstance &CI);
122+
107123
llvm::StringRef getName() const override;
108124

109125
private:
@@ -112,15 +128,21 @@ class LazySwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
112128
llvm::orc::SymbolFlagsMap Symbols);
113129
void materialize(
114130
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override;
131+
115132
void discard(const llvm::orc::JITDylib &JD,
116133
const llvm::orc::SymbolStringPtr &Sym) override;
134+
117135
SymbolSourceMap Sources;
118136
SwiftJIT &JIT;
119137
CompilerInstance &CI;
120138
};
121139

140+
/// Eagerly materializes a whole `SILModule`
122141
class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
123142
public:
143+
144+
/// Create a new `EagerSwiftMaterializationUnit` with the JIT stack `JIT`
145+
/// and provided compiler options
124146
EagerSwiftMaterializationUnit(SwiftJIT &JIT, const CompilerInstance &CI,
125147
const IRGenOptions &IRGenOpts,
126148
std::unique_ptr<SILModule> SM);
@@ -130,17 +152,22 @@ class EagerSwiftMaterializationUnit : public llvm::orc::MaterializationUnit {
130152
private:
131153
void materialize(
132154
std::unique_ptr<llvm::orc::MaterializationResponsibility> MR) override;
155+
156+
/// Get the linker-level interface defined by the `SILModule` being materialized
133157
static MaterializationUnit::Interface
134158
getInterface(SwiftJIT &JIT, const CompilerInstance &CI);
159+
135160
void dumpJIT(const llvm::Module &Module);
161+
136162
void discard(const llvm::orc::JITDylib &JD,
137163
const llvm::orc::SymbolStringPtr &Sym) override;
164+
138165
SwiftJIT &JIT;
139166
const CompilerInstance &CI;
140167
const IRGenOptions &IRGenOpts;
141168
std::unique_ptr<SILModule> SM;
142169
};
143170

144-
} // namespace swift
171+
} // end namespace swift
145172

146173
#endif // SWIFT_IMMEDIATE_SWIFTMATERIALIZATIONUNIT_H

0 commit comments

Comments
 (0)