[PATCH] D24020: [LTO] Added flag to generate assembly file with after LTO passes

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 30 06:46:18 PDT 2016


tejohnson added a comment.

Thanks for the patch. Looks like there wasn't a way to dump assembly before codegen even before the restructuring of this out of gold-plugin.

Your patch does not follow LLVM coding conventions. Please clang-format it.

Please also add a test.


================
Comment at: lib/LTO/LTOBackend.cpp:45
@@ +44,3 @@
+static cl::opt<bool>
+FLTOPrintAsm("flto-print-asm",
+             cl::desc("Print assembly file in after LTO phase"),
----------------
Just "lto-print-asm" (drop leading 'f' since this is an internal option)

================
Comment at: lib/LTO/LTOBackend.cpp:46
@@ +45,3 @@
+FLTOPrintAsm("flto-print-asm",
+             cl::desc("Print assembly file in after LTO phase"),
+             cl::init(false), cl::Hidden);
----------------
s/in//

================
Comment at: lib/LTO/LTOBackend.cpp:172
@@ -158,1 +171,3 @@
 
+// Generates assembly file with -Wl,-plugin-opt=-flto-print-asm
+void genAssemblyFile(TargetMachine *TM, Module &M){
----------------
The -Wl,-plugin-opt is gold specific, and this LTO support is used by multiple clients (with more coming). Just remove the "-Wl,-plugin-opt=" (and update option name. 

================
Comment at: lib/LTO/LTOBackend.cpp:173
@@ +172,3 @@
+// Generates assembly file with -Wl,-plugin-opt=-flto-print-asm
+void genAssemblyFile(TargetMachine *TM, Module &M){
+  int FD;
----------------
This should be a static function. But in any case I am suggesting a different approach below where this would go away.

================
Comment at: lib/LTO/LTOBackend.cpp:178
@@ +177,3 @@
+
+  if(FLTOAsmFilename == ""){
+    EC = sys::fs::createTemporaryFile("llvm-flto", "s", FD, OutputFile);
----------------
Better to set this up in addSaveTemps (but keep optional) and use the same file naming used there (and remove the FLTOAsmFilename option). You could then do it via a new variant of setHook (e.g. setAsmHook) and create a new config hook like PrintAsmHook.

E.g. something like

auto setAsmHook = [&](ModuleHookFn &Hook) {
    // Keep track of the hook created earlier, which also needs to run.
    ModuleHookFn ExistingHook = Hook;
    Hook = [=](unsigned Task, const Module &M, const TargetMachine *TM) {
   ... create the filename as in setHook but with .s extension and invoke addPassesToEmitFile...
}
...
setAsmHook(PrintAsmHook);

Then you would replace where you are calling genAssemblyFile with an invocation of that new hook.



https://reviews.llvm.org/D24020





More information about the llvm-commits mailing list