@@ -117,16 +117,55 @@ class SYCLToolchain {
117
117
}
118
118
};
119
119
120
+ std::vector<std::string> createCommandLine (const InputArgList &UserArgList,
121
+ BinaryFormat Format,
122
+ std::string_view SourceFilePath) {
123
+ DerivedArgList DAL{UserArgList};
124
+ const auto &OptTable = getDriverOptTable ();
125
+ DAL.AddFlagArg (nullptr , OptTable.getOption (OPT_fsycl_device_only));
126
+ // User args may contain options not intended for the frontend, but we can't
127
+ // claim them here to tell the driver they're used later. Hence, suppress
128
+ // the unused argument warning.
129
+ DAL.AddFlagArg (nullptr , OptTable.getOption (OPT_Qunused_arguments));
130
+
131
+ if (Format == BinaryFormat::PTX || Format == BinaryFormat::AMDGCN) {
132
+ auto [CPU, Features] =
133
+ Translator::getTargetCPUAndFeatureAttrs (nullptr , " " , Format);
134
+ (void )Features;
135
+ StringRef OT = Format == BinaryFormat::PTX ? " nvptx64-nvidia-cuda"
136
+ : " amdgcn-amd-amdhsa" ;
137
+ DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_fsycl_targets_EQ), OT);
138
+ DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_Xsycl_backend_EQ), OT);
139
+ DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_offload_arch_EQ), CPU);
140
+ }
141
+
142
+ ArgStringList ASL;
143
+ for_each (DAL, [&DAL, &ASL](Arg *A) { A->render (DAL, ASL); });
144
+ for_each (UserArgList,
145
+ [&UserArgList, &ASL](Arg *A) { A->render (UserArgList, ASL); });
146
+
147
+ std::vector<std::string> CommandLine;
148
+ CommandLine.reserve (ASL.size () + 2 );
149
+ CommandLine.emplace_back (ClangXXExe);
150
+ transform (ASL, std::back_inserter (CommandLine),
151
+ [](const char *AS) { return std::string{AS}; });
152
+ CommandLine.emplace_back (SourceFilePath);
153
+ return CommandLine;
154
+ }
155
+
120
156
public:
121
157
static SYCLToolchain &instance () {
122
158
static SYCLToolchain Instance;
123
159
return Instance;
124
160
}
125
161
126
- bool run (const std::vector<std::string> &CommandLine ,
127
- FrontendAction &FEAction,
162
+ bool run (const InputArgList &UserArgList, BinaryFormat Format ,
163
+ const char *SourceFilePath, FrontendAction &FEAction,
128
164
IntrusiveRefCntPtr<FileSystem> FSOverlay = nullptr ,
129
165
DiagnosticConsumer *DiagConsumer = nullptr ) {
166
+ std::vector<std::string> CommandLine =
167
+ createCommandLine (UserArgList, Format, SourceFilePath);
168
+
130
169
auto FS = llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(
131
170
llvm::vfs::getRealFileSystem ());
132
171
FS->pushOverlay (ToolchainFS);
@@ -226,42 +265,6 @@ class LLVMDiagnosticWrapper : public llvm::DiagnosticHandler {
226
265
227
266
} // anonymous namespace
228
267
229
- static std::vector<std::string>
230
- createCommandLine (const InputArgList &UserArgList, BinaryFormat Format,
231
- std::string_view SourceFilePath) {
232
- DerivedArgList DAL{UserArgList};
233
- const auto &OptTable = getDriverOptTable ();
234
- DAL.AddFlagArg (nullptr , OptTable.getOption (OPT_fsycl_device_only));
235
- // User args may contain options not intended for the frontend, but we can't
236
- // claim them here to tell the driver they're used later. Hence, suppress the
237
- // unused argument warning.
238
- DAL.AddFlagArg (nullptr , OptTable.getOption (OPT_Qunused_arguments));
239
-
240
- if (Format == BinaryFormat::PTX || Format == BinaryFormat::AMDGCN) {
241
- auto [CPU, Features] =
242
- Translator::getTargetCPUAndFeatureAttrs (nullptr , " " , Format);
243
- (void )Features;
244
- StringRef OT = Format == BinaryFormat::PTX ? " nvptx64-nvidia-cuda"
245
- : " amdgcn-amd-amdhsa" ;
246
- DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_fsycl_targets_EQ), OT);
247
- DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_Xsycl_backend_EQ), OT);
248
- DAL.AddJoinedArg (nullptr , OptTable.getOption (OPT_offload_arch_EQ), CPU);
249
- }
250
-
251
- ArgStringList ASL;
252
- for_each (DAL, [&DAL, &ASL](Arg *A) { A->render (DAL, ASL); });
253
- for_each (UserArgList,
254
- [&UserArgList, &ASL](Arg *A) { A->render (UserArgList, ASL); });
255
-
256
- std::vector<std::string> CommandLine;
257
- CommandLine.reserve (ASL.size () + 2 );
258
- CommandLine.emplace_back (SYCLToolchain::instance ().getClangXXExe ());
259
- transform (ASL, std::back_inserter (CommandLine),
260
- [](const char *AS) { return std::string{AS}; });
261
- CommandLine.emplace_back (SourceFilePath);
262
- return CommandLine;
263
- }
264
-
265
268
static llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>
266
269
getInMemoryFS (InMemoryFile SourceFile, View<InMemoryFile> IncludeFiles) {
267
270
auto InMemoryFS = llvm::makeIntrusiveRefCnt<llvm::vfs::InMemoryFileSystem>();
@@ -283,9 +286,6 @@ Expected<std::string> jit_compiler::calculateHash(
283
286
const InputArgList &UserArgList, BinaryFormat Format) {
284
287
TimeTraceScope TTS{" calculateHash" };
285
288
286
- std::vector<std::string> CommandLine =
287
- createCommandLine (UserArgList, Format, SourceFile.Path );
288
-
289
289
class HashPreprocessedAction : public PreprocessorFrontendAction {
290
290
protected:
291
291
void ExecuteAction () override {
@@ -315,7 +315,8 @@ Expected<std::string> jit_compiler::calculateHash(
315
315
BLAKE3 Hasher;
316
316
HashPreprocessedAction HashAction{Hasher};
317
317
318
- if (!SYCLToolchain::instance ().run (CommandLine, HashAction,
318
+ if (!SYCLToolchain::instance ().run (UserArgList, Format, SourceFile.Path ,
319
+ HashAction,
319
320
getInMemoryFS (SourceFile, IncludeFiles)))
320
321
return createStringError (" Calculating source hash failed" );
321
322
@@ -324,10 +325,11 @@ Expected<std::string> jit_compiler::calculateHash(
324
325
ArrayRef<uint8_t >{reinterpret_cast <const uint8_t *>(&Format),
325
326
reinterpret_cast <const uint8_t *>(&Format + 1 )});
326
327
327
- // Last argument is "rtc_N.cpp" source file name which is never the same,
328
- // ignore it:
329
- for (auto &Opt : drop_end (CommandLine, 1 ))
330
- Hasher.update (Opt);
328
+ for (Arg *Opt : UserArgList) {
329
+ Hasher.update (Opt->getSpelling ());
330
+ for (const char *Val : Opt->getValues ())
331
+ Hasher.update (Val);
332
+ }
331
333
332
334
std::string EncodedHash = encodeBase64 (Hasher.result ());
333
335
@@ -346,9 +348,9 @@ Expected<ModuleUPtr> jit_compiler::compileDeviceCode(
346
348
DiagnosticOptions DiagOpts;
347
349
ClangDiagnosticWrapper Wrapper (BuildLog, &DiagOpts);
348
350
349
- if (SYCLToolchain::instance ().run (
350
- createCommandLine (UserArgList, Format, SourceFile. Path ), ELOA ,
351
- getInMemoryFS (SourceFile, IncludeFiles), Wrapper.consumer ())) {
351
+ if (SYCLToolchain::instance ().run (UserArgList, Format, SourceFile. Path , ELOA,
352
+ getInMemoryFS ( SourceFile, IncludeFiles) ,
353
+ Wrapper.consumer ())) {
352
354
return ELOA.takeModule ();
353
355
} else {
354
356
return createStringError (BuildLog);
0 commit comments