@@ -2066,31 +2066,35 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2066
2066
2067
2067
uint64_t getStreamBusyWaitMicroseconds () const { return OMPX_StreamBusyWait; }
2068
2068
2069
- Expected<std::unique_ptr<MemoryBuffer>>
2070
- doJITPostProcessing ( std::unique_ptr<MemoryBuffer> MB) const override {
2069
+ Expected<std::unique_ptr<MemoryBuffer>> doJITPostProcessing (
2070
+ std::vector<std:: unique_ptr<MemoryBuffer>> && MB) const override {
2071
2071
2072
2072
// TODO: We should try to avoid materialization but there seems to be no
2073
2073
// good linker interface w/o file i/o.
2074
- SmallString<128 > LinkerInputFilePath;
2075
- std::error_code EC = sys::fs::createTemporaryFile (" amdgpu-pre-link-jit" ,
2076
- " o" , LinkerInputFilePath);
2077
- if (EC)
2078
- return Plugin::error (ErrorCode::HOST_IO,
2079
- " failed to create temporary file for linker" );
2080
-
2081
- // Write the file's contents to the output file.
2082
- Expected<std::unique_ptr<FileOutputBuffer>> OutputOrErr =
2083
- FileOutputBuffer::create (LinkerInputFilePath, MB->getBuffer ().size ());
2084
- if (!OutputOrErr)
2085
- return OutputOrErr.takeError ();
2086
- std::unique_ptr<FileOutputBuffer> Output = std::move (*OutputOrErr);
2087
- llvm::copy (MB->getBuffer (), Output->getBufferStart ());
2088
- if (Error E = Output->commit ())
2089
- return std::move (E);
2074
+ llvm::SmallVector<SmallString<128 >> InputFilenames;
2075
+ for (auto &B : MB) {
2076
+ SmallString<128 > LinkerInputFilePath;
2077
+ auto &Dest = InputFilenames.emplace_back ();
2078
+ std::error_code EC =
2079
+ sys::fs::createTemporaryFile (" amdgpu-pre-link-jit" , " o" , Dest);
2080
+ if (EC)
2081
+ return Plugin::error (ErrorCode::HOST_IO,
2082
+ " failed to create temporary file for linker" );
2083
+
2084
+ // Write the file's contents to the output file.
2085
+ Expected<std::unique_ptr<FileOutputBuffer>> OutputOrErr =
2086
+ FileOutputBuffer::create (Dest, B->getBuffer ().size ());
2087
+ if (!OutputOrErr)
2088
+ return OutputOrErr.takeError ();
2089
+ std::unique_ptr<FileOutputBuffer> Output = std::move (*OutputOrErr);
2090
+ llvm::copy (B->getBuffer (), Output->getBufferStart ());
2091
+ if (Error E = Output->commit ())
2092
+ return std::move (E);
2093
+ }
2090
2094
2091
2095
SmallString<128 > LinkerOutputFilePath;
2092
- EC = sys::fs::createTemporaryFile (" amdgpu-pre-link-jit " , " so " ,
2093
- LinkerOutputFilePath);
2096
+ std::error_code EC = sys::fs::createTemporaryFile (
2097
+ " amdgpu-pre-link-jit " , " so " , LinkerOutputFilePath);
2094
2098
if (EC)
2095
2099
return Plugin::error (ErrorCode::HOST_IO,
2096
2100
" failed to create temporary file for linker" );
@@ -2105,15 +2109,12 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2105
2109
" Using `%s` to link JITed amdgcn output." , LLDPath.c_str ());
2106
2110
2107
2111
std::string MCPU = " -plugin-opt=mcpu=" + getComputeUnitKind ();
2108
- StringRef Args[] = {LLDPath,
2109
- " -flavor" ,
2110
- " gnu" ,
2111
- " --no-undefined" ,
2112
- " -shared" ,
2113
- MCPU,
2114
- " -o" ,
2115
- LinkerOutputFilePath.data (),
2116
- LinkerInputFilePath.data ()};
2112
+ std::vector<StringRef> Args = {
2113
+ LLDPath, " -flavor" , " gnu" , " --no-undefined" ,
2114
+ " -shared" , MCPU, " -o" , LinkerOutputFilePath.data ()};
2115
+ for (auto &N : InputFilenames) {
2116
+ Args.push_back (N);
2117
+ }
2117
2118
2118
2119
std::string Error;
2119
2120
int RC = sys::ExecuteAndWait (LLDPath, Args, std::nullopt, {}, 0 , 0 , &Error);
@@ -2131,9 +2132,11 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
2131
2132
if (sys::fs::remove (LinkerOutputFilePath))
2132
2133
return Plugin::error (ErrorCode::HOST_IO,
2133
2134
" failed to remove temporary output file for lld" );
2134
- if (sys::fs::remove (LinkerInputFilePath))
2135
- return Plugin::error (ErrorCode::HOST_IO,
2136
- " failed to remove temporary input file for lld" );
2135
+ for (auto &N : InputFilenames) {
2136
+ if (sys::fs::remove (N))
2137
+ return Plugin::error (ErrorCode::HOST_IO,
2138
+ " failed to remove temporary input file for lld" );
2139
+ }
2137
2140
2138
2141
return std::move (*BufferOrErr);
2139
2142
}
0 commit comments