[PATCH] D56114: [LTO] emit assembly listing from LTO stage
Denis Bakhvalov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 27 15:00:07 PST 2018
dendibakh created this revision.
dendibakh added reviewers: mehdi_amini, tejohnson.
Herald added subscribers: llvm-commits, dexonsmith, inglorion.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D56114
Files:
tools/gold/gold-plugin.cpp
Index: tools/gold/gold-plugin.cpp
===================================================================
--- tools/gold/gold-plugin.cpp
+++ tools/gold/gold-plugin.cpp
@@ -128,6 +128,7 @@
OT_NORMAL,
OT_DISABLE,
OT_BC_ONLY,
+ OT_ASM_ONLY,
OT_SAVE_TEMPS
};
static OutputType TheOutputType = OT_NORMAL;
@@ -229,6 +230,8 @@
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 @@
check(Conf.addSaveTemps(output_name + ".",
/* UseInputModulePath */ true));
break;
+ case options::OT_ASM_ONLY:
+ Conf.CGFileType = TargetMachine::CGFT_AssemblyFile;
+ break;
}
if (!options::sample_profile.empty())
@@ -1060,6 +1066,23 @@
options::TheOutputType == options::OT_BC_ONLY)
return LDPS_OK;
+ if (options::TheOutputType == options::OT_ASM_ONLY) {
+ auto CopyFile = [](const std::string &from, const std::string &to) {
+ std::error_code EC = sys::fs::copy_file(from, to);
+ if (EC)
+ message(LDPL_ERROR, "Failed to copy assembly to '%s': %s", to.c_str(),
+ EC.message().c_str());
+ };
+
+ if (Files.size() == 1)
+ CopyFile(Files.front().first.str(), output_name);
+ else
+ for (unsigned i = 0; i < Files.size(); ++i)
+ CopyFile(Files[i].first.str(), output_name + '.' + std::to_string(i));
+
+ return LDPS_OK;
+ }
+
if (options::thinlto_index_only) {
llvm_shutdown();
cleanup_hook();
@@ -1082,6 +1105,7 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56114.179587.patch
Type: text/x-patch
Size: 2046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181227/dcc4086a/attachment.bin>
More information about the llvm-commits
mailing list