Skip to content

Commit d08c2fa

Browse files
committed
[ORC] Require ExecutorProcessControl when constructing an ExecutionSession.
Wrapper function call and dispatch handler helpers are moved to ExecutionSession, and existing EPC-based tools are re-written to take an ExecutionSession argument instead. Requiring an ExecutorProcessControl instance simplifies existing EPC based utilities (which only need to take an ES now), and should encourage more utilities to use the EPC interface. It also simplifies process termination, since the session can automatically call ExecutorProcessControl::disconnect (previously this had to be done manually, and carefully ordered with the rest of JIT tear-down to work correctly).
1 parent e9073c9 commit d08c2fa

34 files changed

+522
-390
lines changed

Diff for: examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace orc {
3232

3333
class KaleidoscopeJIT {
3434
private:
35-
std::unique_ptr<ExecutorProcessControl> EPC;
3635
std::unique_ptr<ExecutionSession> ES;
3736

3837
DataLayout DL;
@@ -44,11 +43,9 @@ class KaleidoscopeJIT {
4443
JITDylib &MainJD;
4544

4645
public:
47-
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
48-
std::unique_ptr<ExecutionSession> ES,
46+
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES,
4947
JITTargetMachineBuilder JTMB, DataLayout DL)
50-
: EPC(std::move(EPC)), ES(std::move(ES)), DL(std::move(DL)),
51-
Mangle(*this->ES, this->DL),
48+
: ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
5249
ObjectLayer(*this->ES,
5350
[]() { return std::make_unique<SectionMemoryManager>(); }),
5451
CompileLayer(*this->ES, ObjectLayer,
@@ -65,21 +62,21 @@ class KaleidoscopeJIT {
6562
}
6663

6764
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
68-
auto SSP = std::make_shared<SymbolStringPool>();
69-
auto EPC = SelfExecutorProcessControl::Create(SSP);
65+
auto EPC = SelfExecutorProcessControl::Create();
7066
if (!EPC)
7167
return EPC.takeError();
7268

73-
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
69+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
7470

75-
JITTargetMachineBuilder JTMB((*EPC)->getTargetTriple());
71+
JITTargetMachineBuilder JTMB(
72+
ES->getExecutorProcessControl().getTargetTriple());
7673

7774
auto DL = JTMB.getDefaultDataLayoutForTarget();
7875
if (!DL)
7976
return DL.takeError();
8077

81-
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
82-
std::move(JTMB), std::move(*DL));
78+
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB),
79+
std::move(*DL));
8380
}
8481

8582
const DataLayout &getDataLayout() const { return DL; }

Diff for: examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace orc {
3737

3838
class KaleidoscopeJIT {
3939
private:
40-
std::unique_ptr<ExecutorProcessControl> EPC;
4140
std::unique_ptr<ExecutionSession> ES;
4241

4342
DataLayout DL;
@@ -50,11 +49,9 @@ class KaleidoscopeJIT {
5049
JITDylib &MainJD;
5150

5251
public:
53-
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
54-
std::unique_ptr<ExecutionSession> ES,
52+
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES,
5553
JITTargetMachineBuilder JTMB, DataLayout DL)
56-
: EPC(std::move(EPC)), ES(std::move(ES)), DL(std::move(DL)),
57-
Mangle(*this->ES, this->DL),
54+
: ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
5855
ObjectLayer(*this->ES,
5956
[]() { return std::make_unique<SectionMemoryManager>(); }),
6057
CompileLayer(*this->ES, ObjectLayer,
@@ -72,21 +69,21 @@ class KaleidoscopeJIT {
7269
}
7370

7471
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
75-
auto SSP = std::make_shared<SymbolStringPool>();
76-
auto EPC = SelfExecutorProcessControl::Create(SSP);
72+
auto EPC = SelfExecutorProcessControl::Create();
7773
if (!EPC)
7874
return EPC.takeError();
7975

80-
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
76+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
8177

82-
JITTargetMachineBuilder JTMB((*EPC)->getTargetTriple());
78+
JITTargetMachineBuilder JTMB(
79+
ES->getExecutorProcessControl().getTargetTriple());
8380

8481
auto DL = JTMB.getDefaultDataLayoutForTarget();
8582
if (!DL)
8683
return DL.takeError();
8784

88-
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
89-
std::move(JTMB), std::move(*DL));
85+
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB),
86+
std::move(*DL));
9087
}
9188

9289
const DataLayout &getDataLayout() const { return DL; }

Diff for: examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h

