Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp813125ybm; Wed, 27 May 2020 08:37:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXgKTzIzoixVxcxtDxiYdmInYNhXd0UbmwQhpKUP+Q6hDKkmokELqxI7PsfmFT2O0OICVa X-Received: by 2002:a17:906:703:: with SMTP id y3mr6773850ejb.61.1590593826676; Wed, 27 May 2020 08:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590593826; cv=none; d=google.com; s=arc-20160816; b=oTeyt/mDqcBr9Q/ZmmgtwwHPORfJPKJSrZAs3r5Q5FKrjNKYfF5No1mKyZaFcFt1ev ftzuAeClwXzqbi7hxXpKJTFxU6YOzIPzDTZZ8cQ7rEBxt8ZFNa//6SKQqoqNUYRKbe3g D+fkTfb8ZmJLDpnWFs0lgUZnmSPn8VFLrGkVjVT6J/+PdTjV2Uh546Ot3rIKeqTtCslm TlXkoHw0DWJIsrDnfAMIpUfu3VtQtqausEqIVCgGy9ilUOPJYXgy07Ycjf4MNttEG2JH VJ0WxP19iBg0orw/81cQ//Xf1lGMEtmZCzthl3xuxYpUAtyq2wvenX/1Aj+HZm/xEgQA p52w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=DosOYF3ps8rgQKGpMQeCZ1cwpGKFHV+Ez1qTc9wvzYQ=; b=P2qbqngl7uWIyvPJb5fcLIPOyECtrB7t3H4HacSE4bFv1NXyDGebu6Tnv/zfZLs9kp /2bmwy4hbwlq2pibjafEBIrbEB/PPK7gWRpqcku8S8JPJ9Z7uOBHnOWfvtJfYMshqaSi gDYrfYlG5Fxyr2fi860Mx6qPH9vqgHJyxrkI871KgPYzV6D2zQwkTR8Pj/6Ll3cxB7+Q oSyPx/6cEnbxTkJGMAYhQIZmxttSw41RnF9FIp+W44J7kaKm3e7ISkWj8SxJHMWQG1db 5d2jH74YmkqvfeJ2a3WIW7BpnTLr7FiFDHL1d5TEvqmEKvRK9OpNYjyahb5NvmGPSp5p 9+vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h9B95SbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si1192404edb.335.2020.05.27.08.36.42; Wed, 27 May 2020 08:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=h9B95SbK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729857AbgE0KdN (ORCPT + 99 others); Wed, 27 May 2020 06:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729062AbgE0KdM (ORCPT ); Wed, 27 May 2020 06:33:12 -0400 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1A02C061A0F for ; Wed, 27 May 2020 03:33:12 -0700 (PDT) Received: by mail-qt1-x849.google.com with SMTP id e44so25364922qta.9 for ; Wed, 27 May 2020 03:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=DosOYF3ps8rgQKGpMQeCZ1cwpGKFHV+Ez1qTc9wvzYQ=; b=h9B95SbKbShNt1lB+ySn2GyjP+UgZXssfV8mgIcHh91KiWoQD1RFqGw610hkzIMyVt oEr7U4NQaBt2sU9PhCOavnznY0CNYUp/jgZC1eIaeHP3U9qslxxuvuCZ8riTmZTGHu4M xwO+B07QB7X1mqLaG3UL0ZC5u6rDyl4J2QVObU/d9uSUSxnPR2R6jn398mwlYdWkDRNn 9uIHzTCcwNSIiasWnmlK+qfzJqoqrOmNDRfAXNedcWwSLDjI4HN/M9D1SZ4Ow5WIfs4A M67Xq+Tu0TONXoKQ0dQSH9gyp5TUv38XEhAnypzN9cv3qOeORY5zCyECVnNKvABgxxCW iwcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=DosOYF3ps8rgQKGpMQeCZ1cwpGKFHV+Ez1qTc9wvzYQ=; b=fZyhmqmqQ+W1LmkPjuD927fswx2Ldx1zT5jK0OFLAW9U3TiJmjLMofTTE1fxg8pMOV cN7U2vtRcEp0zEP2fuDI0pc5UKimvS0IekXKrUbYsem3v4Y+FC+mDX0wHBu/8arbWyxn 5OS5T9WKIV2oR92dt0PTzSgkIFc+bZ9Q5CEqP25k1VkBhP394nrOSH/wMTxq4nkY9ZkM lPUABCASPyU8iW6FW1oqLqhFbpCn7YMkkolF2YuMd6N/p+4tmSmKlIOmKSy586o90PP+ DzCEuHkAONZL8nEJd8YS2/ewii/9mHN3XIQs1xu/m3mhSBxrHyAniVSZXCeCji33p/B4 MazQ== X-Gm-Message-State: AOAM533O3gC2KCqSY4CoTTGHFbNXgH32KnSO/oTbo+Q40kqznVPBt8lG TjfbbFTTNajBKOR3zMvLO9CWHymv0A== X-Received: by 2002:ad4:5684:: with SMTP id bc4mr24918443qvb.85.1590575591788; Wed, 27 May 2020 03:33:11 -0700 (PDT) Date: Wed, 27 May 2020 12:32:36 +0200 Message-Id: <20200527103236.148700-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.27.0.rc0.183.gde8f92d652-goog Subject: [PATCH -tip] compiler_types.h: Optimize __unqual_scalar_typeof compilation time From: Marco Elver To: elver@google.com Cc: will@kernel.org, peterz@infradead.org, bp@alien8.de, tglx@linutronix.de, mingo@kernel.org, clang-built-linux@googlegroups.com, paulmck@kernel.org, dvyukov@google.com, glider@google.com, andreyknvl@google.com, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Arnd Bergmann , Nick Desaulniers , Stephen Rothwell Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If the compiler supports C11's _Generic, use it to speed up compilation times of __unqual_scalar_typeof(). GCC version 4.9 or later and all supported versions of Clang support the feature (the oldest supported compiler that doesn't support _Generic is GCC 4.8, for which we use the slower alternative). The non-_Generic variant relies on multiple expansions of __pick_integer_type -> __pick_scalar_type -> __builtin_choose_expr, which increases pre-processed code size, and can cause compile times to increase in files with numerous expansions of READ_ONCE(), or other users of __unqual_scalar_typeof(). Summary of compile-time benchmarking done by Arnd Bergmann [1]: clang-11 gcc-9 this patch 0.78 0.91 ideal 0.76 0.86 [1] https://lkml.kernel.org/r/CAK8P3a3UYQeXhiufUevz=rwe09WM_vSTCd9W+KvJHJcOeQyWVA@mail.gmail.com Further compile-testing done with: gcc 4.8, 4.9, 5.5, 6.4, 7.5, 8.4; clang 9, 10. Reported-by: Arnd Bergmann Signed-off-by: Marco Elver Cc: Borislav Petkov Cc: Ingo Molnar Cc: Nick Desaulniers Cc: Paul E. McKenney Cc: Peter Zijlstra Cc: Stephen Rothwell Cc: Thomas Gleixner Cc: Will Deacon Link: https://lkml.kernel.org/r/CAK8P3a0RJtbVi1JMsfik=jkHCNFv+DJn_FeDg-YLW+ueQW3tNg@mail.gmail.com --- Same version as in: https://lkml.kernel.org/r/20200526173312.GA30240@google.com --- include/linux/compiler_types.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h index 5faf68eae204..a529fa263906 100644 --- a/include/linux/compiler_types.h +++ b/include/linux/compiler_types.h @@ -245,7 +245,9 @@ struct ftrace_likely_data { /* * __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving * non-scalar types unchanged. - * + */ +#if defined(CONFIG_CC_IS_GCC) && CONFIG_GCC_VERSION < 40900 +/* * We build this out of a couple of helper macros in a vain attempt to * help you keep your lunch down while reading it. */ @@ -267,6 +269,24 @@ struct ftrace_likely_data { __pick_integer_type(x, int, \ __pick_integer_type(x, long, \ __pick_integer_type(x, long long, x)))))) +#else +/* + * If supported, prefer C11 _Generic for better compile-times. As above, 'char' + * is not type-compatible with 'signed char', and we define a separate case. + */ +#define __scalar_type_to_expr_cases(type) \ + type: (type)0, unsigned type: (unsigned type)0 + +#define __unqual_scalar_typeof(x) typeof( \ + _Generic((x), \ + __scalar_type_to_expr_cases(char), \ + signed char: (signed char)0, \ + __scalar_type_to_expr_cases(short), \ + __scalar_type_to_expr_cases(int), \ + __scalar_type_to_expr_cases(long), \ + __scalar_type_to_expr_cases(long long), \ + default: (x))) +#endif /* Is this type a native word size -- useful for atomic operations */ #define __native_word(t) \ -- 2.27.0.rc0.183.gde8f92d652-goog