From dce722961a8a421f2cfeb08d417834b4f008dc4e Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 15 Apr 2015 01:16:18 +0000 Subject: [PATCH] uselistorder: -mllvm -preserve-bc-use-list-order => -emit-llvm-uselists Stop relying on `cl::opt` to pass along the driver's decision to preserve use-lists. Create a new `-cc1` option called `-emit-llvm-uselists` that does the right thing (when -emit-llvm-bc). Note that despite its generic name, it *doesn't* do the right thing when -emit-llvm (LLVM assembly) yet. I'll hook that up soon. This doesn't really change the behaviour of the driver. The default is still to preserve use-lists for `clang -emit-llvm` and `clang -save-temps`, and nothing else. But it stops relying on global state (and also is a nicer interface for hackers using `clang -cc1`). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234962 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/CC1Options.td | 5 +++++ include/clang/Frontend/CodeGenOptions.def | 2 ++ lib/CodeGen/BackendUtil.cpp | 2 +- lib/Driver/Tools.cpp | 6 ++---- lib/Frontend/CompilerInvocation.cpp | 4 ++++ test/Driver/preserve-uselistorder.c | 4 ++-- test/Driver/save-temps.c | 4 ++-- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index 451d3939b2..b6b37c32d2 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -403,6 +403,11 @@ def migrate : Flag<["-"], "migrate">, HelpText<"Migrate source code">; } +def emit_llvm_uselists : Flag<["-"], "emit-llvm-uselists">, + HelpText<"Preserve order of LLVM use-lists when serializing">; +def no_emit_llvm_uselists : Flag<["-"], "no-emit-llvm-uselists">, + HelpText<"Don't preserve order of LLVM use-lists when serializing">; + def mt_migrate_directory : Separate<["-"], "mt-migrate-directory">, HelpText<"Directory for temporary files produced during ARC or ObjC migration">; def arcmt_check : Flag<["-"], "arcmt-check">, diff --git a/include/clang/Frontend/CodeGenOptions.def b/include/clang/Frontend/CodeGenOptions.def index aeea18da56..cd42c72068 100644 --- a/include/clang/Frontend/CodeGenOptions.def +++ b/include/clang/Frontend/CodeGenOptions.def @@ -145,6 +145,8 @@ VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information ///< in debug info. +CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists. + /// The user specified number of registers to be used for integral arguments, /// or 0 if unspecified. VALUE_CODEGENOPT(NumRegisterParameters, 32, 0) diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index 705d0cc0ce..a6d09f7b8c 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -603,7 +603,7 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action, case Backend_EmitBC: getPerModulePasses()->add( - createBitcodeWriterPass(*OS, shouldPreserveBitcodeUseListOrder())); + createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists)); break; case Backend_EmitLL: diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 2d2526c4bd..fda410687c 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2683,10 +2683,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // loading the bitcode up in 'opt' or 'llc' and running passes gives the // same result as running passes here. For LTO, we don't need to preserve // the use-list order, since serialization to bitcode is part of the flow. - if (JA.getType() == types::TY_LLVM_BC) { - CmdArgs.push_back("-mllvm"); - CmdArgs.push_back("-preserve-bc-uselistorder"); - } + if (JA.getType() == types::TY_LLVM_BC) + CmdArgs.push_back("-emit-llvm-uselists"); } // We normally speed up the clang process a bit by skipping destructors at diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 9632d4ea8c..968f212dda 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -405,6 +405,10 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK, // Default Dwarf version is 4 if we are generating debug information. Opts.DwarfVersion = 4; + if (const Arg *A = + Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists)) + Opts.EmitLLVMUseLists = A->getOption().getID() == OPT_emit_llvm_uselists; + Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); diff --git a/test/Driver/preserve-uselistorder.c b/test/Driver/preserve-uselistorder.c index ac022300f2..aee75a6827 100644 --- a/test/Driver/preserve-uselistorder.c +++ b/test/Driver/preserve-uselistorder.c @@ -1,9 +1,9 @@ // RUN: %clang -target x86_64-apple-darwin -emit-llvm -arch x86_64 %s -### 2>&1 \ // RUN: | FileCheck %s // CHECK: "-emit-llvm-bc" -// CHECK: "-preserve-bc-uselistorder" +// CHECK: "-emit-llvm-uselists" // RUN: %clang -target x86_64-apple-darwin -flto -arch x86_64 %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=LTO %s // LTO: "-emit-llvm-bc" -// LTO-NOT: "-preserve-bc-uselistorder" +// LTO-NOT: "-emit-llvm-uselists" diff --git a/test/Driver/save-temps.c b/test/Driver/save-temps.c index 0b1a17f34f..277a901eeb 100644 --- a/test/Driver/save-temps.c +++ b/test/Driver/save-temps.c @@ -1,7 +1,7 @@ // RUN: %clang -target x86_64-apple-darwin -save-temps -arch x86_64 %s -### 2>&1 \ // RUN: | FileCheck %s // CHECK: "-o" "save-temps.i" -// CHECK: "-preserve-bc-uselistorder" +// CHECK: "-emit-llvm-uselists" // CHECK: "-disable-llvm-optzns" // CHECK: "-o" "save-temps.bc" // CHECK: "-o" "save-temps.s" @@ -13,7 +13,7 @@ // RUN: %clang -target x86_64-apple-darwin -save-temps=cwd -arch x86_64 %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefix=CWD // CWD: "-o" "save-temps.i" -// CWD: "-preserve-bc-uselistorder" +// CWD: "-emit-llvm-uselists" // CWD: "-disable-llvm-optzns" // CWD: "-o" "save-temps.bc" // CWD: "-o" "save-temps.s" -- 2.40.0