+10-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ namespace orc {
3939

4040
class KaleidoscopeJIT {
4141
private:
42-
std::unique_ptr<ExecutorProcessControl> EPC;
4342
std::unique_ptr<ExecutionSession> ES;
4443
std::unique_ptr<EPCIndirectionUtils> EPCIU;
4544

@@ -59,12 +58,11 @@ class KaleidoscopeJIT {
5958
}
6059

6160
public:
62-
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
63-
std::unique_ptr<ExecutionSession> ES,
61+
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES,
6462
std::unique_ptr<EPCIndirectionUtils> EPCIU,
6563
JITTargetMachineBuilder JTMB, DataLayout DL)
66-
: EPC(std::move(EPC)), ES(std::move(ES)), EPCIU(std::move(EPCIU)),
67-
DL(std::move(DL)), Mangle(*this->ES, this->DL),
64+
: ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
65+
Mangle(*this->ES, this->DL),
6866
ObjectLayer(*this->ES,
6967
[]() { return std::make_unique<SectionMemoryManager>(); }),
7068
CompileLayer(*this->ES, ObjectLayer,
@@ -87,14 +85,13 @@ class KaleidoscopeJIT {
8785
}
8886

8987
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
90-
auto SSP = std::make_shared<SymbolStringPool>();
91-
auto EPC = SelfExecutorProcessControl::Create(SSP);
88+
auto EPC = SelfExecutorProcessControl::Create();
9289
if (!EPC)
9390
return EPC.takeError();
9491

95-
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
92+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
9693

97-
auto EPCIU = EPCIndirectionUtils::Create(**EPC);
94+
auto EPCIU = EPCIndirectionUtils::Create(ES->getExecutorProcessControl());
9895
if (!EPCIU)
9996
return EPCIU.takeError();
10097

@@ -104,15 +101,15 @@ class KaleidoscopeJIT {
104101
if (auto Err = setUpInProcessLCTMReentryViaEPCIU(**EPCIU))
105102
return std::move(Err);
106103

107-
JITTargetMachineBuilder JTMB((*EPC)->getTargetTriple());
104+
JITTargetMachineBuilder JTMB(
105+
ES->getExecutorProcessControl().getTargetTriple());
108106

109107
auto DL = JTMB.getDefaultDataLayoutForTarget();
110108
if (!DL)
111109
return DL.takeError();
112110

113-
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
114-
std::move(*EPCIU), std::move(JTMB),
115-
std::move(*DL));
111+
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(*EPCIU),
112+
std::move(JTMB), std::move(*DL));
116113
}
117114

118115
const DataLayout &getDataLayout() const { return DL; }

Diff for: examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h

+8-12
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ void KaleidoscopeASTMaterializationUnit::materialize(
126126

127127
class KaleidoscopeJIT {
128128
private:
129-
std::unique_ptr<ExecutorProcessControl> EPC;
130129
std::unique_ptr<ExecutionSession> ES;
131130
std::unique_ptr<EPCIndirectionUtils> EPCIU;
132131

@@ -146,12 +145,11 @@ class KaleidoscopeJIT {
146145
}
147146

148147
public:
149-
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
150-
std::unique_ptr<ExecutionSession> ES,
148+
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES,
151149
std::unique_ptr<EPCIndirectionUtils> EPCIU,
152150
JITTargetMachineBuilder JTMB, DataLayout DL)
153-
: EPC(std::move(EPC)), ES(std::move(ES)), EPCIU(std::move(EPCIU)),
154-
DL(std::move(DL)), Mangle(*this->ES, this->DL),
151+
: ES(std::move(ES)), EPCIU(std::move(EPCIU)), DL(std::move(DL)),
152+
Mangle(*this->ES, this->DL),
155153
ObjectLayer(*this->ES,
156154
[]() { return std::make_unique<SectionMemoryManager>(); }),
157155
CompileLayer(*this->ES, ObjectLayer,
@@ -172,14 +170,13 @@ class KaleidoscopeJIT {
172170
}
173171

174172
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
175-
auto SSP = std::make_shared<SymbolStringPool>();
176-
auto EPC = SelfExecutorProcessControl::Create(SSP);
173+
auto EPC = SelfExecutorProcessControl::Create();
177174
if (!EPC)
178175
return EPC.takeError();
179176

180-
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
177+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
181178

182-
auto EPCIU = EPCIndirectionUtils::Create(**EPC);
179+
auto EPCIU = EPCIndirectionUtils::Create(ES->getExecutorProcessControl());
183180
if (!EPCIU)
184181
return EPCIU.takeError();
185182

@@ -195,9 +192,8 @@ class KaleidoscopeJIT {
195192
if (!DL)
196193
return DL.takeError();
197194

198-
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
199-
std::move(*EPCIU), std::move(JTMB),
200-
std::move(*DL));
195+
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(*EPCIU),
196+
std::move(JTMB), std::move(*DL));
201197
}
202198

203199
const DataLayout &getDataLayout() const { return DL; }

