aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CodeGenTypes.cpp
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-03-05 03:16:41 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-03-05 03:16:41 +0000
commitb3b6b9b27ab8bdb2a435a5a92ce62e74e3399377 (patch)
tree6d8bba2005fc21c5b8c26f4fb36a0e427143cac8 /lib/CodeGen/CodeGenTypes.cpp
parentefcfcc0e27ade4e0bb6626824f2bdc0a01bab32b (diff)
Initial implementation of CodeGen for incomplete function types; fixes
PR3688. (The FIXME is a rather big performance issue, but it only affects code using this feature, which is relatively rare.) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66128 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTypes.cpp')
-rw-r--r--lib/CodeGen/CodeGenTypes.cpp57
1 files changed, 53 insertions, 4 deletions
diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp
index 95b78fe107..5eb925e5e7 100644
--- a/lib/CodeGen/CodeGenTypes.cpp
+++ b/lib/CodeGen/CodeGenTypes.cpp
@@ -138,6 +138,21 @@ const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) {
}
+// Code to verify a given function type is complete, i.e. the return type
+// and all of the argument types are complete.
+static const TagType *VerifyFuncTypeComplete(const Type* T) {
+ const FunctionType *FT = cast<FunctionType>(T);
+ if (const TagType* TT = FT->getResultType()->getAsTagType())
+ if (!TT->getDecl()->isDefinition())
+ return TT;
+ if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(T))
+ for (unsigned i = 0; i < FPT->getNumArgs(); i++)
+ if (const TagType* TT = FPT->getArgType(i)->getAsTagType())
+ if (!TT->getDecl()->isDefinition())
+ return TT;
+ return 0;
+}
+
/// UpdateCompletedType - When we find the full definition for a TagDecl,
/// replace the 'opaque' type we previously made for it if applicable.
void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) {
@@ -160,6 +175,26 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) {
// Refine the old opaque type to its new definition.
cast<llvm::OpaqueType>(OpaqueHolder.get())->refineAbstractTypeTo(NT);
+
+ // Since we just completed a tag type, check to see if any function types
+ // were completed along with the tag type.
+ // FIXME: This is very inefficient; if we track which function types depend
+ // on which tag types, though, it should be reasonably efficient.
+ llvm::DenseMap<const Type*, llvm::PATypeHolder>::iterator i;
+ for (i = FunctionTypes.begin(); i != FunctionTypes.end(); ++i) {
+ if (const TagType* TT = VerifyFuncTypeComplete(i->first)) {
+ // This function type still depends on an incomplete tag type; make sure
+ // that tag type has an associated opaque type.
+ ConvertTagDeclType(TT->getDecl());
+ } else {
+ // This function no longer depends on an incomplete tag type; create the
+ // function type, and refine the opaque type to the new function type.
+ llvm::PATypeHolder OpaqueHolder = i->second;
+ const llvm::Type *NFT = ConvertNewType(QualType(i->first, 0));
+ cast<llvm::OpaqueType>(OpaqueHolder.get())->refineAbstractTypeTo(NFT);
+ FunctionTypes.erase(i);
+ }
+ }
}
static const llvm::Type* getTypeForFormat(const llvm::fltSemantics &format) {
@@ -273,11 +308,25 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
VT.getNumElements());
}
case Type::FunctionNoProto:
- return GetFunctionType(getFunctionInfo(cast<FunctionNoProtoType>(&Ty)),
- true);
case Type::FunctionProto: {
- const FunctionProtoType *FTP = cast<FunctionProtoType>(&Ty);
- return GetFunctionType(getFunctionInfo(FTP), FTP->isVariadic());
+ // First, check whether we can build the full function type.
+ if (const TagType* TT = VerifyFuncTypeComplete(&Ty)) {
+ // This function's type depends on an incomplete tag type; make sure
+ // we have an opaque type corresponding to the tag type.
+ ConvertTagDeclType(TT->getDecl());
+ // Create an opaque type for this function type, save it, and return it.
+ llvm::Type *ResultType = llvm::OpaqueType::get();
+ FunctionTypes.insert(std::make_pair(&Ty, ResultType));
+ return ResultType;
+ }
+ // The function type can be built; call the appropriate routines to
+ // build it.
+ if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(&Ty)) {
+ return GetFunctionType(getFunctionInfo(FPT), FPT->isVariadic());
+ } else {
+ const FunctionNoProtoType *FNPT = cast<FunctionNoProtoType>(&Ty);
+ return GetFunctionType(getFunctionInfo(FNPT), true);
+ }
}
case Type::ExtQual: