forked from OSchip/llvm-project
Minor refactor of how we get compilation phases.
There is now a single function to get the list of phases for a given output Type. No functionality change intended. llvm-svn: 176628
This commit is contained in:
parent
074a3568fc
commit
7ab8b2b2e0
|
@ -23,6 +23,10 @@ namespace phases {
|
||||||
Link
|
Link
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MaxNumberOfPhases = Link + 1
|
||||||
|
};
|
||||||
|
|
||||||
const char *getPhaseName(ID Id);
|
const char *getPhaseName(ID Id);
|
||||||
|
|
||||||
} // end namespace phases
|
} // end namespace phases
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#define CLANG_DRIVER_TYPES_H_
|
#define CLANG_DRIVER_TYPES_H_
|
||||||
|
|
||||||
#include "clang/Driver/Phases.h"
|
#include "clang/Driver/Phases.h"
|
||||||
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
namespace driver {
|
namespace driver {
|
||||||
|
@ -73,13 +74,11 @@ namespace types {
|
||||||
/// specified type name.
|
/// specified type name.
|
||||||
ID lookupTypeForTypeSpecifier(const char *Name);
|
ID lookupTypeForTypeSpecifier(const char *Name);
|
||||||
|
|
||||||
/// getNumCompilationPhases - Return the complete number of phases
|
/// getCompilationPhases - Get the list of compilation phases ('Phases') to be
|
||||||
/// to be done for this type.
|
/// done for type 'Id'.
|
||||||
unsigned getNumCompilationPhases(ID Id);
|
void getCompilationPhases(
|
||||||
|
ID Id,
|
||||||
/// getCompilationPhase - Return the \p N th compilation phase to
|
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> &Phases);
|
||||||
/// be done for this type.
|
|
||||||
phases::ID getCompilationPhase(ID Id, unsigned N);
|
|
||||||
|
|
||||||
/// lookupCXXTypeForCType - Lookup CXX input type that corresponds to given
|
/// lookupCXXTypeForCType - Lookup CXX input type that corresponds to given
|
||||||
/// C type (used for clang++ emulation of g++ behaviour)
|
/// C type (used for clang++ emulation of g++ behaviour)
|
||||||
|
|
|
@ -1038,17 +1038,17 @@ void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
|
||||||
// Construct the actions to perform.
|
// Construct the actions to perform.
|
||||||
ActionList LinkerInputs;
|
ActionList LinkerInputs;
|
||||||
ActionList SplitInputs;
|
ActionList SplitInputs;
|
||||||
unsigned NumSteps = 0;
|
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
|
||||||
for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Inputs.size(); i != e; ++i) {
|
||||||
types::ID InputType = Inputs[i].first;
|
types::ID InputType = Inputs[i].first;
|
||||||
const Arg *InputArg = Inputs[i].second;
|
const Arg *InputArg = Inputs[i].second;
|
||||||
|
|
||||||
NumSteps = types::getNumCompilationPhases(InputType);
|
PL.clear();
|
||||||
assert(NumSteps && "Invalid number of steps!");
|
types::getCompilationPhases(InputType, PL);
|
||||||
|
|
||||||
// If the first step comes after the final phase we are doing as part of
|
// If the first step comes after the final phase we are doing as part of
|
||||||
// this compilation, warn the user about it.
|
// this compilation, warn the user about it.
|
||||||
phases::ID InitialPhase = types::getCompilationPhase(InputType, 0);
|
phases::ID InitialPhase = PL[0];
|
||||||
if (InitialPhase > FinalPhase) {
|
if (InitialPhase > FinalPhase) {
|
||||||
// Claim here to avoid the more general unused warning.
|
// Claim here to avoid the more general unused warning.
|
||||||
InputArg->claim();
|
InputArg->claim();
|
||||||
|
@ -1083,8 +1083,9 @@ void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
|
||||||
|
|
||||||
// Build the pipeline for this file.
|
// Build the pipeline for this file.
|
||||||
OwningPtr<Action> Current(new InputAction(*InputArg, InputType));
|
OwningPtr<Action> Current(new InputAction(*InputArg, InputType));
|
||||||
for (unsigned i = 0; i != NumSteps; ++i) {
|
for (llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases>::iterator
|
||||||
phases::ID Phase = types::getCompilationPhase(InputType, i);
|
i = PL.begin(), e = PL.end(); i != e; ++i) {
|
||||||
|
phases::ID Phase = *i;
|
||||||
|
|
||||||
// We are done if this step is past what the user requested.
|
// We are done if this step is past what the user requested.
|
||||||
if (Phase > FinalPhase)
|
if (Phase > FinalPhase)
|
||||||
|
@ -1092,7 +1093,7 @@ void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
|
||||||
|
|
||||||
// Queue linker inputs.
|
// Queue linker inputs.
|
||||||
if (Phase == phases::Link) {
|
if (Phase == phases::Link) {
|
||||||
assert(i + 1 == NumSteps && "linking must be final compilation step.");
|
assert((i + 1) == e && "linking must be final compilation step.");
|
||||||
LinkerInputs.push_back(Current.take());
|
LinkerInputs.push_back(Current.take());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1120,7 +1121,7 @@ void Driver::BuildActions(const ToolChain &TC, const DerivedArgList &Args,
|
||||||
|
|
||||||
// If we are linking, claim any options which are obviously only used for
|
// If we are linking, claim any options which are obviously only used for
|
||||||
// compilation.
|
// compilation.
|
||||||
if (FinalPhase == phases::Link && (NumSteps == 1))
|
if (FinalPhase == phases::Link && PL.size() == 1)
|
||||||
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
|
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,47 +179,29 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Why don't we just put this list in the defs file, eh.
|
// FIXME: Why don't we just put this list in the defs file, eh.
|
||||||
|
void types::getCompilationPhases(
|
||||||
unsigned types::getNumCompilationPhases(ID Id) {
|
ID Id,
|
||||||
if (Id == TY_Object)
|
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> &P) {
|
||||||
return 1;
|
if (Id != TY_Object) {
|
||||||
|
|
||||||
unsigned N = 0;
|
|
||||||
if (getPreprocessedType(Id) != TY_INVALID)
|
|
||||||
N += 1;
|
|
||||||
|
|
||||||
if (onlyAssembleType(Id))
|
|
||||||
return N + 2; // assemble, link
|
|
||||||
if (onlyPrecompileType(Id))
|
|
||||||
return N + 1; // precompile
|
|
||||||
|
|
||||||
return N + 3; // compile, assemble, link
|
|
||||||
}
|
|
||||||
|
|
||||||
phases::ID types::getCompilationPhase(ID Id, unsigned N) {
|
|
||||||
assert(N < getNumCompilationPhases(Id) && "Invalid index.");
|
|
||||||
|
|
||||||
if (Id == TY_Object)
|
|
||||||
return phases::Link;
|
|
||||||
|
|
||||||
if (getPreprocessedType(Id) != TY_INVALID) {
|
if (getPreprocessedType(Id) != TY_INVALID) {
|
||||||
if (N == 0)
|
P.push_back(phases::Preprocess);
|
||||||
return phases::Preprocess;
|
|
||||||
--N;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlyAssembleType(Id))
|
if (onlyPrecompileType(Id)) {
|
||||||
return N == 0 ? phases::Assemble : phases::Link;
|
P.push_back(phases::Precompile);
|
||||||
|
} else {
|
||||||
if (onlyPrecompileType(Id))
|
if (!onlyAssembleType(Id)) {
|
||||||
return phases::Precompile;
|
P.push_back(phases::Compile);
|
||||||
|
}
|
||||||
if (N == 0)
|
P.push_back(phases::Assemble);
|
||||||
return phases::Compile;
|
}
|
||||||
if (N == 1)
|
}
|
||||||
return phases::Assemble;
|
if (!onlyPrecompileType(Id)) {
|
||||||
|
P.push_back(phases::Link);
|
||||||
return phases::Link;
|
}
|
||||||
|
assert(0 < P.size() && "Not enough phases in list");
|
||||||
|
assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ID types::lookupCXXTypeForCType(ID Id) {
|
ID types::lookupCXXTypeForCType(ID Id) {
|
||||||
|
|
Loading…
Reference in New Issue