[llvm-commits] [gcc-plugin] r83280 - in /gcc-plugin/trunk: llvm-convert.cpp llvm-internal.h llvm-types.cpp

Duncan Sands baldrick at free.fr
Sun Oct 4 09:11:44 PDT 2009


Author: baldrick
Date: Sun Oct  4 11:11:44 2009
New Revision: 83280

URL: http://llvm.org/viewvc/llvm-project?rev=83280&view=rev
Log:
Simplify COMPONENT_REF handling now that all Ada evil has been
taken care of already by gcc and so is no longer seen by us.

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

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

==============================================================================
--- gcc-plugin/trunk/llvm-convert.cpp (original)
+++ gcc-plugin/trunk/llvm-convert.cpp Sun Oct  4 11:11:44 2009
@@ -5713,29 +5713,6 @@
 //                         ... L-Value Expressions ...
 //===----------------------------------------------------------------------===//
 
-/// getFieldOffsetInBits - Return the offset (in bits) of a FIELD_DECL in a
-/// structure.
-static unsigned getFieldOffsetInBits(tree Field) {
-  assert(DECL_FIELD_BIT_OFFSET(Field) != 0);
-  unsigned Result = TREE_INT_CST_LOW(DECL_FIELD_BIT_OFFSET(Field));
-  if (DECL_FIELD_OFFSET(Field))
-    Result += TREE_INT_CST_LOW(DECL_FIELD_OFFSET(Field))*8;
-  return Result;
-}
-
-/// getComponentRefOffsetInBits - Return the offset (in bits) of the field
-/// referenced in a COMPONENT_REF exp.
-static unsigned getComponentRefOffsetInBits(tree exp) {
-  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!");
-  assert(DECL_FIELD_BIT_OFFSET(field) && "Field's bit offset not defined!");
-  unsigned Result = TREE_INT_CST_LOW(DECL_FIELD_BIT_OFFSET(field));
-  if (DECL_FIELD_OFFSET(field))
-    Result += TREE_INT_CST_LOW(DECL_FIELD_OFFSET(field)) * BITS_PER_UNIT;
-  return Result;
-}
-
 Value *TreeToLLVM::EmitFieldAnnotation(Value *FieldPtr, tree FieldDecl) {
   tree AnnotateAttr = lookup_attribute("annotate", DECL_ATTRIBUTES(FieldDecl));
 
@@ -5937,12 +5914,11 @@
 
   // BitStart - This is the actual offset of the field from the start of the
   // struct, in bits.  For bitfields this may be on a non-byte boundary.
-  unsigned BitStart = getComponentRefOffsetInBits(exp);
+  unsigned BitStart = getFieldOffsetInBits(TREE_OPERAND(exp, 1));
   Value *FieldPtr;
 
-  tree field_offset = TREE_OPERAND(exp, 2);
   // If this is a normal field at a fixed offset from the start, handle it.
-  if (!field_offset || TREE_CODE(field_offset) == INTEGER_CST) {
+  if (!TREE_OPERAND(exp, 2)) {
     unsigned int MemberIndex = GetFieldIndex(FieldDecl);
 
     // If the LLVM struct has zero field, don't try to index into it, just use
@@ -5983,14 +5959,14 @@
       FieldPtr = EmitFieldAnnotation(FieldPtr, FieldDecl);
   } else {
     // Offset is the field offset in octets.
-    Value *Offset = Emit(field_offset, 0);
+    Value *Offset = Emit(TREE_OPERAND(exp, 2), 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.
+    // Here BitStart gives the offset of the field in bits from Offset.
     // Incorporate as much of it as possible into the pointer computation.
     unsigned ByteOffset = BitStart/8;
     if (ByteOffset > 0) {
@@ -8023,13 +7999,12 @@
 
   // BitStart - This is the actual offset of the field from the start of the
   // struct, in bits.  For bitfields this may be on a non-byte boundary.
-  unsigned BitStart = getComponentRefOffsetInBits(exp);
+  unsigned BitStart = getFieldOffsetInBits(TREE_OPERAND(exp, 1));
   Constant *FieldPtr;
   const TargetData &TD = getTargetData();
 
-  tree field_offset = TREE_OPERAND(exp, 2);
   // If this is a normal field at a fixed offset from the start, handle it.
-  if (!field_offset || TREE_CODE(field_offset) == INTEGER_CST) {
+  if (!TREE_OPERAND(exp, 2)) {
     unsigned int MemberIndex = GetFieldIndex(FieldDecl);
 
     Constant *Ops[] = {
@@ -8052,7 +8027,7 @@
 
   } else {
     // Offset is the field offset in octets.
-    Constant *Offset = Convert(field_offset);
+    Constant *Offset = Convert(TREE_OPERAND(exp, 2));
     if (BITS_PER_UNIT != 8) {
       assert(!(BITS_PER_UNIT & 7) && "Unit size not a multiple of 8 bits!");
       Offset = TheFolder->CreateMul(Offset,

Modified: gcc-plugin/trunk/llvm-internal.h
URL: http://llvm.org/viewvc/llvm-project/gcc-plugin/trunk/llvm-internal.h?rev=83280&r1=83279&r2=83280&view=diff

==============================================================================
--- gcc-plugin/trunk/llvm-internal.h (original)
+++ gcc-plugin/trunk/llvm-internal.h Sun Oct  4 11:11:44 2009
@@ -237,6 +237,15 @@
 /// isBitfield - Returns whether to treat the specified field as a bitfield.
 bool isBitfield(tree_node *field_decl);
 
+/// getFieldOffsetInBits - Return the bit offset of a FIELD_DECL in a structure.
+inline uint64_t getFieldOffsetInBits(tree_node *field) {
+  assert(DECL_FIELD_BIT_OFFSET(field) != 0);
+  uint64_t Result = getInt64(DECL_FIELD_BIT_OFFSET(field), true);
+  if (DECL_FIELD_OFFSET(field))
+    Result += getInt64(DECL_FIELD_OFFSET(field), true) * BITS_PER_UNIT;
+  return Result;
+}
+
 /// getDeclaredType - Get the declared type for the specified field, and
 /// not the shrunk-to-fit type that GCC gives us in TREE_TYPE.
 tree_node *getDeclaredType(tree_node *field_decl);

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

==============================================================================
--- gcc-plugin/trunk/llvm-types.cpp (original)
+++ gcc-plugin/trunk/llvm-types.cpp Sun Oct  4 11:11:44 2009
@@ -442,17 +442,6 @@
 //                              Helper Routines
 //===----------------------------------------------------------------------===//
 
-
-/// getFieldOffsetInBits - Return the offset (in bits) of a FIELD_DECL in a
-/// structure.
-static uint64_t getFieldOffsetInBits(tree Field) {
-  assert(DECL_FIELD_BIT_OFFSET(Field) != 0);
-  uint64_t Result = getInt64(DECL_FIELD_BIT_OFFSET(Field), true);
-  if (DECL_FIELD_OFFSET(Field))
-    Result += getInt64(DECL_FIELD_OFFSET(Field), true)*8;
-  return Result;
-}
-
 /// FindLLVMTypePadding - If the specified struct has any inter-element padding,
 /// add it to the Padding array.
 static void FindLLVMTypePadding(const Type *Ty, tree type, uint64_t BitOffset,





More information about the llvm-commits mailing list