<div dir="ltr">Sorry for the inconvenience!<div><br></div><div>I will follow-up in the PR.</div><div><br></div><div>-- </div><div>Mehdi</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-28 12:42 GMT-07:00 Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I reverted this in r311898 as it caused Chromium builds to fail with<br>
an assertion; see PR34348.<br>
<div class="HOEnZb"><div class="h5"><br>
On Sun, Aug 27, 2017 at 1:24 PM, Mehdi Amini via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: mehdi_amini<br>
> Date: Sun Aug 27 13:24:09 2017<br>
> New Revision: 311857<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=311857&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=311857&view=rev</a><br>
> Log:<br>
> Emit static constexpr member as available_externally definition<br>
><br>
> By exposing the constant initializer, the optimizer can fold many<br>
> of these constructs.<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D34992" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D34992</a><br>
><br>
> Added:<br>
>     cfe/trunk/test/CodeGenCXX/<wbr>cxx11-extern-constexpr.cpp<br>
> Modified:<br>
>     cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=311857&r1=311856&r2=311857&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp?rev=311857&<wbr>r1=311856&r2=311857&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/<wbr>CodeGenModule.cpp Sun Aug 27 13:24:09 2017<br>
> @@ -2437,6 +2437,28 @@ CodeGenModule::<wbr>GetOrCreateLLVMGlobal(Str<br>
>          D->getType().isConstant(<wbr>Context) &&<br>
>          isExternallyVisible(D-><wbr>getLinkageAndVisibility().<wbr>getLinkage()))<br>
>        GV->setSection(".cp.rodata");<br>
> +<br>
> +    // Check if we a have a const declaration with an initializer, we may be<br>
> +    // able to emit it as available_externally to expose it's value to the<br>
> +    // optimizer.<br>
> +    if (Context.getLangOpts().<wbr>CPlusPlus && GV->hasExternalLinkage() &&<br>
> +        D->getType().isConstQualified(<wbr>) && !GV->hasInitializer() &&<br>
> +        !D->hasDefinition() && D->hasInit() && !D->hasAttr<DLLImportAttr>()) {<br>
> +      const auto *Record =<br>
> +          Context.getBaseElementType(D-><wbr>getType())-><wbr>getAsCXXRecordDecl();<br>
> +      bool HasMutableFields = Record && Record->hasMutableFields();<br>
> +      if (!HasMutableFields) {<br>
> +        const VarDecl *InitDecl;<br>
> +        const Expr *InitExpr = D->getAnyInitializer(InitDecl)<wbr>;<br>
> +        if (InitExpr) {<br>
> +          GV->setConstant(true);<br>
> +          GV->setLinkage(llvm::<wbr>GlobalValue::<wbr>AvailableExternallyLinkage);<br>
> +          ConstantEmitter emitter(*this);<br>
> +          GV->setInitializer(emitter.<wbr>tryEmitForInitializer(*<wbr>InitDecl));<br>
> +          emitter.finalize(GV);<br>
> +        }<br>
> +      }<br>
> +    }<br>
>    }<br>
><br>
>    auto ExpectedAS =<br>
><br>
> Added: cfe/trunk/test/CodeGenCXX/<wbr>cxx11-extern-constexpr.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cxx11-extern-constexpr.cpp?rev=311857&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/cfe/trunk/test/<wbr>CodeGenCXX/cxx11-extern-<wbr>constexpr.cpp?rev=311857&view=<wbr>auto</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/CodeGenCXX/<wbr>cxx11-extern-constexpr.cpp (added)<br>
> +++ cfe/trunk/test/CodeGenCXX/<wbr>cxx11-extern-constexpr.cpp Sun Aug 27 13:24:09 2017<br>
> @@ -0,0 +1,55 @@<br>
> +// RUN: %clang_cc1 -std=c++11 %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK --check-prefix=CXX11<br>
> +// RUN: %clang_cc1 -std=c++1z %s -emit-llvm -o - -triple x86_64-linux-gnu | FileCheck %s --check-prefix=CHECK --check-prefix=CXX17<br>
> +<br>
> +struct A {<br>
> +  static const int Foo = 123;<br>
> +};<br>
> +// CHECK: @_ZN1A3FooE = constant i32 123, align 4<br>
> +const int *p = &A::Foo; // emit available_externally<br>
> +const int A::Foo;       // convert to full definition<br>
> +<br>
> +struct Bar {<br>
> +  int b;<br>
> +};<br>
> +<br>
> +struct MutableBar {<br>
> +  mutable int b;<br>
> +};<br>
> +<br>
> +struct Foo {<br>
> +  // CXX11: @_<wbr>ZN3Foo21ConstexprStaticMemberE = available_externally constant i32 42,<br>
> +  // CXX17: @_<wbr>ZN3Foo21ConstexprStaticMemberE = linkonce_odr constant i32 42,<br>
> +  static constexpr int ConstexprStaticMember = 42;<br>
> +  // CHECK: @_ZN3Foo17ConstStaticMemberE = available_externally constant i32 43,<br>
> +  static const int ConstStaticMember = 43;<br>
> +<br>
> +  // CXX11: @_<wbr>ZN3Foo23ConstStaticStructMembe<wbr>rE = available_externally constant %struct.Bar { i32 44 },<br>
> +  // CXX17: @_<wbr>ZN3Foo23ConstStaticStructMembe<wbr>rE = linkonce_odr constant %struct.Bar { i32 44 },<br>
> +  static constexpr Bar ConstStaticStructMember = {44};<br>
> +<br>
> +  // CXX11: @_<wbr>ZN3Foo34ConstexprStaticMutable<wbr>StructMemberE = external global %struct.MutableBar,<br>
> +  // CXX17: @_<wbr>ZN3Foo34ConstexprStaticMutable<wbr>StructMemberE = linkonce_odr global %struct.MutableBar { i32 45 },<br>
> +  static constexpr MutableBar ConstexprStaticMutableStructMe<wbr>mber = {45};<br>
> +};<br>
> +// CHECK: @_ZL15ConstStaticexpr = internal constant i32 46,<br>
> +static constexpr int ConstStaticexpr = 46;<br>
> +// CHECK: @_ZL9ConstExpr = internal constant i32 46, align 4<br>
> +static const int ConstExpr = 46;<br>
> +<br>
> +// CHECK: @_ZL21ConstexprStaticStruct = internal constant %struct.Bar { i32 47 },<br>
> +static constexpr Bar ConstexprStaticStruct = {47};<br>
> +<br>
> +// CHECK: @_<wbr>ZL28ConstexprStaticMutableStru<wbr>ct = internal global %struct.MutableBar { i32 48 },<br>
> +static constexpr MutableBar ConstexprStaticMutableStruct = {48};<br>
> +<br>
> +void use(const int &);<br>
> +void foo() {<br>
> +  use(Foo::<wbr>ConstexprStaticMember);<br>
> +  use(Foo::ConstStaticMember);<br>
> +  use(Foo::<wbr>ConstStaticStructMember.b);<br>
> +  use(Foo::<wbr>ConstexprStaticMutableStructMe<wbr>mber.b);<br>
> +  use(ConstStaticexpr);<br>
> +  use(ConstExpr);<br>
> +  use(ConstexprStaticStruct.b);<br>
> +  use(<wbr>ConstexprStaticMutableStruct.<wbr>b);<br>
> +}<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>