Skip to content

Commit ba7a92c

Browse files
committed
[Support] Don't include VirtualFileSystem.h in CommandLine.h
CommandLine.h is indirectly included in ~50% of TUs when building clang, and VirtualFileSystem.h is large. (Already remarked by jhenderson on D70769.) No behavior change. Differential Revision: https://reviews.llvm.org/D100957
1 parent 2f69975 commit ba7a92c

File tree

27 files changed

+65
-21
lines changed

27 files changed

+65
-21
lines changed

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "clang/Sema/CodeCompleteOptions.h"
1616
#include "clang/Serialization/ModuleFileExtension.h"
1717
#include "llvm/ADT/StringRef.h"
18+
#include "llvm/Support/MemoryBuffer.h"
1819
#include <cassert>
1920
#include <map>
2021
#include <memory>

clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class ExpandResponseFilesDatabase : public CompilationDatabase {
6060
continue;
6161
llvm::BumpPtrAllocator Alloc;
6262
llvm::StringSaver Saver(Alloc);
63-
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, *FS,
64-
llvm::StringRef(Cmd.Directory));
63+
llvm::cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false,
64+
llvm::StringRef(Cmd.Directory), *FS);
6565
// Don't assign directly, Argv aliases CommandLine.
6666
std::vector<std::string> ExpandedArgv(Argv.begin(), Argv.end());
6767
Cmd.CommandLine = std::move(ExpandedArgv);

clang/tools/apinotes-test/APINotesTest.cpp

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

99
#include "clang/APINotes/APINotesYAMLCompiler.h"
1010
#include "llvm/Support/CommandLine.h"
11+
#include "llvm/Support/FileSystem.h"
12+
#include "llvm/Support/MemoryBuffer.h"
1113
#include "llvm/Support/Signals.h"
1214
#include "llvm/Support/ToolOutputFile.h"
1315
#include "llvm/Support/WithColor.h"

clang/tools/clang-offload-wrapper/ClangOffloadWrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Support/Errc.h"
2828
#include "llvm/Support/Error.h"
2929
#include "llvm/Support/ErrorOr.h"
30+
#include "llvm/Support/FileSystem.h"
3031
#include "llvm/Support/MemoryBuffer.h"
3132
#include "llvm/Support/Signals.h"
3233
#include "llvm/Support/ToolOutputFile.h"

llvm/include/llvm/Support/CommandLine.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "llvm/ADT/iterator_range.h"
3232
#include "llvm/Support/ErrorHandling.h"
3333
#include "llvm/Support/ManagedStatic.h"
34-
#include "llvm/Support/VirtualFileSystem.h"
3534
#include "llvm/Support/raw_ostream.h"
3635
#include <cassert>
3736
#include <climits>
@@ -44,6 +43,10 @@
4443

