[PATCH] D55294: [GISel]: Refactor MachineIRBuilder to allow passing additional parameters to build Instrs

Aditya Nandakumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 4 13:20:03 PST 2018


aditya_nandakumar created this revision.
aditya_nandakumar added reviewers: bogner, qcolombet, ab, volkan, dsanders, aemerson, jpaquette, rtereshin.
Herald added subscribers: jfb, atanasyan, jrtc27, javed.absar, sdardis.
Herald added a reviewer: paquette.

Previously MachineIRBuilder::buildInstr used to accept variadic arguments for sources (which were either unsigned or MachineInstrBuilder). While this worked well in common cases, it doesn't allow us to build instructions that have multiple destinations. Additionally passing in other optional parameters in the end (such as flags) is not possible trivially. Also a trivial call such as

  B.buildInstr(Opc, Reg1, Reg2, Reg3)

can be interpreted differently based on the opcode (2defs + 1 src for unmerge vs 1 def + 2srcs).
This patch refactors the buildInstr to

  buildInstr(Opc, ArrayRef<DstOps>, ArrayRef<SrcOps>)

- where DstOps and SrcOps are typed unions that know how to add itself to MachineInstrBuilder.

After this patch, most invocations would look like

  B.buildInstr(Opc, {s32, DstReg}, {SrcRegs..., SrcMIBs..});

Now all the other calls (such as buildAdd, buildSub etc) forward to buildInstr. It also makes it possible to build instructions with multiple defs.
Additionally in a subsequent patch, we should make it possible to add flags directly while building instructions.
Additionally, the main buildInstr method is now virtual and other builders now only have to override buildInstr (for say constant folding/cseing) is straightforward.


Repository:
  rL LLVM

https://reviews.llvm.org/D55294

Files:
  include/llvm/CodeGen/GlobalISel/ConstantFoldingMIRBuilder.h
  include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
  include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
  lib/CodeGen/GlobalISel/IRTranslator.cpp
  lib/CodeGen/GlobalISel/LegalizerHelper.cpp
  lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
  lib/Target/AArch64/AArch64InstructionSelector.cpp
  lib/Target/Mips/MipsInstructionSelector.cpp
  unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp
  unittests/CodeGen/GlobalISel/PatternMatchTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55294.176698.patch
Type: text/x-patch
Size: 85140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181204/a721005a/attachment-0001.bin>


More information about the llvm-commits mailing list