Skip to content

Commit 4b198d6

Browse files
committed
Auto merge of rust-lang#132584 - Zalathar:includes, r=cuviper
Trim and tidy includes in `rustc_llvm` These includes tend to accumulate over time, and are usually only removed when something breaks in a new LLVM version, so it's nice to clean them up manually once in a while. General strategy used for this PR: - Remove all includes from `LLVMWrapper.h` that aren't needed by the header itself, transplanting them to individual source files as necessary. - For each source file, temporarily remove each include if doing so doesn't cause a compile error. - If a “required” include looks like it shouldn't be needed, try replacing it with its sub-includes, then trim that list. - After doing all of the above, go back and re-add any removed include if the file does actually use things defined in that header, even if the header happens to also be included by something else.
2 parents 62bb2ac + 920d277 commit 4b198d6

File tree

7 files changed

+145
-164
lines changed

7 files changed

+145
-164
lines changed

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub enum DLLStorageClass {
204204
DllExport = 2, // Function to be accessible from DLL.
205205
}
206206

207-
/// Matches LLVMRustAttribute in LLVMWrapper.h
207+
/// Must match the layout of `LLVMRustAttributeKind`.
208208
/// Semantically a subset of the C++ enum llvm::Attribute::AttrKind,
209209
/// though it is not ABI compatible (since it's a C++ enum)
210210
#[repr(C)]

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include "LLVMWrapper.h"
2+
23
#include "llvm/ADT/ArrayRef.h"
4+
#include "llvm/ADT/SmallVector.h"
5+
#include "llvm/ADT/StringRef.h"
6+
#include "llvm/IR/Module.h"
37
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
48
#include "llvm/ProfileData/Coverage/CoverageMappingWriter.h"
59
#include "llvm/ProfileData/InstrProf.h"
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,23 @@
1+
#ifndef INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
2+
#define INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H
3+
14
#include "SuppressLLVMWarnings.h"
25

3-
#include "llvm-c/BitReader.h"
4-
#include "llvm-c/Core.h"
5-
#include "llvm-c/Object.h"
6-
#include "llvm/ADT/ArrayRef.h"
7-
#include "llvm/ADT/DenseSet.h"
8-
#include "llvm/ADT/SmallVector.h"
9-
#include "llvm/Analysis/Lint.h"
10-
#include "llvm/Analysis/Passes.h"
11-
#include "llvm/IR/IRBuilder.h"
12-
#include "llvm/IR/InlineAsm.h"
13-
#include "llvm/IR/LLVMContext.h"
14-
#include "llvm/IR/Module.h"
15-
#include "llvm/Support/CommandLine.h"
16-
#include "llvm/Support/Debug.h"
17-
#include "llvm/Support/DynamicLibrary.h"
18-
#include "llvm/Support/FormattedStream.h"
19-
#include "llvm/Support/JSON.h"
20-
#include "llvm/Support/Memory.h"
21-
#include "llvm/Support/SourceMgr.h"
22-
#include "llvm/Support/TargetSelect.h"
23-
#include "llvm/Support/Timer.h"
24-
#include "llvm/Support/raw_ostream.h"
25-
#include "llvm/Target/TargetMachine.h"
26-
#include "llvm/Target/TargetOptions.h"
27-
#include "llvm/Transforms/IPO.h"
28-
#include "llvm/Transforms/Scalar.h"
6+
#include "llvm/Config/llvm-config.h" // LLVM_VERSION_MAJOR, LLVM_VERSION_MINOR
7+
#include "llvm/Support/raw_ostream.h" // llvm::raw_ostream
8+
#include <cstddef> // size_t etc
9+
#include <cstdint> // uint64_t etc
2910