4544
namespace llvm {
4645

46+
namespace vfs {
47+
class FileSystem;
48+
}
49+
4750
class StringSaver;
4851

4952
/// cl Namespace - This namespace contains all of the command line option
@@ -2091,11 +2094,18 @@ bool readConfigFile(StringRef CfgFileName, StringSaver &Saver,
20912094
/// \param [in] CurrentDir Path used to resolve relative rsp files. If set to
20922095
/// None, process' cwd is used instead.
20932096
/// \return true if all @files were expanded successfully or there were none.
2097+
bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
2098+
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
2099+
bool RelativeNames,
2100+
llvm::Optional<llvm::StringRef> CurrentDir,
2101+
llvm::vfs::FileSystem &FS);
2102+
2103+
/// An overload of ExpandResponseFiles() that uses
2104+
/// llvm::vfs::getRealFileSystem().
20942105
bool ExpandResponseFiles(
20952106
StringSaver &Saver, TokenizerCallback Tokenizer,
20962107
SmallVectorImpl<const char *> &Argv, bool MarkEOLs = false,
20972108
bool RelativeNames = false,
2098-
llvm::vfs::FileSystem &FS = *llvm::vfs::getRealFileSystem(),
20992109
llvm::Optional<llvm::StringRef> CurrentDir = llvm::None);
21002110

21012111
/// A convenience helper which concatenates the options specified by the

llvm/lib/Analysis/ModuleSummaryAnalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/Pass.h"
5151
#include "llvm/Support/Casting.h"
5252
#include "llvm/Support/CommandLine.h"
53+
#include "llvm/Support/FileSystem.h"
5354
#include <algorithm>
5455
#include <cassert>
5556
#include <cstdint>

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
#include "llvm/Support/CommandLine.h"
111111
#include "llvm/Support/Compiler.h"
112112
#include "llvm/Support/ErrorHandling.h"
113+
#include "llvm/Support/FileSystem.h"
113114
#include "llvm/Support/Format.h"
114115
#include "llvm/Support/MathExtras.h"
115116
#include "llvm/Support/Path.h"

llvm/lib/CodeGen/CommandFlags.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/MC/SubtargetFeature.h"
1818
#include "llvm/Support/CommandLine.h"
1919
#include "llvm/Support/Host.h"
20+
#include "llvm/Support/MemoryBuffer.h"
2021

2122
using namespace llvm;
2223

llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "llvm/CodeGen/GlobalISel/CSEInfo.h"
1212
#include "llvm/CodeGen/MachineRegisterInfo.h"
1313
#include "llvm/InitializePasses.h"
14+
#include "llvm/Support/Error.h"
1415

1516
#define DEBUG_TYPE "cseinfo"
1617

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/Object/IRObjectFile.h"
3636
#include "llvm/Support/CommandLine.h"
3737
#include "llvm/Support/Error.h"
38+
#include "llvm/Support/FileSystem.h"
3839
#include "llvm/Support/ManagedStatic.h"
3940
#include "llvm/Support/MemoryBuffer.h"
4041
#include "llvm/Support/Path.h"

llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/ADT/Triple.h"
2222
#include "llvm/Object/Binary.h"
23+
#include "llvm/Object/COFF.h"
2324
#include "llvm/Object/Error.h"
2425
#include "llvm/Object/MachOUniversal.h"
2526
#include "llvm/Object/ObjectFile.h"
26-
#include "llvm/Object/COFF.h"
2727
#include "llvm/ProfileData/InstrProf.h"
2828
#include "llvm/Support/Casting.h"
2929
#include "llvm/Support/Compression.h"
@@ -33,6 +33,7 @@
3333
#include "llvm/Support/ErrorHandling.h"
3434
#include "llvm/Support/LEB128.h"
3535
#include "llvm/Support/MathExtras.h"
36+
#include "llvm/Support/Path.h"
3637
#include "llvm/Support/raw_ostream.h"
3738
#include <vector>
3839

llvm/lib/Remarks/YAMLRemarkSerializer.cpp

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

1414
#include "llvm/Remarks/YAMLRemarkSerializer.h"
1515
#include "llvm/Support/CommandLine.h"
16+
#include "llvm/Support/FileSystem.h"
1617

1718
using namespace llvm;
1819
using namespace llvm::remarks;

llvm/lib/Support/CommandLine.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,8 +1138,9 @@ static llvm::Error ExpandResponseFile(
11381138
/// StringSaver and tokenization strategy.
11391139
bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
11401140
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
1141-
bool RelativeNames, llvm::vfs::FileSystem &FS,
1142-
llvm::Optional<llvm::StringRef> CurrentDir) {
1141+
bool RelativeNames,
1142+
llvm::Optional<llvm::StringRef> CurrentDir,
1143+
llvm::vfs::FileSystem &FS) {
11431144
bool AllExpanded = true;
11441145
struct ResponseFileRecord {
11451146
std::string File;
@@ -1247,6 +1248,15 @@ bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
12471248
return AllExpanded;
12481249
}
12491250

1251+
bool cl::ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer,
1252+
SmallVectorImpl<const char *> &Argv, bool MarkEOLs,
1253+
bool RelativeNames,
1254+
llvm::Optional<StringRef> CurrentDir) {
1255+
return ExpandResponseFiles(Saver, std::move(Tokenizer), Argv, MarkEOLs,
1256+
RelativeNames, std::move(CurrentDir),
1257+
*vfs::getRealFileSystem());
1258+
}
1259+
12501260
bool cl::expandResponseFiles(int Argc, const char *const *Argv,
12511261
const char *EnvVar, StringSaver &Saver,
12521262
SmallVectorImpl<const char *> &NewArgv) {
@@ -1273,14 +1283,14 @@ bool cl::readConfigFile(StringRef CfgFile, StringSaver &Saver,
12731283
}
12741284
if (llvm::Error Err =
12751285
ExpandResponseFile(CfgFile, Saver, cl::tokenizeConfigFile, Argv,
1276-
/*MarkEOLs*/ false, /*RelativeNames*/ true,
1286+
/*MarkEOLs=*/false, /*RelativeNames=*/true,
12771287
*llvm::vfs::getRealFileSystem())) {
12781288
// TODO: The error should be propagated up the stack.
12791289
llvm::consumeError(std::move(Err));
12801290
return false;
12811291
}
12821292
return ExpandResponseFiles(Saver, cl::tokenizeConfigFile, Argv,
1283-
/*MarkEOLs*/ false, /*RelativeNames*/ true);
1293+
/*MarkEOLs=*/false, /*RelativeNames=*/true);
12841294
}
12851295

