diff options
author | Devang Patel <dpatel@apple.com> | 2007-10-25 18:32:36 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2007-10-25 18:32:36 +0000 |
commit | 30ec9972be5a5af1f7a2277360dfa3aa1540b4fa (patch) | |
tree | 40aec197a326c44f78a45d114feaccadb83c1929 /CodeGen/CodeGenTypes.cpp | |
parent | 0a449eed1dd2439b4b9c0a6291084816eab390c1 (diff) |
Cache llvm::Type through PATypeHolder.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43355 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'CodeGen/CodeGenTypes.cpp')
-rw-r--r-- | CodeGen/CodeGenTypes.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/CodeGen/CodeGenTypes.cpp b/CodeGen/CodeGenTypes.cpp index 31c76b3306..0b225291d2 100644 --- a/CodeGen/CodeGenTypes.cpp +++ b/CodeGen/CodeGenTypes.cpp @@ -69,7 +69,21 @@ CodeGenTypes::~CodeGenTypes() { /// ConvertType - Convert the specified type to its LLVM form. const llvm::Type *CodeGenTypes::ConvertType(QualType T) { - // FIXME: Cache these, move the CodeGenModule, expand, etc. + // See if type is already cached. + llvm::DenseMap<Type *, llvm::PATypeHolder *>::iterator + I = TypeHolderMap.find(T.getTypePtr()); + if (I != TypeHolderMap.end()) { + llvm::PATypeHolder *PAT = I->second; + return PAT->get(); + } + + const llvm::Type *ResultType = ConvertNewType(T); + llvm::PATypeHolder *PAT = new llvm::PATypeHolder(ResultType); + TypeHolderMap[T.getTypePtr()] = PAT; + return ResultType; +} + +const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { const clang::Type &Ty = *T.getCanonicalType(); switch (Ty.getTypeClass()) { @@ -166,7 +180,10 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) { // Struct return passes the struct byref. if (!ResultType->isFirstClassType() && ResultType != llvm::Type::VoidTy) { - ArgTys.push_back(llvm::PointerType::get(ResultType)); + const llvm::Type *RType = llvm::PointerType::get(ResultType); + QualType RTy = Context.getPointerType(FP.getResultType()); + TypeHolderMap[RTy.getTypePtr()] = new llvm::PATypeHolder(RType); + ArgTys.push_back(RType); ResultType = llvm::Type::VoidTy; } @@ -215,6 +232,8 @@ const llvm::Type *CodeGenTypes::ConvertType(QualType T) { // Reevaluate this when performance analyis finds tons of opaque types. llvm::OpaqueType *OpaqueTy = llvm::OpaqueType::get(); RecordTypesToResolve[RD] = OpaqueTy; + QualType Opq; + TypeHolderMap[Opq.getTypePtr()] = new llvm::PATypeHolder(OpaqueTy); // Layout fields. RecordOrganizer RO; @@ -281,8 +300,12 @@ void CodeGenTypes::DecodeArgumentTypes(const FunctionTypeProto &FTP, const llvm::Type *Ty = ConvertType(FTP.getArgType(i)); if (Ty->isFirstClassType()) ArgTys.push_back(Ty); - else - ArgTys.push_back(llvm::PointerType::get(Ty)); + else { + QualType PTy = Context.getPointerType(FTP.getArgType(i)); + const llvm::Type *PtrTy = llvm::PointerType::get(Ty); + TypeHolderMap[PTy.getTypePtr()] = new llvm::PATypeHolder(PtrTy); + ArgTys.push_back(PtrTy); + } } } |