[llvm-dev] [RFC] Heterogeneous LLVM-IR Modules

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Thu Jul 30 04:01:01 PDT 2020


On 28/07/2020 07:00, Johannes Doerfert via llvm-dev wrote:
> TL;DR
> -----
> 
> Let's allow to merge to LLVM-IR modules for different targets (with
> compatible data layouts) into a single LLVM-IR module to facilitate
> host-device code optimizations.

I think it's worth taking a step back here and thinking through the 
problem.  The proposed solution makes me nervous because it is quite a 
significant change to the compiler flow that comes from thinking of 
heterogeneous optimisation as an fat LTO problem, when to me it feels 
more like a thin LTO problem.

At the moment, there's an implicit assumption that everything in a 
Module will flow to the same CodeGen back end.  It can make global 
assumptions about cost models, can inline everything, and so on.

It sounds as if we have a couple of use cases:

  - Analysis flow between modules
  - Transforms that modify two modules

The first case is where the motivating example of constant propagation. 
This feels like the right approach is something like ThinLTO, where you 
can collect in one module the fact that a kernel is invoked only with 
specific constant arguments in the host module and consume that result 
in the target module.

The second example is what you'd need for things like kernel fusion, 
where you need to both combine two kernels in the target module and also 
modify the callers to invoke the single kernel and skip some data flow. 
For this, you need a kind of pass that can work over things that begin 
in two modules.

It seems that a less invasive change would be:

  - Use ThinLTO metadata for the first case, extend it as required.
  - Add a new kind of ModuleSetPass that takes a set of Modules and is 
allowed to modify both.

This avoids any modifications for the common (single-target) case, but 
should give you the required functionality.  Am I missing something?

David



More information about the llvm-dev mailing list