[PATCH] D88309: [LTO][Legacy] Add API to set result type to assembly

wael yehia via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 08:14:41 PDT 2020


w2yehia created this revision.
w2yehia added reviewers: steven_wu, tejohnson.
Herald added a reviewer: deadalnix.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya, inglorion.
Herald added a project: LLVM.
w2yehia requested review of this revision.

I'm trying to make libLTO (https://llvm.org/docs/LinkTimeOptimization.html#liblto) generate an assembly file instead of object format.
Right now, the --filetype=asm option has no effect in libLTO. This option is used by tools such as llvm-lto and llc.
libLTO directly interacts with LTOCodeGenerator, which does not use the option but has a method to override the default file type (CGFT_ObjectFile) .
My current solution is to add a new function to lto.h that sets the filetype to asm.

Another solution is to have one of the libLTO functions that create LTOCodeGenerator, and after the ParseCommandLineOptions has run, to query the --filetype option and call LTOCodeGenerator::setFileType if the option was specified (I haven't tried that, but shud work in theory).


https://reviews.llvm.org/D88309

Files:
  llvm/include/llvm-c/lto.h
  llvm/tools/lto/lto.cpp
  llvm/tools/lto/lto.exports


Index: llvm/tools/lto/lto.exports
===================================================================
--- llvm/tools/lto/lto.exports
+++ llvm/tools/lto/lto.exports
@@ -35,6 +35,7 @@
 lto_codegen_write_merged_modules
 lto_codegen_debug_options
 lto_codegen_debug_options_array
+lto_codegen_emit_asm
 lto_codegen_set_assembler_args
 lto_codegen_set_assembler_path
 lto_codegen_set_cpu
Index: llvm/tools/lto/lto.cpp
===================================================================
--- llvm/tools/lto/lto.cpp
+++ llvm/tools/lto/lto.cpp
@@ -490,6 +490,10 @@
   unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(Options));
 }
 
+void lto_codegen_emit_asm(lto_code_gen_t cg) {
+  unwrap(cg)->setFileType(CGFT_AssemblyFile);
+}
+
 unsigned int lto_api_version() { return LTO_API_VERSION; }
 
 void lto_codegen_set_should_internalize(lto_code_gen_t cg,
Index: llvm/include/llvm-c/lto.h
===================================================================
--- llvm/include/llvm-c/lto.h
+++ llvm/include/llvm-c/lto.h
@@ -548,6 +548,11 @@
                                             const char *const *, int number);
 
 /**
+ * Sets the result filetype to assembly.
+ */
+extern void lto_codegen_emit_asm(lto_code_gen_t cg);
+
+/**
  * Initializes LLVM disassemblers.
  * FIXME: This doesn't really belong here.
  *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88309.294316.patch
Type: text/x-patch
Size: 1305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200925/54d65b65/attachment.bin>


More information about the llvm-commits mailing list