diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index a8988d75ea2ea..375e1dc693341 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -477,7 +477,7 @@ OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) { // If we've already bypassed just use the existing one. auto Insertion = SeenBypassFileEntries->insert( - {VF.getNameAsRequested(), std::errc::no_such_file_or_directory}); + {VF.getName(), std::errc::no_such_file_or_directory}); if (!Insertion.second) return FileEntryRef(*Insertion.first); diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 7c8fd631913b8..10e5364b0ddea 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -2076,16 +2076,9 @@ ModuleLoadResult CompilerInstance::findOrCompileModuleAndReadAST( // Check whether M refers to the file in the prebuilt module path. if (M && M->getASTFile()) - if (auto ModuleFile = FileMgr->getOptionalFileRef(ModuleFilename)) { + if (auto ModuleFile = FileMgr->getFile(ModuleFilename)) if (*ModuleFile == M->getASTFile()) return M; -#if !defined(__APPLE__) - // Workaround for ext4 file system. Also check bypass file if exists. - if (auto Bypass = FileMgr->getBypassFile(*ModuleFile)) - if (*Bypass == M->getASTFile()) - return M; -#endif - } getDiagnostics().Report(ModuleNameLoc, diag::err_module_prebuilt) << ModuleName; diff --git a/clang/lib/Frontend/Rewrite/FrontendActions.cpp b/clang/lib/Frontend/Rewrite/FrontendActions.cpp index 2ee97a5b0f648..cf5a9437e89e6 100644 --- a/clang/lib/Frontend/Rewrite/FrontendActions.cpp +++ b/clang/lib/Frontend/Rewrite/FrontendActions.cpp @@ -213,15 +213,9 @@ class RewriteIncludesAction::RewriteImportsListener : public ASTReaderListener { void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override { - auto File = CI.getFileManager().getOptionalFileRef(Filename); + auto File = CI.getFileManager().getFile(Filename); assert(File && "missing file for loaded module?"); -#if !defined(__APPLE__) - // Workaround for ext4 file system. - if (auto Bypass = CI.getFileManager().getBypassFile(*File)) - File = *Bypass; -#endif - // Only rewrite each module file once. if (!Rewritten.insert(*File).second) return; diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index 6c852130ad93b..3e1298f60e18e 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -42,18 +42,8 @@ using namespace clang; using namespace serialization; ModuleFile *ModuleManager::lookupByFileName(StringRef Name) const { - auto Entry = FileMgr.getOptionalFileRef(Name, /*OpenFile=*/false, - /*CacheFailure=*/false); -#if !defined(__APPLE__) - if (Entry) { - // On Linux ext4 FileManager's inode caching system does not - // provide us correct behaviour for ModuleCache directories. - // inode can be reused after PCM delete resulting in cache misleading. - if (auto BypassFile = FileMgr.getBypassFile(*Entry)) - Entry = *BypassFile; - } -#endif - + auto Entry = FileMgr.getFile(Name, /*OpenFile=*/false, + /*CacheFailure=*/false); if (Entry) return lookup(*Entry); @@ -455,18 +445,6 @@ bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, File = FileMgr.getOptionalFileRef(FileName, /*OpenFile=*/true, /*CacheFailure=*/false); -#if !defined(__APPLE__) - if (File) { - // On Linux ext4 FileManager's inode caching system does not - // provide us correct behaviour for ModuleCache directories. - // inode can be reused after PCM delete resulting in cache misleading. - // Only use the bypass file if bypass succeed in case the underlying file - // system doesn't support bypass (thus there is no need for the workaround). - if (auto Bypass = FileMgr.getBypassFile(*File)) - File = *Bypass; - } -#endif - // If the file is known to the module cache but not in the filesystem, it is // a memory buffer. Create a virtual file for it. if (!File) { diff --git a/clang/test/Modules/explicit-build-relpath.cpp b/clang/test/Modules/explicit-build-relpath.cpp index 0f431b1d8ad07..708c9fd208b81 100644 --- a/clang/test/Modules/explicit-build-relpath.cpp +++ b/clang/test/Modules/explicit-build-relpath.cpp @@ -1,6 +1,3 @@ -/// Due to module bypass workaround in https://reviews.llvm.org/D97850 for ext4 FS, relative and absolute path do not match after bypass. -// REQUIRES: system-darwin - // RUN: rm -rf %t // RUN: mkdir %t // RUN: cd %t diff --git a/llvm/include/llvm-c/Transforms/PassBuilder.h b/llvm/include/llvm-c/Transforms/PassBuilder.h index d0466dd7fc0a1..de054bb01b226 100644 --- a/llvm/include/llvm-c/Transforms/PassBuilder.h +++ b/llvm/include/llvm-c/Transforms/PassBuilder.h @@ -102,6 +102,9 @@ void LLVMPassBuilderOptionsSetMergeFunctions(LLVMPassBuilderOptionsRef Options, void LLVMPassBuilderOptionsSetInlinerThreshold( LLVMPassBuilderOptionsRef Options, int Threshold); +void LLVMPassBuilderOptionsSetMaxDevirtIterations( + LLVMPassBuilderOptionsRef Options, int Iterations); + /** * Dispose of a heap-allocated PassBuilderOptions instance */ diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h index 50da57c6854cd..ac331695f47b2 100644 --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -96,6 +96,9 @@ class PipelineTuningOptions { // analyses after various module->function or cgscc->function adaptors in the // default pipelines. bool EagerlyInvalidateAnalyses; + + /// Tuning option to override default devirtualization iterations. + int MaxDevirtIterations; }; /// This class provides access to building LLVM's passes. diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 0ad5f93291c69..6d76f75e03b58 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -1783,7 +1783,7 @@ void ThinLTOCodeGenerator::run() { }; struct ModuleInfo { std::unique_ptr Entry; - std::atomic State = ModuleState::MS_Empty; + std::atomic State = 0b0000; std::unique_ptr ComputedBuffer; std::unique_ptr CachedBuffer; }; diff --git a/llvm/lib/Passes/PassBuilderBindings.cpp b/llvm/lib/Passes/PassBuilderBindings.cpp index b80dc0231ed5f..cc36c97f83c6e 100644 --- a/llvm/lib/Passes/PassBuilderBindings.cpp +++ b/llvm/lib/Passes/PassBuilderBindings.cpp @@ -145,6 +145,11 @@ void LLVMPassBuilderOptionsSetInlinerThreshold( unwrap(Options)->PTO.InlinerThreshold = Threshold; } +void LLVMPassBuilderOptionsSetMaxDevirtIterations( + LLVMPassBuilderOptionsRef Options, int Iterations) { + unwrap(Options)->PTO.MaxDevirtIterations = Iterations; +} + void LLVMDisposePassBuilderOptions(LLVMPassBuilderOptionsRef Options) { delete unwrap(Options); } diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index bc595869ab869..8bbc2cb6965e4 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -321,6 +321,7 @@ PipelineTuningOptions::PipelineTuningOptions() { UnifiedLTO = false; MergeFunctions = EnableMergeFunctions; InlinerThreshold = -1; + MaxDevirtIterations = -1; EagerlyInvalidateAnalyses = EnableEagerlyInvalidateAnalyses; } @@ -912,9 +913,10 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level, if (PGOOpt) IP.EnableDeferral = EnablePGOInlineDeferral; + int MDI = PTO.MaxDevirtIterations == -1 ? MaxDevirtIterations : PTO.MaxDevirtIterations; ModuleInlinerWrapperPass MIWP(IP, PerformMandatoryInliningsFirst, InlineContext{Phase, InlinePass::CGSCCInliner}, - UseInlineAdvisor, MaxDevirtIterations); + UseInlineAdvisor, MDI); // Require the GlobalsAA analysis for the module so we can query it within // the CGSCC pipeline. diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index f53aea177d612..ee9385d08d0d0 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -344,8 +344,12 @@ static void uninstallExceptionOrSignalHandlers() { #include +/// KOTLIN/NATIVE SPECIFIC HACK +/// +/// We need to disable handling of signals that can originate from the JVM GC, +/// since they should not trigger the LLVM signal handler. static const int Signals[] = - { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV, SIGTRAP }; + { SIGABRT, /* SIGBUS, SIGFPE, SIGILL, SIGSEGV, */ SIGTRAP }; static const unsigned NumSignals = std::size(Signals); static struct sigaction PrevActions[NumSignals]; diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index 298fde1a387cc..0cd0b483cc06b 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -303,6 +303,17 @@ static void RegisterHandlers() { // Not signal-safe. enum class SignalKind { IsKill, IsInfo }; auto registerHandler = [&](int Signal, SignalKind Kind) { + /// KOTLIN/NATIVE SPECIFIC HACK + /// + /// We need to disable handling of signals that can originate from the JVM GC, + /// since they should not trigger the LLVM signal handler. + + static const int JvmSigs[] = { + SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGUSR1, SIGUSR2 + }; + + for (auto S : JvmSigs) if (Signal == S) return; + unsigned Index = NumRegisteredSignals.load(); assert(Index < std::size(RegisteredSignalInfo) && "Out of space for signal handlers!");