From 45372a6fdcd2b0840704569478db456822e02bae Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 23 Jul 2009 03:17:50 +0000 Subject: Check in CGRecordLayoutBuilder which is a reimplementation of the record layout code. (Yay, no more packed structs unless absolutely necessary). We currently don't use the layouts being built but that will change when the new code is mature enough :) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76845 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'lib/CodeGen/CodeGenTypes.cpp') diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 41d2ba24fe..59463fa24f 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -21,6 +21,7 @@ #include "llvm/Target/TargetData.h" #include "CGCall.h" +#include "CGRecordLayoutBuilder.h" using namespace clang; using namespace CodeGen; @@ -456,21 +457,30 @@ const llvm::Type *CodeGenTypes::ConvertTagDeclType(const TagDecl *TD) { ResultType = llvm::StructType::get(std::vector()); } else { // Layout fields. - RecordOrganizer RO(*this, *RD); + CGRecordLayout *Layout = + CGRecordLayoutBuilder::ComputeLayout(*this, RD); - if (TD->isStruct() || TD->isClass()) - RO.layoutStructFields(Context.getASTRecordLayout(RD)); - else { - assert(TD->isUnion() && "unknown tag decl kind!"); - RO.layoutUnionFields(Context.getASTRecordLayout(RD)); + if (!Layout) { + // Layout fields. + RecordOrganizer RO(*this, *RD); + + if (TD->isStruct() || TD->isClass()) + RO.layoutStructFields(Context.getASTRecordLayout(RD)); + else { + assert(TD->isUnion() && "unknown tag decl kind!"); + RO.layoutUnionFields(Context.getASTRecordLayout(RD)); + } + + Layout = new CGRecordLayout(RO.getLLVMType(), + RO.getPaddingFields()); } // Get llvm::StructType. const Type *Key = Context.getTagDeclType(const_cast(TD)).getTypePtr(); - CGRecordLayouts[Key] = new CGRecordLayout(RO.getLLVMType(), - RO.getPaddingFields()); - ResultType = RO.getLLVMType(); + + CGRecordLayouts[Key] = Layout; + ResultType = Layout->getLLVMType(); } // Refine our Opaque type to ResultType. This can invalidate ResultType, so -- cgit v1.2.3