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

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 16:52:01 PDT 2020


steven_wu added a comment.

In D88309#2295403 <https://reviews.llvm.org/D88309#2295403>, @w2yehia wrote:

> @steven_wu what about the alternative solution where we make libLTO query the `--filetype` command line option. This will not require adding a new function to the API, but it does change the behavior of existing functions (lto_codegen_write_merged_modules, lto_codegen_compile, lto_codegen_optimize, lto_codegen_compile_optimized, lto_codegen_compile_to_file)
>
>   diff --git a/llvm/tools/lto/lto.cpp b/llvm/tools/lto/lto.cpp
>   index b680714..8251f7b 100644
>   --- a/llvm/tools/lto/lto.cpp
>   +++ b/llvm/tools/lto/lto.cpp
>   @@ -157,20 +157,23 @@
>    
>    // Convert the subtarget features into a string to pass to LTOCodeGenerator.
>    static void lto_add_attrs(lto_code_gen_t cg) {
>      LTOCodeGenerator *CG = unwrap(cg);
>      auto MAttrs = codegen::getMAttrs();
>      if (!MAttrs.empty()) {
>        std::string attrs = join(MAttrs, ",");
>        CG->setAttr(attrs);
>      }
>    
>   +  if (auto FT = codegen::getExplicitFileType())
>   +    CG->setFileType(FT.getValue());
>   +
>      if (OptLevel < '0' || OptLevel > '3')
>        report_fatal_error("Optimization level must be between 0 and 3");
>      CG->setOptLevel(OptLevel - '0');
>      CG->setFreestanding(EnableFreestanding);
>    }
>     

That is not a bad idea but I think this is riskier than just adding a new API. Also, passing LTO option through `-mllvm` option (aka, through commanline option flags) is not officially supported.

I would go with a new C API.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88309/new/

https://reviews.llvm.org/D88309



More information about the llvm-commits mailing list