r367063 - [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.
Puyan Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 25 15:05:55 PDT 2019
Author: zer0
Date: Thu Jul 25 15:05:55 2019
New Revision: 367063
URL: http://llvm.org/viewvc/llvm-project?rev=367063&view=rev
Log:
[NFC][clang] Refactor getCompilationPhases()+Types.def step 2.
- Removing a few of the entries in the Flags for the Types.def table.
- Removing redundant parts of getCompilationPhases().
Flags have been removed from Types.def:
a - The type should only be assembled: Now, check that Phases contains
phases::Assemble but not phases::Compile or phases::Backend.
p - The type should only be precompiled: Now, check that Phases contains
phases::Precompile but that Flags does not contain 'm'.
m - Precompiling this type produces a module file: Now, check that
isPrepeocessedModuleType.
Differential Revision: https://reviews.llvm.org/D65176
Modified:
cfe/trunk/include/clang/Driver/Types.def
cfe/trunk/lib/Driver/Types.cpp
Modified: cfe/trunk/include/clang/Driver/Types.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Types.def?rev=367063&r1=367062&r2=367063&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Types.def (original)
+++ cfe/trunk/include/clang/Driver/Types.def Thu Jul 25 15:05:55 2019
@@ -30,15 +30,12 @@
// of this type, or null if unspecified.
// The fifth value is a string containing option flags. Valid values:
-// a - The type should only be assembled.
-// p - The type should only be precompiled.
// u - The type can be user specified (with -x).
-// m - Precompiling this type produces a module file.
-// 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.
+// Most of the options in Flags have been removed in favor of subsuming their
+// meaning from the phases list.
// C family source language (with and without preprocessing).
TYPE("cpp-output", PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +58,22 @@ TYPE("objective-c++", ObjCXX,
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", 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)
+TYPE("c-header-cpp-output", PP_CHeader, INVALID, "i", "", phases::Precompile)
+TYPE("c-header", CHeader, PP_CHeader, "h", "u", phases::Preprocess, phases::Precompile)
+TYPE("cl-header", CLHeader, PP_CHeader, "h", "u", phases::Preprocess, phases::Precompile)
+TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID, "mi", "", phases::Precompile)
+TYPE("objective-c-header", ObjCHeader, PP_ObjCHeader, "h", "u", phases::Preprocess, phases::Precompile)
+TYPE("c++-header-cpp-output", PP_CXXHeader, INVALID, "ii", "", phases::Precompile)
+TYPE("c++-header", CXXHeader, PP_CXXHeader, "hh", "u", phases::Preprocess, phases::Precompile)
+TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "", phases::Precompile)
+TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "u", phases::Preprocess, phases::Precompile)
+TYPE("c++-module", CXXModule, PP_CXXModule, "cppm", "u", phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c++-module-cpp-output", PP_CXXModule, INVALID, "iim", "", phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
// Other languages.
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("assembler", PP_Asm, INVALID, "s", "u", phases::Assemble, phases::Link)
+TYPE("assembler-with-cpp", Asm, PP_Asm, "S", "u", 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)
@@ -96,12 +93,12 @@ TYPE("plist", Plist,
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("precompiled-header", PCH, INVALID, "gch", "", 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("dSYM", dSYM, INVALID, "dSYM", "", 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("cuda-fatbin", CUDA_FATBIN, INVALID, "fatbin","", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("hip-fatbin", HIP_FATBIN, INVALID, "hipfb", "", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
TYPE("none", Nothing, INVALID, nullptr, "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
Modified: cfe/trunk/lib/Driver/Types.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Types.cpp?rev=367063&r1=367062&r2=367063&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Types.cpp (original)
+++ cfe/trunk/lib/Driver/Types.cpp Thu Jul 25 15:05:55 2019
@@ -42,11 +42,19 @@ const char *types::getTypeName(ID Id) {
}
types::ID types::getPreprocessedType(ID Id) {
- return getInfo(Id).PreprocessedType;
+ ID PPT = getInfo(Id).PreprocessedType;
+ assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) !=
+ (PPT == TY_INVALID)) &&
+ "Unexpected Preprocess Type.");
+ return PPT;
+}
+
+static bool isPrepeocessedModuleType(ID Id) {
+ return Id == TY_CXXModule || Id == TY_PP_CXXModule;
}
types::ID types::getPrecompiledType(ID Id) {
- if (strchr(getInfo(Id).Flags, 'm'))
+ if (isPrepeocessedModuleType(Id))
return TY_ModuleFile;
if (onlyPrecompileType(Id))
return TY_PCH;
@@ -71,11 +79,14 @@ const char *types::getTypeTempSuffix(ID
}
bool types::onlyAssembleType(ID Id) {
- return strchr(getInfo(Id).Flags, 'a');
+ return llvm::is_contained(getInfo(Id).Phases, phases::Assemble) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Compile) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Backend);
}
bool types::onlyPrecompileType(ID Id) {
- return strchr(getInfo(Id).Flags, 'p');
+ return llvm::is_contained(getInfo(Id).Phases, phases::Precompile) &&
+ !isPrepeocessedModuleType(Id);
}
bool types::canTypeBeUserSpecified(ID Id) {
@@ -83,7 +94,8 @@ bool types::canTypeBeUserSpecified(ID Id
}
bool types::appendSuffixForType(ID Id) {
- return strchr(getInfo(Id).Flags, 'A');
+ return Id == TY_PCH || Id == TY_dSYM || Id == TY_CUDA_FATBIN ||
+ Id == TY_HIP_FATBIN;
}
bool types::canLipoType(ID Id) {
@@ -269,39 +281,7 @@ types::ID types::lookupTypeForTypeSpecif
// 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) {
- P.push_back(phases::Preprocess);
- }
-
- if (getPrecompiledType(Id) != TY_INVALID) {
- P.push_back(phases::Precompile);
- }
-
- if (!onlyPrecompileType(Id)) {
- if (!onlyAssembleType(Id)) {
- P.push_back(phases::Compile);
- P.push_back(phases::Backend);
- }
- P.push_back(phases::Assemble);
- }
- }
-
- 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;
+ P = getInfo(Id).Phases;
assert(0 < P.size() && "Not enough phases in list");
assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
}
More information about the cfe-commits
mailing list