Skip to content

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)
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