I'm getting an error building the llvm-gcc because this patch was partially propagated to the svn mirror. The changes in llvm-convert.cpp and llvm-types.cpp was propagated but the changes in llvm-internals.h wasn't.
<br><br>The error:<br>c++ -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wno-variadic-macros -DHAVE_CONFIG_H -Wno-unused -DTARGET_NAME=\"arm-linux-gnueabi\" -DNDEBUG -DENABLE_LLVM -D__STDC_LIMIT_MACROS   -I. -I. -I../../gcc -I../../gcc/. -I../../gcc/../include -I../../gcc/../libcpp/include  -I/home/laurov/llvm/llvm/include -I/home/laurov/llvm/llvm/build/include ../../gcc/llvm-
convert.cpp -o llvm-convert.o<br>../../gcc/llvm-convert.cpp: In function 'void CopyAggregate(llvm::Value*, llvm::Value*, bool, bool, llvm::BasicBlock*)':<br>../../gcc/llvm-convert.cpp:1088: error: 'isPaddingElement' was not declared in this scope
<br>make[1]: *** [llvm-convert.o] Error 1<br>make[1]: Leaving directory `/home/laurov/llvm/llvm-gcc/build_arm/gcc'<br>make: *** [all-gcc] Error 2<br><br>Lauro<br><div><span class="gmail_quote">2007/5/8, <a href="mailto:dpatel@apple.com">
dpatel@apple.com</a> <<a href="mailto:dpatel@apple.com">dpatel@apple.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Revision: 126997
<br>Author:   dpatel<br>Date:     2007-05-07 23:15:09 -0700 (Mon, 07 May 2007)<br><br>Log Message:<br>-----------<br>Fix PR1278.<br><br>- While adding padding elements at the end of LLVM struct use<br>  an array of i32 (instead of an array of i8) if possible.
<br><br>- Keep track of padding elements at the end of LLVM struct.<br>  Do not copy them while copying aggregates.<br><br>Modified Paths:<br>--------------<br>    apple-local/branches/llvm/gcc/llvm-convert.cpp<br>    apple-local/branches/llvm/gcc/llvm-
internal.h<br>    apple-local/branches/llvm/gcc/llvm-types.cpp<br><br>Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp<br>===================================================================<br>--- apple-local/branches/llvm/gcc/llvm-
convert.cpp      2007-05-08 05:09:41 UTC (rev 126996)<br>+++ apple-local/branches/llvm/gcc/llvm-convert.cpp      2007-05-08 06:15:09 UTC (rev 126997)<br>@@ -1085,6 +1085,8 @@<br>   } else if (const StructType *STy = dyn_cast<StructType>(ElTy)) {
<br>     Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);<br>     for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {<br>+      if (isPaddingElement(STy, i))<br>+        continue;<br>       Constant *Idx = ConstantInt::get(Type::Int32Ty, i);
<br>       Value *DElPtr = new GetElementPtrInst(DestPtr, Zero, Idx, "tmp", CurBB);<br>       Value *SElPtr = new GetElementPtrInst(SrcPtr, Zero, Idx, "tmp", CurBB);<br><br>Modified: apple-local/branches/llvm/gcc/llvm-
internal.h<br>===================================================================<br>--- apple-local/branches/llvm/gcc/llvm-internal.h       2007-05-08 05:09:41 UTC (rev 126996)<br>+++ apple-local/branches/llvm/gcc/llvm-internal.h
       2007-05-08 06:15:09 UTC (rev 126997)<br>@@ -96,6 +96,10 @@<br><br> struct StructTypeConversionInfo;<br><br>+/// Return true if and only if field no. N from struct type T is a padding<br>+/// element added to match llvm struct type size and gcc struct type size.
<br>+bool isPaddingElement(const Type *T, unsigned N);<br>+<br> /// TypeConverter - Implement the converter from GCC types to LLVM types.<br> ///<br> class TypeConverter {<br><br>Modified: apple-local/branches/llvm/gcc/llvm-
types.cpp<br>===================================================================<br>--- apple-local/branches/llvm/gcc/llvm-types.cpp        2007-05-08 05:09:41 UTC (rev 126996)<br>+++ apple-local/branches/llvm/gcc/llvm-types.cpp
        2007-05-08 06:15:09 UTC (rev 126997)<br>@@ -893,6 +893,7 @@<br>   std::vector<const Type*> Elements;<br>   std::vector<uint64_t> ElementOffsetInBytes;<br>   std::vector<uint64_t> ElementSizeInBytes;
<br>+  std::vector<bool> PaddingElement; // True if field is used for padding<br>   const TargetData &TD;<br>   unsigned GCCStructAlignmentInBytes;<br>   bool Packed; // True if struct is packed<br>@@ -1071,10 +1072,12 @@
<br><br>   /// addElement - Add an element to the structure with the specified type,<br>   /// offset and size.<br>-  void addElement(const Type *Ty, uint64_t Offset, uint64_t Size) {<br>+  void addElement(const Type *Ty, uint64_t Offset, uint64_t Size,
<br>+                  bool ExtraPadding = false) {<br>     Elements.push_back(Ty);<br>     ElementOffsetInBytes.push_back(Offset);<br>     ElementSizeInBytes.push_back(Size);<br>+    PaddingElement.push_back(ExtraPadding);
<br>     lastFieldStartsAtNonByteBoundry(false);<br>     ExtraBitsAvailable = 0;<br>   }<br>@@ -1223,7 +1226,25 @@<br>   }<br> }<br><br>+std::map<const Type *, StructTypeConversionInfo *> StructTypeInfoMap;<br><br>+/// Return true if and only if field no. N from struct type T is a padding
<br>+/// element added to match llvm struct type size and gcc struct type size.<br>+bool isPaddingElement(const Type *Ty, unsigned index) {<br>+<br>+  StructTypeConversionInfo *Info = StructTypeInfoMap[Ty];<br>+<br>+  // If info is not available then be conservative and return false.
<br>+  if (!Info)<br>+    return false;<br>+<br>+  assert ( Info->Elements.size() == Info->PaddingElement.size()<br>+           && "Invalid StructTypeConversionInfo");<br>+  assert ( index < Info->
PaddingElement.size()<br>+           && "Invalid PaddingElement index");<br>+  return Info->PaddingElement[index];<br>+}<br>+<br> /// getFieldOffsetInBits - Return the offset (in bits) of a FIELD_DECL in a
<br> /// structure.<br> static unsigned getFieldOffsetInBits(tree Field) {<br>@@ -1417,29 +1438,46 @@<br>       ConvertType(BINFO_TYPE(BINFO_BASE_BINFO(binfo, i)));<br>   }<br><br>-  StructTypeConversionInfo Info(*TheTarget, TYPE_ALIGN_UNIT(type),
<br>-                                TYPE_PACKED(type));<br>+  StructTypeConversionInfo *Info =<br>+    new StructTypeConversionInfo(*TheTarget, TYPE_ALIGN_UNIT(type),<br>+                             TYPE_PACKED(type));<br>
+<br><br>   // Convert over all of the elements of the struct.<br>   for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field))<br>-    DecodeStructFields(Field, Info);<br>+    DecodeStructFields(Field, *Info);
<br><br>-  Info.RemoveExtraBytes();<br>+  Info->RemoveExtraBytes();<br>   // If the LLVM struct requires explicit tail padding to be the same size as<br>   // the GCC struct, insert tail padding now.  This handles, e.g
., "{}" in C++.<br>   if (TYPE_SIZE(type) && TREE_CODE(TYPE_SIZE(type)) == INTEGER_CST) {<br>-    uint64_t LLVMStructSize = Info.getSizeAsLLVMStruct();<br>+    uint64_t LLVMStructSize = Info->getSizeAsLLVMStruct();
<br>     uint64_t GCCTypeSize = ((uint64_t)TREE_INT_CST_LOW(TYPE_SIZE(type))+7)/8;<br><br>     if (LLVMStructSize != GCCTypeSize) {<br>       assert(LLVMStructSize < GCCTypeSize &&<br>              "LLVM type size doesn't match GCC type size!");
<br>-      uint64_t LLVMLastElementEnd = Info.getNewElementByteOffset(1);<br>-      const Type *PadTy = Type::Int8Ty;<br>-      if (GCCTypeSize-LLVMLastElementEnd != 1)<br>-        PadTy = ArrayType::get(PadTy, GCCTypeSize-LLVMStructSize);
<br>-      Info.addElement(PadTy, GCCTypeSize-LLVMLastElementEnd,<br>-                      GCCTypeSize-LLVMLastElementEnd);<br>+      uint64_t LLVMLastElementEnd = Info->getNewElementByteOffset(1);<br>+<br>+      // If only one byte is needed then insert i8.
<br>+      if (GCCTypeSize-LLVMLastElementEnd == 1)<br>+        Info->addElement(Type::Int8Ty, 1, 1);<br>+      else {<br>+        if ( ((GCCTypeSize-LLVMStructSize) % 4) == 0) {<br>+          // insert array of i32<br>
+          unsigned Int32ArraySize = (GCCTypeSize-LLVMStructSize)/4;<br>+          const Type *PadTy = ArrayType::get(Type::Int32Ty, Int32ArraySize);<br>+          Info->addElement(PadTy, GCCTypeSize - LLVMLastElementEnd,
<br>+                           Int32ArraySize, true /* Padding Element */);<br>+        } else {<br>+          const Type *PadTy =<br>+            ArrayType::get(Type::Int8Ty, GCCTypeSize-LLVMStructSize);<br>+          Info->addElement(PadTy, GCCTypeSize - LLVMLastElementEnd,
<br>+                           GCCTypeSize - LLVMLastElementEnd,<br>+                           true /* Padding Element */);<br>+<br>+        }<br>+      }<br>     }<br>   }<br><br>@@ -1460,7 +1498,7 @@<br>       if (tree DeclaredType = DECL_BIT_FIELD_TYPE(Field)) {
<br>         // If this is a bitfield, the declared type must be an integral type.<br>         const Type *DeclFieldTy = ConvertType(DeclaredType);<br>-        unsigned DeclBitAlignment = Info.getTypeAlignment(DeclFieldTy)*8;
<br>+        unsigned DeclBitAlignment = Info->getTypeAlignment(DeclFieldTy)*8;<br><br>         FieldOffsetInBits &= ~(DeclBitAlignment-1ULL);<br>       }<br>@@ -1471,11 +1509,12 @@<br>         integer_zerop(TYPE_SIZE(FieldType));
<br><br>       unsigned FieldNo =<br>-        Info.getLLVMFieldFor(FieldOffsetInBits, CurFieldNo, isZeroSizeField);<br>+        Info->getLLVMFieldFor(FieldOffsetInBits, CurFieldNo, isZeroSizeField);<br>       SET_DECL_LLVM(Field, ConstantInt::get(Type::Int32Ty, FieldNo));
<br>     }<br><br>-  const Type *ResultTy = Info.getLLVMType();<br>+  const Type *ResultTy = Info->getLLVMType();<br>+  StructTypeInfoMap[ResultTy] = Info;<br><br>   const OpaqueType *OldTy = cast_or_null<OpaqueType>(GET_TYPE_LLVM(type));
<br>   TypeDB.setType(type, ResultTy);<br><br><br>_______________________________________________<br>llvm-commits mailing list<br><a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits">
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br></blockquote></div><br>