[llvm-commits] [llvm-gcc-4-2] r39878 - in /llvm-gcc-4-2/trunk/gcc: llvm-convert.cpp llvm-internal.h llvm-types.cpp

Duncan Sands baldrick at free.fr
Sun Jul 15 10:58:08 PDT 2007


Author: baldrick
Date: Sun Jul 15 12:58:07 2007
New Revision: 39878

URL: http://llvm.org/viewvc/llvm-project?rev=39878&view=rev
Log:
We used to stash the index of the LLVM field corresponding to
a FIELD_DECL directly in the field declaration.  But the place
we would store it doesn't exist in gcc 4.2, so use (yet another)
map instead.

Modified:
    llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp
    llvm-gcc-4-2/trunk/gcc/llvm-internal.h
    llvm-gcc-4-2/trunk/gcc/llvm-types.cpp

Modified: llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp?rev=39878&r1=39877&r2=39878&view=diff

==============================================================================
--- llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4-2/trunk/gcc/llvm-convert.cpp Sun Jul 15 12:58:07 2007
@@ -4928,15 +4928,15 @@
   tree field_offset = component_ref_field_offset (exp);
   // If this is a normal field at a fixed offset from the start, handle it.
   if (TREE_CODE(field_offset) == INTEGER_CST) {
-    assert(DECL_LLVM_SET_P(FieldDecl) && "Struct not laid out for LLVM?");
-    ConstantInt *CI = cast<ConstantInt>(DECL_LLVM(FieldDecl));
-    uint32_t MemberIndex = CI->getZExtValue();
+    unsigned int MemberIndex = TheTypeConverter->GetFieldIndex(FieldDecl);
+    assert(MemberIndex != ~0U && "Struct not laid out for LLVM?");
     assert(MemberIndex < StructTy->getNumContainedTypes() &&
            "Field Idx out of range!");
     FieldPtr = Builder.CreateGEP(StructAddrLV.Ptr,
-                                 Constant::getNullValue(Type::Int32Ty), CI,
+                                 Constant::getNullValue(Type::Int32Ty),
+                                 ConstantInt::get(Type::Int32Ty, MemberIndex),
                                  "tmp");
-    
+
     // Now that we did an offset from the start of the struct, subtract off
     // the offset from BitStart.
     if (MemberIndex) {
@@ -5630,7 +5630,7 @@
   // that contains bits from the bitfield overlayed with the declared type of
   // the bitfield.  This bitfield value may be spread across multiple fields, or
   // it may be just this field, or it may just be a small part of this field.
-  unsigned FieldNo = cast<ConstantInt>(DECL_LLVM(Field))->getZExtValue();
+  unsigned int FieldNo = TheTypeConverter->GetFieldIndex(Field);
   assert(FieldNo < ResultElts.size() && "Invalid struct field number!");
   
   // Get the offset and size of the LLVM field.
@@ -5768,8 +5768,8 @@
       ProcessBitFieldInitialization(Field, Val, STy, ResultElts);
     } else {
       // If not, things are much simpler.
-      assert(DECL_LLVM_SET_P(Field) && "Struct not laid out for LLVM?");
-      unsigned FieldNo = cast<ConstantInt>(DECL_LLVM(Field))->getZExtValue();
+      unsigned int FieldNo = TheTypeConverter->GetFieldIndex(Field);
+      assert(FieldNo != ~0U && "Struct not laid out for LLVM?");
       assert(FieldNo < ResultElts.size() && "Invalid struct field number!");
 
       // Example: struct X { int A; char C[]; } x = { 4, "foo" };
@@ -6002,13 +6002,12 @@
   tree field_offset = component_ref_field_offset (exp);
   // If this is a normal field at a fixed offset from the start, handle it.
   if (TREE_CODE(field_offset) == INTEGER_CST) {
-    assert(DECL_LLVM_SET_P(FieldDecl) && "Struct not laid out for LLVM?");
-    ConstantInt *CI = cast<ConstantInt>(DECL_LLVM(FieldDecl));
-    uint64_t MemberIndex = CI->getZExtValue();
+    unsigned int MemberIndex = TheTypeConverter->GetFieldIndex(FieldDecl);
+    assert(MemberIndex != ~0U && "Struct not laid out for LLVM?");
     
     std::vector<Value*> Idxs;
     Idxs.push_back(Constant::getNullValue(Type::Int32Ty));
-    Idxs.push_back(CI);
+    Idxs.push_back(ConstantInt::get(Type::Int32Ty, MemberIndex));
     FieldPtr = ConstantExpr::getGetElementPtr(StructAddrLV, &Idxs[0],
                                               Idxs.size());
     

Modified: llvm-gcc-4-2/trunk/gcc/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/llvm-internal.h?rev=39878&r1=39877&r2=39878&view=diff

==============================================================================
--- llvm-gcc-4-2/trunk/gcc/llvm-internal.h (original)
+++ llvm-gcc-4-2/trunk/gcc/llvm-internal.h Sun Jul 15 12:58:07 2007
@@ -124,11 +124,20 @@
   /// POINTER_TYPE to this list.
   ///
   std::vector<tree_node*> PointersToReresolve;
+
+  /// FieldIndexMap - Holds the mapping from a FIELD_DECL to the index of the
+  /// corresponding LLVM field.
+  std::map<tree_node *, unsigned int> FieldIndexMap;
 public:
   TypeConverter() : ConvertingStruct(false) {}
   
   const Type *ConvertType(tree_node *type);
-  
+
+  /// GetFieldIndex - Returns the index of the LLVM field corresponding to
+  /// this FIELD_DECL, or ~0U if the type the field belongs to has not yet
+  /// been converted.
+  unsigned int GetFieldIndex(tree_node *field_decl);
+
   /// GCCTypeOverlapsWithLLVMTypePadding - Return true if the specified GCC type
   /// has any data that overlaps with structure padding in the specified LLVM
   /// type.
@@ -153,6 +162,7 @@
 private:
   const Type *ConvertRECORD(tree_node *type, tree_node *orig_type);
   const Type *ConvertUNION(tree_node *type, tree_node *orig_type);
+  void SetFieldIndex(tree_node *field_decl, unsigned int Index);
   void DecodeStructFields(tree_node *Field, StructTypeConversionInfo &Info);
   void DecodeStructBitField(tree_node *Field, StructTypeConversionInfo &Info);
 };

Modified: llvm-gcc-4-2/trunk/gcc/llvm-types.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4-2/trunk/gcc/llvm-types.cpp?rev=39878&r1=39877&r2=39878&view=diff

==============================================================================
--- llvm-gcc-4-2/trunk/gcc/llvm-types.cpp (original)
+++ llvm-gcc-4-2/trunk/gcc/llvm-types.cpp Sun Jul 15 12:58:07 2007
@@ -602,6 +602,25 @@
   }
 }
 
