llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.35k stars 12.14k forks source link

Support GHC (Haskell) Tables-next-to-code #14452

Open ggreif opened 12 years ago

ggreif commented 12 years ago
Bugzilla Link 14080
Version unspecified
OS All
CC @lattner

Extended Description

This is a design bug for accumulation the ideas of the TNTC feature that GHC Haskell needs.

http://blog.llvm.org/2010/05/glasgow-haskell-compiler-and-llvm.html describes the Haskell LLVM backend. At the end it details the TNTC problem.

There is a hack in place for merging (object sections) that achieves the same effect on sufficiently capable platforms, but clean support would be preferable.

So far following ideas have been discussed: (please feel free to comment on this if you have more ideas)

1) LLVM construct to connect Data with Code ('before ' annotation on globals or 'after ' annotation on code)

2) some intrinsic that directs the code generator to 'inline' global data into the code (and a corresponding intrinsic to extract the data from a function pointer):

  • llvm.inlinedata.before
  • llvm.extract.inlinedata -->

3) parametrizable calling convention; a new calling convention that specifies what data should be made available in a function-relative position. This would allow to use special 'nop' (or fixed-offset branch) instructions to encode the data in opcodes. These usually do not cost on modern processors.

Discussion:

1) is frowned upon, as it needs .ll-parser changes for a very specific feature

2) sounds very generic and probably only needs (target-unspecific) codegen changes (besides declaring the intrinsics).

3) again parser changes, but best describes the TNTC semantics in Haskell. How to embed pointers is an open question. Target specific feature. Usually only a few bits of data is needed anyway, and GHC's TNTC already wastes many bits.

2a/3a) certain ABIs require code descriptors already (e.g. PowerOpen PPC64 ABI) for cross shlib calls. The tables could be added to these conveniently.

Additional material:

lattner commented 12 years ago

This is better discussed on llvmdev than in a bugzilla.