]> granicus.if.org Git - clang/commitdiff
Add BMI, BMI2, and LZCNT feature flags to enable adding intrinsics.
authorCraig Topper <craig.topper@gmail.com>
Sun, 25 Dec 2011 05:06:45 +0000 (05:06 +0000)
committerCraig Topper <craig.topper@gmail.com>
Sun, 25 Dec 2011 05:06:45 +0000 (05:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147262 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
lib/Basic/Targets.cpp
lib/Headers/immintrin.h

index 331b248bf9035b8d27080a88a943cd4cfe8fa9c8..aafea88a0f182a390d78ce97960726764e229d05 100644 (file)
@@ -612,6 +612,9 @@ def mno_ssse3 : Flag<"-mno-ssse3">, Group<m_x86_Features_Group>;
 def mno_aes : Flag<"-mno-aes">, Group<m_x86_Features_Group>;
 def mno_avx : Flag<"-mno-avx">, Group<m_x86_Features_Group>;
 def mno_avx2 : Flag<"-mno-avx2">, Group<m_x86_Features_Group>;
+def mno_lzcnt : Flag<"-mno-lzcnt">, Group<m_x86_Features_Group>;
+def mno_bmi : Flag<"-mno-bmi">, Group<m_x86_Features_Group>;
+def mno_bmi2 : Flag<"-mno-bmi2">, Group<m_x86_Features_Group>;
 
 def mno_thumb : Flag<"-mno-thumb">, Group<m_Group>;
 def marm : Flag<"-marm">, Alias<mno_thumb>;
@@ -637,6 +640,9 @@ def mssse3 : Flag<"-mssse3">, Group<m_x86_Features_Group>;
 def maes : Flag<"-maes">, Group<m_x86_Features_Group>;
 def mavx : Flag<"-mavx">, Group<m_x86_Features_Group>;
 def mavx2 : Flag<"-mavx2">, Group<m_x86_Features_Group>;
+def mlzcnt : Flag<"-mlzcnt">, Group<m_x86_Features_Group>;
+def mbmi : Flag<"-mbmi">, Group<m_x86_Features_Group>;
+def mbmi2 : Flag<"-mbmi2">, Group<m_x86_Features_Group>;
 def mthumb : Flag<"-mthumb">, Group<m_Group>;
 def mtune_EQ : Joined<"-mtune=">, Group<m_Group>;
 def multi__module : Flag<"-multi_module">;
index d61d3cd7cf3be4a85370be9072fa17f53f4112b8..34258c10546cf37ca7110db7aa1c492992100b5b 100644 (file)
@@ -1195,6 +1195,9 @@ class X86TargetInfo : public TargetInfo {
   bool HasAES;
   bool HasAVX;
   bool HasAVX2;
+  bool HasLZCNT;
+  bool HasBMI;
+  bool HasBMI2;
 
   /// \brief Enumeration of all of the X86 CPUs supported by Clang.
   ///
@@ -1331,7 +1334,8 @@ class X86TargetInfo : public TargetInfo {
 public:
   X86TargetInfo(const std::string& triple)
     : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
-      HasAES(false), HasAVX(false), HasAVX2(false), CPU(CK_Generic) {
+      HasAES(false), HasAVX(false), HasAVX2(false), HasLZCNT(false),
+      HasBMI(false), HasBMI2(false), CPU(CK_Generic) {
     BigEndian = false;
     LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
   }
@@ -1508,6 +1512,9 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
   Features["aes"] = false;
   Features["avx"] = false;
   Features["avx2"] = false;
+  Features["lzcnt"] = false;
+  Features["bmi"] = false;
+  Features["bmi2"] = false;
 
   // FIXME: This *really* should not be here.
 
@@ -1575,6 +1582,9 @@ void X86TargetInfo::getDefaultFeatures(llvm::StringMap<bool> &Features) const {
     setFeatureEnabled(Features, "mmx", true);
     setFeatureEnabled(Features, "sse4", true);
     setFeatureEnabled(Features, "aes", true);
+    setFeatureEnabled(Features, "lzcnt", true);
+    setFeatureEnabled(Features, "bmi", true);
+    setFeatureEnabled(Features, "bmi2", true);
     //setFeatureEnabled(Features, "avx2", true);
     break;
   case CK_K6:
@@ -1675,6 +1685,12 @@ bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
         Features["avx"] = Features["avx2"] = true;
     else if (Name == "sse4a")
       Features["mmx"] = Features["sse4a"] = true;
+    else if (Name == "lzcnt")
+      Features["lzcnt"] = true;
+    else if (Name == "bmi")
+      Features["bmi"] = true;
+    else if (Name == "bmi2")
+      Features["bmi2"] = true;
   } else {
     if (Name == "mmx")
       Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
@@ -1705,6 +1721,12 @@ bool X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
       Features["avx2"] = false;
     else if (Name == "sse4a")
       Features["sse4a"] = false;
+    else if (Name == "lzcnt")
+      Features["lzcnt"] = false;
+    else if (Name == "bmi")
+      Features["bmi"] = false;
+    else if (Name == "bmi2")
+      Features["bmi2"] = false;
   }
 
   return true;
@@ -1724,6 +1746,21 @@ void X86TargetInfo::HandleTargetFeatures(std::vector<std::string> &Features) {
       continue;
     }
 
+    if (Features[i].substr(1) == "lzcnt") {
+      HasLZCNT = true;
+      continue;
+    }
+
+    if (Features[i].substr(1) == "bmi") {
+      HasBMI = true;
+      continue;
+    }
+
+    if (Features[i].substr(1) == "bmi2") {
+      HasBMI2 = true;
+      continue;
+    }
+
     // FIXME: Not sure yet how to treat AVX in regard to SSE levels.
     // For now let it be enabled together with other SSE levels.
     if (Features[i].substr(1) == "avx2") {
@@ -1946,6 +1983,15 @@ void X86TargetInfo::getTargetDefines(const LangOptions &Opts,
   if (HasAVX2)
     Builder.defineMacro("__AVX2__");
 
+  if (HasLZCNT)
+    Builder.defineMacro("__LZCNT__");
+
+  if (HasBMI)
+    Builder.defineMacro("__BMI__");
+
+  if (HasBMI2)
+    Builder.defineMacro("__BMI2__");
+
   // Each case falls through to the previous one here.
   switch (SSELevel) {
   case SSE42:
index 80b24484a636de0dcedcf7c143233031a70ab6a1..53838ec78b9169bfe5d33b784514272fc804689a 100644 (file)
@@ -48,7 +48,7 @@
 #include <smmintrin.h>
 #endif
 
-#if defined (__AES__) || defined (__PCLMUL__)
+#if defined (__AES__)
 #include <wmmintrin.h>
 #endif