r317279 - Modular Codegen: Don't home always_inline functions

David Blaikie via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 15:28:50 PDT 2017


Author: dblaikie
Date: Thu Nov  2 15:28:50 2017
New Revision: 317279

URL: http://llvm.org/viewvc/llvm-project?rev=317279&view=rev
Log:
Modular Codegen: Don't home always_inline functions

Since they'll likely (not always - if the address is taken, etc) be
inlined away, even at -O0, separately provided weak definitions are
likely to be unused so skip all of that.

Modified:
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
    cfe/trunk/test/Modules/Inputs/codegen/foo.h
    cfe/trunk/test/Modules/Inputs/codegen/use.cpp
    cfe/trunk/test/Modules/codegen.test

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=317279&r1=317278&r2=317279&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Thu Nov  2 15:28:50 2017
@@ -2270,9 +2270,11 @@ void ASTRecordWriter::AddFunctionDefinit
     if (Writer->Context->getLangOpts().ModulesCodegen) {
       // Under -fmodules-codegen, codegen is performed for all non-internal,
       // non-always_inline functions.
-      if (!Linkage)
-        Linkage = Writer->Context->GetGVALinkageForFunction(FD);
-      ModulesCodegen = *Linkage != GVA_Internal;
+      if (!FD->hasAttr<AlwaysInlineAttr>()) {
+        if (!Linkage)
+          Linkage = Writer->Context->GetGVALinkageForFunction(FD);
+        ModulesCodegen = *Linkage != GVA_Internal;
+      }
     }
   }
   Record->push_back(ModulesCodegen);

Modified: cfe/trunk/test/Modules/Inputs/codegen/foo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/codegen/foo.h?rev=317279&r1=317278&r2=317279&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/codegen/foo.h (original)
+++ cfe/trunk/test/Modules/Inputs/codegen/foo.h Thu Nov  2 15:28:50 2017
@@ -29,4 +29,7 @@ inline void inst_decl() {
   inst<float>();
 }
 
+__attribute__((always_inline)) inline void always_inl() {
+}
+
 asm("narf");

Modified: cfe/trunk/test/Modules/Inputs/codegen/use.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/codegen/use.cpp?rev=317279&r1=317278&r2=317279&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/codegen/use.cpp (original)
+++ cfe/trunk/test/Modules/Inputs/codegen/use.cpp Thu Nov  2 15:28:50 2017
@@ -6,3 +6,6 @@ void non_modular_use_of_implicit_dtor()
 void use_of_instantiated_declaration_without_definition() {
   inst<int>();
 }
+void call_always_inline() {
+  always_inl();
+}

Modified: cfe/trunk/test/Modules/codegen.test
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/codegen.test?rev=317279&r1=317278&r2=317279&view=diff
==============================================================================
--- cfe/trunk/test/Modules/codegen.test (original)
+++ cfe/trunk/test/Modules/codegen.test Thu Nov  2 15:28:50 2017
@@ -4,7 +4,7 @@ REQUIRES: x86-registered-target
 RUN: %clang_cc1 -triple=x86_64-linux-gnu -fmodules-codegen -fmodules-debuginfo -x c++ -fmodules -emit-module -fmodule-name=foo %S/Inputs/codegen/foo.modulemap -o %t/foo.pcm
 
 RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - %t/foo.pcm | FileCheck --check-prefix=FOO --check-prefix=BOTH %s
-RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -fmodules -fmodule-file=%t/foo.pcm %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=BOTH --check-prefix=USE %s
+RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -debug-info-kind=limited -o - -fmodules -disable-llvm-passes -fmodule-file=%t/foo.pcm %S/Inputs/codegen/use.cpp | FileCheck --check-prefix=BOTH --check-prefix=USE %s
 
 For want of any better definition, inline asm goes "everywhere" the same as it
 if it were in a header (with the disadvantage that the inline asm will be
@@ -23,6 +23,7 @@ USE: module asm "narf"
 FOO: $_Z2f1PKcz = comdat any
 FOO: $_ZN13implicit_dtorD1Ev = comdat any
 USE: $_Z4instIiEvv = comdat any
+USE: $_Z10always_inlv = comdat any
 FOO: $_ZN13implicit_dtorD2Ev = comdat any
 FOO: define weak_odr void @_Z2f1PKcz(i8* %fmt, ...) #{{[0-9]+}} comdat
 FOO:   call void @llvm.va_start(i8* %{{[a-zA-Z0-9]*}})
@@ -38,6 +39,7 @@ FOO: define weak_odr void @_ZN13implicit
 
 USE: define linkonce_odr void @_ZN20uninst_implicit_dtorD1Ev
 USE: define linkonce_odr void @_Z4instIiEvv
+USE: define linkonce_odr void @_Z10always_inlv
 USE: define linkonce_odr void @_ZN20uninst_implicit_dtorD2Ev
 
 Modular debug info puts the definition of a class defined in a module in that




More information about the cfe-commits mailing list