save temps option currently doesn't generate assembly file with -flto flag.
To generate assembly file after LTO passes use -Wl,-plugin-opt=-save-temps
Details
- Reviewers
tejohnson
Diff Detail
Event Timeline
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.
lib/LTO/LTOBackend.cpp | ||
---|---|---|
45 | Just "lto-print-asm" (drop leading 'f' since this is an internal option) | |
46 | s/in// | |
205 | 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. | |
206 | This should be a static function. But in any case I am suggesting a different approach below where this would go away. | |
211 | 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... } Then you would replace where you are calling genAssemblyFile with an invocation of that new hook. |
lib/LTO/LTOBackend.cpp | ||
---|---|---|
49 | I rather not have any cl::opt controlling the behavior of the API. | |
211 | I agree that this would be better, however usual hooks don't have access to the targetMachine, and more important, the CodeGen actually modifies the Module, which forces it to be cloned entirely before dumping the ASM. |
I have modified save temps to generate assembly file too. But, I had to clone the module for assembly generation. I would like to know if there is a work around to generate assembly without cloning module.
I already mentioned it in my previous comments: the codegen is modifying the IR. So running it two times on the same module is likely to give different results (Depending on your use-case, it may or may not matter to you, but it can be surprising).
include/llvm/LTO/Config.h | ||
---|---|---|
150 | Comment says "before", name is "after". Also you shouldn't describe what a hook is actually doing, this is up to the client. | |
lib/LTO/LTOBackend.cpp | ||
123 | This will be "costly", we don't want this by default with "addSaveTemps". |
include/llvm/LTO/Config.h | ||
---|---|---|
150 | Part of the issue is that there is already a PreCodeGenModuleHook. That can't be used here though because of the need for passing the TM. So either name it something specific to asm generation like PreCodeGenAsmHook, or specific to taking the TM like PreCodeGenTMHook. Mehdi - WDYT? | |
248 | Remove the whitespace change. | |
lib/LTO/LTOBackend.cpp | ||
91 | The block below here that computes the name and opens the file can be refactored out into a named lambda or helper function. | |
123 | Right, I had suggested keeping this optional in my original suggestion about moving this to a hook. I think it should go back under the option from the original patch. | |
230 | Remove whitespace change |
Comment says "before", name is "after".
Also you shouldn't describe what a hook is actually doing, this is up to the client.