Skip to content

Commit 02e3583

Browse files
committed
[Driver] Simplify code. NFCI.
1 parent 96458fc commit 02e3583

File tree

4 files changed

+32
-57
lines changed

4 files changed

+32
-57
lines changed

clang/include/clang/Driver/Phases.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ namespace phases {
2222
Assemble,
2323
Link,
2424
IfsMerge,
25+
LastPhase = IfsMerge,
2526
};
2627

2728
enum {
28-
MaxNumberOfPhases = IfsMerge + 1
29+
MaxNumberOfPhases = LastPhase + 1
2930
};
3031

3132
const char *getPhaseName(ID Id);

clang/include/clang/Driver/Types.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ namespace types {
4545
/// temp file of this type, or null if unspecified.
4646
const char *getTypeTempSuffix(ID Id, bool CLMode = false);
4747

48-
/// onlyAssembleType - Should this type only be assembled.
49-
bool onlyAssembleType(ID Id);
50-
5148
/// onlyPrecompileType - Should this type only be precompiled.
5249
bool onlyPrecompileType(ID Id);
5350

@@ -101,13 +98,12 @@ namespace types {
10198
ID lookupTypeForTypeSpecifier(const char *Name);
10299

103100
/// getCompilationPhases - Get the list of compilation phases ('Phases') to be
104-
/// done for type 'Id'.
105-
void getCompilationPhases(
106-
ID Id,
107-
llvm::SmallVectorImpl<phases::ID> &Phases);
108-
void getCompilationPhases(const clang::driver::Driver &Driver,
109-
llvm::opt::DerivedArgList &DAL, ID Id,
110-
llvm::SmallVectorImpl<phases::ID> &Phases);
101+
/// done for type 'Id' up until including LastPhase.
102+
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases>
103+
getCompilationPhases(ID Id, phases::ID LastPhase = phases::LastPhase);
104+
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases>
105+
getCompilationPhases(const clang::driver::Driver &Driver,
106+
llvm::opt::DerivedArgList &DAL, ID Id);
111107

112108
/// lookupCXXTypeForCType - Lookup CXX input type that corresponds to given
113109
/// C type (used for clang++ emulation of g++ behaviour)

clang/lib/Driver/Driver.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,8 +3276,7 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
32763276
types::ID InputType = I.first;
32773277
const Arg *InputArg = I.second;
32783278

3279-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
3280-
types::getCompilationPhases(InputType, PL);
3279+
auto PL = types::getCompilationPhases(InputType);
32813280
LastPLSize = PL.size();
32823281

32833282
// If the first step comes after the final phase we are doing as part of
@@ -3322,11 +3321,9 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args,
33223321
// Add a separate precompile phase for the compile phase.
33233322
if (FinalPhase >= phases::Compile) {
33243323
const types::ID HeaderType = lookupHeaderTypeForSourceType(InputType);
3325-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PCHPL;
3326-
types::getCompilationPhases(HeaderType, PCHPL);
33273324
// Build the pipeline for the pch file.
33283325
Action *ClangClPch = C.MakeAction<InputAction>(*InputArg, HeaderType);
3329-
for (phases::ID Phase : PCHPL)
3326+
for (phases::ID Phase : types::getCompilationPhases(HeaderType))
33303327
ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch);
33313328
assert(ClangClPch);
33323329
Actions.push_back(ClangClPch);
@@ -3409,13 +3406,11 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
34093406
types::ID InputType = I.first;
34103407
const Arg *InputArg = I.second;
34113408

3412-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
3413-
types::getCompilationPhases(*this, Args, InputType, PL);
3409+
auto PL = types::getCompilationPhases(*this, Args, InputType);
34143410
if (PL.empty())
34153411
continue;
34163412

3417-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> FullPL;
3418-
types::getCompilationPhases(InputType, FullPL);
3413+
auto FullPL = types::getCompilationPhases(InputType);
34193414

34203415
// Build the pipeline for this file.
34213416
Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);
@@ -3509,15 +3504,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
35093504
C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));
35103505

