Skip to content

Commit 1b6a46a

Browse files
authored
[ORC][COFF] Remove the ExecutionSession& argument to COFFPlatform factory & constructor (#112419)
We can get a reference to the `ExecutionSession` from the `ObjectLinkingLayer` argument, so there's no need to pass it in separately. This mirrors recent changes to `ElfNixPlatform` and `MachOPlatform` by @lhames in 3dba4ca and cc20dd2.
1 parent cc13d4f commit 1b6a46a

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

llvm/include/llvm/ExecutionEngine/Orc/COFFPlatform.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,16 @@ class COFFPlatform : public Platform {
4040
/// Try to create a COFFPlatform instance, adding the ORC runtime to the
4141
/// given JITDylib.
4242
static Expected<std::unique_ptr<COFFPlatform>>
43-
Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
44-
JITDylib &PlatformJD,
43+
Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
4544
std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
4645
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime = false,
4746
const char *VCRuntimePath = nullptr,
4847
std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
4948

5049
static Expected<std::unique_ptr<COFFPlatform>>
51-
Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
52-
JITDylib &PlatformJD, const char *OrcRuntimePath,
53-
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime = false,
54-
const char *VCRuntimePath = nullptr,
50+
Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
51+
const char *OrcRuntimePath, LoadDynamicLibrary LoadDynLibrary,
52+
bool StaticVCRuntime = false, const char *VCRuntimePath = nullptr,
5553
std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
5654

5755
ExecutionSession &getExecutionSession() const { return ES; }
@@ -138,8 +136,7 @@ class COFFPlatform : public Platform {
138136
static bool supportedTarget(const Triple &TT);
139137

140138
COFFPlatform(
141-
ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
142-
JITDylib &PlatformJD,
139+
ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
143140
std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
144141
std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
145142
std::unique_ptr<object::Archive> OrcRuntimeArchive,

llvm/lib/ExecutionEngine/Orc/COFFPlatform.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,14 @@ class COFFHeaderMaterializationUnit : public MaterializationUnit {
159159
namespace llvm {
160160
namespace orc {
161161

162-
Expected<std::unique_ptr<COFFPlatform>> COFFPlatform::Create(
163-
ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
164-
JITDylib &PlatformJD, std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
165-
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime,
166-
const char *VCRuntimePath, std::optional<SymbolAliasMap> RuntimeAliases) {
162+
Expected<std::unique_ptr<COFFPlatform>>
163+
COFFPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
164+
std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
165+
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime,
166+
const char *VCRuntimePath,
167+
std::optional<SymbolAliasMap> RuntimeAliases) {
168+
169+
auto &ES = ObjLinkingLayer.getExecutionSession();
167170

168171
// If the target is not supported then bail out immediately.
169172
if (!supportedTarget(ES.getTargetTriple()))
@@ -214,7 +217,7 @@ Expected<std::unique_ptr<COFFPlatform>> COFFPlatform::Create(
214217
// Create the instance.
215218
Error Err = Error::success();
216219
auto P = std::unique_ptr<COFFPlatform>(new COFFPlatform(
217-
ES, ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
220+
ObjLinkingLayer, PlatformJD, std::move(*OrcRuntimeArchiveGenerator),
218221
std::move(OrcRuntimeArchiveBuffer), std::move(RuntimeArchive),
219222
std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath, Err));
220223
if (Err)
@@ -223,8 +226,8 @@ Expected<std::unique_ptr<COFFPlatform>> COFFPlatform::Create(
223226
}
224227

225228
Expected<std::unique_ptr<COFFPlatform>>
226-
COFFPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
227-
JITDylib &PlatformJD, const char *OrcRuntimePath,
229+
COFFPlatform::Create(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
230+
const char *OrcRuntimePath,
228231
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime,
229232
const char *VCRuntimePath,
230233
std::optional<SymbolAliasMap> RuntimeAliases) {
@@ -233,7 +236,7 @@ COFFPlatform::Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
233236
if (!ArchiveBuffer)
234237
return createFileError(OrcRuntimePath, ArchiveBuffer.getError());
235238

236-
return Create(ES, ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
239+
return Create(ObjLinkingLayer, PlatformJD, std::move(*ArchiveBuffer),
237240
std::move(LoadDynLibrary), StaticVCRuntime, VCRuntimePath,
238241
std::move(RuntimeAliases));
239242
}
@@ -382,14 +385,14 @@ bool COFFPlatform::supportedTarget(const Triple &TT) {
382385
}
383386

384387
COFFPlatform::COFFPlatform(
385-
ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
386-
JITDylib &PlatformJD,
388+
ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
387389
std::unique_ptr<StaticLibraryDefinitionGenerator> OrcRuntimeGenerator,
388390
std::unique_ptr<MemoryBuffer> OrcRuntimeArchiveBuffer,
389391
std::unique_ptr<object::Archive> OrcRuntimeArchive,
390392
LoadDynamicLibrary LoadDynLibrary, bool StaticVCRuntime,
391393
const char *VCRuntimePath, Error &Err)
392-
: ES(ES), ObjLinkingLayer(ObjLinkingLayer),
394+
: ES(ObjLinkingLayer.getExecutionSession()),
395+
ObjLinkingLayer(ObjLinkingLayer),
393396
LoadDynLibrary(std::move(LoadDynLibrary)),
394397
OrcRuntimeArchiveBuffer(std::move(OrcRuntimeArchiveBuffer)),
395398
OrcRuntimeArchive(std::move(OrcRuntimeArchive)),

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ Expected<JITDylibSP> ExecutorNativePlatform::operator()(LLJIT &J) {
11721172
StaticVCRuntime = VCRuntime->second;
11731173
}
11741174
if (auto P = COFFPlatform::Create(
1175-
ES, *ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
1175+
*ObjLinkingLayer, PlatformJD, std::move(RuntimeArchiveBuffer),
11761176
LoadAndLinkDynLibrary(J), StaticVCRuntime, VCRuntimePath))
11771177
J.getExecutionSession().setPlatform(std::move(*P));
11781178
else

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,9 +1057,9 @@ Session::Session(std::unique_ptr<ExecutorProcessControl> EPC, Error &Err)
10571057
return loadAndLinkDynamicLibrary(JD, DLLName);
10581058
};
10591059

1060-
if (auto P = COFFPlatform::Create(ES, ObjLayer, *PlatformJD,
1061-
OrcRuntime.c_str(),
1062-
std::move(LoadDynLibrary)))
1060+
if (auto P =
1061+
COFFPlatform::Create(ObjLayer, *PlatformJD, OrcRuntime.c_str(),
1062+
std::move(LoadDynLibrary)))
10631063
ES.setPlatform(std::move(*P));
10641064
else {
10651065
Err = P.takeError();

0 commit comments

Comments
 (0)