+/// GetFieldIndex - Returns the index of the LLVM field corresponding to
+/// this FIELD_DECL, or ~0U if the type the field belongs to has not yet
+/// been converted.
+unsigned int TypeConverter::GetFieldIndex(tree_node *field_decl) {
+  assert(TREE_CODE(field_decl) == FIELD_DECL && "Not a FIELD_DECL!");
+  std::map<tree, unsigned int>::iterator I = FieldIndexMap.find(field_decl);
+  if (I != FieldIndexMap.end())
+    return I->second;
+  else
+    return ~0U;
+}
+
+/// SetFieldIndex - Set the index of the LLVM field corresponding to
+/// this FIELD_DECL.
+void TypeConverter::SetFieldIndex(tree_node *field_decl, unsigned int Index) {
+  assert(TREE_CODE(field_decl) == FIELD_DECL && "Not a FIELD_DECL!");
+  FieldIndexMap[field_decl] = Index;
+}
+
 bool TypeConverter::GCCTypeOverlapsWithLLVMTypePadding(tree type, 
                                                        const Type *Ty) {
   
@@ -1255,8 +1274,8 @@
     return getFieldEndOffsetInBytes(ElementOffsetInBytes.size()-1);
   }
 
-  /// getLLVMFieldFor - When we are assigning DECL_LLVM indexes to FieldDecls,
-  /// this method determines which struct element to use.  Since the offset of
+  /// getLLVMFieldFor - When we are assigning indices to FieldDecls, this
+  /// method determines which struct element to use.  Since the offset of
   /// the fields cannot go backwards, CurFieldNo retains the last element we
   /// looked at, to keep this a nice fast linear process.  If isZeroSizeField
   /// is true, this should return some zero sized field that starts at the
@@ -1657,8 +1676,8 @@
   }
   
   // Now that the LLVM struct is finalized, figure out a safe place to index to
-  // and set the DECL_LLVM values for each FieldDecl that doesn't start at a
-  // variable offset.
+  // and set index values for each FieldDecl that doesn't start at a variable
+  // offset.
   unsigned CurFieldNo = 0;
   for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field))
     if (TREE_CODE(Field) == FIELD_DECL &&
@@ -1685,7 +1704,7 @@
 
       unsigned FieldNo = 
         Info->getLLVMFieldFor(FieldOffsetInBits, CurFieldNo, isZeroSizeField);
-      SET_DECL_LLVM(Field, ConstantInt::get(Type::Int32Ty, FieldNo));
+      SetFieldIndex(Field, FieldNo);
     }
   
   const Type *ResultTy = Info->getLLVMType();
@@ -1767,14 +1786,13 @@
   const TargetData &TD = getTargetData();
   const Type *UnionTy = 0;
   unsigned MaxSize = 0, MaxAlign = 0;
-  Value *Idx = Constant::getNullValue(Type::Int32Ty);
   for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field)) {
     if (TREE_CODE(Field) != FIELD_DECL) continue;
     assert(getFieldOffsetInBits(Field) == 0 && "Union with non-zero offset?");
 
     // Set the field idx to zero for all fields.
-    SET_DECL_LLVM(Field, Idx);
-    
+    SetFieldIndex(Field, 0);
+
     const Type *TheTy = ConvertType(TREE_TYPE(Field));
     unsigned Size     = TD.getTypeSize(TheTy);
     unsigned Align = TD.getABITypeAlignment(TheTy);





More information about the llvm-commits mailing list