Author: Nico Weber Date: 2021-09-30T14:17:14-04:00 New Revision: fa32fd3bf7c070e62487e5ccba00557d57b2ee5c
URL: https://github.com/llvm/llvm-project/commit/fa32fd3bf7c070e62487e5ccba00557d57b2ee5c DIFF: https://github.com/llvm/llvm-project/commit/fa32fd3bf7c070e62487e5ccba00557d57b2ee5c.diff LOG: [clang] Remove duplication in types::getCompilationPhases() Call Driver::getFinalPhase() instead of duplicating it. https://reviews.llvm.org/D65993 added the duplication, then 02e35832c301e maded it more obviously a copy of getFinalPhase(). The only difference is that getCompilationPhases() used to use LastPhase / IfsMerge where getFinalPhase() used Link. Adapt getFinalPhase() to return IfsMerge when needed. No intentional behavior change. Differential Revision: https://reviews.llvm.org/D110770 Added: Modified: clang/include/clang/Driver/Driver.h 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/Driver.h b/clang/include/clang/Driver/Driver.h index da7e8386a151c..8b1f7091e7015 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -253,6 +253,14 @@ class Driver { /// or when using the -gen-reproducer driver flag. unsigned GenReproducer : 1; + // getFinalPhase - Determine which compilation mode we are in and record + // which option we used to determine the final phase. + // TODO: Much of what getFinalPhase returns are not actually true compiler + // modes. Fold this functionality into Types::getCompilationPhases and + // handleArguments. + phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, + llvm::opt::Arg **FinalPhaseArg = nullptr) const; + private: /// Certain options suppress the 'no input files' warning. unsigned SuppressMissingInputWarning : 1; @@ -270,14 +278,6 @@ class Driver { llvm::opt::DerivedArgList * TranslateInputArgs(const llvm::opt::InputArgList &Args) const; - // getFinalPhase - Determine which compilation mode we are in and record - // which option we used to determine the final phase. - // TODO: Much of what getFinalPhase returns are not actually true compiler - // modes. Fold this functionality into Types::getCompilationPhases and - // handleArguments. - phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, - llvm::opt::Arg **FinalPhaseArg = nullptr) const; - // handleArguments - All code related to claiming and printing diagnostics // related to arguments to the driver are done here. void handleArguments(Compilation &C, llvm::opt::DerivedArgList &Args, diff --git a/clang/include/clang/Driver/Phases.h b/clang/include/clang/Driver/Phases.h index ce914dd705140..9003c58573513 100644 --- a/clang/include/clang/Driver/Phases.h +++ b/clang/include/clang/Driver/Phases.h @@ -22,11 +22,10 @@ namespace phases { Assemble, Link, IfsMerge, - LastPhase = IfsMerge, }; enum { - MaxNumberOfPhases = LastPhase + 1 + MaxNumberOfPhases = IfsMerge + 1 }; const char *getPhaseName(ID Id); diff --git a/clang/include/clang/Driver/Types.h b/clang/include/clang/Driver/Types.h index c9d63551090cf..4aecf7ee1e528 100644 --- a/clang/include/clang/Driver/Types.h +++ b/clang/include/clang/Driver/Types.h @@ -111,7 +111,7 @@ namespace types { /// getCompilationPhases - Get the list of compilation phases ('Phases') to be /// done for type 'Id' up until including LastPhase. llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> - getCompilationPhases(ID Id, phases::ID LastPhase = phases::LastPhase); + getCompilationPhases(ID Id, phases::ID LastPhase = phases::IfsMerge); llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> getCompilationPhases(const clang::driver::Driver &Driver, llvm::opt::DerivedArgList &DAL, ID Id); diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index b32fc65074642..0c73db892ab80 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -304,6 +304,9 @@ phases::ID Driver::getFinalPhase(const DerivedArgList &DAL, } else if ((PhaseArg = DAL.getLastArg(options::OPT_c))) { FinalPhase = phases::Assemble; + } else if ((PhaseArg = DAL.getLastArg(options::OPT_emit_interface_stubs))) { + FinalPhase = phases::IfsMerge; + // Otherwise do everything. } else FinalPhase = phases::Link; @@ -3841,7 +3844,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, if (Args.hasArg(options::OPT_emit_interface_stubs)) { auto PhaseList = types::getCompilationPhases( types::TY_IFS_CPP, - Args.hasArg(options::OPT_c) ? phases::Compile : phases::LastPhase); + Args.hasArg(options::OPT_c) ? phases::Compile : phases::IfsMerge); ActionList MergerInputs; diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp index 3cb2d6e8f6fd7..1bd187ad2fc0a 100644 --- a/clang/lib/Driver/Types.cpp +++ b/clang/lib/Driver/Types.cpp @@ -362,46 +362,7 @@ types::getCompilationPhases(ID Id, phases::ID LastPhase) { 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. - // -S runs the compiler in Assembly listing mode. - if (Driver.CCCIsCPP() || DAL.getLastArg(options::OPT_E) || - DAL.getLastArg(options::OPT__SLASH_EP) || - DAL.getLastArg(options::OPT_M, options::OPT_MM) || - DAL.getLastArg(options::OPT__SLASH_P)) - 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)) - LastPhase = phases::Precompile; - - // -{fsyntax-only,-analyze,emit-ast} only run up to the compiler. - else if (DAL.getLastArg(options::OPT_fsyntax_only) || - DAL.getLastArg(options::OPT_print_supported_cpus) || - DAL.getLastArg(options::OPT_module_file_info) || - DAL.getLastArg(options::OPT_verify_pch) || - DAL.getLastArg(options::OPT_rewrite_objc) || - DAL.getLastArg(options::OPT_rewrite_legacy_objc) || - DAL.getLastArg(options::OPT__migrate) || - DAL.getLastArg(options::OPT__analyze) || - DAL.getLastArg(options::OPT_emit_ast)) - LastPhase = phases::Compile; - - else if (DAL.getLastArg(options::OPT_S) || - DAL.getLastArg(options::OPT_emit_llvm)) - LastPhase = phases::Backend; - - else if (DAL.getLastArg(options::OPT_c)) - LastPhase = phases::Assemble; - - // Generally means, do every phase until Link. - else - LastPhase = phases::LastPhase; - - return types::getCompilationPhases(Id, LastPhase); + return types::getCompilationPhases(Id, Driver.getFinalPhase(DAL)); } ID types::lookupCXXTypeForCType(ID Id) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits