From 3a0ec954dcab893b92e49bcfccfd276c7dffba34 Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Tue, 25 Aug 2015 13:45:28 +0000 Subject: [PATCH] Rewrite the PPC target feature handling to more resemble other targets. This involved specializing handleUserFeatures so that we could perform diagnostics on -only- user supplied features and migrating the rest of the initialization functions to set features based on enabling and disabling full feature sets. No functional change intended. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245936 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/Targets.cpp | 74 ++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp index 5c4a016b55..7c02731ca2 100644 --- a/lib/Basic/Targets.cpp +++ b/lib/Basic/Targets.cpp @@ -867,6 +867,9 @@ public: bool handleTargetFeatures(std::vector &Features, DiagnosticsEngine &Diags) override; + bool handleUserFeatures(llvm::StringMap &Features, + std::vector &UserFeatures, + DiagnosticsEngine &Diags) override; bool hasFeature(StringRef Feature) const override; void setFeatureEnabled(llvm::StringMap &Features, StringRef Name, bool Enabled) const override; @@ -1071,26 +1074,41 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector &Features, // all. } + return true; +} + +bool PPCTargetInfo::handleUserFeatures(llvm::StringMap &Features, + std::vector &UserFeatures, + DiagnosticsEngine &Diags) { + // Handle explicit options being passed to the compiler here: if we've // explicitly turned off vsx and turned on power8-vector or direct-move then // go ahead and error since the customer has expressed a somewhat incompatible // set of options. - if (std::find(Features.begin(), Features.end(), "-vsx") != Features.end()) { - if (std::find(Features.begin(), Features.end(), "+power8-vector") != - Features.end()) { + if (std::find(UserFeatures.begin(), UserFeatures.end(), "-vsx") != + UserFeatures.end()) { + if (std::find(UserFeatures.begin(), UserFeatures.end(), "+power8-vector") != + UserFeatures.end()) { Diags.Report(diag::err_opt_not_valid_with_opt) << "-mpower8-vector" << "-mno-vsx"; return false; } - if (std::find(Features.begin(), Features.end(), "+direct-move") != - Features.end()) { + if (std::find(UserFeatures.begin(), UserFeatures.end(), "+direct-move") != + UserFeatures.end()) { Diags.Report(diag::err_opt_not_valid_with_opt) << "-mdirect-move" << "-mno-vsx"; return false; } } + for (const auto &F : UserFeatures) { + const char *Name = F.c_str(); + // Apply the feature via the target. + bool Enabled = Name[0] == '+'; + setFeatureEnabled(Features, Name + 1, Enabled); + } + return true; } @@ -1332,37 +1350,29 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const { .Default(false); } -/* There is no clear way for the target to know which of the features in the - final feature vector came from defaults and which are actually specified by - the user. To that end, we use the fact that this function is not called on - default features - only user specified ones. By the first time this - function is called, the default features are populated. - We then keep track of the features that the user specified so that we - can ensure we do not override a user's request (only defaults). - For example: - -mcpu=pwr8 -mno-vsx (should disable vsx and everything that depends on it) - -mcpu=pwr8 -mdirect-move -mno-vsx (should actually be diagnosed) - -NOTE: Do not call this from PPCTargetInfo::initDefaultFeatures -*/ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap &Features, StringRef Name, bool Enabled) const { - static llvm::StringMap ExplicitFeatures; - ExplicitFeatures[Name] = Enabled; - - // At this point, -mno-vsx turns off the dependent features but we respect - // the user's requests. - if (!Enabled && Name == "vsx") { - Features["direct-move"] = ExplicitFeatures["direct-move"]; - Features["power8-vector"] = ExplicitFeatures["power8-vector"]; - } - if ((Enabled && Name == "power8-vector") || - (Enabled && Name == "direct-move")) { - if (ExplicitFeatures.find("vsx") == ExplicitFeatures.end()) { - Features["vsx"] = true; + // If we're enabling direct-move or power8-vector go ahead and enable vsx + // as well. Do the inverse if we're disabling vsx. We'll diagnose any user + // incompatible options. + if (Enabled) { + if (Name == "vsx") { + Features[Name] = true; + } else if (Name == "direct-move") { + Features[Name] = Features["vsx"] = true; + } else if (Name == "power8-vector") { + Features[Name] = Features["vsx"] = true; + } else { + Features[Name] = true; + } + } else { + if (Name == "vsx") { + Features[Name] = Features["direct-move"] = Features["power8-vector"] = + false; + } else { + Features[Name] = false; } } - Features[Name] = Enabled; } const char * const PPCTargetInfo::GCCRegNames[] = { -- 2.40.0