Author: johannes Date: Fri Feb 15 16:02:22 2008 New Revision: 47180 URL: http://llvm.org/viewvc/llvm-project?rev=47180&view=rev Log: Put back fixed version of code to avoid copying padding within structs (sometimes).
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=47180&r1=47179&r2=47180&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Fri Feb 15 16:02:22 2008 @@ -1229,7 +1229,8 @@ /// CopyAggregate - Recursively traverse the potientially aggregate src/dest /// ptrs, copying all of the elements. -static void CopyAggregate(MemRef DestLoc, MemRef SrcLoc, LLVMBuilder &Builder) { +static void CopyAggregate(MemRef DestLoc, MemRef SrcLoc, LLVMBuilder &Builder, + tree gccType) { assert(DestLoc.Ptr->getType() == SrcLoc.Ptr->getType() && "Cannot copy between two pointers of different type!"); const Type *ElTy = @@ -1246,6 +1247,8 @@ const StructLayout *SL = getTargetData().getStructLayout(STy); Constant *Zero = ConstantInt::get(Type::Int32Ty, 0); for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { + if (gccType && isPaddingElement(gccType, i)) + continue; Constant *Idx = ConstantInt::get(Type::Int32Ty, i); Value *Idxs[2] = { Zero, Idx }; Value *DElPtr = Builder.CreateGEP(DestLoc.Ptr, Idxs, Idxs + 2, "tmp"); @@ -1253,7 +1256,7 @@ unsigned Align = MinAlign(Alignment, SL->getElementOffset(i)); CopyAggregate(MemRef(DElPtr, Align, DestLoc.Volatile), MemRef(SElPtr, Align, SrcLoc.Volatile), - Builder); + Builder, 0); } } else { const ArrayType *ATy = cast<ArrayType>(ElTy); @@ -1267,7 +1270,7 @@ unsigned Align = MinAlign(Alignment, i * EltSize); CopyAggregate(MemRef(DElPtr, Align, DestLoc.Volatile), MemRef(SElPtr, Align, SrcLoc.Volatile), - Builder); + Builder, 0); } } } @@ -1311,7 +1314,7 @@ CountAggregateElements(LLVMTy) <= 8) { DestLoc.Ptr = BitCastToType(DestLoc.Ptr, PointerType::getUnqual(LLVMTy)); SrcLoc.Ptr = BitCastToType(SrcLoc.Ptr, PointerType::getUnqual(LLVMTy)); - CopyAggregate(DestLoc, SrcLoc, Builder); + CopyAggregate(DestLoc, SrcLoc, Builder, type); return; } } 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=47180&r1=47179&r2=47180&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-internal.h (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-internal.h Fri Feb 15 16:02:22 2008 @@ -116,7 +116,7 @@ /// Return true if and only if field no. N from struct type T is a padding /// element added to match llvm struct type size and gcc struct type size. -bool isPaddingElement(const Type *T, unsigned N); +bool isPaddingElement(union tree_node*, unsigned N); /// TypeConverter - Implement the converter from GCC types to LLVM types. /// 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=47180&r1=47179&r2=47180&view=diff ============================================================================== --- llvm-gcc-4.2/trunk/gcc/llvm-types.cpp (original) +++ llvm-gcc-4.2/trunk/gcc/llvm-types.cpp Fri Feb 15 16:02:22 2008 @@ -1577,13 +1577,13 @@ } } -std::map<const Type *, StructTypeConversionInfo *> StructTypeInfoMap; +std::map<tree, StructTypeConversionInfo *> StructTypeInfoMap; /// Return true if and only if field no. N from struct type T is a padding /// element added to match llvm struct type size and gcc struct type size. -bool isPaddingElement(const Type *Ty, unsigned index) { +bool isPaddingElement(tree type, unsigned index) { - StructTypeConversionInfo *Info = StructTypeInfoMap[Ty]; + StructTypeConversionInfo *Info = StructTypeInfoMap[type]; // If info is not available then be conservative and return false. if (!Info) @@ -1600,10 +1600,10 @@ /// structs then adjust their PaddingElement bits. Padding /// field in one struct may not be a padding field in another /// struct. -void adjustPaddingElement(const Type *OldTy, const Type *NewTy) { +void adjustPaddingElement(tree oldtree, tree newtree) { - StructTypeConversionInfo *OldInfo = StructTypeInfoMap[OldTy]; - StructTypeConversionInfo *NewInfo = StructTypeInfoMap[NewTy]; + StructTypeConversionInfo *OldInfo = StructTypeInfoMap[oldtree]; + StructTypeConversionInfo *NewInfo = StructTypeInfoMap[newtree]; if (!OldInfo || !NewInfo) return; @@ -2084,7 +2084,7 @@ RestoreBaseClassFields(type); const Type *ResultTy = Info->getLLVMType(); - StructTypeInfoMap[ResultTy] = Info; + StructTypeInfoMap[type] = Info; const OpaqueType *OldTy = cast_or_null<OpaqueType>(GET_TYPE_LLVM(type)); TypeDB.setType(type, ResultTy); @@ -2148,6 +2148,7 @@ // match union size. const TargetData &TD = getTargetData(); const Type *UnionTy = 0; + tree GccUnionTy = 0; unsigned MaxSize = 0, MaxAlign = 0; for (tree Field = TYPE_FIELDS(type); Field; Field = TREE_CHAIN(Field)) { if (TREE_CODE(Field) != FIELD_DECL) continue; @@ -2161,16 +2162,18 @@ integer_zerop(DECL_QUALIFIER(Field))) continue; - const Type *TheTy = ConvertType(TREE_TYPE(Field)); + tree TheGccTy = TREE_TYPE(Field); + const Type *TheTy = ConvertType(TheGccTy); unsigned Size = TD.getABITypeSize(TheTy); unsigned Align = TD.getABITypeAlignment(TheTy); - adjustPaddingElement(UnionTy, TheTy); + adjustPaddingElement(GccUnionTy, TheGccTy); // Select TheTy as union type if it meets one of the following criteria // 1) UnionTy is 0 // 2) TheTy alignment is more then UnionTy - // 3) TheTy size is greater than UnionTy size and TheTy alignment is equal to UnionTy + // 3) TheTy size is greater than UnionTy size and TheTy alignment is + // equal to UnionTy // 4) TheTy size is greater then UnionTy size and TheTy is packed bool useTheTy = false; if (UnionTy == 0) @@ -2184,6 +2187,7 @@ if (useTheTy) { UnionTy = TheTy; + GccUnionTy = TheGccTy; MaxSize = MAX(MaxSize, Size); MaxAlign = Align; } _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits