[LLVMdev] GHC, aliases, and LLVM HEAD

Peter Wortmann scpmw at leeds.ac.uk
Mon May 26 18:30:03 PDT 2014



To maybe clarify a bit - this is about a pass in GHC that translates an
intermediate program representation called "Cmm" into LLVM code. The
trouble stems from the fact that

1) Cmm is untyped, so whenever we see a label it might refer to data or
   functions, of pretty much arbitrary type

2) The Cmm code is generated iteratively, and as a good consumer we
   would like to "stream" the LLVM code as well. These intermediate
   representations can easily go up to millions of lines, after all.

This all works out fairly well, with the only stumbling block being the
types. After all, at the point where we emit a reference to a label we
don't know whether it is going to be defined later on in the output
file. We especially have no idea what its LLVM type is going to be. 

To get around that we use aliases to essentially "strip" type
information from label references: If we refer to "label$alias" instead
of "label", we are still free to define "label" later on in whatever way
we see fit. Then we just set "label$alias" to a suitable cast, and let
the LLVM infrastructure handle the resolution.

That being said - there are actually a number of possible solutions
here, and we are currently trying to settle on what the "right thing to
do" is. In case we are being to tricky here, we might try to instead do
two passes over the output file, or scrap streaming altogether. All
depends on whether or not it is likely that this kind of usage remains
possible in future LLVM versions.

Greetings,
  Peter Wortmann





More information about the llvm-dev mailing list