GlobalISel: Make MachineCSE runnable in the middle of the GlobalISel
authorJustin Bogner <mail@justinbogner.com>
Thu, 18 Jan 2018 02:06:56 +0000 (02:06 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 18 Jan 2018 02:06:56 +0000 (02:06 +0000)
commita9346e050f301dfea9e1cf50d39a4b7180091b44
tree65abd702e3ae3d94d045681c3fc33f6586250b6a
parent3feefe001b2ec9bd0fd867284560cf99d7345b1f
GlobalISel: Make MachineCSE runnable in the middle of the GlobalISel

Right now, it is not possible to run MachineCSE in the middle of the
GlobalISel pipeline. Being able to run generic optimizations between the
core passes of GlobalISel was one of the goals of the new ISel framework.
This is the first attempt to do it.

The problem is that MachineCSE pass assumes all register operands have a
register class, which, in GlobalISel context, won't be true until after the
InstructionSelect pass. The reason for this behaviour is that before
replacing one virtual register with another, MachineCSE pass (and most of
the other optimization machine passes) must check if the virtual registers'
constraints have a (sufficiently large) intersection, and constrain the
resulting register appropriately if such intersection exists.

GlobalISel extends the representation of such constraints from just a
register class to a triple (low-level type, register bank, register
class).

This commit adds MachineRegisterInfo::constrainRegAttrs method that extends
MachineRegisterInfo::constrainRegClass to such a triple.

The idea is that going forward we should use:

- RegisterBankInfo::constrainGenericRegister within GlobalISel's
  InstructionSelect pass
- MachineRegisterInfo::constrainRegClass within SelectionDAG ISel
- MachineRegisterInfo::constrainRegAttrs everywhere else regardless
  the target and instruction selector it uses.

Patch by Roman Tereshin. Thanks!

llvm-svn: 322805
llvm/include/llvm/CodeGen/GlobalISel/RegisterBankInfo.h
llvm/include/llvm/CodeGen/MachineRegisterInfo.h
llvm/lib/CodeGen/MachineCSE.cpp
llvm/lib/CodeGen/MachineRegisterInfo.cpp
llvm/test/CodeGen/AArch64/GlobalISel/machine-cse-mid-pipeline.mir [new file with mode: 0644]