r369846 - [OpenCL] Microoptimize OCL2Qual a bit
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 24 06:04:34 PDT 2019
Author: d0k
Date: Sat Aug 24 06:04:34 2019
New Revision: 369846
URL: http://llvm.org/viewvc/llvm-project?rev=369846&view=rev
Log:
[OpenCL] Microoptimize OCL2Qual a bit
Still not optimal, but makes clang 25k smaller.
Modified:
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=369846&r1=369845&r2=369846&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sat Aug 24 06:04:34 2019
@@ -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<QualType> &RetTypes,
- SmallVector<std::vector<QualType>, 5> &ArgTypes) {
+ unsigned &GenTypeMaxCnt, SmallVector<QualType, 1> &RetTypes,
+ SmallVector<SmallVector<QualType, 1>, 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<QualType> Ty;
+ SmallVector<QualType, 1> 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<QualType> &FunctionList,
- std::vector<QualType> &RetTypes,
- SmallVector<std::vector<QualType>, 5> &ArgTypes) {
+static void GetOpenCLBuiltinFctOverloads(
+ ASTContext &Context, unsigned GenTypeMaxCnt,
+ std::vector<QualType> &FunctionList, SmallVector<QualType, 1> &RetTypes,
+ SmallVector<SmallVector<QualType, 1>, 5> &ArgTypes) {
FunctionProtoType::ExtProtoInfo PI;
PI.Variadic = false;
@@ -765,8 +764,8 @@ static void InsertOCLBuiltinDeclarations
BuiltinTable[FctIndex + SignatureIndex];
ASTContext &Context = S.Context;
- std::vector<QualType> RetTypes;
- SmallVector<std::vector<QualType>, 5> ArgTypes;
+ SmallVector<QualType, 1> RetTypes;
+ SmallVector<SmallVector<QualType, 1>, 5> ArgTypes;
// Obtain QualType lists for the function signature.
GetQualTypesForOpenCLBuiltin(Context, OpenCLBuiltin, GenTypeMaxCnt,
Modified: cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp?rev=369846&r1=369845&r2=369846&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp Sat Aug 24 06:04:34 2019
@@ -434,17 +434,17 @@ void BuiltinNameEmitter::EmitQualTypeFin
// Step 2: Qualifiers and other type properties such as vector size are
// applied.
static void OCL2Qual(ASTContext &Context, const OpenCLTypeStruct &Ty,
- std::vector<QualType> &QT) {
+ llvm::SmallVectorImpl<QualType> &QT) {
// Number of scalar types in the GenType.
unsigned GenTypeNumTypes;
// Pointer to the list of vector sizes for the GenType.
- llvm::SmallVector<unsigned, 6> *GenVectorSizes;
+ llvm::ArrayRef<unsigned> GenVectorSizes;
)";
// Generate list of vector sizes for each generic type.
for (const auto *VectList : Records.getAllDerivedDefinitions("IntList")) {
- OS << " llvm::SmallVector<unsigned, 6> 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
// 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
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
<< ";\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
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]);
}
}
}
More information about the cfe-commits
mailing list