This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Add custom MachineInstr builder. NFC.
AbandonedPublic

Authored by rovka on Dec 22 2016, 5:08 AM.

Details

Summary

Add a subclass of MIBuilderBase for the ARM backend. This should allow us to get
rid of the AddDefaultPred, AddDefaultCC etc helpers and have a cleaner interface
instead.

This patch doesn't remove uses of the helpers, but it contains an example of how
to use the new builder in the ARM backend. A more thorough cleanup will follow
in other patches.

Diff Detail

Event Timeline

rovka updated this revision to Diff 82332.Dec 22 2016, 5:08 AM
rovka retitled this revision from to [ARM] Add custom MachineInstr builder. NFC..
rovka updated this object.
rovka added subscribers: llvm-commits, rengolin.
MatzeB edited edge metadata.Jan 2 2017, 5:09 AM

I wonder if the added complexity of a custom arm instruction builder is worth it. How about a solution that just provides functions to construct the operands but keeps using the default MachineInstrBuilder to add them:

MachineOperand CCRegOp(unsigned CCReg = 0) {
  return MachineOperand::CreateReg(CCReg, false);
}

// Use:
BuildMI(). ... .addOperand(CCRegOp())
  • We could rename MachineInstrBuilder::addOperand() to add() to make this a bit shorter.

For the predicate condition code + register pair you could either provide two functions or maybe extend MachineInstrBuilder to accept pairs of operands:

class MachineInstrBuilder {
  // ...
  add(std::pair<MachineOperand, MachineOperand> Operands) {
    add(Operands.first);
    add(Operands.second);
  }
};
// ...
std::pair<MachineOperand, MachineOperand> predOps(ARMCC::CondCodes Pred = ARMCC::AL,
                                 unsigned PredReg = 0) const {
  return std::make_pair(
    MachineOperand::CreateImm(static_cast<int64_t>(Pred))),
    MachineOperand::CreateReg(PredReg, false)
  );
}
// ...
// Use
BuildMI(). ... .add(predOps(Pred))
rovka abandoned this revision.Jan 11 2017, 4:39 AM

Abandoning this in favor of https://reviews.llvm.org/D28557 & co.