Index: include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h =================================================================== --- include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -70,12 +70,20 @@ return getMF().getRegInfo().createVirtualRegister(RC); } - unsigned getRegFromArg(unsigned Reg) { return Reg; } + void addUseFromArg(MachineInstrBuilder &MIB, unsigned Reg) { + MIB.addUse(Reg); + } - unsigned getRegFromArg(const MachineInstrBuilder &MIB) { - return MIB->getOperand(0).getReg(); + void addUseFromArg(MachineInstrBuilder &MIB, const MachineInstrBuilder &UseMIB) { + MIB.addUse(UseMIB->getOperand(0).getReg()); } + void addUsesFromArgs(MachineInstrBuilder &MIB) { } + template + void addUsesFromArgs(MachineInstrBuilder &MIB, UseArgTy &&Arg1, UseArgsTy &&... Args) { + addUseFromArg(MIB, Arg1); + addUsesFromArgs(std::forward(Args)...); + } public: /// Getter for the function we currently build. MachineFunction &getMF() { @@ -146,9 +154,7 @@ 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(Args)...); return MIB; }