This is an archive of the discontinued LLVM Phabricator instance.

[GISel]: Split buildSources part of buildInstr separately
ClosedPublic

Authored by aditya_nandakumar on Jul 17 2017, 4:31 PM.

Details

Summary

For cases where there are no arguments (creating IMPLICIT_DEF), don't attempt to create zero sized arrays.

Diff Detail

Event Timeline

dsanders edited edge metadata.Jul 24 2017, 5:37 AM

I'm not sure I understand why this change is needed. I'd expect the original version of buildInstr<unsigned>, to expand to:

MachineInstrBuilder buildInstr(unsigned Opc, unsigned &&Ty) {
  auto MIB = buildInstr(Opc).addDef(getDestFromArg(Ty));
  unsigned It[] = {};
  for (const auto &i : It)
    MIB.addUse(i);
  return MIB;
}

which should then optimize to:

MachineInstrBuilder buildInstr(unsigned Opc, unsigned &&Ty) {
  auto MIB = buildInstr(Opc).addDef(getDestFromArg(Ty));
  return MIB;
}

which appears to be the same thing the new version expands and optimizes to.

Am I missing something?

Add the ability to accept machine operands to the buildInstr method so it will directly call MIB.add(MO) on that.

@dsanders - the main goal was to avoid the compiler warning of having to create a zero sized array. Now with the splitting of arguments, we can also accept MachineOperands which can directly be added to the instruction.

@dsanders - the main goal was to avoid the compiler warning of having to create a zero sized array.

You mean the unsigned It[] = {};? Ok, that makes sense. The subject line should reflect that though. E.g:

[GISel] Avoid zero-length array when adding uses to instructions that lack them (e.g IMPLICIT_DEF).
include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
77–80

This should be added by the patch that uses it.

81

Just for consistency, should we name this addUsesFromArgs()?

84–85

I think this is missing some std::forward's

aditya_nandakumar marked 2 inline comments as done.Jul 24 2017, 12:35 PM
aditya_nandakumar added inline comments.
include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
77–80

Will remove this part. Will add it later.

Updated based on feedback.

dsanders accepted this revision.Jul 26 2017, 2:18 AM

LGTM with a better commit message.

This revision is now accepted and ready to land.Jul 26 2017, 2:18 AM

Thanks. Closing.