3011
#define LLVM_VERSION_GE(major, minor) \
3112
(LLVM_VERSION_MAJOR > (major) || \
3213
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
3314

3415
#define LLVM_VERSION_LT(major, minor) (!LLVM_VERSION_GE((major), (minor)))
3516

36-
#if LLVM_VERSION_GE(20, 0)
37-
#include "llvm/Transforms/Utils/Instrumentation.h"
38-
#else
39-
#include "llvm/Transforms/Instrumentation.h"
40-
#endif
41-
42-
#include "llvm/IR/LegacyPassManager.h"
43-
44-
#include "llvm/Bitcode/BitcodeReader.h"
45-
#include "llvm/Bitcode/BitcodeWriter.h"
46-
47-
#include "llvm/IR/DIBuilder.h"
48-
#include "llvm/IR/DebugInfo.h"
49-
#include "llvm/IR/IRPrintingPasses.h"
50-
#include "llvm/Linker/Linker.h"
51-
52-
#include "llvm/TargetParser/Triple.h"
53-
5417
extern "C" void LLVMRustSetLastError(const char *);
5518

5619
enum class LLVMRustResult { Success, Failure };
5720

58-
enum LLVMRustAttribute {
59-
AlwaysInline = 0,
60-
ByVal = 1,
61-
Cold = 2,
62-
InlineHint = 3,
63-
MinSize = 4,
64-
Naked = 5,
65-
NoAlias = 6,
66-
NoCapture = 7,
67-
NoInline = 8,
68-
NonNull = 9,
69-
NoRedZone = 10,
70-
NoReturn = 11,
71-
NoUnwind = 12,
72-
OptimizeForSize = 13,
73-
ReadOnly = 14,
74-
SExt = 15,
75-
StructRet = 16,
76-
UWTable = 17,
77-
ZExt = 18,
78-
InReg = 19,
79-
SanitizeThread = 20,
80-
SanitizeAddress = 21,
81-
SanitizeMemory = 22,
82-
NonLazyBind = 23,
83-
OptimizeNone = 24,
84-
ReadNone = 26,
85-
SanitizeHWAddress = 28,
86-
WillReturn = 29,
87-
StackProtectReq = 30,
88-
StackProtectStrong = 31,
89-
StackProtect = 32,
90-
NoUndef = 33,
91-
SanitizeMemTag = 34,
92-
NoCfCheck = 35,
93-
ShadowCallStack = 36,
94-
AllocSize = 37,
95-
AllocatedPointer = 38,
96-
AllocAlign = 39,
97-
SanitizeSafeStack = 40,
98-
FnRetThunkExtern = 41,
99-
Writable = 42,
100-
DeadOnUnwind = 43,
101-
};
102-
10321
typedef struct OpaqueRustString *RustStringRef;
10422
typedef struct LLVMOpaqueTwine *LLVMTwineRef;
10523
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
@@ -127,3 +45,5 @@ class RawRustStringOstream : public llvm::raw_ostream {
12745
flush();
12846
}
12947
};
48+
49+
#endif // INCLUDED_RUSTC_LLVM_LLVMWRAPPER_H

compiler/rustc_llvm/llvm-wrapper/Linker.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#include "llvm/Linker/Linker.h"
2-
#include "SuppressLLVMWarnings.h"
3-
41
#include "LLVMWrapper.h"
52

3+
#include "llvm/Bitcode/BitcodeReader.h"
4+
#include "llvm/IR/Module.h"
5+
#include "llvm/Linker/Linker.h"
6+
#include "llvm/Support/MemoryBuffer.h"
7+
68
using namespace llvm;
79

810
struct RustLinker {

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
#include <stdio.h>
2-
3-
#include <cstddef>
4-
#include <iomanip>
5-
#include <set>
6-
#include <vector>
7-
81
#include "LLVMWrapper.h"
92

10-
#include "llvm/Analysis/AliasAnalysis.h"
3+
#include "llvm-c/Core.h"
4+
#include "llvm/ADT/ArrayRef.h"
5+
#include "llvm/ADT/DenseSet.h"
6+
#include "llvm/ADT/SmallVector.h"
7+
#include "llvm/Analysis/Lint.h"
118
#include "llvm/Analysis/TargetLibraryInfo.h"
12-
#include "llvm/Analysis/TargetTransformInfo.h"
139
#include "llvm/Bitcode/BitcodeWriter.h"
1410
#include "llvm/CodeGen/CommandFlags.h"
15-
#include "llvm/CodeGen/TargetSubtargetInfo.h"
1611
#include "llvm/IR/AssemblyAnnotationWriter.h"
1712
#include "llvm/IR/AutoUpgrade.h"
18-
#include "llvm/IR/IntrinsicInst.h"
13+
#include "llvm/IR/LegacyPassManager.h"
14+
#include "llvm/IR/PassManager.h"
1915
#include "llvm/IR/Verifier.h"
2016
#include "llvm/LTO/LTO.h"
17+
#include "llvm/MC/MCSubtargetInfo.h"
2118
#include "llvm/MC/TargetRegistry.h"
22-
#include "llvm/Object/IRObjectFile.h"
2319
#include "llvm/Object/ObjectFile.h"
2420
#include "llvm/Passes/PassBuilder.h"
2521
#include "llvm/Passes/PassPlugin.h"
@@ -30,25 +26,28 @@
3026
#include "llvm/Support/VirtualFileSystem.h"
3127
#include "llvm/Target/TargetMachine.h"
3228
#include "llvm/TargetParser/Host.h"
33-
#include "llvm/Transforms/IPO/AlwaysInliner.h"
3429
#include "llvm/Transforms/IPO/FunctionImport.h"
3530
#include "llvm/Transforms/IPO/Internalize.h"
3631
#include "llvm/Transforms/IPO/LowerTypeTests.h"
3732
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
3833
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
3934
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
40-
#include "llvm/Transforms/Utils/AddDiscriminators.h"
41-
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
42-
#if LLVM_VERSION_GE(19, 0)
43-
#include "llvm/Support/PGOOptions.h"
44-
#endif
4535
#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
4636
#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
4737
#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
4838
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
49-
#include "llvm/Transforms/Utils.h"
5039
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
40+
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
5141
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
42+
#include <set>
43+
#include <string>
44+
#include <vector>
45+
46+
// Conditional includes prevent clang-format from fully sorting the list,
47+
// so keep them separate.
48+
#if LLVM_VERSION_GE(19, 0)
49+
#include "llvm/Support/PGOOptions.h"
50+
#endif
5251

5352
using namespace llvm;
5453

0 commit comments

Comments
 (0)