[llvm-commits] [gcc-plugin] r83279 - /gcc-plugin/trunk/llvm-convert.cpp

Duncan Sands baldrick at free.fr
Sun Oct 4 08:52:31 PDT 2009


Author: baldrick
Date: Sun Oct  4 10:52:31 2009
New Revision: 83279

URL: http://llvm.org/viewvc/llvm-project?rev=83279&view=rev
Log:
It used to be that field offsets in a COMPONENT_REF needed to
be calculated by calling component_ref_field_offset - this
function handled all the horrible Ada cases.  But in mainline
GCC everything has been gimplified and it suffices to look at
operand 2 of the COMPONENT_REF, which has the advantage that
it contains properly normalized expressions rather than the
uncontrolled trees that component_ref_field_offset returns.

Modified:
    gcc-plugin/trunk/llvm-convert.cpp

Modified: gcc-plugin/trunk/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-convert.cpp?rev=83279&r1=83278&r2=83279&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Sun Oct  4 10:52:31 2009
@@ -5729,11 +5729,10 @@
   assert(TREE_CODE(exp) == COMPONENT_REF && "not a COMPONENT_REF!");
   tree field = TREE_OPERAND(exp, 1);
   assert(TREE_CODE(field) == FIELD_DECL && "not a FIELD_DECL!");
-  tree field_offset = component_ref_field_offset (exp);
-  assert(DECL_FIELD_BIT_OFFSET(field) && field_offset);
+  assert(DECL_FIELD_BIT_OFFSET(field) && "Field's bit offset not defined!");
   unsigned Result = TREE_INT_CST_LOW(DECL_FIELD_BIT_OFFSET(field));
-  if (TREE_CODE(field_offset) == INTEGER_CST)
-    Result += TREE_INT_CST_LOW(field_offset)*8;
+  if (DECL_FIELD_OFFSET(field))
+    Result += TREE_INT_CST_LOW(DECL_FIELD_OFFSET(field)) * BITS_PER_UNIT;
   return Result;
 }
 
@@ -5941,9 +5940,9 @@
   unsigned BitStart = getComponentRefOffsetInBits(exp);
   Value *FieldPtr;
 
-  tree field_offset = component_ref_field_offset (exp);
+  tree field_offset = TREE_OPERAND(exp, 2);
   // If this is a normal field at a fixed offset from the start, handle it.
-  if (TREE_CODE(field_offset) == INTEGER_CST) {
+  if (!field_offset || TREE_CODE(field_offset) == INTEGER_CST) {
     unsigned int MemberIndex = GetFieldIndex(FieldDecl);
 
     // If the LLVM struct has zero field, don't try to index into it, just use
@@ -5983,7 +5982,13 @@
     if (lookup_attribute("annotate", DECL_ATTRIBUTES(FieldDecl)))
       FieldPtr = EmitFieldAnnotation(FieldPtr, FieldDecl);
   } else {
+    // Offset is the field offset in octets.
     Value *Offset = Emit(field_offset, 0);
+    if (BITS_PER_UNIT != 8) {
+      assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
+      Offset = Builder.CreateMul(Offset, ConstantInt::get(Offset->getType(),
+                                                          BITS_PER_UNIT / 8));
+    }
 
     // Here BitStart gives the offset of the field in bits from field_offset.
     // Incorporate as much of it as possible into the pointer computation.
@@ -8022,9 +8027,9 @@
   Constant *FieldPtr;
   const TargetData &TD = getTargetData();
 
-  tree field_offset = component_ref_field_offset (exp);
+  tree field_offset = TREE_OPERAND(exp, 2);
   // If this is a normal field at a fixed offset from the start, handle it.
-  if (TREE_CODE(field_offset) == INTEGER_CST) {
+  if (!field_offset || TREE_CODE(field_offset) == INTEGER_CST) {
     unsigned int MemberIndex = GetFieldIndex(FieldDecl);
 
     Constant *Ops[] = {
@@ -8046,7 +8051,14 @@
     }
 
   } else {
+    // Offset is the field offset in octets.
     Constant *Offset = Convert(field_offset);
+    if (BITS_PER_UNIT != 8) {
+      assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
+      Offset = TheFolder->CreateMul(Offset,
+                                    ConstantInt::get(Offset->getType(),
+                                                     BITS_PER_UNIT / 8));
+    }
     Constant *Ptr = TheFolder->CreatePtrToInt(StructAddrLV, Offset->getType());
     Ptr = TheFolder->CreateAdd(Ptr, Offset);
     FieldPtr = TheFolder->CreateIntToPtr(Ptr,





More information about the llvm-commits mailing list