Move the logic for selecting the last feature in the command line to the driver.
This is a partial revert of r188817 now that the driver handles -target-feature
in a single place.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188910 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Basic/Targets.cpp b/lib/Basic/Targets.cpp
index e2898cc..22a7bda 100644
--- a/lib/Basic/Targets.cpp
+++ b/lib/Basic/Targets.cpp
@@ -5503,26 +5503,10 @@
llvm::StringMap<bool> Features;
Target->getDefaultFeatures(Features);
- // Fist the last of each option;
- llvm::StringMap<unsigned> LastOpt;
- for (unsigned I = 0, N = Opts->FeaturesAsWritten.size();
- I < N; ++I) {
- const char *Name = Opts->FeaturesAsWritten[I].c_str() + 1;
- LastOpt[Name] = I;
- }
-
// Apply the user specified deltas.
for (unsigned I = 0, N = Opts->FeaturesAsWritten.size();
I < N; ++I) {
const char *Name = Opts->FeaturesAsWritten[I].c_str();
-
- // If this option was overridden, ignore it.
- llvm::StringMap<unsigned>::iterator LastI = LastOpt.find(Name + 1);
- assert(LastI != LastOpt.end());
- unsigned Last = LastI->second;
- if (Last != I)
- continue;
-
// Apply the feature via the target.
bool Enabled = Name[0] == '+';
Target->setFeatureEnabled(Features, Name + 1, Enabled);
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 7e66caa..7463000 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1431,11 +1431,26 @@
getX86TargetFeatures(Args, Features);
break;
}
- for (std::vector<const char *>::iterator I = Features.begin(),
- E = Features.end();
- I != E; ++I) {
+
+ // Find the last of each feature.
+ llvm::StringMap<unsigned> LastOpt;
+ for (unsigned I = 0, N = Features.size(); I < N; ++I) {
+ const char *Name = Features[I];
+ assert(Name[0] == '-' || Name[0] == '+');
+ LastOpt[Name + 1] = I;
+ }
+
+ for (unsigned I = 0, N = Features.size(); I < N; ++I) {
+ // If this feature was overridden, ignore it.
+ const char *Name = Features[I];
+ llvm::StringMap<unsigned>::iterator LastI = LastOpt.find(Name + 1);
+ assert(LastI != LastOpt.end());
+ unsigned Last = LastI->second;
+ if (Last != I)
+ continue;
+
CmdArgs.push_back("-target-feature");
- CmdArgs.push_back(*I);
+ CmdArgs.push_back(Name);
}
}
diff --git a/test/Driver/x86_features.c b/test/Driver/x86_features.c
index 5470bbc..6fbf5ca 100644
--- a/test/Driver/x86_features.c
+++ b/test/Driver/x86_features.c
@@ -1,2 +1,3 @@
// RUN: %clang -target i386-unknown-unknown -### -S %s -msse -msse4 -mno-sse -mno-mmx -msse 2>&1 | FileCheck %s
-// CHECK: "pentium4" "-target-feature" "+sse" "-target-feature" "+sse4" "-target-feature" "-sse" "-target-feature" "-mmx" "-target-feature" "+sse"
+// CHECK: "pentium4" "-target-feature" "+sse4" "-target-feature" "-mmx" "-target-feature" "+sse"
+// Note that we filter out all but the last -m(no)sse.