Diff for: examples/Kaleidoscope/include/KaleidoscopeJIT.h

+8-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ namespace orc {
3232

3333
class KaleidoscopeJIT {
3434
private:
35-
std::unique_ptr<ExecutorProcessControl> EPC;
3635
std::unique_ptr<ExecutionSession> ES;
3736

3837
DataLayout DL;
@@ -44,11 +43,9 @@ class KaleidoscopeJIT {
4443
JITDylib &MainJD;
4544

4645
public:
47-
KaleidoscopeJIT(std::unique_ptr<ExecutorProcessControl> EPC,
48-
std::unique_ptr<ExecutionSession> ES,
46+
KaleidoscopeJIT(std::unique_ptr<ExecutionSession> ES,
4947
JITTargetMachineBuilder JTMB, DataLayout DL)
50-
: EPC(std::move(EPC)), ES(std::move(ES)), DL(std::move(DL)),
51-
Mangle(*this->ES, this->DL),
48+
: ES(std::move(ES)), DL(std::move(DL)), Mangle(*this->ES, this->DL),
5249
ObjectLayer(*this->ES,
5350
[]() { return std::make_unique<SectionMemoryManager>(); }),
5451
CompileLayer(*this->ES, ObjectLayer,
@@ -65,21 +62,21 @@ class KaleidoscopeJIT {
6562
}
6663

6764
static Expected<std::unique_ptr<KaleidoscopeJIT>> Create() {
68-
auto SSP = std::make_shared<SymbolStringPool>();
69-
auto EPC = SelfExecutorProcessControl::Create(SSP);
65+
auto EPC = SelfExecutorProcessControl::Create();
7066
if (!EPC)
7167
return EPC.takeError();
7268

73-
auto ES = std::make_unique<ExecutionSession>(std::move(SSP));
69+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
7470

75-
JITTargetMachineBuilder JTMB((*EPC)->getTargetTriple());
71+
JITTargetMachineBuilder JTMB(
72+
ES->getExecutorProcessControl().getTargetTriple());
7673

7774
auto DL = JTMB.getDefaultDataLayoutForTarget();
7875
if (!DL)
7976
return DL.takeError();
8077

81-
return std::make_unique<KaleidoscopeJIT>(std::move(*EPC), std::move(ES),
82-
std::move(JTMB), std::move(*DL));
78+
return std::make_unique<KaleidoscopeJIT>(std::move(ES), std::move(JTMB),
79+
std::move(*DL));
8380
}
8481

8582
const DataLayout &getDataLayout() const { return DL; }

Diff for: examples/OrcV2Examples/LLJITWithTargetProcessControl/LLJITWithTargetProcessControl.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ int main(int argc, char *argv[]) {
134134
ExitOnErr.setBanner(std::string(argv[0]) + ": ");
135135

136136
// (1) Create LLJIT instance.
137-
auto SSP = std::make_shared<SymbolStringPool>();
138-
auto EPC = ExitOnErr(SelfExecutorProcessControl::Create(std::move(SSP)));
139-
auto J = ExitOnErr(LLJITBuilder().setExecutorProcessControl(*EPC).create());
137+
auto EPC = ExitOnErr(SelfExecutorProcessControl::Create());
138+
auto J = ExitOnErr(
139+
LLJITBuilder().setExecutorProcessControl(std::move(EPC)).create());
140140

141141
// (2) Install transform to print modules as they are compiled:
142142
J->getIRTransformLayer().setTransform(
@@ -154,7 +154,8 @@ int main(int argc, char *argv[]) {
154154
J->getExecutionSession(), pointerToJITTargetAddress(&reportErrorAndExit));
155155
auto ISM = EPCIU->createIndirectStubsManager();
156156
J->getMainJITDylib().addGenerator(
157-
ExitOnErr(EPCDynamicLibrarySearchGenerator::GetForTargetProcess(*EPC)));
157+
ExitOnErr(EPCDynamicLibrarySearchGenerator::GetForTargetProcess(
158+
J->getExecutionSession())));
158159

159160
// (4) Add modules.
160161
ExitOnErr(J->addIRModule(ExitOnErr(parseExampleModule(FooMod, "foo-mod"))));

Diff for: examples/SpeculativeJIT/SpeculativeJIT.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ class SpeculativeJIT {
4949
if (!DL)
5050
return DL.takeError();
5151

52-
auto ES = std::make_unique<ExecutionSession>();
52+
auto EPC = SelfExecutorProcessControl::Create();
53+
if (!EPC)
54+
return EPC.takeError();
55+
56+
auto ES = std::make_unique<ExecutionSession>(std::move(*EPC));
5357

5458
auto LCTMgr = createLocalLazyCallThroughManager(
5559
JTMB->getTargetTriple(), *ES,

0 commit comments

Comments
 (0)