[clang] 9b704d3 - [Clang] Add option to disable -mconstructor-aliases with -mno-constructor-aliases

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 30 15:12:53 PST 2021


Author: modimo
Date: 2021-11-30T15:12:45-08:00
New Revision: 9b704d31b54a61615e7d172a1ed040bff7423e9b

URL: https://github.com/llvm/llvm-project/commit/9b704d31b54a61615e7d172a1ed040bff7423e9b
DIFF: https://github.com/llvm/llvm-project/commit/9b704d31b54a61615e7d172a1ed040bff7423e9b.diff

LOG: [Clang] Add option to disable -mconstructor-aliases with -mno-constructor-aliases

We've found that when profiling, counts are only generated for the real definition of constructor aliases (C2 in mangled name). However, when compiling the C1 version is present at the callsite and leads to a lack of counts due to this aliasing. This causes us to miss out on inlining an otherwise hot constructor.

-mconstructor-aliases is AFAICT an optimization, so having a disabling flag if wanted seems valuable.

Testing:
ninja check-all

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D114130

Added: 
    

Modified: 
    clang/include/clang/Driver/Options.td
    clang/test/CodeGenCXX/constructor-alias.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 724eedd05da44..a6932b3fa4b8d 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5065,9 +5065,10 @@ def msmall_data_limit : Separate<["-"], "msmall-data-limit">,
 def funwind_tables_EQ : Joined<["-"], "funwind-tables=">,
   HelpText<"Generate unwinding tables for all functions">,
   MarshallingInfoInt<CodeGenOpts<"UnwindTables">>;
-def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">,
-  HelpText<"Emit complete constructors and destructors as aliases when possible">,
-  MarshallingInfoFlag<CodeGenOpts<"CXXCtorDtorAliases">>;
+defm constructor_aliases : BoolOption<"m", "constructor-aliases",
+  CodeGenOpts<"CXXCtorDtorAliases">, DefaultFalse,
+  PosFlag<SetTrue, [], "Enable">, NegFlag<SetFalse, [], "Disable">,
+  BothFlags<[CC1Option], " emitting complete constructors and destructors as aliases when possible">>;
 def mlink_bitcode_file : Separate<["-"], "mlink-bitcode-file">,
   HelpText<"Link the given bitcode file before performing optimizations.">;
 def mlink_builtin_bitcode : Separate<["-"], "mlink-builtin-bitcode">,

diff  --git a/clang/test/CodeGenCXX/constructor-alias.cpp b/clang/test/CodeGenCXX/constructor-alias.cpp
index 4c89aaf028e4d..b8729584e2a56 100644
--- a/clang/test/CodeGenCXX/constructor-alias.cpp
+++ b/clang/test/CodeGenCXX/constructor-alias.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -emit-llvm -triple mipsel--linux-gnu -mconstructor-aliases -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple mipsel--linux-gnu -mno-constructor-aliases -mconstructor-aliases -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -triple mipsel--linux-gnu -mconstructor-aliases -mno-constructor-aliases -o - %s | FileCheck %s --check-prefix=NO-ALIAS
 
 // The target attribute code used to get confused with aliases. Make sure
 // we don't crash when an alias is used.
@@ -10,3 +11,4 @@ B::B() {
 }
 
 // CHECK: @_ZN1BC1Ev ={{.*}} unnamed_addr alias void (%struct.B*), void (%struct.B*)* @_ZN1BC2Ev
+// NO-ALIAS-NOT: @_ZN1BC1Ev ={{.*}} unnamed_addr alias void (%struct.B*), void (%struct.B*)* @_ZN1BC2Ev


        


More information about the cfe-commits mailing list