Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

Identified with misc-include-cleaner.

Identified with misc-include-cleaner.
@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2024

@llvm/pr-subscribers-llvm-ir

Author: Kazu Hirata (kazutakahirata)

Changes

Identified with misc-include-cleaner.


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

13 Files Affected:

  • (modified) llvm/lib/IR/AsmWriter.cpp (-1)
  • (modified) llvm/lib/IR/ConstantFold.cpp (-1)
  • (modified) llvm/lib/IR/DIBuilder.cpp (-1)
  • (modified) llvm/lib/IR/Function.cpp (-1)
  • (modified) llvm/lib/IR/Intrinsics.cpp (-3)
  • (modified) llvm/lib/IR/LLVMContextImpl.cpp (-3)
  • (modified) llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp (-1)
  • (modified) llvm/lib/IR/Metadata.cpp (-1)
  • (modified) llvm/lib/IR/Module.cpp (-1)
  • (modified) llvm/lib/IR/ProfDataUtils.cpp (-3)
  • (modified) llvm/lib/IR/SSAContext.cpp (-1)
  • (modified) llvm/lib/IR/StructuralHash.cpp (-1)
  • (modified) llvm/lib/IR/Verifier.cpp (-2)
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 6adb8d6a742255..4bc7d9e68280d5 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -74,7 +74,6 @@
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostream.h"
-#include <algorithm>
 #include <cassert>
 #include <cctype>
 #include <cstddef>
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index c2780faee403d4..cfe87937c372cd 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -22,7 +22,6 @@
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
-#include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/GlobalAlias.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/Instructions.h"
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 447a9d65174636..a0aaea43d519b1 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -19,7 +19,6 @@
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/Module.h"
-#include "llvm/Support/CommandLine.h"
 #include <optional>
 
 using namespace llvm;
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index 889295956dbf7c..9c5dd5aeb92e97 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -18,7 +18,6 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/AbstractCallSite.h"
 #include "llvm/IR/Argument.h"
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index 1b92daf15b463e..3130a0bd2955a5 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -17,7 +17,6 @@
 #include "llvm/IR/IntrinsicsAMDGPU.h"
 #include "llvm/IR/IntrinsicsARM.h"
 #include "llvm/IR/IntrinsicsBPF.h"
-#include "llvm/IR/IntrinsicsDirectX.h"
 #include "llvm/IR/IntrinsicsHexagon.h"
 #include "llvm/IR/IntrinsicsLoongArch.h"
 #include "llvm/IR/IntrinsicsMips.h"
@@ -26,9 +25,7 @@
 #include "llvm/IR/IntrinsicsR600.h"
 #include "llvm/IR/IntrinsicsRISCV.h"
 #include "llvm/IR/IntrinsicsS390.h"
-#include "llvm/IR/IntrinsicsSPIRV.h"
 #include "llvm/IR/IntrinsicsVE.h"
-#include "llvm/IR/IntrinsicsWebAssembly.h"
 #include "llvm/IR/IntrinsicsX86.h"
 #include "llvm/IR/IntrinsicsXCore.h"
 #include "llvm/IR/Module.h"
diff --git a/llvm/lib/IR/LLVMContextImpl.cpp b/llvm/lib/IR/LLVMContextImpl.cpp
index f2c965a45df3ae..5e51b3ca4e87d0 100644
--- a/llvm/lib/IR/LLVMContextImpl.cpp
+++ b/llvm/lib/IR/LLVMContextImpl.cpp
@@ -15,7 +15,6 @@
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/StringMapEntry.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/DiagnosticHandler.h"
 #include "llvm/IR/LLVMRemarkStreamer.h"
 #include "llvm/IR/Module.h"
@@ -24,10 +23,8 @@
 #include "llvm/IR/Use.h"
 #include "llvm/IR/User.h"
 #include "llvm/Remarks/RemarkStreamer.h"
-#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/TypeSize.h"
 #include <cassert>
 #include <utility>
 
diff --git a/llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp b/llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp
index 19f438d890aee8..819cad3366787e 100644
--- a/llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp
+++ b/llvm/lib/IR/MemoryModelRelaxationAnnotations.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/MemoryModelRelaxationAnnotations.h"
-#include "llvm/ADT/StringSet.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/Support/Debug.h"
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index ea2d1dc8440bce..28f2ca550f5ec9 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -47,7 +47,6 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include <algorithm>
 #include <cassert>
 #include <cstddef>
 #include <cstdint>
diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp
index ab48d3e4101b72..7f5c0159e1764c 100644
--- a/llvm/lib/IR/Module.cpp
+++ b/llvm/lib/IR/Module.cpp
@@ -44,7 +44,6 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/RandomNumberGenerator.h"
 #include "llvm/Support/VersionTuple.h"
-#include <algorithm>
 #include <cassert>
 #include <cstdint>
 #include <memory>
diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp
index 4d2fbdde3f9f08..5441228b3291ee 100644
--- a/llvm/lib/IR/ProfDataUtils.cpp
+++ b/llvm/lib/IR/ProfDataUtils.cpp
@@ -12,7 +12,6 @@
 
 #include "llvm/IR/ProfDataUtils.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/Twine.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instructions.h"
@@ -20,8 +19,6 @@
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/ProfDataUtils.h"
-#include "llvm/Support/BranchProbability.h"
-#include "llvm/Support/CommandLine.h"
 
 using namespace llvm;
 
diff --git a/llvm/lib/IR/SSAContext.cpp b/llvm/lib/IR/SSAContext.cpp
index 220abe3083ebd7..20b6ea1e972d4a 100644
--- a/llvm/lib/IR/SSAContext.cpp
+++ b/llvm/lib/IR/SSAContext.cpp
@@ -13,7 +13,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/SSAContext.h"
-#include "llvm/IR/Argument.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/Instructions.h"
diff --git a/llvm/lib/IR/StructuralHash.cpp b/llvm/lib/IR/StructuralHash.cpp
index a51f9124af04da..ccc534a8904191 100644
--- a/llvm/lib/IR/StructuralHash.cpp
+++ b/llvm/lib/IR/StructuralHash.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/IR/StructuralHash.h"
-#include "llvm/ADT/Hashing.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/InstrTypes.h"
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index ffcab98db9aa02..85e60452b75c3d 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -53,13 +53,11 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/MapVector.h"
-#include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/BinaryFormat/Dwarf.h"

@MaskRay
Copy link
Member

MaskRay commented Nov 2, 2024

Can you share the commands you use the ensure this doesn't regress IWYU?

@kazutakahirata
Copy link
Contributor Author

Can you share the commands you use the ensure this doesn't regress IWYU?

Sure. I have a hacky script that post-processes the result from clang-tidy.

  • I only handle straightforward removals.
  • I keep includes of macro-oriented header files like llvm-config.h, config.h, and Compiler.h to avoid causing problems that my build environment might miss.
  • I remove one include at a time and do a test build.
#!/bin/sh

set -e

# The build directory.
BUILD_DIR="$1"

# The path filter
PATH_FILTER="$2"

RESULT="$(mktemp)"

check_local_changes()
{
  echo "$(date): Checking for local changes..."
  if [ $(git diff | wc -l) != "0" ]; then
    echo "There are some uncommitted local changed."
    git diff
    exit 1
  fi
  echo "$(date): Done"
}

process_one_file()
{
  local file="$1"
  local line

  echo "$(date): Processing $file"
  "$BUILD_DIR/bin/clang-tidy" -p "$BUILD_DIR" \
    -checks=-*,misc-include-cleaner "$file" 2>&1 | \
    grep "not used directly" | \
    grep -vE " (llvm-config.h|config.h|Compiler.h) " | \
    tac | while IFS= read line ; do \
    file="$(echo $line | cut -d: -f1)"
    lineno="$(echo $line | cut -d: -f2)"
    sed -e "${lineno}d" -i "$file"
    echo "$(date): Trying:"
    git diff
    if ninja -j140 -C "$BUILD_DIR" ; then
      echo "$(date): Accepting:"
      git commit -a --amend --no-edit
    else
      echo "$(date): Rejecting:"
      git checkout .
    fi
  done
}

check_local_changes

git commit --allow-empty -m "[...] Remove unused includes (NFC)"

find | grep "$PATH_FILTER" | sort | while IFS= read line ; do \
  process_one_file "$line"
done

@kazutakahirata kazutakahirata merged commit 6f10b65 into llvm:main Nov 2, 2024
8 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_unused_includes_IR branch November 2, 2024 23:54
smallp-o-p pushed a commit to smallp-o-p/llvm-project that referenced this pull request Nov 3, 2024
Identified with misc-include-cleaner.
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
Identified with misc-include-cleaner.
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
Identified with misc-include-cleaner.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants