@@ -66,38 +66,6 @@ using namespace jit_compiler;
66
66
67
67
namespace {
68
68
69
- class HashPreprocessedAction : public PreprocessorFrontendAction {
70
- protected:
71
- void ExecuteAction () override {
72
- CompilerInstance &CI = getCompilerInstance ();
73
-
74
- std::string PreprocessedSource;
75
- raw_string_ostream PreprocessStream (PreprocessedSource);
76
-
77
- PreprocessorOutputOptions Opts;
78
- Opts.ShowCPP = 1 ;
79
- Opts.MinimizeWhitespace = 1 ;
80
- // Make cache key insensitive to virtual source file and header locations.
81
- Opts.ShowLineMarkers = 0 ;
82
-
83
- DoPrintPreprocessedInput (CI.getPreprocessor (), &PreprocessStream, Opts);
84
-
85
- Hash = BLAKE3::hash (arrayRefFromStringRef (PreprocessedSource));
86
- Executed = true ;
87
- }
88
-
89
- public:
90
- BLAKE3Result<> takeHash () {
91
- assert (Executed);
92
- Executed = false ;
93
- return std::move (Hash);
94
- }
95
-
96
- private:
97
- BLAKE3Result<> Hash;
98
- bool Executed = false ;
99
- };
100
-
101
69
class SYCLToolchain {
102
70
SYCLToolchain () {
103
71
using namespace jit_compiler ::resource;
@@ -318,28 +286,54 @@ Expected<std::string> jit_compiler::calculateHash(
318
286
std::vector<std::string> CommandLine =
319
287
createCommandLine (UserArgList, Format, SourceFile.Path );
320
288
321
- HashPreprocessedAction HashAction;
289
+ class HashPreprocessedAction : public PreprocessorFrontendAction {
290
+ protected:
291
+ void ExecuteAction () override {
292
+ CompilerInstance &CI = getCompilerInstance ();
322
293
323
- if (SYCLToolchain::instance ().run (CommandLine, HashAction,
324
- getInMemoryFS (SourceFile, IncludeFiles))) {
325
- BLAKE3Result<> SourceHash = HashAction.takeHash ();
326
- // Last argument is the source file in the format `rtc_N.cpp` which is
327
- // unique for each query, so drop it:
328
- CommandLine.pop_back ();
294
+ std::string PreprocessedSource;
295
+ raw_string_ostream PreprocessStream (PreprocessedSource);
329
296
330
- // TODO: Include hash of the current libsycl-jit.so/.dll somehow...
331
- BLAKE3Result<> CommandLineHash =
332
- BLAKE3::hash (arrayRefFromStringRef (join (CommandLine, " ," )));
297
+ PreprocessorOutputOptions Opts;
298
+ Opts.ShowCPP = 1 ;
299
+ Opts.MinimizeWhitespace = 1 ;
300
+ // Make cache key insensitive to virtual source file and header locations.
301
+ Opts.ShowLineMarkers = 0 ;
333
302
334
- std::string EncodedHash =
335
- encodeBase64 (SourceHash) + encodeBase64 (CommandLineHash);
336
- // Make the encoding filesystem-friendly.
337
- std::replace (EncodedHash.begin (), EncodedHash.end (), ' /' , ' -' );
338
- return std::move (EncodedHash);
303
+ DoPrintPreprocessedInput (CI.getPreprocessor (), &PreprocessStream, Opts);
339
304
340
- } else {
305
+ Hasher.update (PreprocessedSource);
306
+ }
307
+
308
+ public:
309
+ HashPreprocessedAction (BLAKE3 &Hasher) : Hasher(Hasher) {}
310
+
311
+ private:
312
+ BLAKE3 &Hasher;
313
+ };
314
+
315
+ BLAKE3 Hasher;
316
+ HashPreprocessedAction HashAction{Hasher};
317
+
318
+ if (!SYCLToolchain::instance ().run (CommandLine, HashAction,
319
+ getInMemoryFS (SourceFile, IncludeFiles)))
341
320
return createStringError (" Calculating source hash failed" );
342
- }
321
+
322
+ Hasher.update (CLANG_VERSION_STRING);
323
+ Hasher.update (
324
+ ArrayRef<uint8_t >{reinterpret_cast <const uint8_t *>(&Format),
325
+ reinterpret_cast <const uint8_t *>(&Format + 1 )});
326
+
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);
331
+
332
+ std::string EncodedHash = encodeBase64 (Hasher.result ());
333
+
334
+ // Make the encoding filesystem-friendly.
335
+ std::replace (EncodedHash.begin (), EncodedHash.end (), ' /' , ' -' );
336
+ return std::move (EncodedHash);
343
337
}
344
338
345
339
Expected<ModuleUPtr> jit_compiler::compileDeviceCode (
0 commit comments