This is an archive of the discontinued LLVM Phabricator instance.

[GISel] Refactor MachineIRBuilder so we can optionally do constant folding/other transformations during building
ClosedPublic

Authored by aditya_nandakumar on Mar 29 2018, 3:45 PM.

Details

Summary

This change attempts to do two things:

  1. It separates out the state that is stored in the MachineIRBuilder (insertion point, MF, MRI, InsertFunction etc.) into a separate object called MachineIRBuilderState.
  2. Add the ability to constant fold operations while building instructions (optionally). MachineIRBuilder is now refactored into a MachineIRBuilderBase which contains lots of non foldable build methods and their implementation. Instructions which can be constant folded/transformed are now in a class called FoldableInstructionBuilder which uses CRTP to use the implementation of the derived class for buildBinaryOps. Additionally buildInstr in the derived class can be used to implement other kinds of transformations.

MachineIRBuilder currently does no transformations where as ConstantFoldingMachineIRBuilder does constant folding (as used in the unit test).

Diff Detail

Repository
rL LLVM

Event Timeline

Forgot to mention one other benefit of separating out the state.
If given a MachineIRBuilder in some API, but instead want to use another kind of builder locally, we can just construct the new builder locally from the state.

void doFoo(MachineIRBuilder &B) {
MyCustomBuilder CustomB(B.getState());
// Use CustomB for building.
}
aemerson accepted this revision.Apr 9 2018, 3:09 AM

LGTM, thanks.

This revision is now accepted and ready to land.Apr 9 2018, 3:09 AM

Thanks Amara.
Committed in r329596.