]> granicus.if.org Git - clang/commitdiff
Move the logic for selecting the last feature in the command line to the driver.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 21 Aug 2013 17:34:32 +0000 (17:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 21 Aug 2013 17:34:32 +0000 (17:34 +0000)
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

lib/Basic/Targets.cpp
lib/Driver/Tools.cpp
test/Driver/x86_features.c

index e2898cc86b57471bced521c2777d3da2f78c5fbe..22a7bda1aa8cafc97ca22e2debabf8100bd70779 100644 (file)
@@ -5503,26 +5503,10 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
   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);
index 7e66caa6c3700e255782358cf7c0a0a2dd3a9a22..746300000f2fa36e32419d9469567e9b27da9bb1 100644 (file)
@@ -1431,11 +1431,26 @@ static void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
     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);
   }
 }
 
index 5470bbcdeaaa95781f9396c6a9972c4afa877133..6fbf5ca4aec473e98429d042c71506ca8f3d7bbf 100644 (file)
@@ -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.