Author: Benjamin Kramer Date: 2020-06-07T20:18:14+02:00 New Revision: 02e35832c301e9813b0bb18e94db2a31c4849a73
URL: https://github.com/llvm/llvm-project/commit/02e35832c301e9813b0bb18e94db2a31c4849a73 DIFF: https://github.com/llvm/llvm-project/commit/02e35832c301e9813b0bb18e94db2a31c4849a73.diff LOG: [Driver] Simplify code. NFCI. Added: Modified: clang/include/clang/Driver/Phases.h clang/include/clang/Driver/Types.h clang/lib/Driver/Driver.cpp clang/lib/Driver/Types.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Phases.h b/clang/include/clang/Driver/Phases.h index 9003c5857351..ce914dd70514 100644 --- a/clang/include/clang/Driver/Phases.h +++ b/clang/include/clang/Driver/Phases.h @@ -22,10 +22,11 @@ namespace phases { Assemble, Link, IfsMerge, + LastPhase = IfsMerge, }; enum { - MaxNumberOfPhases = IfsMerge + 1 + MaxNumberOfPhases = LastPhase + 1 }; const char *getPhaseName(ID Id); diff --git a/clang/include/clang/Driver/Types.h b/clang/include/clang/Driver/Types.h index c7c38fa52593..97bf5fd672ab 100644 --- a/clang/include/clang/Driver/Types.h +++ b/clang/include/clang/Driver/Types.h @@ -45,9 +45,6 @@ namespace types { /// temp file of this type, or null if unspecified. const char *getTypeTempSuffix(ID Id, bool CLMode = false); - /// onlyAssembleType - Should this type only be assembled. - bool onlyAssembleType(ID Id); - /// onlyPrecompileType - Should this type only be precompiled. bool onlyPrecompileType(ID Id); @@ -101,13 +98,12 @@ namespace types { ID lookupTypeForTypeSpecifier(const char *Name); /// getCompilationPhases - Get the list of compilation phases ('Phases') to be - /// done for type 'Id'. - void getCompilationPhases( - ID Id, - llvm::SmallVectorImpl<phases::ID> &Phases); - void getCompilationPhases(const clang::driver::Driver &Driver, - llvm::opt::DerivedArgList &DAL, ID Id, - llvm::SmallVectorImpl<phases::ID> &Phases); + /// done for type 'Id' up until including LastPhase. + llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> + getCompilationPhases(ID Id, phases::ID LastPhase = phases::LastPhase); + llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> + getCompilationPhases(const clang::driver::Driver &Driver, + llvm::opt::DerivedArgList &DAL, ID Id); /// lookupCXXTypeForCType - Lookup CXX input type that corresponds to given /// C type (used for clang++ emulation of g++ behaviour) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 5c726b23148f..8cc5eceaa512 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -3276,8 +3276,7 @@ void Driver::handleArguments(Compilation &C, DerivedArgList &Args, types::ID InputType = I.first; const Arg *InputArg = I.second; - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL; - types::getCompilationPhases(InputType, PL); + auto PL = types::getCompilationPhases(InputType); LastPLSize = PL.size(); // 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, // Add a separate precompile phase for the compile phase. if (FinalPhase >= phases::Compile) { const types::ID HeaderType = lookupHeaderTypeForSourceType(InputType); - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PCHPL; - types::getCompilationPhases(HeaderType, PCHPL); // Build the pipeline for the pch file. Action *ClangClPch = C.MakeAction<InputAction>(*InputArg, HeaderType); - for (phases::ID Phase : PCHPL) + for (phases::ID Phase : types::getCompilationPhases(HeaderType)) ClangClPch = ConstructPhaseAction(C, Args, Phase, ClangClPch); assert(ClangClPch); Actions.push_back(ClangClPch); @@ -3409,13 +3406,11 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, types::ID InputType = I.first; const Arg *InputArg = I.second; - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL; - types::getCompilationPhases(*this, Args, InputType, PL); + auto PL = types::getCompilationPhases(*this, Args, InputType); if (PL.empty()) continue; - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> FullPL; - types::getCompilationPhases(InputType, FullPL); + auto FullPL = types::getCompilationPhases(InputType); // Build the pipeline for this file. Action *Current = C.MakeAction<InputAction>(*InputArg, InputType); @@ -3509,15 +3504,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image)); if (Args.hasArg(options::OPT_emit_interface_stubs)) { - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList; - if (Args.hasArg(options::OPT_c)) { - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> CompilePhaseList; - types::getCompilationPhases(types::TY_IFS_CPP, CompilePhaseList); - llvm::copy_if(CompilePhaseList, std::back_inserter(PhaseList), - [&](phases::ID Phase) { return Phase <= phases::Compile; }); - } else { - types::getCompilationPhases(types::TY_IFS_CPP, PhaseList); - } + auto PhaseList = types::getCompilationPhases( + types::TY_IFS_CPP, + Args.hasArg(options::OPT_c) ? phases::Compile : phases::LastPhase); ActionList MergerInputs; diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp index 8e1236bd08ec..3ab48a0180c1 100644 --- a/clang/lib/Driver/Types.cpp +++ b/clang/lib/Driver/Types.cpp @@ -90,12 +90,6 @@ const char *types::getTypeTempSuffix(ID Id, bool CLMode) { return getInfo(Id).TempSuffix; } -bool types::onlyAssembleType(ID Id) { - return getInfo(Id).Phases.contains(phases::Assemble) && - !getInfo(Id).Phases.contains(phases::Compile) && - !getInfo(Id).Phases.contains(phases::Backend); -} - bool types::onlyPrecompileType(ID Id) { return getInfo(Id).Phases.contains(phases::Precompile) && !isPreprocessedModuleType(Id); @@ -311,23 +305,21 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) { return TY_INVALID; } -// FIXME: Why don't we just put this list in the defs file, eh. -// FIXME: The list is now in Types.def but for now this function will verify -// the old behavior and a subsequent change will delete most of the body. -void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl<phases::ID> &P) { +llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> +types::getCompilationPhases(ID Id, phases::ID LastPhase) { + llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> P; const auto &Info = getInfo(Id); - for (int I = 0; I != phases::MaxNumberOfPhases; ++I) + for (int I = 0; I <= LastPhase; ++I) if (Info.Phases.contains(static_cast<phases::ID>(I))) P.push_back(static_cast<phases::ID>(I)); - assert(0 < P.size() && "Not enough phases in list"); assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list"); + return P; } -void types::getCompilationPhases(const clang::driver::Driver &Driver, - llvm::opt::DerivedArgList &DAL, ID Id, - llvm::SmallVectorImpl<phases::ID> &P) { - llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhaseList; - types::getCompilationPhases(Id, PhaseList); +llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> +types::getCompilationPhases(const clang::driver::Driver &Driver, + llvm::opt::DerivedArgList &DAL, ID Id) { + phases::ID LastPhase; // Filter to compiler mode. When the compiler is run as a preprocessor then // compilation is not an option. @@ -336,14 +328,12 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver, DAL.getLastArg(options::OPT__SLASH_EP) || DAL.getLastArg(options::OPT_M, options::OPT_MM) || DAL.getLastArg(options::OPT__SLASH_P)) - llvm::copy_if(PhaseList, std::back_inserter(P), - [](phases::ID Phase) { return Phase <= phases::Preprocess; }); + LastPhase = phases::Preprocess; // --precompile only runs up to precompilation. // This is a clang extension and is not compatible with GCC. else if (DAL.getLastArg(options::OPT__precompile)) - llvm::copy_if(PhaseList, std::back_inserter(P), - [](phases::ID Phase) { return Phase <= phases::Precompile; }); + LastPhase = phases::Precompile; // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. else if (DAL.getLastArg(options::OPT_fsyntax_only) || @@ -355,21 +345,20 @@ void types::getCompilationPhases(const clang::driver::Driver &Driver, DAL.getLastArg(options::OPT__migrate) || DAL.getLastArg(options::OPT__analyze) || DAL.getLastArg(options::OPT_emit_ast)) - llvm::copy_if(PhaseList, std::back_inserter(P), - [](phases::ID Phase) { return Phase <= phases::Compile; }); + LastPhase = phases::Compile; else if (DAL.getLastArg(options::OPT_S) || DAL.getLastArg(options::OPT_emit_llvm)) - llvm::copy_if(PhaseList, std::back_inserter(P), - [](phases::ID Phase) { return Phase <= phases::Backend; }); + LastPhase = phases::Backend; else if (DAL.getLastArg(options::OPT_c)) - llvm::copy_if(PhaseList, std::back_inserter(P), - [](phases::ID Phase) { return Phase <= phases::Assemble; }); + LastPhase = phases::Assemble; // Generally means, do every phase until Link. else - P = PhaseList; + LastPhase = phases::LastPhase; + + return types::getCompilationPhases(Id, LastPhase); } ID types::lookupCXXTypeForCType(ID Id) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits