diff options
author | Chris Lattner <sabre@nondot.org> | 2011-07-13 05:31:19 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2011-07-13 05:31:19 +0000 |
commit | 2045b2dd6a779e9b35ac42a60cf30a6b07cb4bb6 (patch) | |
tree | 8dcf9804606fa4bb9b882ad41da0b723ded6e84b /lib/CodeGen/CodeGenTypes.cpp | |
parent | 6af13f3a3538d6c075a6282a7f393c26ee1563c7 (diff) |
per john's advice, speculatively lower uses of forward-declared enums to
i32. They almost always end up this way in the end anyway, and if we get
lucky, this avoids generating some bitcasts.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@135032 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenTypes.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 8efe9e1eea..8dae84e48f 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -154,8 +154,13 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) { // from the enum to be recomputed. if (const EnumDecl *ED = dyn_cast<EnumDecl>(TD)) { // Only flush the cache if we've actually already converted this type. - if (TypeCache.count(ED->getTypeForDecl())) - TypeCache.clear(); + if (TypeCache.count(ED->getTypeForDecl())) { + // Okay, we formed some types based on this. We speculated that the enum + // would be lowered to i32, so we only need to flush the cache if this + // didn't happen. + if (!ConvertType(ED->getIntegerType())->isIntegerTy(32)) + TypeCache.clear(); + } return; } @@ -416,12 +421,14 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) { break; } - case Type::Enum: { + case Type::Enum: { const EnumDecl *ED = cast<EnumType>(Ty)->getDecl(); if (ED->isDefinition() || ED->isFixed()) return ConvertType(ED->getIntegerType()); - // Return a placeholder '{}' type. - ResultType = llvm::StructType::get(getLLVMContext()); + // Return a placeholder 'i32' type. This can be changed later when the + // type is defined (see UpdateCompletedType), but is likely to be the + // "right" answer. + ResultType = llvm::Type::getInt32Ty(getLLVMContext()); break; } |