Skip to content

Commit af450ea

Browse files
committed
Avoid including FileSystem.h from MemoryBuffer.h
Lots of headers pass around MemoryBuffer objects, but very few open them. Let those that do include FileSystem.h. Saves ~250 includes of Chrono.h & FileSystem.h: $ diff -u thedeps-before.txt thedeps-after.txt | grep '^[-+] ' | sort | uniq -c | sort -nr 254 - ../llvm/include/llvm/Support/FileSystem.h 253 - ../llvm/include/llvm/Support/Chrono.h 237 - ../llvm/include/llvm/Support/NativeFormatting.h 237 - ../llvm/include/llvm/Support/FormatProviders.h 192 - ../llvm/include/llvm/ADT/StringSwitch.h 190 - ../llvm/include/llvm/Support/FormatVariadicDetails.h ... This requires duplicating the file_t typedef, which is unfortunate. I sunk the choice of mapping mode down into the cpp file using variable template specializations instead of class members in headers.
1 parent 798e661 commit af450ea

File tree

20 files changed

+47
-11
lines changed

20 files changed

+47
-11
lines changed

clang/lib/Frontend/SerializedDiagnosticPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/ADT/StringRef.h"
2323
#include "llvm/Bitstream/BitCodes.h"
2424
#include "llvm/Bitstream/BitstreamReader.h"
25+
#include "llvm/Support/FileSystem.h"
2526
#include "llvm/Support/raw_ostream.h"
2627
#include <utility>
2728

clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/CharInfo.h"
1919
#include "clang/Basic/Diagnostic.h"
2020
#include "clang/Lex/LexDiagnostic.h"
21+
#include "llvm/ADT/StringMap.h"
2122
#include "llvm/ADT/StringSwitch.h"
2223
#include "llvm/Support/MemoryBuffer.h"
2324

clang/tools/libclang/CIndexer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/Driver/Driver.h"
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/ADT/SmallString.h"
20+
#include "llvm/Support/FileSystem.h"
2021
#include "llvm/Support/MD5.h"
2122
#include "llvm/Support/Path.h"
2223
#include "llvm/Support/Program.h"

clang/utils/TableGen/ClangDiagnosticsEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/ADT/SmallString.h"
2020
#include "llvm/ADT/SmallVector.h"
2121
#include "llvm/ADT/StringMap.h"
22+
#include "llvm/ADT/StringSwitch.h"
2223
#include "llvm/ADT/Twine.h"
2324
#include "llvm/Support/Casting.h"
2425
#include "llvm/TableGen/Error.h"

clang/utils/TableGen/MveEmitter.cpp

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

6161
#include "llvm/ADT/APInt.h"
6262
#include "llvm/ADT/StringRef.h"
63+
#include "llvm/ADT/StringSwitch.h"
6364
#include "llvm/Support/Casting.h"
6465
#include "llvm/Support/raw_ostream.h"
6566
#include "llvm/TableGen/Error.h"

llvm/include/llvm/BinaryFormat/MsgPackReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#ifndef LLVM_SUPPORT_MSGPACKREADER_H
3434
#define LLVM_SUPPORT_MSGPACKREADER_H
3535

36+
#include "llvm/Support/Error.h"
3637
#include "llvm/Support/MemoryBuffer.h"
3738
#include "llvm/Support/raw_ostream.h"
3839
#include <cstdint>

llvm/include/llvm/Bitstream/BitstreamReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/SmallVector.h"
1919
#include "llvm/Bitstream/BitCodes.h"
2020
#include "llvm/Support/Endian.h"
21+
#include "llvm/Support/Error.h"
2122
#include "llvm/Support/ErrorHandling.h"
2223
#include "llvm/Support/MathExtras.h"
2324
#include "llvm/Support/MemoryBuffer.h"

llvm/include/llvm/Support/MemoryBuffer.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/Twine.h"
2020
#include "llvm/Support/CBindingWrapping.h"
2121
#include "llvm/Support/ErrorOr.h"
22-
#include "llvm/Support/FileSystem.h"
2322
#include <cstddef>
2423
#include <cstdint>
2524
#include <memory>
@@ -28,6 +27,18 @@ namespace llvm {
2827

2928
class MemoryBufferRef;
3029

30+
namespace sys {
31+
namespace fs {
32+
// Duplicated from FileSystem.h to avoid a dependency.
33+
#if defined(_WIN32)
34+
// A Win32 HANDLE is a typedef of void*
35+
using file_t = void *;
36+
#else
37+
using file_t = int;
38+
#endif
39+
} // namespace fs
40+
} // namespace sys
41+
3142
/// This interface provides simple read-only access to a block of memory, and
3243
/// provides simple methods for reading files and standard input into a memory
3344
/// buffer. In addition to basic access to the characters in the file, this
@@ -48,9 +59,6 @@ class MemoryBuffer {
4859
void init(const char *BufStart, const char *BufEnd,
4960
bool RequiresNullTerminator);
5061

51-
static constexpr sys::fs::mapped_file_region::mapmode Mapmode =
52-
sys::fs::mapped_file_region::readonly;
53-
5462
public:
5563
MemoryBuffer(const MemoryBuffer &) = delete;
5664
MemoryBuffer &operator=(const MemoryBuffer &) = delete;
@@ -156,9 +164,6 @@ class WritableMemoryBuffer : public MemoryBuffer {
156164
protected:
157165
WritableMemoryBuffer() = default;
158166

159-
static constexpr sys::fs::mapped_file_region::mapmode Mapmode =
160-
sys::fs::mapped_file_region::priv;
161-
162167
public:
163168
using MemoryBuffer::getBuffer;
164169
using MemoryBuffer::getBufferEnd;
@@ -218,9 +223,6 @@ class WriteThroughMemoryBuffer : public MemoryBuffer {
218223
protected:
219224
WriteThroughMemoryBuffer() = default;
220225

221-
static constexpr sys::fs::mapped_file_region::mapmode Mapmode =
222-
sys::fs::mapped_file_region::readwrite;
223-
224226
public:
225227
using MemoryBuffer::getBuffer;
226228
using MemoryBuffer::getBufferEnd;

llvm/lib/BinaryFormat/AMDGPUMetadataVerifier.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//===----------------------------------------------------------------------===//
1313

1414
#include "llvm/BinaryFormat/AMDGPUMetadataVerifier.h"
15+
#include "llvm/ADT/StringSwitch.h"
1516
#include "llvm/Support/AMDGPUMetadata.h"
1617

1718
namespace llvm {

llvm/lib/ExecutionEngine/Orc/DebugUtils.cpp

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

99
#include "llvm/ExecutionEngine/Orc/DebugUtils.h"
1010
#include "llvm/Support/Debug.h"
11+
#include "llvm/Support/FileSystem.h"
1112
#include "llvm/Support/MemoryBuffer.h"
1213
#include "llvm/Support/Path.h"
1314
#include "llvm/Support/raw_ostream.h"

0 commit comments

Comments
 (0)