[dragonegg] r182208 - Fix up vector usage so that it works with both gcc-4.8 and earlier versions of

Duncan Sands baldrick at free.fr
Sun May 19 02:52:41 PDT 2013


Author: baldrick
Date: Sun May 19 04:52:40 2013
New Revision: 182208

URL: http://llvm.org/viewvc/llvm-project?rev=182208&view=rev
Log:
Fix up vector usage so that it works with both gcc-4.8 and earlier versions of
gcc.

Modified:
    dragonegg/trunk/include/dragonegg/Trees.h
    dragonegg/trunk/src/Convert.cpp

Modified: dragonegg/trunk/include/dragonegg/Trees.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Trees.h?rev=182208&r1=182207&r2=182208&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Trees.h (original)
+++ dragonegg/trunk/include/dragonegg/Trees.h Sun May 19 04:52:40 2013
@@ -141,4 +141,26 @@ unsigned getFieldAlignment(const_tree fi
 /// isBitfield - Returns whether to treat the specified field as a bitfield.
 bool isBitfield(const_tree field_decl);
 
+// Compatibility hacks for older versions of GCC.
+#if (GCC_MINOR < 8)
+// Supported allocation types:
+struct va_gc {
+}; // Allocation uses ggc_alloc.
+
+// Fake vector class specialized below.
+template <typename T, typename A> class vec {
+};
+
+#define INSTANTIATE_VECTOR(TT)                                                 \
+  template<> class vec<TT, va_gc> {                                            \
+    VEC(TT, gc) & v;                                                           \
+  public:                                                                      \
+    vec(VEC(TT, gc) & V) : v(V) {}                                             \
+                                                                               \
+    bool is_empty() const { return VEC_empty(TT, &v); }                        \
+    unsigned length() const { return VEC_length(TT, &v); }                     \
+    TT &operator[](unsigned i) const { return *VEC_index(TT, &v, i); }         \
+  }
+#endif
+
 #endif /* DRAGONEGG_TREES_H */

Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=182208&r1=182207&r2=182208&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Sun May 19 04:52:40 2013
@@ -2894,6 +2894,10 @@ Value *TreeToLLVM::EmitOBJ_TYPE_REF(tree
                                getRegType(TREE_TYPE(exp)));
 }
 
+#if (GCC_MINOR < 8)
+INSTANTIATE_VECTOR(constructor_elt);
+#endif
+
 /// EmitCONSTRUCTOR - emit the constructor into the location specified by
 /// DestLoc.
 Value *TreeToLLVM::EmitCONSTRUCTOR(tree exp, const MemRef *DestLoc) {
@@ -2938,25 +2942,27 @@ Value *TreeToLLVM::EmitCONSTRUCTOR(tree
   // Start out with the value zero'd out.
   EmitAggregateZero(*DestLoc, type);
 
-  VEC(constructor_elt, gc) *elt = CONSTRUCTOR_ELTS(exp);
+  if (!CONSTRUCTOR_ELTS(exp))
+    return 0; // No elements.
+
+  const vec<constructor_elt, va_gc> &elt = *CONSTRUCTOR_ELTS(exp);
+
+  if (elt.is_empty())
+    return 0; // No elements.
+
   switch (TREE_CODE(TREE_TYPE(exp))) {
   case ARRAY_TYPE:
   case RECORD_TYPE:
   default:
-    if (!elt || !VEC_length(constructor_elt, elt))
-      return 0;
     debug_tree(exp);
     llvm_unreachable("We don't handle elements yet!");
   case QUAL_UNION_TYPE:
   case UNION_TYPE:
     // Store each element of the constructor into the corresponding field of
     // DEST.
-    if (!elt || VEC_empty(constructor_elt, elt))
-      return 0; // no elements
-    assert(VEC_length(constructor_elt, elt) == 1 &&
-           "Union CONSTRUCTOR should have one element!");
-    tree tree_purpose = VEC_index(constructor_elt, elt, 0)->index;
-    tree tree_value = VEC_index(constructor_elt, elt, 0)->value;
+    assert(elt.length() == 1 && "Union CONSTRUCTOR should have one element!");
+    tree tree_purpose = elt[0].index;
+    tree tree_value = elt[0].value;
     if (!tree_purpose)
       return 0; // Not actually initialized?
 
@@ -6695,14 +6701,25 @@ bool TreeToLLVM::EmitBuiltinCall(gimple
     Constant *TreeToLLVM::EmitVectorRegisterConstant(tree reg) {
       // If there are no elements then immediately return the default value for a
       // small speedup.
+#if (GCC_MINOR < 8)
       if (!TREE_VECTOR_CST_ELTS(reg))
+#else
+      if (!VECTOR_CST_NELTS(reg))
+#endif
         return getDefaultValue(getRegType(TREE_TYPE(reg)));
 
       // Convert the elements.
       SmallVector<Constant *, 16> Elts;
       tree elt_type = TREE_TYPE(TREE_TYPE(reg));
-      for (tree elt = TREE_VECTOR_CST_ELTS(reg); elt; elt = TREE_CHAIN(elt))
-        Elts.push_back(EmitRegisterConstantWithCast(TREE_VALUE(elt), elt_type));
+#if (GCC_MINOR < 8)
+      for (tree ch = TREE_VECTOR_CST_ELTS(reg); ch; ch = TREE_CHAIN(ch)) {
+        tree elt = TREE_VALUE(ch);
+#else
+      for (unsigned i = 0, e = VECTOR_CST_NELTS(reg); i != e; ++i) {
+        tree elt = VECTOR_CST_ELT(reg, i);
+#endif
+        Elts.push_back(EmitRegisterConstantWithCast(elt, elt_type));
+      }
 
       // If there weren't enough elements then set the rest of the vector to the
       // default value.





More information about the llvm-commits mailing list