Make VTs and UnicodeCharSet ctors constexpr if the compiler supports it.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Mar 2015 18:10:07 +0000 (18:10 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 1 Mar 2015 18:10:07 +0000 (18:10 +0000)
There are static variables of this around that we really want to go
into a read-only segment. Sadly compilers are not smart enough to figure
that out without constexpr.

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

include/llvm/CodeGen/MachineValueType.h
include/llvm/CodeGen/ValueTypes.h
include/llvm/Support/UnicodeCharRanges.h

index 7ad782f0b72003930e36ec164ea120399f3b2605..3eb4d0b85de422c856bd0fe3c169e920f83b4557 100644 (file)
@@ -161,8 +161,8 @@ namespace llvm {
 
     SimpleValueType SimpleTy;
 
-    MVT() : SimpleTy((SimpleValueType)(INVALID_SIMPLE_VALUE_TYPE)) {}
-    MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
+    LLVM_CONSTEXPR MVT() : SimpleTy(INVALID_SIMPLE_VALUE_TYPE) {}
+    LLVM_CONSTEXPR MVT(SimpleValueType SVT) : SimpleTy(SVT) { }
 
     bool operator>(const MVT& S)  const { return SimpleTy >  S.SimpleTy; }
     bool operator<(const MVT& S)  const { return SimpleTy <  S.SimpleTy; }
index 4e93940e223ef8295e3376d91b747737bd68453e..e1a9fd38290ba20846d33687181ece75726ecbb9 100644 (file)
@@ -34,10 +34,9 @@ namespace llvm {
     Type *LLVMTy;
 
   public:
-    EVT() : V((MVT::SimpleValueType)(MVT::INVALID_SIMPLE_VALUE_TYPE)),
-            LLVMTy(nullptr) {}
-    EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(nullptr) { }
-    EVT(MVT S) : V(S), LLVMTy(nullptr) {}
+    LLVM_CONSTEXPR EVT() : V(MVT::INVALID_SIMPLE_VALUE_TYPE), LLVMTy(nullptr) {}
+    LLVM_CONSTEXPR EVT(MVT::SimpleValueType SVT) : V(SVT), LLVMTy(nullptr) {}
+    LLVM_CONSTEXPR EVT(MVT S) : V(S), LLVMTy(nullptr) {}
 
     bool operator==(EVT VT) const {
       return !(*this != VT);
index 79137bf353633787c31489af22e14df96656e226..9f738dff11075287bb9f6e8a0f93b731823cbbcf 100644 (file)
@@ -50,9 +50,13 @@ public:
   /// the UnicodeCharSet instance, and should not change. Array is validated by
   /// the constructor, so it makes sense to create as few UnicodeCharSet
   /// instances per each array of ranges, as possible.
+#ifdef NDEBUG
+  LLVM_CONSTEXPR UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {}
+#else
   UnicodeCharSet(CharRanges Ranges) : Ranges(Ranges) {
     assert(rangesAreValid());
   }
+#endif
 
   /// \brief Returns true if the character set contains the Unicode code point
   /// \p C.