Refactor librustc_codegen_llvm for multiple codegen backends.

3bdd304
Opened by Eduard-Mihai Burtescu at 2022-10-29 13:28:34

~~Rename librustc_trans to librustc_codegen_llvm.~~ ~~Then make rustc_driver either able to choose codegen backends, or even better, pass rustc_codegen_llvm to rustc_driver from rustc-main. See also #45226.~~

Possible refactoring steps:

  • ~~remove SharedCrateContext, use TyCtxt~~
  • ~~rename (Local)CrateContext to CodegenContext, remove accessor methods~~
  • [WIP by @irinagpopa] merge librustc_llvm into librustc_codegen_llvm
    • pass ValueRef as &Value instead, encode LLVM lifetimes in FFI signatures
  • split the metadata reading/writing and linking parts out of it
  • refer to cretonne and llvm2cretonne for common Cretonne/LLVM builder APIs
    • common tools used by SSA backends could be placed in rustc_codegen_ssa
  1. ~~[#50615] Rename librustc_trans to librustc_codegen_llvm.~~ ~~Make rustc_driver either able to choose codegen backends, or even better, pass rustc_codegen_llvm to rustc_driver from rustc-main. See also #45226.~~

    Possible refactoring steps:

    • ~~remove SharedCrateContext, use TyCtxt~~
    • ~~rename (Local)CrateContext to CodegenContext, remove accessor methods~~
    • [#52461] ~~merge librustc_llvm into librustc_codegen_llvm~~
      • ~~pass ValueRef as &'ll Value instead, encode LLVM lifetimes in FFI signatures~~
      • ~~use this technique for C++ objects that borrow others: https://github.com/rust-lang/rust/issues/43467#issuecomment-405808005~~
    • use this technique for the DI* inheritance hierarchy: https://github.com/rust-lang/rust/issues/43467#issuecomment-399509319
    • use &'ll Module<'ll>, &'ll Value<'ll>, &'ll Type<'ll> etc. to correctly model lifetime relationships (without an invariant lifetime parameter, very little is actually enforced)
    • refer to cranelift and llvm2cranelift for common Cranelift/LLVM builder APIs
      • [#55627] ~~common tools used by SSA backends could be placed in rustc_codegen_ssa~~
      • refactor rustc_codegen_ssa APIs to match Cranelift, leave LLVM second-class
        • unaddressed comments from #55627 may be relevant here
    • split the metadata, "optimize + generate machine code" (should it be called "binemit"?) and linking components, out of rustc_codegen_ssa

    Eduard-Mihai Burtescu at 2018-07-13 17:55:15