summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorPuyan Lotfi <puyan@puyan.org>2019-07-22 23:10:10 +0000
committerPuyan Lotfi <puyan@puyan.org>2019-07-22 23:10:10 +0000
commit298a1ed4add3247819650fd719b2848e6d8df4b6 (patch)
tree45e641d2bcaf0730668fdb8fbe5c4f4b94babb6c /clang/lib
parent67713e2687d3699a2c44db9f600669f19261e730 (diff)
downloadbcm5719-llvm-298a1ed4add3247819650fd719b2848e6d8df4b6.tar.gz
bcm5719-llvm-298a1ed4add3247819650fd719b2848e6d8df4b6.zip
[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
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/Driver.cpp16
-rw-r--r--clang/lib/Driver/Types.cpp22
2 files changed, 27 insertions, 11 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 396ddf4dd81..bc6b23d5827 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -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);
}
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index 96937678ac6..9b725565397 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -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");
}
OpenPOWER on IntegriCloud