From d2f4b7d77828dba831f4b7429a7c970d71eb853b Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 13 May 2021 20:26:50 -0700 Subject: [PATCH] Use enum comparison instead of generated switch/case, NFC Clang's coverage data for auto-generated switch cases is really, really large. Before this change, when I enable code coverage, SemaDeclAttr.obj is 4.0GB. Naturally, this fails to link. Replacing the RISCV builtin id check with a comparison reduces object file size from 4.0GB to 330MB. Replacing the AArch64 SVE range check reduces the size again down to 17MB, which is reasonable. I think the RISCV switch is larger in coverage data because it uses more levels of macro expansion, while the SVE intrinsics only use one. In any case, please try to avoid switches with 1000+ cases, they usually don't optimize well. --- clang/lib/Sema/SemaDeclAttr.cpp | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 7286822..c470598e 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -5133,15 +5133,8 @@ static bool ArmCdeAliasValid(unsigned BuiltinID, StringRef AliasName) { } static bool ArmSveAliasValid(unsigned BuiltinID, StringRef AliasName) { - switch (BuiltinID) { - default: - return false; -#define GET_SVE_BUILTINS -#define BUILTIN(name, types, attr) case SVE::BI##name: -#include "clang/Basic/arm_sve_builtins.inc" -#undef BUILTIN - return true; - } + return BuiltinID >= AArch64::FirstSVEBuiltin && + BuiltinID <= AArch64::LastSVEBuiltin; } static void handleArmBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { @@ -5167,14 +5160,8 @@ static void handleArmBuiltinAliasAttr(Sema &S, Decl *D, const ParsedAttr &AL) { } static bool RISCVAliasValid(unsigned BuiltinID, StringRef AliasName) { - switch (BuiltinID) { - default: - return false; -#define BUILTIN(ID, TYPE, ATTRS) case RISCV::BI##ID: -#include "clang/Basic/BuiltinsRISCV.def" -#undef BUILTIN - return true; - } + return BuiltinID >= Builtin::FirstTSBuiltin && + BuiltinID < RISCV::LastTSBuiltin; } static void handleBuiltinAliasAttr(Sema &S, Decl *D, -- 2.7.4