summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2019-08-24 13:04:34 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2019-08-24 13:04:34 +0000
commit19651b68d956e6e526203ecb94698691ca76ce61 (patch)
tree7642ab3167dcdb86172bdf33ffe64ec088121a23
parent0d7252b783697c2737069ffd91f7195eaa1afdc3 (diff)
downloadbcm5719-llvm-19651b68d956e6e526203ecb94698691ca76ce61.tar.gz
bcm5719-llvm-19651b68d956e6e526203ecb94698691ca76ce61.zip
[OpenCL] Microoptimize OCL2Qual a bit
Still not optimal, but makes clang 25k smaller. llvm-svn: 369846
-rw-r--r--clang/lib/Sema/SemaLookup.cpp21
-rw-r--r--clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp20
2 files changed, 21 insertions, 20 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 813b62932b4..8bae219f5ad 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/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<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 InsertOCLBuiltinDeclarationsFromTable(Sema &S, LookupResult &LR,
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,
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 4bf59c3a923..7707cb0ee0a 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/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<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, 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]);
}
}
}
OpenPOWER on IntegriCloud