forked from OSchip/llvm-project
[NFC][clang] Refactor getCompilationPhases()+Types.def step 1.
Moves list of phases into Types.def table: Currently Types.def contains a table of strings that are used to assemble a list of compilation phases to be setup in the clang driver's jobs pipeline. This change makes it so that the table itself contains the list of phases. A subsequent patch will remove the strings. Differential Revision: https://reviews.llvm.org/D64098 llvm-svn: 366761
This commit is contained in:
parent
67713e2687
commit
298a1ed4ad
|
@ -37,69 +37,71 @@
|
|||
// A - The type's temporary suffix should be appended when generating
|
||||
// outputs of this type.
|
||||
|
||||
// The sixth value is a variadic list of phases for each type. Eventually the
|
||||
// options flag string will be replaced with this variadic list.
|
||||
|
||||
// C family source language (with and without preprocessing).
|
||||
TYPE("cpp-output", PP_C, INVALID, "i", "u")
|
||||
TYPE("c", C, PP_C, "c", "u")
|
||||
TYPE("cl", CL, PP_C, "cl", "u")
|
||||
TYPE("cuda-cpp-output", PP_CUDA, INVALID, "cui", "u")
|
||||
TYPE("cuda", CUDA, PP_CUDA, "cu", "u")
|
||||
TYPE("cuda", CUDA_DEVICE, PP_CUDA, "cu", "")
|
||||
TYPE("hip-cpp-output", PP_HIP, INVALID, "cui", "u")
|
||||
TYPE("hip", HIP, PP_HIP, "cu", "u")
|
||||
TYPE("hip", HIP_DEVICE, PP_HIP, "cu", "")
|
||||
TYPE("objective-c-cpp-output", PP_ObjC, INVALID, "mi", "u")
|
||||
TYPE("objc-cpp-output", PP_ObjC_Alias, INVALID, "mi", "u")
|
||||
TYPE("objective-c", ObjC, PP_ObjC, "m", "u")
|
||||
TYPE("c++-cpp-output", PP_CXX, INVALID, "ii", "u")
|
||||
TYPE("c++", CXX, PP_CXX, "cpp", "u")
|
||||
TYPE("objective-c++-cpp-output", PP_ObjCXX, INVALID, "mii", "u")
|
||||
TYPE("objc++-cpp-output", PP_ObjCXX_Alias, INVALID, "mii", "u")
|
||||
TYPE("objective-c++", ObjCXX, PP_ObjCXX, "mm", "u")
|
||||
TYPE("renderscript", RenderScript, PP_C, "rs", "u")
|
||||
TYPE("cpp-output", PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("c", C, PP_C, "c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("cl", CL, PP_C, "cl", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("cuda-cpp-output", PP_CUDA, INVALID, "cui", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("cuda", CUDA, PP_CUDA, "cu", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("cuda", CUDA_DEVICE, PP_CUDA, "cu", "" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("hip-cpp-output", PP_HIP, INVALID, "cui", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("hip", HIP, PP_HIP, "cu", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("hip", HIP_DEVICE, PP_HIP, "cu", "" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objective-c-cpp-output", PP_ObjC, INVALID, "mi", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objc-cpp-output", PP_ObjC_Alias, INVALID, "mi", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objective-c", ObjC, PP_ObjC, "m", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("c++-cpp-output", PP_CXX, INVALID, "ii", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("c++", CXX, PP_CXX, "cpp", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objective-c++-cpp-output", PP_ObjCXX, INVALID, "mii", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objc++-cpp-output", PP_ObjCXX_Alias, INVALID, "mii", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("objective-c++", ObjCXX, PP_ObjCXX, "mm", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("renderscript", RenderScript, PP_C, "rs", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
|
||||
// C family input files to precompile.
|
||||
TYPE("c-header-cpp-output", PP_CHeader, INVALID, "i", "p")
|
||||
TYPE("c-header", CHeader, PP_CHeader, "h", "pu")
|
||||
TYPE("cl-header", CLHeader, PP_CHeader, "h", "pu")
|
||||
TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID, "mi", "p")
|
||||
TYPE("objective-c-header", ObjCHeader, PP_ObjCHeader, "h", "pu")
|
||||
TYPE("c++-header-cpp-output", PP_CXXHeader, INVALID, "ii", "p")
|
||||
TYPE("c++-header", CXXHeader, PP_CXXHeader, "hh", "pu")
|
||||
TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p")
|
||||
TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "pu")
|
||||
TYPE("c++-module", CXXModule, PP_CXXModule, "cppm", "mu")
|
||||
TYPE("c++-module-cpp-output", PP_CXXModule, INVALID, "iim", "m")
|
||||
TYPE("c-header-cpp-output", PP_CHeader, INVALID, "i", "p", phases::Precompile)
|
||||
TYPE("c-header", CHeader, PP_CHeader, "h", "pu", phases::Preprocess, phases::Precompile)
|
||||
TYPE("cl-header", CLHeader, PP_CHeader, "h", "pu", phases::Preprocess, phases::Precompile)
|
||||
TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID, "mi", "p", phases::Precompile)
|
||||
TYPE("objective-c-header", ObjCHeader, PP_ObjCHeader, "h", "pu", phases::Preprocess, phases::Precompile)
|
||||
TYPE("c++-header-cpp-output", PP_CXXHeader, INVALID, "ii", "p", phases::Precompile)
|
||||
TYPE("c++-header", CXXHeader, PP_CXXHeader, "hh", "pu", phases::Preprocess, phases::Precompile)
|
||||
TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p", phases::Precompile)
|
||||
TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "pu", phases::Preprocess, phases::Precompile)
|
||||
TYPE("c++-module", CXXModule, PP_CXXModule, "cppm", "mu", phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("c++-module-cpp-output", PP_CXXModule, INVALID, "iim", "m", phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
|
||||
// Other languages.
|
||||
TYPE("ada", Ada, INVALID, nullptr, "u")
|
||||
TYPE("assembler", PP_Asm, INVALID, "s", "au")
|
||||
TYPE("assembler-with-cpp", Asm, PP_Asm, "S", "au")
|
||||
TYPE("f95", PP_Fortran, INVALID, nullptr, "u")
|
||||
TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, "u")
|
||||
TYPE("java", Java, INVALID, nullptr, "u")
|
||||
TYPE("ada", Ada, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("assembler", PP_Asm, INVALID, "s", "au", phases::Assemble, phases::Link)
|
||||
TYPE("assembler-with-cpp", Asm, PP_Asm, "S", "au", phases::Preprocess, phases::Assemble, phases::Link)
|
||||
TYPE("f95", PP_Fortran, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("f95-cpp-input", Fortran, PP_Fortran, nullptr, "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("java", Java, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
|
||||
// LLVM IR/LTO types. We define separate types for IR and LTO because LTO
|
||||
// outputs should use the standard suffixes.
|
||||
TYPE("ir", LLVM_IR, INVALID, "ll", "u")
|
||||
TYPE("ir", LLVM_BC, INVALID, "bc", "u")
|
||||
TYPE("lto-ir", LTO_IR, INVALID, "s", "")
|
||||
TYPE("lto-bc", LTO_BC, INVALID, "o", "")
|
||||
TYPE("ir", LLVM_IR, INVALID, "ll", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("ir", LLVM_BC, INVALID, "bc", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("lto-ir", LTO_IR, INVALID, "s", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("lto-bc", LTO_BC, INVALID, "o", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
|
||||
// Misc.
|
||||
TYPE("ast", AST, INVALID, "ast", "u")
|
||||
TYPE("ifs", IFS, INVALID, "ifs", "u")
|
||||
TYPE("pcm", ModuleFile, INVALID, "pcm", "u")
|
||||
TYPE("plist", Plist, INVALID, "plist", "")
|
||||
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", "")
|
||||
TYPE("rewritten-legacy-objc", RewrittenLegacyObjC,INVALID, "cpp", "")
|
||||
TYPE("remap", Remap, INVALID, "remap", "")
|
||||
TYPE("precompiled-header", PCH, INVALID, "gch", "A")
|
||||
TYPE("object", Object, INVALID, "o", "")
|
||||
TYPE("treelang", Treelang, INVALID, nullptr, "u")
|
||||
TYPE("image", Image, INVALID, "out", "")
|
||||
TYPE("dSYM", dSYM, INVALID, "dSYM", "A")
|
||||
TYPE("dependencies", Dependencies, INVALID, "d", "")
|
||||
TYPE("cuda-fatbin", CUDA_FATBIN, INVALID, "fatbin","A")
|
||||
TYPE("hip-fatbin", HIP_FATBIN, INVALID, "hipfb", "A")
|
||||
TYPE("none", Nothing, INVALID, nullptr, "u")
|
||||
TYPE("ast", AST, INVALID, "ast", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("ifs", IFS, INVALID, "ifs", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("pcm", ModuleFile, INVALID, "pcm", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("plist", Plist, INVALID, "plist", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("rewritten-objc", RewrittenObjC,INVALID, "cpp", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("rewritten-legacy-objc", RewrittenLegacyObjC,INVALID, "cpp", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("remap", Remap, INVALID, "remap", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("precompiled-header", PCH, INVALID, "gch", "A", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("object", Object, INVALID, "o", "", phases::Link)
|
||||
TYPE("treelang", Treelang, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("image", Image, INVALID, "out", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("dSYM", dSYM, INVALID, "dSYM", "A", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("dependencies", Dependencies, INVALID, "d", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("cuda-fatbin", CUDA_FATBIN, INVALID, "fatbin","A", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("hip-fatbin", HIP_FATBIN, INVALID, "hipfb", "A", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
TYPE("none", Nothing, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace driver {
|
|||
namespace types {
|
||||
enum ID {
|
||||
TY_INVALID,
|
||||
#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) TY_##ID,
|
||||
#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
|
||||
#include "clang/Driver/Types.def"
|
||||
#undef TYPE
|
||||
TY_LAST
|
||||
|
|
|
@ -2223,7 +2223,7 @@ class OffloadingActionBuilder final {
|
|||
/// Builder interface. It doesn't build anything or keep any state.
|
||||
class DeviceActionBuilder {
|
||||
public:
|
||||
typedef llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PhasesTy;
|
||||
typedef const llvm::SmallVectorImpl<phases::ID> PhasesTy;
|
||||
|
||||
enum ActionBuilderReturnCode {
|
||||
// The builder acted successfully on the current action.
|
||||
|
@ -3237,13 +3237,14 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
|
|||
HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
|
||||
ActionList LinkerInputs;
|
||||
|
||||
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
|
||||
unsigned LastPLSize = 0;
|
||||
for (auto &I : Inputs) {
|
||||
types::ID InputType = I.first;
|
||||
const Arg *InputArg = I.second;
|
||||
|
||||
PL.clear();
|
||||
llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> PL;
|
||||
types::getCompilationPhases(InputType, PL);
|
||||
LastPLSize = PL.size();
|
||||
|
||||
// If the first step comes after the final phase we are doing as part of
|
||||
// this compilation, warn the user about it.
|
||||
|
@ -3309,9 +3310,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
|
|||
if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg))
|
||||
break;
|
||||
|
||||
for (SmallVectorImpl<phases::ID>::iterator i = PL.begin(), e = PL.end();
|
||||
i != e; ++i) {
|
||||
phases::ID Phase = *i;
|
||||
for (phases::ID Phase : PL) {
|
||||
|
||||
// We are done if this step is past what the user requested.
|
||||
if (Phase > FinalPhase)
|
||||
|
@ -3325,7 +3324,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
|
|||
|
||||
// Queue linker inputs.
|
||||
if (Phase == phases::Link) {
|
||||
assert((i + 1) == e && "linking must be final compilation step.");
|
||||
assert(Phase == PL.back() && "linking must be final compilation step.");
|
||||
LinkerInputs.push_back(Current);
|
||||
Current = nullptr;
|
||||
break;
|
||||
|
@ -3382,7 +3381,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
|
|||
|
||||
// If we are linking, claim any options which are obviously only used for
|
||||
// compilation.
|
||||
if (FinalPhase == phases::Link && PL.size() == 1) {
|
||||
// FIXME: Understand why the last Phase List length is used here.
|
||||
if (FinalPhase == phases::Link && LastPLSize == 1) {
|
||||
Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
|
||||
Args.ClaimAllArgs(options::OPT_cl_compile_Group);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
#include "clang/Driver/Types.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/StringSwitch.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include <cassert>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace clang::driver;
|
||||
using namespace clang::driver::types;
|
||||
|
@ -20,11 +21,12 @@ struct TypeInfo {
|
|||
const char *Flags;
|
||||
const char *TempSuffix;
|
||||
ID PreprocessedType;
|
||||
const llvm::SmallVector<phases::ID, phases::MaxNumberOfPhases> Phases;
|
||||
};
|
||||
|
||||
static const TypeInfo TypeInfos[] = {
|
||||
#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
|
||||
{ NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
|
||||
#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
|
||||
{ NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
|
||||
#include "clang/Driver/Types.def"
|
||||
#undef TYPE
|
||||
};
|
||||
|
@ -264,6 +266,8 @@ types::ID types::lookupTypeForTypeSpecifier(const char *Name) {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
if (Id != TY_Object) {
|
||||
if (getPreprocessedType(Id) != TY_INVALID) {
|
||||
|
@ -286,6 +290,18 @@ void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl<phases::ID> &P) {
|
|||
if (!onlyPrecompileType(Id)) {
|
||||
P.push_back(phases::Link);
|
||||
}
|
||||
|
||||
// Check that the static Phase list matches.
|
||||
// TODO: These will be deleted.
|
||||
const llvm::SmallVectorImpl<phases::ID> &Phases = getInfo(Id).Phases;
|
||||
assert(Phases.size() == P.size() &&
|
||||
std::equal(Phases.begin(), Phases.end(), P.begin()) &&
|
||||
"Invalid phase or size");
|
||||
|
||||
// TODO: This function is still being used to assert that the phase list in
|
||||
// Types.def is correct. Everything above this comment will be removed
|
||||
// in a subsequent NFC commit.
|
||||
P = Phases;
|
||||
assert(0 < P.size() && "Not enough phases in list");
|
||||
assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue