diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 131dbdcc20007..a1d6f4185701b 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -268,6 +268,8 @@ class HeaderSearch { /// The hash used for module cache paths. std::string ModuleHash; + std::string ContextModuleHash; + /// The path to the module cache. std::string ModuleCachePath; @@ -406,6 +408,8 @@ class HeaderSearch { /// Set the hash to use for module cache paths. void setModuleHash(StringRef Hash) { ModuleHash = std::string(Hash); } + void setContextModuleHash(StringRef Hash) { ContextModuleHash = std::string(Hash); } + /// Set the path to the module cache. void setModuleCachePath(StringRef CachePath) { ModuleCachePath = std::string(CachePath); diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index df9a0eda914f1..cc07b57550aea 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5235,6 +5235,25 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back( Args.MakeArgString(Twine("-fsycl-unique-prefix=") + UniqueID)); + if (getenv("USE_MODULE")) { + SmallString<128> CachePath; + const bool HasPath = Driver::getDefaultModuleCachePath(CachePath); + if (HasPath) { + SmallString<128> BaseDir(C.getDriver().Dir); + llvm::sys::path::append(BaseDir, "..", "include"); + llvm::sys::path::append(BaseDir, "module.modulemap"); + + CmdArgs.push_back("-fmodules"); // VLAD + // + CmdArgs.push_back( + Args.MakeArgString(Twine("-fmodules-cache-path=") + CachePath)); + + CmdArgs.push_back( + Args.MakeArgString(Twine("-fmodule-map-file=") + BaseDir)); + CmdArgs.push_back("-fmodules-validate-system-headers"); + } + } + // Disable parallel for range-rounding for anything involving FPGA auto SYCLTCRange = C.getOffloadToolChains(); bool HasFPGA = false; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 3906dc0ce54b7..bab6397b42c3d 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -58,6 +58,7 @@ #include #include #include +#include using namespace clang; @@ -497,6 +498,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { if (PP->getLangOpts().Modules && PP->getLangOpts().ImplicitModules) { std::string ModuleHash = getInvocation().getModuleHash(); + /* printf("VLAD Hash Orig= %s\n", ModuleHash.c_str()); */ PP->getHeaderSearchInfo().setModuleHash(ModuleHash); PP->getHeaderSearchInfo().setModuleCachePath( getSpecificModuleCachePath(ModuleHash)); @@ -1731,6 +1733,19 @@ bool CompilerInstance::loadModuleFile(StringRef FileName) { auto &ListenerRef = *Listener; ASTReader::ListenerScope ReadModuleNamesListener(*TheASTReader, std::move(Listener)); + getInvocation().getModuleHash(); + +#if 0 + if (auto FilteredMacros = llvm::make_filter_range( + this->getPreprocessor().macros(), + [](const auto &Macro) { return true || Macro.first->isFromAST(); }); + !FilteredMacros.empty()) { + printf(" Macro Definitions:\n"); + for (/* pair*/ const auto &Macro : + FilteredMacros) + printf("%s\n", Macro.first->getName().str().c_str()); + } +#endif // Try to load the module file. switch (TheASTReader->ReadAST( @@ -1780,6 +1795,7 @@ static ModuleSource selectModuleSource( ModuleFilename = BuiltModuleIt->second; return MS_ModuleBuildPragma; } + // VLAD // Try to load the module from the prebuilt module path. const HeaderSearchOptions &HSOpts = HS.getHeaderSearchOpts(); @@ -1801,6 +1817,138 @@ static ModuleSource selectModuleSource( return MS_ModuleNotFound; } +static std::string getModuleHash(CompilerInvocation &CInvok, + CompilerInstance &CInst) { + // FIXME: Consider using SHA1 instead of MD5. + llvm::HashBuilder HBuilder; + + // Note: For QoI reasons, the things we use as a hash here should all be + // dumped via the -module-info flag. + + // Start the signature with the compiler version. + HBuilder.add(getClangFullRepositoryVersion()); + + // Also include the serialization version, in case LLVM_APPEND_VC_REV is off + // and getClangFullRepositoryVersion() doesn't include git revision. + HBuilder.add(serialization::VERSION_MAJOR, serialization::VERSION_MINOR); + + // Extend the signature with the language options +#define LANGOPT(Name, Bits, Default, Description) HBuilder.add(CInvok.LangOpts->Name); +#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ + HBuilder.add(static_cast(CInvok.LangOpts->get##Name())); +#define BENIGN_LANGOPT(Name, Bits, Default, Description) +#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) +#include "clang/Basic/LangOptions.def" + + HBuilder.addRange(CInvok.LangOpts->ModuleFeatures); + + HBuilder.add(CInvok.LangOpts->ObjCRuntime); + HBuilder.addRange(CInvok.LangOpts->CommentOpts.BlockCommandNames); + + // Extend the signature with the target options. + HBuilder.add(CInvok.TargetOpts->Triple, CInvok.TargetOpts->CPU, CInvok.TargetOpts->TuneCPU, + CInvok.TargetOpts->ABI); + HBuilder.addRange(CInvok.TargetOpts->FeaturesAsWritten); + + // Extend the signature with preprocessor options. + const PreprocessorOptions &ppOpts = CInvok.getPreprocessorOpts(); + HBuilder.add(ppOpts.UsePredefines, ppOpts.DetailedRecord); + + const HeaderSearchOptions &hsOpts = CInvok.getHeaderSearchOpts(); + for (const auto &Macro : CInvok.getPreprocessorOpts().Macros) { + // If we're supposed to ignore this macro for the purposes of modules, + // don't put it into the hash. + /* fprintf(stderr, "VLAD MacroDef = %s\n", Macro.first.c_str()); */ + if (!hsOpts.ModulesIgnoreMacros.empty()) { + // Check whether we're ignoring this macro. + StringRef MacroDef = Macro.first; + if (hsOpts.ModulesIgnoreMacros.count( + llvm::CachedHashString(MacroDef.split('=').first))) + continue; + } + + HBuilder.add(Macro); + } + + for (IdentifierTable::iterator + Id = CInst.getPreprocessor().getIdentifierTable().begin(), + IdEnd = CInst.getPreprocessor().getIdentifierTable().end(); + Id != IdEnd; ++Id) { + + auto Name = Id->second->getName(); + + /* fprintf(stderr, "VLAD MacroDef = %s\n", Name.str().c_str()); */ + + if (Id->second->hadMacroDefinition()) { + /* fprintf(stderr, "hadMacroDefinition VLAD MacroDef = %s\n", Name.str().c_str()); */ + MacroDefinition Macro = + CInst.getPreprocessor().getMacroDefinition(Id->second); + + MacroInfo *MacroInfoVal = Macro.getMacroInfo(); + /* MacroInfoVal->dump(); */ + /* fprintf(stderr, "\n"); */ + + std::stringstream MacroDef; + SmallString<128> SpellingBuffer; + for (const auto &T : MacroInfoVal->tokens()) { + if (T.hasLeadingSpace()) + MacroDef << ' '; + + MacroDef << CInst.getPreprocessor().getSpelling(T, SpellingBuffer).str(); + } + /* fprintf(stderr, "MacroDef = %s\n", MacroDef.str().c_str()); */ + + HBuilder.add(Name); + HBuilder.add(MacroDef.str()); + + } + } + + // Extend the signature with the sysroot and other header search options. + HBuilder.add(hsOpts.Sysroot, hsOpts.ModuleFormat, hsOpts.UseDebugInfo, + hsOpts.UseBuiltinIncludes, hsOpts.UseStandardSystemIncludes, + hsOpts.UseStandardCXXIncludes, hsOpts.UseLibcxx, + hsOpts.ModulesValidateDiagnosticOptions); + HBuilder.add(hsOpts.ResourceDir); + + if (hsOpts.ModulesStrictContextHash) { + HBuilder.addRange(hsOpts.SystemHeaderPrefixes); + HBuilder.addRange(hsOpts.UserEntries); + + const DiagnosticOptions &diagOpts = CInvok.getDiagnosticOpts(); +#define DIAGOPT(Name, Bits, Default) HBuilder.add(diagOpts.Name); +#define ENUM_DIAGOPT(Name, Type, Bits, Default) \ + HBuilder.add(diagOpts.get##Name()); +#include "clang/Basic/DiagnosticOptions.def" +#undef DIAGOPT +#undef ENUM_DIAGOPT + } + + // Extend the signature with the user build path. + HBuilder.add(hsOpts.ModuleUserBuildPath); + + // Extend the signature with the module file extensions. + for (const auto &ext : CInvok.getFrontendOpts().ModuleFileExtensions) + ext->hashExtension(HBuilder); + + // When compiling with -gmodules, also hash -fdebug-prefix-map as it + // affects the debug info in the PCM. + if (CInvok.getCodeGenOpts().DebugTypeExtRefs) + HBuilder.addRange(CInvok.getCodeGenOpts().DebugPrefixMap); + + // Extend the signature with the enabled sanitizers, if at least one is + // enabled. Sanitizers which cannot affect AST generation aren't hashed. + SanitizerSet SanHash = CInvok.LangOpts->Sanitize; + SanHash.clear(getPPTransparentSanitizers()); + if (!SanHash.empty()) + HBuilder.add(SanHash.Mask); + + llvm::MD5::MD5Result Result; + HBuilder.getHasher().final(Result); + uint64_t Hash = Result.high() ^ Result.low(); + return toString(llvm::APInt(64, Hash), 36, /*Signed=*/false); +} + ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( StringRef ModuleName, SourceLocation ImportLoc, SourceLocation ModuleNameLoc, bool IsInclusionDirective) { @@ -1811,6 +1959,22 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // Select the source and filename for loading the named module. std::string ModuleFilename; + /* printf("VLAD Before loading\n"); */ + /* std::string ModuleHash = getModuleHash(getInvocation(), *this); */ + + /* printf("VLAD Hash Context = %s\n", ModuleHash.c_str()); */ + + /* HS.setContextModuleHash(ModuleHash); */ + + /* std::string OldHash = HS.getModuleHash().str(); */ + /* std::string OldModuleCachePath = HS.getModuleCachePath().str(); */ + /* HS.setModuleHash(ModuleHash); */ + + /* SmallString<256> ParentPath = */ + /* llvm::sys::path::parent_path(OldModuleCachePath); */ + /* llvm::sys::path::append(ParentPath, ModuleHash); */ + /* HS.setModuleCachePath(ParentPath); */ + ModuleSource Source = selectModuleSource(M, ModuleName, ModuleFilename, BuiltModules, HS); if (Source == MS_ModuleNotFound) { @@ -1956,6 +2120,10 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( return nullptr; } + //RESOTRE + /* HS.setModuleHash(OldHash); */ + /* HS.setModuleCachePath(OldModuleCachePath); */ + // Okay, we've rebuilt and now loaded the module. return M; } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index a88753ca7b132..688543fda41b0 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4735,6 +4735,7 @@ std::string CompilerInvocation::getModuleHash() const { for (const auto &Macro : getPreprocessorOpts().Macros) { // If we're supposed to ignore this macro for the purposes of modules, // don't put it into the hash. + /* fprintf(stderr, "VLAD MacroDef = %s\n", Macro.first.c_str()); */ if (!hsOpts.ModulesIgnoreMacros.empty()) { // Check whether we're ignoring this macro. StringRef MacroDef = Macro.first; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index d94fe09274ed6..a7aa74229353a 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -264,7 +264,8 @@ std::string HeaderSearch::getCachedModuleFileNameImpl(StringRef ModuleName, SmallString<128> HashStr; llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36); - llvm::sys::path::append(Result, ModuleName + "-" + HashStr + ".pcm"); + llvm::sys::path::append(Result, ModuleName + "-" + HashStr + "-" + + ContextModuleHash + ".pcm"); } return Result.str().str(); } diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index eb4aac06ee3e1..c81466fc5c019 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1812,6 +1812,7 @@ void ASTStmtReader::VisitSYCLBuiltinFieldTypeExpr(SYCLBuiltinFieldTypeExpr *E) { E->setLocation(readSourceLocation()); E->SourceTy = Record.readType(); E->Index = Record.readExpr(); + E->setType(E->SourceTy); } void ASTStmtReader::VisitSYCLBuiltinNumBasesExpr(SYCLBuiltinNumBasesExpr *E) { @@ -1823,6 +1824,7 @@ void ASTStmtReader::VisitSYCLBuiltinBaseTypeExpr(SYCLBuiltinBaseTypeExpr *E) { E->setLocation(readSourceLocation()); E->SourceTy = Record.readType(); E->Index = Record.readExpr(); + E->setType(E->SourceTy); } void ASTStmtReader::VisitUserDefinedLiteral(UserDefinedLiteral *E) { diff --git a/llvm/include/module.modulemap.build b/llvm/include/module.modulemap.build index 2a5b23f2a4128..0e8e1e4fce6da 100644 --- a/llvm/include/module.modulemap.build +++ b/llvm/include/module.modulemap.build @@ -11,3 +11,8 @@ module LLVM_Config_Config { header "llvm/Config/llvm-config.h" export * } + +module SYCL { + header "sycl/sycl.hpp" + export * +} diff --git a/sycl/include/sycl/ext/intel/esimd.hpp b/sycl/include/sycl/ext/intel/esimd.hpp index 99e44c5d3ad5c..fcee432c4ab2e 100644 --- a/sycl/include/sycl/ext/intel/esimd.hpp +++ b/sycl/include/sycl/ext/intel/esimd.hpp @@ -79,6 +79,8 @@ #pragma clang diagnostic ignored "-Wpsabi" #endif // !defined(__SYCL_DEVICE_ONLY__) && defined(__clang__) +#include + #include #include #include diff --git a/sycl/include/sycl/ext/intel/fpga_extensions.hpp b/sycl/include/sycl/ext/intel/fpga_extensions.hpp index c3b30f5558c82..d92c57cad374b 100644 --- a/sycl/include/sycl/ext/intel/fpga_extensions.hpp +++ b/sycl/include/sycl/ext/intel/fpga_extensions.hpp @@ -7,6 +7,9 @@ //===----------------------------------------------------------------------===// #pragma once + +#include + #include #include #include diff --git a/sycl/include/sycl/sycl.hpp b/sycl/include/sycl/sycl.hpp index f972b95908f81..2ab0e56b54a9b 100644 --- a/sycl/include/sycl/sycl.hpp +++ b/sycl/include/sycl/sycl.hpp @@ -8,6 +8,12 @@ #pragma once +#ifdef HAHA +int foo() { return 33; } +#endif + +#if 0 + #include #include #include @@ -86,3 +92,4 @@ #include #include #include +#endif diff --git a/sycl/test/extensions/fpga.cpp b/sycl/test/extensions/fpga.cpp index b952f00706f80..a2e7b71c6607c 100644 --- a/sycl/test/extensions/fpga.cpp +++ b/sycl/test/extensions/fpga.cpp @@ -5,6 +5,7 @@ #include +#if 1 namespace intelfpga { template struct ethernet_pipe_id { static constexpr unsigned id = ID; @@ -163,3 +164,4 @@ int main() { return 0; } +#endif