From 52c0f6adb667a6095270466254c52a1fd8af7026 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Mon, 29 Sep 2014 20:30:22 +0000 Subject: [PATCH] Speedup ClangToLLVMArgMapping construction. NFC. Add a method to calculate the number of arguments given QualType expnads to. Use this method in ClangToLLVMArgMapping calculation. This number may be cached in CodeGenTypes for efficiency, if needed. llvm-svn: 218623 --- clang/lib/CodeGen/CGCall.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 5f22d3929f74..e4da4e141134 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -612,6 +612,23 @@ getTypeExpansion(QualType Ty, const ASTContext &Context) { return llvm::make_unique(); } +static int getExpansionSize(QualType Ty, const ASTContext &Context) { + auto Exp = getTypeExpansion(Ty, Context); + if (auto CAExp = dyn_cast(Exp.get())) { + return CAExp->NumElts * getExpansionSize(CAExp->EltTy, Context); + } + if (auto RExp = dyn_cast(Exp.get())) { + int Res = 0; + for (auto FD : RExp->Fields) + Res += getExpansionSize(FD->getType(), Context); + return Res; + } + if (isa(Exp.get())) + return 2; + assert(isa(Exp.get())); + return 1; +} + void CodeGenTypes::GetExpandedTypes(QualType type, SmallVectorImpl &expandedTypes) { auto Exp = getTypeExpansion(type, Context); @@ -1222,12 +1239,7 @@ void ClangToLLVMArgMapping::construct(CodeGenModule &CGM, IRArgs.NumberOfArgs = 0; break; case ABIArgInfo::Expand: { - SmallVector Types; - // FIXME: This is rather inefficient. Do we ever actually need to do - // anything here? The result should be just reconstructed on the other - // side, so extension should be a non-issue. - CGM.getTypes().GetExpandedTypes(ArgType, Types); - IRArgs.NumberOfArgs = Types.size(); + IRArgs.NumberOfArgs = getExpansionSize(ArgType, CGM.getContext()); break; } }