From: Benjamin Kramer Date: Sat, 24 Aug 2019 13:04:34 +0000 (+0000) Subject: [OpenCL] Microoptimize OCL2Qual a bit X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=838d250a16cebc2f19ed3a8d14d9625279ae9f3c;p=clang [OpenCL] Microoptimize OCL2Qual a bit Still not optimal, but makes clang 25k smaller. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@369846 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 813b62932b..8bae219f5a 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -686,8 +686,8 @@ LLVM_DUMP_METHOD void LookupResult::dump() { /// of (vector sizes) x (types) . static void GetQualTypesForOpenCLBuiltin( ASTContext &Context, const OpenCLBuiltinStruct &OpenCLBuiltin, - unsigned &GenTypeMaxCnt, std::vector &RetTypes, - SmallVector, 5> &ArgTypes) { + unsigned &GenTypeMaxCnt, SmallVector &RetTypes, + SmallVector, 5> &ArgTypes) { // Get the QualType instances of the return types. unsigned Sig = SignatureTable[OpenCLBuiltin.SigTableIndex]; OCL2Qual(Context, TypeTable[Sig], RetTypes); @@ -696,11 +696,11 @@ static void GetQualTypesForOpenCLBuiltin( // Get the QualType instances of the arguments. // First type is the return type, skip it. for (unsigned Index = 1; Index < OpenCLBuiltin.NumTypes; Index++) { - std::vector Ty; + SmallVector Ty; OCL2Qual(Context, TypeTable[SignatureTable[OpenCLBuiltin.SigTableIndex + Index]], Ty); - ArgTypes.push_back(Ty); GenTypeMaxCnt = (Ty.size() > GenTypeMaxCnt) ? Ty.size() : GenTypeMaxCnt; + ArgTypes.push_back(std::move(Ty)); } } @@ -713,11 +713,10 @@ static void GetQualTypesForOpenCLBuiltin( /// \param FunctionList (out) List of FunctionTypes. /// \param RetTypes (in) List of the possible return types. /// \param ArgTypes (in) List of the possible types for the arguments. -static void -GetOpenCLBuiltinFctOverloads(ASTContext &Context, unsigned GenTypeMaxCnt, - std::vector &FunctionList, - std::vector &RetTypes, - SmallVector, 5> &ArgTypes) { +static void GetOpenCLBuiltinFctOverloads( + ASTContext &Context, unsigned GenTypeMaxCnt, + std::vector &FunctionList, SmallVector &RetTypes, + SmallVector, 5> &ArgTypes) { FunctionProtoType::ExtProtoInfo PI; PI.Variadic = false; @@ -765,8 +764,8 @@ static void InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR, BuiltinTable[FctIndex + SignatureIndex]; ASTContext &Context = S.Context; - std::vector RetTypes; - SmallVector, 5> ArgTypes; + SmallVector RetTypes; + SmallVector, 5> ArgTypes; // Obtain QualType lists for the function signature. GetQualTypesForOpenCLBuiltin(Context, OpenCLBuiltin, GenTypeMaxCnt, diff --git a/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp index 4bf59c3a92..7707cb0ee0 100644 --- a/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp +++ b/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp @@ -434,17 +434,17 @@ void BuiltinNameEmitter::EmitQualTypeFinder() { // Step 2: Qualifiers and other type properties such as vector size are // applied. static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty, - std::vector &QT) { + llvm::SmallVectorImpl &QT) { // Number of scalar types in the GenType. unsigned GenTypeNumTypes; // Pointer to the list of vector sizes for the GenType. - llvm::SmallVector *GenVectorSizes; + llvm::ArrayRef GenVectorSizes; )"; // Generate list of vector sizes for each generic type. for (const auto *VectList : Records.getAllDerivedDefinitions("IntList")) { - OS << " llvm::SmallVector List" - << VectList->getValueAsString("Name") << "{"; + OS << " constexpr unsigned List" + << VectList->getValueAsString("Name") << "[] = {"; for (const auto V : VectList->getValueAsListOfInts("List")) { OS << V << ", "; } @@ -458,6 +458,7 @@ static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty, // Switch cases for generic types. for (const auto *GenType : Records.getAllDerivedDefinitions("GenericType")) { OS << " case OCLT_" << GenType->getValueAsString("Name") << ":\n"; + OS << " QT.append({"; // Build the Cartesian product of (vector sizes) x (types). Only insert // the plain scalar types for now; other type information such as vector @@ -468,10 +469,11 @@ static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty, I++) { for (const auto *T : GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List")) { - OS << " QT.push_back(Context." - << T->getValueAsDef("QTName")->getValueAsString("Name") << ");\n"; + OS << "Context." + << T->getValueAsDef("QTName")->getValueAsString("Name") << ", "; } } + OS << "});\n;"; // GenTypeNumTypes is the number of types in the GenType // (e.g. float/double/half). OS << " GenTypeNumTypes = " @@ -480,7 +482,7 @@ static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty, << ";\n"; // GenVectorSizes is the list of vector sizes for this GenType. // QT contains GenTypeNumTypes * #GenVectorSizes elements. - OS << " GenVectorSizes = &List" + OS << " GenVectorSizes = List" << GenType->getValueAsDef("VectorList")->getValueAsString("Name") << ";\n"; OS << " break;\n"; @@ -521,9 +523,9 @@ static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty, OS << R"( for (unsigned I = 0; I < QT.size(); I++) { // For scalars, size is 1. - if ((*GenVectorSizes)[I / GenTypeNumTypes] != 1) { + if (GenVectorSizes[I / GenTypeNumTypes] != 1) { QT[I] = Context.getExtVectorType(QT[I], - (*GenVectorSizes)[I / GenTypeNumTypes]); + GenVectorSizes[I / GenTypeNumTypes]); } } }