[cfe-commits] r145194 - in /cfe/trunk: lib/Basic/Targets.cpp test/Preprocessor/mmx.c

Rafael Espindola rafael.espindola at gmail.com
Sun Nov 27 12:00:43 PST 2011


Author: rafael
Date: Sun Nov 27 14:00:43 2011
New Revision: 145194

URL: http://llvm.org/viewvc/llvm-project?rev=145194&view=rev
Log:
Make our handling of MMX x SSE closer to what gcc does:

* Enabling sse enables mmx.
* Disabling (-mno-mmx) mmx, doesn't disable sse (we got this right already).
* The order in not important. -msse -mno-mmx is the same as -mno-mmx -msse.

Added:
    cfe/trunk/test/Preprocessor/mmx.c
Modified:
    cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=145194&r1=145193&r2=145194&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sun Nov 27 14:00:43 2011
@@ -1587,23 +1587,26 @@
       (Name != "sse4" && Name != "sse4.2" && Name != "sse4.1"))
     return false;
 
+  // FIXME: this should probably use a switch with fall through.
+
   if (Enabled) {
     if (Name == "mmx")
       Features["mmx"] = true;
     else if (Name == "sse")
-      Features["sse"] = true;
+      Features["mmx"] = Features["sse"] = true;
     else if (Name == "sse2")
-      Features["sse"] = Features["sse2"] = true;
+      Features["mmx"] = Features["sse"] = Features["sse2"] = true;
     else if (Name == "sse3")
-      Features["sse"] = Features["sse2"] = Features["sse3"] = true;
+      Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
+        true;
     else if (Name == "ssse3")
-      Features["sse"] = Features["sse2"] = Features["sse3"] =
+      Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
         Features["ssse3"] = true;
     else if (Name == "sse4" || Name == "sse4.2")
-      Features["sse"] = Features["sse2"] = Features["sse3"] =
+      Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
         Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
     else if (Name == "sse4.1")
-      Features["sse"] = Features["sse2"] = Features["sse3"] =
+      Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
         Features["ssse3"] = Features["sse41"] = true;
     else if (Name == "3dnow")
       Features["mmx"] = Features["3dnow"] = true;
@@ -1612,10 +1615,11 @@
     else if (Name == "aes")
       Features["aes"] = true;
     else if (Name == "avx")
-      Features["avx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
-        Features["ssse3"] = Features["sse41"] = Features["sse42"] = true;
+      Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
+        Features["ssse3"] = Features["sse41"] = Features["sse42"] =
+        Features["avx"] = true;
     else if (Name == "sse4a")
-      Features["sse4a"] = true;
+      Features["mmx"] = Features["sse4a"] = true;
   } else {
     if (Name == "mmx")
       Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
@@ -3671,13 +3675,32 @@
   Target->getDefaultFeatures(Features);
 
   // Apply the user specified deltas.
+  // First the enables.
   for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
          ie = Opts.Features.end(); it != ie; ++it) {
     const char *Name = it->c_str();
 
+    if (Name[0] != '+')
+      continue;
+
+    // Apply the feature via the target.
+    if (!Target->setFeatureEnabled(Features, Name + 1, true)) {
+      Diags.Report(diag::err_target_invalid_feature) << Name;
+      return 0;
+    }
+  }
+
+  // Then the disables.
+  for (std::vector<std::string>::const_iterator it = Opts.Features.begin(),
+         ie = Opts.Features.end(); it != ie; ++it) {
+    const char *Name = it->c_str();
+
+    if (Name[0] == '+')
+      continue;
+
     // Apply the feature via the target.
-    if ((Name[0] != '-' && Name[0] != '+') ||
-        !Target->setFeatureEnabled(Features, Name + 1, (Name[0] == '+'))) {
+    if (Name[0] != '-' ||
+        !Target->setFeatureEnabled(Features, Name + 1, false)) {
       Diags.Report(diag::err_target_invalid_feature) << Name;
       return 0;
     }

Added: cfe/trunk/test/Preprocessor/mmx.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/mmx.c?rev=145194&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/mmx.c (added)
+++ cfe/trunk/test/Preprocessor/mmx.c Sun Nov 27 14:00:43 2011
@@ -0,0 +1,13 @@
+// RUN: %clang -march=i386 -m32 -E -dM %s -msse -o - 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=SSE_AND_MMX
+// RUN: %clang -march=i386 -m32 -E -dM %s -msse -mno-mmx -o - 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=SSE_NO_MMX
+// RUN: %clang -march=i386 -m32 -E -dM %s -mno-mmx -msse -o - 2>&1 \
+// RUN:   | FileCheck %s -check-prefix=SSE_NO_MMX
+
+// SSE_AND_MMX: #define __MMX__
+// SSE_AND_MMX: #define __SSE__
+
+// SSE_NO_MMX-NOT: __MMX__
+// SSE_NO_MMX: __SSE__
+// SSE_NO_MMX-NOT: __MMX__





More information about the cfe-commits mailing list