12861296
bool cl::ParseCommandLineOptions(int argc, const char *const *argv,

llvm/lib/Support/WithColor.cpp

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

99
#include "llvm/Support/WithColor.h"
1010
#include "llvm/Support/CommandLine.h"
11+
#include "llvm/Support/Error.h"
1112

1213
using namespace llvm;
1314

llvm/lib/Transforms/Utils/Debugify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/IR/PassInstrumentation.h"
2626
#include "llvm/Pass.h"
2727
#include "llvm/Support/CommandLine.h"
28+
#include "llvm/Support/FileSystem.h"
2829
#include "llvm/Support/JSON.h"
2930

3031
#define DEBUG_TYPE "debugify"

llvm/tools/llvm-cov/TestingSupport.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/ProfileData/InstrProf.h"
1111
#include "llvm/Support/Alignment.h"
1212
#include "llvm/Support/CommandLine.h"
13+
#include "llvm/Support/FileSystem.h"
1314
#include "llvm/Support/LEB128.h"
1415
#include "llvm/Support/raw_ostream.h"
1516
#include <functional>

llvm/tools/llvm-cxxmap/llvm-cxxmap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "llvm/ADT/DenseSet.h"
1514
#include "llvm/ADT/DenseMap.h"
15+
#include "llvm/ADT/DenseSet.h"
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/Support/CommandLine.h"
18+
#include "llvm/Support/FileSystem.h"
1819
#include "llvm/Support/InitLLVM.h"
1920
#include "llvm/Support/LineIterator.h"
2021
#include "llvm/Support/MemoryBuffer.h"

llvm/tools/llvm-exegesis/llvm-exegesis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/MC/MCSubtargetInfo.h"
3333
#include "llvm/Object/ObjectFile.h"
3434
#include "llvm/Support/CommandLine.h"
35+
#include "llvm/Support/FileSystem.h"
3536
#include "llvm/Support/Format.h"
3637
#include "llvm/Support/Path.h"
3738
#include "llvm/Support/SourceMgr.h"

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "llvm/Support/Debug.h"
3838
#include "llvm/Support/InitLLVM.h"
3939
#include "llvm/Support/MemoryBuffer.h"
40+
#include "llvm/Support/Path.h"
4041
#include "llvm/Support/Process.h"
4142
#include "llvm/Support/TargetRegistry.h"
4243
#include "llvm/Support/TargetSelect.h"

llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Support/CommandLine.h"
2222
#include "llvm/Support/InitLLVM.h"
2323
#include "llvm/Support/LineIterator.h"
24+
#include "llvm/Support/VirtualFileSystem.h"
2425
#include "llvm/Support/WithColor.h"
2526
#include "llvm/TextAPI/Architecture.h"
2627
#include <map>

llvm/tools/llvm-profgen/PerfReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88
#include "PerfReader.h"
99
#include "ProfileGenerator.h"
10+
#include "llvm/Support/FileSystem.h"
1011

1112
static cl::opt<bool> ShowMmapEvents("show-mmap-events", cl::ReallyHidden,
1213
cl::init(false), cl::ZeroOrMore,

llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/Object/SymbolSize.h"
2828
#include "llvm/Support/CommandLine.h"
2929
#include "llvm/Support/DynamicLibrary.h"
30+
#include "llvm/Support/FileSystem.h"
3031
#include "llvm/Support/InitLLVM.h"
3132
#include "llvm/Support/MSVCErrorWorkarounds.h"
3233
#include "llvm/Support/Memory.h"

llvm/tools/split-file/split-file.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/Support/CommandLine.h"
1818
#include "llvm/Support/FileOutputBuffer.h"
19+
#include "llvm/Support/FileSystem.h"
1920
#include "llvm/Support/LineIterator.h"
2021
#include "llvm/Support/MemoryBuffer.h"
2122
#include "llvm/Support/Path.h"

llvm/unittests/Support/CommandLineTest.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,8 @@ TEST(CommandLineTest, ResponseFiles) {
827827
llvm::BumpPtrAllocator A;
828828
llvm::StringSaver Saver(A);
829829
ASSERT_TRUE(llvm::cl::ExpandResponseFiles(
830-
Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true, FS,
831-
/*CurrentDir=*/StringRef(TestRoot)));
830+
Saver, llvm::cl::TokenizeGNUCommandLine, Argv, false, true,
831+
/*CurrentDir=*/StringRef(TestRoot), FS));
832832
EXPECT_THAT(Argv, testing::Pointwise(
833833
StringEquality(),
834834
{"test/test", "-flag_1", "-option_1", "-option_2",
@@ -889,9 +889,9 @@ TEST(CommandLineTest, RecursiveResponseFiles) {
889889
#else
890890
cl::TokenizerCallback Tokenizer = cl::TokenizeGNUCommandLine;
891891
#endif
892-
ASSERT_FALSE(
893-
cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false, FS,
894-
/*CurrentDir=*/llvm::StringRef(TestRoot)));
892+
ASSERT_FALSE(cl::ExpandResponseFiles(Saver, Tokenizer, Argv, false, false,
893+
/*CurrentDir=*/llvm::StringRef(TestRoot),
894+
FS));
895895

896896
EXPECT_THAT(Argv,
897897
testing::Pointwise(StringEquality(),
@@ -929,8 +929,8 @@ TEST(CommandLineTest, ResponseFilesAtArguments) {
929929
BumpPtrAllocator A;
930930
StringSaver Saver(A);
931931
ASSERT_FALSE(cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
932-
false, false, FS,
933-
/*CurrentDir=*/StringRef(TestRoot)));
932+
false, false,
933+
/*CurrentDir=*/StringRef(TestRoot), FS));
934934

935935
// ASSERT instead of EXPECT to prevent potential out-of-bounds access.
936936
ASSERT_EQ(Argv.size(), 1 + NON_RSP_AT_ARGS + 2);
@@ -964,8 +964,8 @@ TEST(CommandLineTest, ResponseFileRelativePath) {
964964
BumpPtrAllocator A;
965965
StringSaver Saver(A);
966966
ASSERT_TRUE(cl::ExpandResponseFiles(Saver, cl::TokenizeGNUCommandLine, Argv,
967-
false, true, FS,
968-
/*CurrentDir=*/StringRef(TestRoot)));
967+
false, true,
968+
/*CurrentDir=*/StringRef(TestRoot), FS));
969969
EXPECT_THAT(Argv,
970970
testing::Pointwise(StringEquality(), {"test/test", "-flag"}));
971971
}
@@ -984,8 +984,8 @@ TEST(CommandLineTest, ResponseFileEOLs) {
984984
BumpPtrAllocator A;
985985
StringSaver Saver(A);
986986
ASSERT_TRUE(cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine,
987-
Argv, true, true, FS,
988-
/*CurrentDir=*/StringRef(TestRoot)));
987+
Argv, true, true,
988+
/*CurrentDir=*/StringRef(TestRoot), FS));
989989
const char *Expected[] = {"clang", "-Xclang", "-Wno-whatever", nullptr,
990990
"input.cpp"};
991991
ASSERT_EQ(array_lengthof(Expected), Argv.size());

llvm/unittests/Transforms/Utils/ScalarEvolutionExpanderTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/Module.h"
2323
#include "llvm/IR/PatternMatch.h"
2424
#include "llvm/IR/Verifier.h"
25+
#include "llvm/Support/SourceMgr.h"
2526
#include "gtest/gtest.h"
2627

2728
namespace llvm {

llvm/unittests/tools/llvm-exegesis/X86/BenchmarkResultTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "X86InstrInfo.h"
1111
#include "llvm/ADT/SmallString.h"
1212
#include "llvm/Support/Error.h"
13+
#include "llvm/Support/FileSystem.h"
1314
#include "llvm/Support/Path.h"
1415
#include "llvm/Support/TargetRegistry.h"
1516
#include "llvm/Support/TargetSelect.h"

llvm/utils/TableGen/GICombinerEmitter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/ADT/Statistic.h"
1616
#include "llvm/ADT/StringSet.h"
1717
#include "llvm/Support/CommandLine.h"
18+
#include "llvm/Support/Debug.h"
1819
#include "llvm/Support/ScopedPrinter.h"
1920
#include "llvm/Support/Timer.h"
2021
#include "llvm/TableGen/Error.h"

0 commit comments

Comments
 (0)