[PATCH] D63977: [NFC][clang] Adding ability to skip compiler phases in clang driver.
Puyan Lotfi via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 30 10:03:40 PDT 2019
plotfi created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Changing getFinalPhase to getPhasesToRun. Instead of only returning the final phase it returns the final phase as well as a collection of the phases to skip. This is useful for cases where you want to do up to a compile phase that emits some information per compilation unit, but then you want a link phase for merging the compilation unit artifacts into one file without having to invoke the backend/assembler phases.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63977
Files:
clang/include/clang/Driver/Driver.h
clang/include/clang/Driver/Phases.h
clang/lib/Driver/Driver.cpp
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ 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;
+ std::set<phases::ID> 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,10 @@
if (Phase > FinalPhase)
break;
+ // If we find Phase in the SkipPhases, then skip it.
+ if (PhasesToRun.SkipPhases.find(Phase) != PhasesToRun.SkipPhases.end())
+ continue;
+
// Add any offload action the host action depends on.
Current = OffloadBuilder.addDeviceDependencesToHostAction(
Current, InputArg, Phase, FinalPhase, PL);
Index: clang/include/clang/Driver/Phases.h
===================================================================
--- clang/include/clang/Driver/Phases.h
+++ clang/include/clang/Driver/Phases.h
@@ -6,6 +6,8 @@
//
//===----------------------------------------------------------------------===//
+#include <set>
+
#ifndef LLVM_CLANG_DRIVER_PHASES_H
#define LLVM_CLANG_DRIVER_PHASES_H
@@ -23,6 +25,11 @@
Link
};
+ struct PhasesToRun {
+ ID FinalPhase;
+ std::set<ID> SkipPhases;
+ };
+
enum {
MaxNumberOfPhases = Link + 1
};
Index: clang/include/clang/Driver/Driver.h
===================================================================
--- clang/include/clang/Driver/Driver.h
+++ 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63977.207222.patch
Type: text/x-patch
Size: 3395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190630/fb366cca/attachment.bin>
More information about the cfe-commits
mailing list