[LLVMdev] Proposal for new Legalization framework

David Chisnall
Thu, 25 Apr 2013 08:50:30 -0000

Hi Dan,

On 25 Apr 2013, at 01:01, Dan Gohman <dan433584 at gmail.com> wrote:

> The main alternative approach that's been discussed is to do FastISel
to a target-independent opcode set on MachineInstrs, and then do legalization
and ultimately the last phase off instruction selection proper after that. The
most obvious advantage of using LLVM IR for legalization is that it's
(currently) more developer-friendly. The most obvious advantage of using
MachineInstrs is that they would make it easier to do low-level manipulations.
Also, doing legalization on MachineInstrs would mean avoiding having
LLVM-IR-level optimization passes which lower the IR, which has historically
been a design goal of LLVM.

The approach taken in WHIRL, which has a lot of advantages, is exactly to lower
the IR.  It seems strange that in the back end we have Machine* classes that
correspond very closely to IR equivalents, but which don't share any code
and often have subtly different interfaces.  The approach taken in WHIRL is to
progressively replace machine-independent bits of the IR with machine-dependent
ones, with abstract instructions being replaced with machine instructions,
abstract registers with machine registers, and so on.

I would be interested to know the rationale behind the design choice to avoid
this, as it seems the obvious way of designing a compiler.  The down side would
be that you couldn't take any random pass that expected target-independent
IR and run it, but you never actually want to do this once you've handed off
to the codegen infrastructure anyway.

David