[LLVMdev] GHC, aliases, and LLVM HEAD

Ben Gamari bgamari.foss at gmail.com
Sun May 25 18:29:13 PDT 2014


Peter: Please feel free to correct me if there are any inaccuracies
       below.

For a while now LLVM has started rejecting aliases referring to things
other than definitions[1]. This unfortunately breaks GHC's LLVM code
generator which referes to most symbols through aliases. This is done in
two situations,

  1. As place-holders for external symbols. As the code generator does
     not know the type of these symbols until the point of usage (nor
     does it need to), i8* aliases are defined at the end of the
     compilation unit,

         @newCAF = external global i8
         @newCAF$alias = alias private i8* @newCAF

     and functions in the current compilation unit calling `newCAF` invoke
     it through `@newCAF$alias$`,

         ...
         %lnYi = bitcast i8* @newCAF$alias to i8* (i8*, i8*)*
         ...

  2. As place-holders for local symbols. All symbol references in
     emitted functions are replaced with references to aliases.  This is
     done so that the compiler can emit LLVM IR definitions for
     functions without waiting for symbols they reference to become
     available (as our internal representation, Core, allows references
     in any order without forward declarations). This theoretically
     offers a performance improvement and somewhat simplifies the code
     generator. Here we emit aliases like,

         @SWn_srt$alias = alias private i8* bitcast (%SWn_srt_struct* @SWn_srt to i8*)

     again, using the `$alias` in all references,


Unfortunately, recent LLVMs reject both of these uses. The first is
rejected as aliases can no longer reference items other than
definitions, e.g.

    opt: hi.ll:414:36: error: Alias must point to function or variable
    @SWn_srt$alias = alias private i8* bitcast (%SWn_srt_struct* @SWn_srt to i8*)

The second is rejected as aliasees must[2] be global objects, which
bitcasts are not,

    /home/ben/trees/root-llvm-head/bin/opt: utils/hpc/dist-install/build/HpcParser.ll:44714:37: error: Alias must point to function or variable
    @c3rB_str$alias = alias private i8* bitcast (%c3rB_str_struct* @c3rB_str to i8*)
                                        ^

Is our (ab)use of aliases reasonable? If so, what options do we have to
fix this before LLVM 3.5? If not, what other mechanisms are there for
addressing the use-cases above in GHC?

Thanks,

- Ben


[1] https://github.com/llvm-mirror/llvm/commit/38048cdb1c016e1429004ddf4adfa40a8d853cbf
[2] https://github.com/llvm-mirror/llvm/blob/68b0d1d2b47f1be8eec2ce57c8119906c354ccd8/lib/AsmParser/LLParser.cpp#L692
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140525/d17a8b96/attachment.sig>


More information about the llvm-dev mailing list