r241467 - Resubmit "Pass down the -flto option to the -cc1 job" (r239481)

Teresa Johnson tejohnson at google.com
Mon Jul 6 11:24:36 PDT 2015


On Mon, Jul 6, 2015 at 11:18 AM, David Blaikie <dblaikie at gmail.com> wrote:

> I think I probably asked this before - but just to check, the reason these
> definitions are left in is because the actual external definition may not
> be in the lto build? (Otherwise you could drop the available externally
> definition in each object/bitcode file and know that you could clone it
> from the actual external definition during lto time?) When does this come
> up (where do we get these available externally definitions at compile time?
> From c99 extern inline? Does it come up that the true extern definition is
> not in the lto scope?)
>

Yep, I think Reid had answered this here:


http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150608/281203.html

Teresa

On Jul 6, 2015 9:28 AM, "Teresa Johnson" <tejohnson at google.com> wrote:
>
>> Author: tejohnson
>> Date: Mon Jul  6 11:23:00 2015
>> New Revision: 241467
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=241467&view=rev
>> Log:
>> Resubmit "Pass down the -flto option to the -cc1 job" (r239481)
>>
>> The patch is the same except for the addition of a new test for the
>> issue that required reverting the dependent llvm commit.
>>
>> --Original Commit Message--
>>
>> Pass down the -flto option to the -cc1 job, and from there into the
>> CodeGenOptions and onto the PassManagerBuilder. This enables gating
>> the new EliminateAvailableExternally module pass on whether we are
>> preparing for LTO.
>>
>> If we are preparing for LTO (e.g. a -flto -c compile), the new pass is not
>> included as we want to preserve available externally functions for
>> possible
>> link time inlining.
>>
>> Added:
>>     cfe/trunk/test/CodeGen/available-externally-hidden.cpp
>> Modified:
>>     cfe/trunk/include/clang/Driver/Options.td
>>     cfe/trunk/include/clang/Frontend/CodeGenOptions.def
>>     cfe/trunk/lib/CodeGen/BackendUtil.cpp
>>     cfe/trunk/lib/Driver/Tools.cpp
>>     cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>>     cfe/trunk/test/CodeGen/available-externally-suppress.c
>>
>> Modified: cfe/trunk/include/clang/Driver/Options.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/Driver/Options.td (original)
>> +++ cfe/trunk/include/clang/Driver/Options.td Mon Jul  6 11:23:00 2015
>> @@ -641,7 +641,7 @@ def flat__namespace : Flag<["-"], "flat_
>>  def flax_vector_conversions : Flag<["-"], "flax-vector-conversions">,
>> Group<f_Group>;
>>  def flimited_precision_EQ : Joined<["-"], "flimited-precision=">,
>> Group<f_Group>;
>>  def flto_EQ : Joined<["-"], "flto=">,
>> Group<clang_ignored_gcc_optimization_f_Group>;
>> -def flto : Flag<["-"], "flto">, Group<f_Group>;
>> +def flto : Flag<["-"], "flto">, Flags<[CC1Option]>, Group<f_Group>;
>>  def fno_lto : Flag<["-"], "fno-lto">, Group<f_Group>;
>>  def fmacro_backtrace_limit_EQ : Joined<["-"], "fmacro-backtrace-limit=">,
>>                                  Group<f_Group>, Flags<[DriverOption,
>> CoreOption]>;
>>
>> Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
>> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Mon Jul  6
>> 11:23:00 2015
>> @@ -67,6 +67,8 @@ CODEGENOPT(InstrumentFunctions , 1, 0) /
>>  CODEGENOPT(InstrumentForProfiling , 1, 0) ///< Set when -pg is enabled.
>>  CODEGENOPT(LessPreciseFPMAD  , 1, 0) ///< Enable less precise MAD
>> instructions to
>>                                       ///< be generated.
>> +CODEGENOPT(PrepareForLTO     , 1, 0) ///< Set when -flto is enabled on
>> the
>> +                                     ///< compile step.
>>  CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
>>  CODEGENOPT(MergeFunctions    , 1, 0) ///< Set when -fmerge-functions is
>> enabled.
>>  CODEGENOPT(MSVolatile        , 1, 0) ///< Set when /volatile:ms is
>> enabled.
>>
>> Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Jul  6 11:23:00 2015
>> @@ -292,6 +292,7 @@ void EmitAssemblyHelper::CreatePasses()
>>    PMBuilder.DisableUnitAtATime = !CodeGenOpts.UnitAtATime;
>>    PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
>>    PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
>> +  PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
>>    PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
>>
>>    PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
>>
>> Modified: cfe/trunk/lib/Driver/Tools.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/Tools.cpp (original)
>> +++ cfe/trunk/lib/Driver/Tools.cpp Mon Jul  6 11:23:00 2015
>> @@ -2805,6 +2805,10 @@ void Clang::ConstructJob(Compilation &C,
>>      assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
>>             "Invalid action for clang tool.");
>>
>> +    if (JA.getType() == types::TY_LTO_IR ||
>> +        JA.getType() == types::TY_LTO_BC) {
>> +      CmdArgs.push_back("-flto");
>> +    }
>>      if (JA.getType() == types::TY_Nothing) {
>>        CmdArgs.push_back("-fsyntax-only");
>>      } else if (JA.getType() == types::TY_LLVM_IR ||
>>
>> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
>> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Jul  6 11:23:00 2015
>> @@ -508,6 +508,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
>>
>>    Opts.MergeFunctions = Args.hasArg(OPT_fmerge_functions);
>>
>> +  Opts.PrepareForLTO = Args.hasArg(OPT_flto);
>> +
>>    Opts.MSVolatile = Args.hasArg(OPT_fms_volatile);
>>
>>    Opts.VectorizeBB = Args.hasArg(OPT_vectorize_slp_aggressive);
>>
>> Added: cfe/trunk/test/CodeGen/available-externally-hidden.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/available-externally-hidden.cpp?rev=241467&view=auto
>>
>> ==============================================================================
>> --- cfe/trunk/test/CodeGen/available-externally-hidden.cpp (added)
>> +++ cfe/trunk/test/CodeGen/available-externally-hidden.cpp Mon Jul  6
>> 11:23:00 2015
>> @@ -0,0 +1,32 @@
>> +// RUN: %clang_cc1 -O2 -fvisibility hidden -std=c++11 -emit-llvm -o -
>> -triple x86_64-apple-darwin10 %s | FileCheck %s
>> +
>> +// Ensure that available_externally functions eliminated at -O2 are now
>> +// declarations, and are not emitted as hidden with -fvisibility=hidden,
>> +// but rather with default visibility.
>> +struct Filter {
>> +  virtual void Foo();
>> +  int a;
>> +};
>> +
>> +class Message{};
>> +class Sender {
>> + public:
>> +  virtual bool Send(Message* msg) = 0;
>> +
>> + protected:
>> +  virtual ~Sender() {}
>> +};
>> +
>> +// CHECK: declare zeroext i1 @_ZThn16_N17SyncMessageFilter4SendEP7Message
>> +class SyncMessageFilter : public Filter, public Sender {
>> + public:
>> +  bool Send(Message* message) override;
>> +};
>> +
>> +class TestSyncMessageFilter : public SyncMessageFilter {
>> +};
>> +
>> +int main() {
>> +TestSyncMessageFilter*  f = new TestSyncMessageFilter;
>> +  f->Send(new Message);
>> +}
>>
>> Modified: cfe/trunk/test/CodeGen/available-externally-suppress.c
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/available-externally-suppress.c?rev=241467&r1=241466&r2=241467&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/CodeGen/available-externally-suppress.c (original)
>> +++ cfe/trunk/test/CodeGen/available-externally-suppress.c Mon Jul  6
>> 11:23:00 2015
>> @@ -1,12 +1,18 @@
>>  // RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin10 %s |
>> FileCheck %s
>> +// RUN: %clang_cc1 -O2 -fno-inline -emit-llvm -o - -triple
>> x86_64-apple-darwin10 %s | FileCheck %s
>> +// RUN: %clang_cc1 -flto -O2 -fno-inline -emit-llvm -o - -triple
>> x86_64-apple-darwin10 %s | FileCheck %s -check-prefix=LTO
>>
>>  // Ensure that we don't emit available_externally functions at -O0.
>> +// Also should not emit them at -O2, unless -flto is present in which
>> case
>> +// we should preserve them for link-time inlining decisions.
>>  int x;
>>
>>  inline void f0(int y) { x = y; }
>>
>>  // CHECK-LABEL: define void @test()
>>  // CHECK: declare void @f0(i32)
>> +// LTO-LABEL: define void @test()
>> +// LTO: define available_externally void @f0
>>  void test() {
>>    f0(17);
>>  }
>> @@ -19,9 +25,13 @@ inline int __attribute__((always_inline)
>>  }
>>
>>  // CHECK: @test1
>> +// LTO: @test1
>>  int test1(int x) {
>>    // CHECK: br i1
>>    // CHECK-NOT: call {{.*}} @f1
>>    // CHECK: ret i32
>> +  // LTO: br i1
>> +  // LTO-NOT: call {{.*}} @f1
>> +  // LTO: ret i32
>>    return f1(x);
>>  }
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>


-- 
Teresa Johnson | Software Engineer | tejohnson at google.com | 408-460-2413
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150706/b10a2a29/attachment.html>


More information about the cfe-commits mailing list