35113506
if (Args.hasArg(options::OPT_emit_interface_stubs)) {
3512-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList;
3513-
if (Args.hasArg(options::OPT_c)) {
3514-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> CompilePhaseList;
3515-
types::getCompilationPhases(types::TY_IFS_CPP, CompilePhaseList);
3516-
llvm::copy_if(CompilePhaseList, std::back_inserter(PhaseList),
3517-
[&](phases::ID Phase) { return Phase <= phases::Compile; });
3518-
} else {
3519-
types::getCompilationPhases(types::TY_IFS_CPP, PhaseList);
3520-
}
3507+
auto PhaseList = types::getCompilationPhases(
3508+
types::TY_IFS_CPP,
3509+
Args.hasArg(options::OPT_c) ? phases::Compile : phases::LastPhase);
35213510

35223511
ActionList MergerInputs;
35233512

clang/lib/Driver/Types.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,6 @@ const char *types::getTypeTempSuffix(ID Id, bool CLMode) {
9090
return getInfo(Id).TempSuffix;
9191
}
9292

93-
bool types::onlyAssembleType(ID Id) {
94-
return getInfo(Id).Phases.contains(phases::Assemble) &&
95-
!getInfo(Id).Phases.contains(phases::Compile) &&
96-
!getInfo(Id).Phases.contains(phases::Backend);
97-
}
98-
9993
bool types::onlyPrecompileType(ID Id) {
10094
return getInfo(Id).Phases.contains(phases::Precompile) &&
10195
!isPreprocessedModuleType(Id);
@@ -311,23 +305,21 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
311305
return TY_INVALID;
312306
}
313307

314-
// FIXME: Why don't we just put this list in the defs file, eh.
315-
// FIXME: The list is now in Types.def but for now this function will verify
316-
// the old behavior and a subsequent change will delete most of the body.
317-
void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl<phases::ID> &P) {
308+
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases>
309+
types::getCompilationPhases(ID Id, phases::ID LastPhase) {
310+
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> P;
318311
const auto &Info = getInfo(Id);
319-
for (int I = 0; I != phases::MaxNumberOfPhases; ++I)
312+
for (int I = 0; I <= LastPhase; ++I)
320313
if (Info.Phases.contains(static_cast<phases::ID>(I)))
321314
P.push_back(static_cast<phases::ID>(I));
322-
assert(0 < P.size() && "Not enough phases in list");
323315
assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
316+
return P;
324317
}
325318

326-
void types::getCompilationPhases(const clang::driver::Driver &Driver,
327-
llvm::opt::DerivedArgList &DAL, ID Id,
328-
llvm::SmallVectorImpl<phases::ID> &P) {
329-
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList;
330-
types::getCompilationPhases(Id, PhaseList);
319+
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases>
320+
types::getCompilationPhases(const clang::driver::Driver &Driver,
321+
llvm::opt::DerivedArgList &DAL, ID Id) {
322+
phases::ID LastPhase;
331323

332324
// Filter to compiler mode. When the compiler is run as a preprocessor then
333325
// compilation is not an option.
@@ -336,14 +328,12 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver,
336328
DAL.getLastArg(options::OPT__SLASH_EP) ||
337329
DAL.getLastArg(options::OPT_M, options::OPT_MM) ||
338330
DAL.getLastArg(options::OPT__SLASH_P))
339-
llvm::copy_if(PhaseList, std::back_inserter(P),
340-
[](phases::ID Phase) { return Phase <= phases::Preprocess; });
331+
LastPhase = phases::Preprocess;
341332

342333
// --precompile only runs up to precompilation.
343334
// This is a clang extension and is not compatible with GCC.
344335
else if (DAL.getLastArg(options::OPT__precompile))
345-
llvm::copy_if(PhaseList, std::back_inserter(P),
346-
[](phases::ID Phase) { return Phase <= phases::Precompile; });
336+
LastPhase = phases::Precompile;
347337

348338
// -{fsyntax-only,-analyze,emit-ast} only run up to the compiler.
349339
else if (DAL.getLastArg(options::OPT_fsyntax_only) ||
@@ -355,21 +345,20 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver,
355345
DAL.getLastArg(options::OPT__migrate) ||
356346
DAL.getLastArg(options::OPT__analyze) ||
357347
DAL.getLastArg(options::OPT_emit_ast))
358-
llvm::copy_if(PhaseList, std::back_inserter(P),
359-
[](phases::ID Phase) { return Phase <= phases::Compile; });
348+
LastPhase = phases::Compile;
360349

361350
else if (DAL.getLastArg(options::OPT_S) ||
362351
DAL.getLastArg(options::OPT_emit_llvm))
363-
llvm::copy_if(PhaseList, std::back_inserter(P),
364-
[](phases::ID Phase) { return Phase <= phases::Backend; });
352+
LastPhase = phases::Backend;
365353

366354
else if (DAL.getLastArg(options::OPT_c))
367-
llvm::copy_if(PhaseList, std::back_inserter(P),
368-
[](phases::ID Phase) { return Phase <= phases::Assemble; });
355+
LastPhase = phases::Assemble;
369356

370357
// Generally means, do every phase until Link.
371358
else
372-
P = PhaseList;
359+
LastPhase = phases::LastPhase;
360+
361+
return types::getCompilationPhases(Id, LastPhase);
373362
}
374363

375364
ID types::lookupCXXTypeForCType(ID Id) {

0 commit comments

Comments
 (0)