[GISel] Refactor MachineIRBuilder to allow transformations while
authorAditya Nandakumar <aditya_nandakumar@apple.com>
Mon, 9 Apr 2018 17:30:56 +0000 (17:30 +0000)
committerAditya Nandakumar <aditya_nandakumar@apple.com>
Mon, 9 Apr 2018 17:30:56 +0000 (17:30 +0000)
commitb1c467dbe7cd9b938be35d0dce95b5c7da51ddf8
treedfbcd889c7968d39b86a00af4c3e74e17b5f77d8
parentdd7c60c2d2f20907b30320890687a5eacaaace8f
[GISel] Refactor MachineIRBuilder to allow transformations while
building.

https://reviews.llvm.org/D45067

This change attempts to do two things:
1) It separates out the state that is stored in the
MachineIRBuilder(InsertionPt, 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.

Also because of separation of state, given a MachineIRBuilder in an API,
if one wishes to use another MachineIRBuilder, a new one can be
constructed from the state locally. For eg,

void doFoo(MachineIRBuilder &B) {
  MyCustomBuilder CustomB(B.getState());
  // Use CustomB for building.
}

reviewed by : aemerson

llvm-svn: 329596
llvm/include/llvm/CodeGen/GlobalISel/ConstantFoldingMIRBuilder.h [new file with mode: 0644]
llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/unittests/CodeGen/GlobalISel/PatternMatchTest.cpp