Skip to content

Commit 75e164f

Browse files
author
serge-sans-paille
committed
[llvm] Cleanup header dependencies in ADT and Support
The cleanup was manual, but assisted by "include-what-you-use". It consists in 1. Removing unused forward declaration. No impact expected. 2. Removing unused headers in .cpp files. No impact expected. 3. Removing unused headers in .h files. This removes implicit dependencies and is generally considered a good thing, but this may break downstream builds. I've updated llvm, clang, lld, lldb and mlir deps, and included a list of the modification in the second part of the commit. 4. Replacing header inclusion by forward declaration. This has the same impact as 3. Notable changes: - llvm/Support/TargetParser.h no longer includes llvm/Support/AArch64TargetParser.h nor llvm/Support/ARMTargetParser.h - llvm/Support/TypeSize.h no longer includes llvm/Support/WithColor.h - llvm/Support/YAMLTraits.h no longer includes llvm/Support/Regex.h - llvm/ADT/SmallVector.h no longer includes llvm/Support/MemAlloc.h nor llvm/Support/ErrorHandling.h You may need to add some of these headers in your compilation units, if needs be. As an hint to the impact of the cleanup, running clang++ -E -Iinclude -I../llvm/include ../llvm/lib/Support/*.cpp -std=c++14 -fno-rtti -fno-exceptions | wc -l before: 8000919 lines after: 7917500 lines Reduced dependencies also helps incremental rebuilds and is more ccache friendly, something not shown by the above metric :-) Discourse thread on the topic: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
1 parent 0abaf64 commit 75e164f

File tree

90 files changed

+63
-93
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+63
-93
lines changed

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "OSTargets.h"
1717
#include "clang/Basic/TargetBuiltins.h"
18+
#include "llvm/Support/AArch64TargetParser.h"
1819
#include "llvm/Support/TargetParser.h"
1920

