From: Teresa Johnson Date: Wed, 2 Jan 2019 23:48:00 +0000 (+0000) Subject: [gold] emit assembly listing from gold plugin on LTO stage X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=02e82c3508b539a123f111378bcaf16267e9277d;p=llvm [gold] emit assembly listing from gold plugin on LTO stage Summary: Sometimes it's useful to emit assembly after LTO stage to modify it manually. Emitting precodegen bitcode file (via save-temps plugin option) and then feeding it to llc doesn't always give the same binary as original. This patch is simpler alternative to https://reviews.llvm.org/D24020. Patch by Denis Bakhvalov. Reviewers: mehdi_amini, tejohnson Reviewed By: tejohnson Subscribers: MaskRay, inglorion, dexonsmith, llvm-commits Differential Revision: https://reviews.llvm.org/D56114 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350276 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/gold/X86/emit-asm.ll b/test/tools/gold/X86/emit-asm.ll new file mode 100644 index 00000000000..40ff71f6143 --- /dev/null +++ b/test/tools/gold/X86/emit-asm.ll @@ -0,0 +1,25 @@ +; RUN: llvm-as %s -o %t.o + +; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ +; RUN: -m elf_x86_64 --plugin-opt=emit-asm \ +; RUN: -shared %t.o -o %t2.s +; RUN: FileCheck --input-file %t2.s %s + +; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ +; RUN: -m elf_x86_64 --plugin-opt=emit-asm --plugin-opt=lto-partitions=2\ +; RUN: -shared %t.o -o %t2.s +; RUN: cat %t2.s %t2.s1 > %t3.s +; RUN: FileCheck --input-file %t3.s %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-DAG: f1: +define void @f1() { + ret void +} + +; CHECK-DAG: f2: +define void @f2() { + ret void +} diff --git a/tools/gold/gold-plugin.cpp b/tools/gold/gold-plugin.cpp index 8ffa5877ba6..738cafa6cac 100644 --- a/tools/gold/gold-plugin.cpp +++ b/tools/gold/gold-plugin.cpp @@ -128,6 +128,7 @@ namespace options { OT_NORMAL, OT_DISABLE, OT_BC_ONLY, + OT_ASM_ONLY, OT_SAVE_TEMPS }; static OutputType TheOutputType = OT_NORMAL; @@ -229,6 +230,8 @@ namespace options { TheOutputType = OT_SAVE_TEMPS; } else if (opt == "disable-output") { TheOutputType = OT_DISABLE; + } else if (opt == "emit-asm") { + TheOutputType = OT_ASM_ONLY; } else if (opt == "thinlto") { thinlto = true; } else if (opt == "thinlto-index-only") { @@ -882,6 +885,9 @@ static std::unique_ptr createLTO(IndexWriteCallback OnIndexWrite, check(Conf.addSaveTemps(output_name + ".", /* UseInputModulePath */ true)); break; + case options::OT_ASM_ONLY: + Conf.CGFileType = TargetMachine::CGFT_AssemblyFile; + break; } if (!options::sample_profile.empty()) @@ -1009,6 +1015,8 @@ static std::vector, bool>> runLTO() { Filename = options::obj_path; else if (options::TheOutputType == options::OT_SAVE_TEMPS) Filename = output_name + ".o"; + else if (options::TheOutputType == options::OT_ASM_ONLY) + Filename = output_name; bool SaveTemps = !Filename.empty(); size_t MaxTasks = Lto->getMaxTasks(); @@ -1057,7 +1065,8 @@ static ld_plugin_status allSymbolsReadHook() { std::vector, bool>> Files = runLTO(); if (options::TheOutputType == options::OT_DISABLE || - options::TheOutputType == options::OT_BC_ONLY) + options::TheOutputType == options::OT_BC_ONLY || + options::TheOutputType == options::OT_ASM_ONLY) return LDPS_OK; if (options::thinlto_index_only) { @@ -1082,6 +1091,7 @@ static ld_plugin_status all_symbols_read_hook(void) { llvm_shutdown(); if (options::TheOutputType == options::OT_BC_ONLY || + options::TheOutputType == options::OT_ASM_ONLY || options::TheOutputType == options::OT_DISABLE) { if (options::TheOutputType == options::OT_DISABLE) { // Remove the output file here since ld.bfd creates the output file