[clang] 0fff659 - [OpenCL] Reduce size of builtin function tables
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 07:09:06 PST 2020
Author: Sven van Haastregt
Date: 2020-02-06T15:08:32Z
New Revision: 0fff6593f8962784d1e2e99994d2ad986f2759a8
URL: https://github.com/llvm/llvm-project/commit/0fff6593f8962784d1e2e99994d2ad986f2759a8
DIFF: https://github.com/llvm/llvm-project/commit/0fff6593f8962784d1e2e99994d2ad986f2759a8.diff
LOG: [OpenCL] Reduce size of builtin function tables
Reduce the size of some of the TableGen'ed OpenCL builtin function
tables:
- Use bit fields for bools such that they are packed together. This
saves about 7kb.
- Use unsigned short for SignatureTable. This saves about 10kb.
Added:
Modified:
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Removed:
################################################################################
diff --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 85933e6d3bd3..b930f2daed42 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -313,11 +313,11 @@ struct OpenCLTypeStruct {
// Vector size (if applicable; 0 for scalars and generic types).
const unsigned VectorWidth;
// 0 if the type is not a pointer.
- const bool IsPointer;
+ const bool IsPointer : 1;
// 0 if the type is not const.
- const bool IsConst;
+ const bool IsConst : 1;
// 0 if the type is not volatile.
- const bool IsVolatile;
+ const bool IsVolatile : 1;
// Access qualifier.
const OpenCLAccessQual AccessQualifier;
// Address space of the pointer (if applicable).
@@ -333,11 +333,11 @@ struct OpenCLBuiltinStruct {
// index SigTableIndex is the return type.
const unsigned NumTypes;
// Function attribute __attribute__((pure))
- const bool IsPure;
+ const bool IsPure : 1;
// Function attribute __attribute__((const))
- const bool IsConst;
+ const bool IsConst : 1;
// Function attribute __attribute__((convergent))
- const bool IsConv;
+ const bool IsConv : 1;
// OpenCL extension(s) required for this overload.
const unsigned short Extension;
// First OpenCL version in which this overload was introduced (e.g. CL20).
@@ -473,11 +473,18 @@ void BuiltinNameEmitter::EmitSignatureTable() {
// Store a type (e.g. int, float, int2, ...). The type is stored as an index
// of a struct OpenCLType table. Multiple entries following each other form a
// signature.
- OS << "static const unsigned SignatureTable[] = {\n";
+ OS << "static const unsigned short SignatureTable[] = {\n";
for (const auto &P : SignaturesList) {
OS << " // " << P.second << "\n ";
for (const Record *R : P.first) {
- OS << TypeMap.find(R)->second << ", ";
+ unsigned Entry = TypeMap.find(R)->second;
+ if (Entry > USHRT_MAX) {
+ // Report an error when seeing an entry that is too large for the
+ // current index type (unsigned short). When hitting this, the type
+ // of SignatureTable will need to be changed.
+ PrintFatalError("Entry in SignatureTable exceeds limit.");
+ }
+ OS << Entry << ", ";
}
OS << "\n";
}
More information about the cfe-commits
mailing list