diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -251,10 +251,11 @@ 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. - phases::ID getFinalPhase(const llvm::opt::DerivedArgList &DAL, - llvm::opt::Arg **FinalPhaseArg = nullptr) const; + // getPhasesToRun - Determine which compilation mode we are in and record + // which option we used to determine the final phase and the phases to skip. + phases::PhasesToRun + getPhasesToRun(const llvm::opt::DerivedArgList &DAL, + llvm::opt::Arg **FinalPhaseArg = nullptr) const; // Before executing jobs, sets up response files for commands that need them. void setUpResponseFiles(Compilation &C, Command &Cmd); diff --git a/clang/include/clang/Driver/Phases.h b/clang/include/clang/Driver/Phases.h --- a/clang/include/clang/Driver/Phases.h +++ b/clang/include/clang/Driver/Phases.h @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include + #ifndef LLVM_CLANG_DRIVER_PHASES_H #define LLVM_CLANG_DRIVER_PHASES_H @@ -23,6 +25,11 @@ Link }; + struct PhasesToRun { + ID FinalPhase; + llvm::SmallSet SkipPhases; + }; + enum { MaxNumberOfPhases = Link + 1 }; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -262,10 +262,11 @@ // Determine which compilation mode we are in. We look for options which // affect the phase, starting with the earliest phases, and record which // option we used to determine the final phase. -phases::ID Driver::getFinalPhase(const DerivedArgList &DAL, - Arg **FinalPhaseArg) const { +phases::PhasesToRun Driver::getPhasesToRun(const DerivedArgList &DAL, + Arg **FinalPhaseArg) const { Arg *PhaseArg = nullptr; phases::ID FinalPhase; + llvm::SmallSet SkipPhases; // -{E,EP,P,M,MM} only run the preprocessor. if (CCCIsCPP() || (PhaseArg = DAL.getLastArg(options::OPT_E)) || @@ -306,7 +307,7 @@ if (FinalPhaseArg) *FinalPhaseArg = PhaseArg; - return FinalPhase; + return { FinalPhase, SkipPhases }; } static Arg *MakeInputArg(DerivedArgList &Args, OptTable &Opts, @@ -3148,7 +3149,8 @@ } Arg *FinalPhaseArg; - phases::ID FinalPhase = getFinalPhase(Args, &FinalPhaseArg); + phases::PhasesToRun PhasesToRun = getPhasesToRun(Args, &FinalPhaseArg); + phases::ID FinalPhase = PhasesToRun.FinalPhase; if (FinalPhase == phases::Link) { if (Args.hasArg(options::OPT_emit_llvm)) @@ -3307,6 +3309,9 @@ if (Phase > FinalPhase) break; + if (llvm::is_contained(PhasesToRun.SkipPhases, Phase)) + continue; + // Add any offload action the host action depends on. Current = OffloadBuilder.addDeviceDependencesToHostAction( Current, InputArg, Phase, FinalPhase, PL);