TableGen: Use 'enum : uint64_t' for feature flags to fix -Wmicrosoft
authorReid Kleckner <reid@kleckner.net>
Mon, 9 Mar 2015 20:23:14 +0000 (20:23 +0000)
committerReid Kleckner <reid@kleckner.net>
Mon, 9 Mar 2015 20:23:14 +0000 (20:23 +0000)
clang-cl would warn that this value is not representable in 'int':
  enum { FeatureX = 1ULL << 31 };
All MS enums are 'ints' unless otherwise specified, so we have to use an
explicit type.  The AMDGPU target just hit 32 features, triggering this
warning.

Now that we have C++11 strong enum types, we can also eliminate the
'const uint64_t' codepath from tablegen and just use 'enum : uint64_t'.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231697 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/MSP430/MCTargetDesc/MSP430MCTargetDesc.h
lib/Target/NVPTX/MCTargetDesc/NVPTXMCTargetDesc.h
lib/Target/R600/MCTargetDesc/AMDGPUMCTargetDesc.h
lib/Target/XCore/MCTargetDesc/XCoreMCTargetDesc.h
utils/TableGen/SubtargetEmitter.cpp

index 586f5d991c940aedc9b6c328495ffb151da17eb1..241f1d6f9c0f6d0ebce06cb891665356343573cf 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef LLVM_LIB_TARGET_MSP430_MCTARGETDESC_MSP430MCTARGETDESC_H
 #define LLVM_LIB_TARGET_MSP430_MCTARGETDESC_MSP430MCTARGETDESC_H
 
+#include "llvm/Support/DataTypes.h"
+
 namespace llvm {
 class Target;
 
index 98821d23137819e269e2fbe3593647335d3d8eeb..bfd51239840882b6810b43993ad98019a8e56805 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCTARGETDESC_H
 #define LLVM_LIB_TARGET_NVPTX_MCTARGETDESC_NVPTXMCTARGETDESC_H
 
+#include <stdint.h>
+
 namespace llvm {
 class Target;
 
index bc8cd53d84b4fa452d2b8da3d22683cdcf11a78e..18ba773a59caf09b08be2715b7dd7cb6d26d6aa0 100644 (file)
@@ -16,6 +16,7 @@
 #ifndef LLVM_LIB_TARGET_R600_MCTARGETDESC_AMDGPUMCTARGETDESC_H
 #define LLVM_LIB_TARGET_R600_MCTARGETDESC_AMDGPUMCTARGETDESC_H
 
+#include "llvm/Support/DataTypes.h"
 #include "llvm/ADT/StringRef.h"
 
 namespace llvm {
index 0ff5961b14432327a8096ddd653977ed6f9530d6..28e0275c72dbe1334b1ee12d2ab9eaf69cc5bfc9 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef LLVM_LIB_TARGET_XCORE_MCTARGETDESC_XCOREMCTARGETDESC_H
 #define LLVM_LIB_TARGET_XCORE_MCTARGETDESC_XCOREMCTARGETDESC_H
 
+#include "llvm/Support/DataTypes.h"
+
 namespace llvm {
 class Target;
 
index d8cf0d1e6ea7de252933f6752cef416c0ebf2242..3403afb65c7b11d3caac965a8a233b330a0dbe27 100644 (file)
@@ -128,42 +128,29 @@ void SubtargetEmitter::Enumeration(raw_ostream &OS,
 
   OS << "namespace " << Target << " {\n";
 
-  // For bit flag enumerations with more than 32 items, emit constants.
-  // Emit an enum for everything else.
-  if (isBits && N > 32) {
-    // For each record
-    for (unsigned i = 0; i < N; i++) {
-      // Next record
-      Record *Def = DefList[i];
-
-      // Get and emit name and expression (1 << i)
-      OS << "  const uint64_t " << Def->getName() << " = 1ULL << " << i << ";\n";
-    }
-  } else {
-    // Open enumeration
-    OS << "enum {\n";
-
-    // For each record
-    for (unsigned i = 0; i < N;) {
-      // Next record
-      Record *Def = DefList[i];
+  // Open enumeration. Use a 64-bit underlying type.
+  OS << "enum : uint64_t {\n";
 
-      // Get and emit name
-      OS << "  " << Def->getName();
+  // For each record
+  for (unsigned i = 0; i < N;) {
+    // Next record
+    Record *Def = DefList[i];
 
-      // If bit flags then emit expression (1 << i)
-      if (isBits)  OS << " = " << " 1ULL << " << i;
+    // Get and emit name
+    OS << "  " << Def->getName();
 
-      // Depending on 'if more in the list' emit comma
-      if (++i < N) OS << ",";
+    // If bit flags then emit expression (1 << i)
+    if (isBits)  OS << " = " << " 1ULL << " << i;
 
-      OS << "\n";
-    }
+    // Depending on 'if more in the list' emit comma
+    if (++i < N) OS << ",";
 
-    // Close enumeration
-    OS << "};\n";
+    OS << "\n";
   }
 
+  // Close enumeration
+  OS << "};\n";
+
   OS << "}\n";
 }