2021
namespace clang {

clang/lib/Basic/Targets/ARM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/TargetOptions.h"
1919
#include "llvm/ADT/Triple.h"
2020
#include "llvm/Support/Compiler.h"
21+
#include "llvm/Support/ARMTargetParser.h"
2122
#include "llvm/Support/TargetParser.h"
2223

2324
namespace clang {

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringSwitch.h"
1717
#include "llvm/Support/Path.h"
1818
#include "llvm/Support/SpecialCaseList.h"
19+
#include "llvm/Support/AArch64TargetParser.h"
1920
#include "llvm/Support/TargetParser.h"
2021
#include "llvm/Support/VirtualFileSystem.h"
2122
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"

clang/lib/Driver/ToolChains/Arch/AArch64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "clang/Driver/DriverDiagnostic.h"
1212
#include "clang/Driver/Options.h"
1313
#include "llvm/Option/ArgList.h"
14+
#include "llvm/Support/AArch64TargetParser.h"
1415
#include "llvm/Support/TargetParser.h"
1516
#include "llvm/Support/Host.h"
1617

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "clang/Driver/Options.h"
1313
#include "llvm/ADT/StringSwitch.h"
1414
#include "llvm/Option/ArgList.h"
15+
#include "llvm/Support/ARMTargetParser.h"
1516
#include "llvm/Support/TargetParser.h"
1617
#include "llvm/Support/Host.h"
1718

clang/lib/Driver/ToolChains/Arch/ARM.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/StringRef.h"
1414
#include "llvm/ADT/Triple.h"
1515
#include "llvm/Option/Option.h"
16+
#include "llvm/Support/ARMTargetParser.h"
1617
#include "llvm/Support/TargetParser.h"
1718
#include <string>
1819
#include <vector>

clang/tools/libclang/BuildSystem.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/Support/CBindingWrapping.h"
1717
#include "llvm/Support/Chrono.h"
1818
#include "llvm/Support/ErrorHandling.h"
19+
#include "llvm/Support/MemAlloc.h"
1920
#include "llvm/Support/Path.h"
2021
#include "llvm/Support/VirtualFileSystem.h"
2122
#include "llvm/Support/raw_ostream.h"

lldb/source/Host/common/Socket.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/Support/Errno.h"
2020
#include "llvm/Support/Error.h"
21+
#include "llvm/Support/Regex.h"
2122
#include "llvm/Support/WindowsError.h"
2223

2324
#if LLDB_ENABLE_POSIX

llvm/include/llvm/ADT/Optional.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "llvm/Support/Compiler.h"
2222
#include "llvm/Support/type_traits.h"
2323
#include <cassert>
24-
#include <memory>
2524
#include <new>
2625
#include <utility>
2726

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
#include "llvm/ADT/iterator_range.h"
1717
#include "llvm/Support/Compiler.h"
18-
#include "llvm/Support/ErrorHandling.h"
19-
#include "llvm/Support/MemAlloc.h"
2018
#include "llvm/Support/type_traits.h"
2119
#include <algorithm>
2220
#include <cassert>

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Support/Error.h"
2828
#include "llvm/Support/MD5.h"
2929
#include "llvm/Support/SMLoc.h"
30+
#include "llvm/Support/ARMTargetParser.h"
3031
#include "llvm/Support/TargetParser.h"
3132
#include "llvm/Support/VersionTuple.h"
3233
#include <cassert>

llvm/include/llvm/Object/ELFObjectFile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/Support/Error.h"
3535
#include "llvm/Support/ErrorHandling.h"
3636
#include "llvm/Support/MemoryBuffer.h"
37+
#include "llvm/Support/ScopedPrinter.h"
3738
#include <cassert>
3839
#include <cstdint>
3940
#include <system_error>

llvm/include/llvm/Support/AArch64TargetParser.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_SUPPORT_AARCH64TARGETPARSER_H
1515
#define LLVM_SUPPORT_AARCH64TARGETPARSER_H
1616

17-
#include "llvm/ADT/SmallVector.h"
1817
#include "llvm/ADT/StringRef.h"
1918
#include "llvm/Support/ARMTargetParser.h"
2019
#include <vector>

llvm/include/llvm/Support/ARMAttributeParser.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111

1212
#include "ARMBuildAttributes.h"
1313
#include "ELFAttributeParser.h"
14-
#include "ScopedPrinter.h"
15-
#include "llvm/ADT/ArrayRef.h"
16-
#include "llvm/Support/DataExtractor.h"
17-
#include "llvm/Support/Endian.h"
14+
#include "llvm/ADT/StringRef.h"
1815
#include "llvm/Support/Error.h"
1916

2017
namespace llvm {
2118

19+
class ScopedPrinter;
20+
2221
class ARMAttributeParser : public ELFAttributeParser {
2322
struct DisplayHandler {
2423
ARMBuildAttrs::AttrType attribute;

llvm/include/llvm/Support/Allocator.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,12 @@
2222
#include "llvm/Support/Alignment.h"
2323
#include "llvm/Support/AllocatorBase.h"
2424
#include "llvm/Support/Compiler.h"
25-
#include "llvm/Support/ErrorHandling.h"
2625
#include "llvm/Support/MathExtras.h"
27-
#include "llvm/Support/MemAlloc.h"
2826
#include <algorithm>
2927
#include <cassert>
3028
#include <cstddef>
3129
#include <cstdint>
32-
#include <cstdlib>
3330
#include <iterator>
34-
#include <type_traits>
3531
#include <utility>
3632

3733
namespace llvm {

llvm/include/llvm/Support/BinaryStreamReader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
#define LLVM_SUPPORT_BINARYSTREAMREADER_H
1111

1212
#include "llvm/ADT/ArrayRef.h"
13-
#include "llvm/ADT/STLExtras.h"
1413
#include "llvm/ADT/StringRef.h"
1514
#include "llvm/Support/Alignment.h"
1615
#include "llvm/Support/BinaryStreamArray.h"
1716
#include "llvm/Support/BinaryStreamRef.h"
1817
#include "llvm/Support/ConvertUTF.h"
1918
#include "llvm/Support/Endian.h"
2019
#include "llvm/Support/Error.h"
21-
#include "llvm/Support/type_traits.h"
2220
#include <type_traits>
2321

2422
namespace llvm {

llvm/include/llvm/Support/BinaryStreamRef.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include "llvm/Support/BinaryStream.h"
1515
#include "llvm/Support/BinaryStreamError.h"
1616
#include "llvm/Support/Error.h"
17-
#include <algorithm>
1817
#include <cstdint>
1918
#include <memory>
2019

llvm/include/llvm/Support/BinaryStreamWriter.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define LLVM_SUPPORT_BINARYSTREAMWRITER_H
1111

1212
#include "llvm/ADT/ArrayRef.h"
13-
#include "llvm/ADT/STLExtras.h"
1413
#include "llvm/ADT/StringRef.h"
1514
#include "llvm/Support/BinaryStreamArray.h"
1615
#include "llvm/Support/BinaryStreamError.h"

llvm/include/llvm/Support/BlockFrequency.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
#ifndef LLVM_SUPPORT_BLOCKFREQUENCY_H
1414
#define LLVM_SUPPORT_BLOCKFREQUENCY_H
1515

16-
#include "llvm/Support/BranchProbability.h"
17-
#include "llvm/Support/DataTypes.h"
16+
#include <cstdint>
1817

1918
namespace llvm {
2019

21-
class raw_ostream;
20+
class BranchProbability;
2221

2322
// This class represents Block Frequency as a 64-bit value.
2423
class BlockFrequency {

llvm/include/llvm/Support/BranchProbability.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/Support/DataTypes.h"
1717
#include <algorithm>
1818
#include <cassert>
19-
#include <climits>
2019
#include <numeric>
2120

2221
namespace llvm {

llvm/include/llvm/Support/ConvertUTF.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191

9292
#include <cstddef>
9393
#include <string>
94-
#include <system_error>
9594

9695
// Wrap everything in namespace llvm so that programs can link with llvm and
9796
// their own version of the unicode libraries.

llvm/include/llvm/Support/ELFAttributeParser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
#define LLVM_SUPPORT_ELFATTRIBUTEPARSER_H
1111

1212
#include "ELFAttributes.h"
13-
#include "ScopedPrinter.h"
1413
#include "llvm/ADT/ArrayRef.h"
1514
#include "llvm/Support/DataExtractor.h"
15+
#include "llvm/Support/Endian.h"
1616
#include "llvm/Support/Error.h"
1717

1818
#include <unordered_map>
1919

2020
namespace llvm {
2121
class StringRef;
22+
class ScopedPrinter;
2223

2324
class ELFAttributeParser {
2425
StringRef vendor;

llvm/include/llvm/Support/Error.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#define LLVM_SUPPORT_ERROR_H
1515

1616
#include "llvm-c/Error.h"
17-
#include "llvm/ADT/STLExtras.h"
1817
#include "llvm/ADT/SmallVector.h"
1918
#include "llvm/ADT/StringExtras.h"
2019
#include "llvm/ADT/Twine.h"

llvm/include/llvm/Support/ExtensibleRTTI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262

6363
namespace llvm {
6464

65-
template <typename ThisT, typename ParentT> class RTTIExtends;
66-
6765
/// Base class for the extensible RTTI hierarchy.
6866
///
6967
/// This class defines virtual methods, dynamicClassID and isA, that enable

llvm/include/llvm/Support/FileCollector.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef LLVM_SUPPORT_FILECOLLECTOR_H
1010
#define LLVM_SUPPORT_FILECOLLECTOR_H
1111

12-
#include "llvm/ADT/SmallVector.h"
1312
#include "llvm/ADT/StringMap.h"
1413
#include "llvm/ADT/StringSet.h"
1514
#include "llvm/Support/VirtualFileSystem.h"

llvm/include/llvm/Support/FileUtilities.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#define LLVM_SUPPORT_FILEUTILITIES_H
1616

1717
#include "llvm/ADT/StringRef.h"
18-
#include "llvm/Support/Errc.h"
19-
#include "llvm/Support/ErrorHandling.h"
18+
#include "llvm/Support/Error.h"
2019
#include "llvm/Support/FileSystem.h"
21-
#include "llvm/Support/Path.h"
20+
21+
#include <system_error>
2222

2323
namespace llvm {
2424

llvm/include/llvm/Support/FormatVariadic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@
2929
#include "llvm/ADT/Optional.h"
3030
#include "llvm/ADT/STLExtras.h"
3131
#include "llvm/ADT/SmallString.h"
32+
#include "llvm/ADT/SmallVector.h"
3233
#include "llvm/ADT/StringRef.h"
3334
#include "llvm/Support/FormatCommon.h"
3435
#include "llvm/Support/FormatProviders.h"
3536
#include "llvm/Support/FormatVariadicDetails.h"
3637
#include "llvm/Support/raw_ostream.h"
38+
#include <array>
3739
#include <cstddef>
3840
#include <string>
3941
#include <tuple>
4042
#include <utility>
41-
#include <vector>
4243

4344
namespace llvm {
4445

llvm/include/llvm/Support/GraphWriter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#include "llvm/Support/DOTGraphTraits.h"
2929
#include "llvm/Support/FileSystem.h"
3030
#include "llvm/Support/raw_ostream.h"
31-
#include <algorithm>
32-
#include <cstddef>
3331
#include <iterator>
3432
#include <string>
3533
#include <type_traits>

llvm/include/llvm/Support/ItaniumManglingCanonicalizer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
1515
#define LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
1616

17-
#include <cstddef>
1817
#include <cstdint>
1918

2019
namespace llvm {

llvm/include/llvm/Support/RISCVISAInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#ifndef LLVM_SUPPORT_RISCVISAINFO_H
1010
#define LLVM_SUPPORT_RISCVISAINFO_H
1111

12-
#include "llvm/ADT/Optional.h"
13-
#include "llvm/ADT/StringMap.h"
1412
#include "llvm/ADT/StringRef.h"
1513
#include "llvm/Support/Error.h"
1614

llvm/include/llvm/Support/SymbolRemappingReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@
6262
#include "llvm/ADT/StringRef.h"
6363
#include "llvm/Support/Error.h"
6464
#include "llvm/Support/ItaniumManglingCanonicalizer.h"
65-
#include "llvm/Support/MemoryBuffer.h"
6665

6766
namespace llvm {
6867

68+
class MemoryBuffer;
69+
6970
class SymbolRemappingParseError : public ErrorInfo<SymbolRemappingParseError> {
7071
public:
7172
SymbolRemappingParseError(StringRef File, int64_t Line, const Twine &Message)

llvm/include/llvm/Support/TargetParser.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
// FIXME: vector is used because that's what clang uses for subtarget feature
1818
// lists, but SmallVector would probably be better
1919
#include "llvm/ADT/Triple.h"
20-
#include "llvm/Support/AArch64TargetParser.h"
21-
#include "llvm/Support/ARMTargetParser.h"
2220
#include "llvm/Support/RISCVISAInfo.h"
2321
#include <vector>
2422

llvm/include/llvm/Support/TimeProfiler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
#define LLVM_SUPPORT_TIMEPROFILER_H
1111

1212
#include "llvm/Support/Error.h"
13-
#include "llvm/Support/raw_ostream.h"
1413

1514
namespace llvm {
1615

16+
class raw_pwrite_stream;
17+
1718
struct TimeTraceProfiler;
1819
TimeTraceProfiler *getTimeTraceProfilerInstance();
1920

llvm/include/llvm/Support/Timer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
#include "llvm/Support/DataTypes.h"
1515
#include <cassert>
1616
#include <string>
17-
#include <utility>
1817
#include <vector>
1918

2019
namespace llvm {
2120

22-
class Timer;
2321
class TimerGroup;
2422
class raw_ostream;
2523

llvm/include/llvm/Support/TrigramIndex.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <vector>
3434

3535
namespace llvm {
36-
class StringRef;
3736

3837
class TrigramIndex {
3938
public:

llvm/include/llvm/Support/TypeSize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "llvm/ADT/ArrayRef.h"
1919
#include "llvm/Support/MathExtras.h"
20-
#include "llvm/Support/WithColor.h"
20+
#include "llvm/Support/raw_ostream.h"
2121

2222
#include <algorithm>
2323
#include <array>

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,13 @@
1818
#include "llvm/Support/AlignOf.h"
1919
#include "llvm/Support/Allocator.h"
2020
#include "llvm/Support/Endian.h"
21-
#include "llvm/Support/Regex.h"
2221
#include "llvm/Support/SMLoc.h"
2322
#include "llvm/Support/SourceMgr.h"
2423
#include "llvm/Support/VersionTuple.h"
2524
#include "llvm/Support/YAMLParser.h"
2625
#include "llvm/Support/raw_ostream.h"
2726
#include <cassert>
2827
#include <cctype>
29-
#include <cstddef>
30-
#include <cstdint>
31-
#include <iterator>
3228
#include <map>
3329
#include <memory>
3430
#include <new>

llvm/lib/Debuginfod/Debuginfod.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
#include "llvm/Debuginfod/HTTPClient.h"
2222
#include "llvm/Support/CachePruning.h"
2323
#include "llvm/Support/Caching.h"
24+
#include "llvm/Support/Errc.h"
2425
#include "llvm/Support/Error.h"
2526
#include "llvm/Support/FileUtilities.h"
27+
#include "llvm/Support/Path.h"
2628
#include "llvm/Support/xxhash.h"
2729

2830
namespace llvm {

0 commit comments

Comments
 (0)