Skip to content

[clang][deps] Remove dependency on llvm targets from lib DependencyScanning #129774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

benlangmuir
Copy link
Collaborator

In d64eccf we split the object file reader from the writer and removed the dependency on clangCodeGen from the dependency scanner. However, we were still initializing all the llvm targets, which was needed for writing object file pcms but not reading them. This caused us to link more llvm target code than necessary. Shrinks clangd by nearly 50% for me.

rdar://144790713

…anning

In d64eccf we split the object file reader from the writer and removed
the dependency on clangCodeGen from the dependency scanner. However, we
were still initializing all the llvm targets, which was needed for
writing object file pcms but not reading them. This caused us to link
more llvm target code than necessary. Shrinks clangd by nearly 50% for
me.

rdar://144790713
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Mar 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2025

@llvm/pr-subscribers-clang

Author: Ben Langmuir (benlangmuir)

Changes

In d64eccf we split the object file reader from the writer and removed the dependency on clangCodeGen from the dependency scanner. However, we were still initializing all the llvm targets, which was needed for writing object file pcms but not reading them. This caused us to link more llvm target code than necessary. Shrinks clangd by nearly 50% for me.

rdar://144790713


Full diff: https://github.com/llvm/llvm-project/pull/129774.diff

2 Files Affected:

  • (modified) clang/lib/Tooling/DependencyScanning/CMakeLists.txt (-1)
  • (modified) clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp (+1-8)
diff --git a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
index 66795b0be0baa..6b500a183bcfc 100644
--- a/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
+++ b/clang/lib/Tooling/DependencyScanning/CMakeLists.txt
@@ -1,5 +1,4 @@
 set(LLVM_LINK_COMPONENTS
-  ${LLVM_TARGETS_TO_BUILD}
   Core
   Option
   Support
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
index 4fb5977580497..96fe40c079c65 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningService.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
-#include "llvm/Support/TargetSelect.h"
 
 using namespace clang;
 using namespace tooling;
@@ -17,10 +16,4 @@ DependencyScanningService::DependencyScanningService(
     ScanningMode Mode, ScanningOutputFormat Format,
     ScanningOptimizations OptimizeArgs, bool EagerLoadModules, bool TraceVFS)
     : Mode(Mode), Format(Format), OptimizeArgs(OptimizeArgs),
-      EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS) {
-  // Initialize targets for object file support.
-  llvm::InitializeAllTargets();
-  llvm::InitializeAllTargetMCs();
-  llvm::InitializeAllAsmPrinters();
-  llvm::InitializeAllAsmParsers();
-}
+      EagerLoadModules(EagerLoadModules), TraceVFS(TraceVFS) {}

Copy link
Contributor

@jansvoboda11 jansvoboda11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thank you!

@benlangmuir benlangmuir merged commit f8ba0df into llvm:main Mar 5, 2025
13 checks passed
@benlangmuir benlangmuir deleted the eng/blangmuir/clangdeps-no-targets branch March 5, 2025 16:25
benlangmuir added a commit to benlangmuir/llvm-project that referenced this pull request Mar 5, 2025
…anning (llvm#129774)

In d64eccf we split the object file reader from the writer and removed
the dependency on clangCodeGen from the dependency scanner. However, we
were still initializing all the llvm targets, which was needed for
writing object file pcms but not reading them. This caused us to link
more llvm target code than necessary. Shrinks clangd by nearly 50% for
me.

rdar://144790713
(cherry picked from commit f8ba0df)
benlangmuir added a commit to benlangmuir/llvm-project that referenced this pull request Mar 5, 2025
…anning (llvm#129774)

In d64eccf we split the object file reader from the writer and removed
the dependency on clangCodeGen from the dependency scanner. However, we
were still initializing all the llvm targets, which was needed for
writing object file pcms but not reading them. This caused us to link
more llvm target code than necessary. Shrinks clangd by nearly 50% for
me.

rdar://144790713
(cherry picked from commit f8ba0df)
(cherry picked from commit c0eb45d)
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
…anning (llvm#129774)

In d64eccf we split the object file reader from the writer and removed
the dependency on clangCodeGen from the dependency scanner. However, we
were still initializing all the llvm targets, which was needed for
writing object file pcms but not reading them. This caused us to link
more llvm target code than necessary. Shrinks clangd by nearly 50% for
me.

rdar://144790713
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants