[GISel]: Avoid zero length array when building Instrs that don't have

uses.

Also splitting the buildSources part allows more overloads such as
adding MachineOperands directly in the arguments for buildInstr.

llvm-svn: 309163
This commit is contained in:
Aditya Nandakumar 2017-07-26 19:58:03 +00:00
parent aaa8e433ad
commit e469a6f550
1 changed files with 13 additions and 7 deletions

View File

@ -70,12 +70,20 @@ class MachineIRBuilder {
return getMF().getRegInfo().createVirtualRegister(RC);
}
unsigned getRegFromArg(unsigned Reg) { return Reg; }
unsigned getRegFromArg(const MachineInstrBuilder &MIB) {
return MIB->getOperand(0).getReg();
void addUseFromArg(MachineInstrBuilder &MIB, unsigned Reg) {
MIB.addUse(Reg);
}
void addUseFromArg(MachineInstrBuilder &MIB, const MachineInstrBuilder &UseMIB) {
MIB.addUse(UseMIB->getOperand(0).getReg());
}
void addUsesFromArgs(MachineInstrBuilder &MIB) { }
template<typename UseArgTy, typename ... UseArgsTy>
void addUsesFromArgs(MachineInstrBuilder &MIB, UseArgTy &&Arg1, UseArgsTy &&... Args) {
addUseFromArg(MIB, Arg1);
addUsesFromArgs(std::forward<UseArgsTy>(Args)...);
}
public:
/// Getter for the function we currently build.
MachineFunction &getMF() {
@ -146,9 +154,7 @@ public:
MachineInstrBuilder buildInstr(unsigned Opc, DstTy &&Ty,
UseArgsTy &&... Args) {
auto MIB = buildInstr(Opc).addDef(getDestFromArg(Ty));
unsigned It[] = {(getRegFromArg(Args))...};
for (const auto &i : It)
MIB.addUse(i);
addUsesFromArgs(MIB, std::forward<UseArgsTy>(Args)...);
return MIB;
}