This is an archive of the discontinued LLVM Phabricator instance.

[MachineInstrBuilder] Introduce MIMetadata to simplify metadata propagation
ClosedPublic

Authored by melver on Aug 1 2022, 1:58 AM.

Details

Summary

In many places DebugLoc and PCSections metadata are just copied along to
propagate them through MachineInstrs. Simplify doing so by bundling them
up in a MIMetadata class that replaces the DebugLoc argument to most
BuildMI() variants.

The DebugLoc-only constructors allow implicit construction, so that
existing usage of BuildMI(.., DL, ..) works as before, and the rest of
the codebase using BuildMI() does not require changes.

NFC.

Depends on D130882

Diff Detail

Event Timeline

melver created this revision.Aug 1 2022, 1:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:58 AM
melver requested review of this revision.Aug 1 2022, 1:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 1:58 AM
melver updated this revision to Diff 450028.Aug 4 2022, 9:57 AM

Rebase.

Would you like to extend llvm/unittests/CodeGen/MachineInstrTest.cpp ?

melver updated this revision to Diff 457541.Sep 2 2022, 2:48 AM

Add simple BuildMI() unit test.

PTAL.

vitalybuka accepted this revision.Sep 2 2022, 10:12 AM

LGTM, but please blocking reviews if you are looking for their feedback in particular

llvm/unittests/CodeGen/MachineInstrTest.cpp
463

I don't insist, but you want to avoid such wrapping of EXPECTs into functions or lambdas.
When test fails it will not provide location of the failed line with CheckMI

If you want to reuse pair of checks,
EXPECT_EQ(MIB->getDebugLoc(), DL);
EXPECT_EQ(MIB->getPCSections(), PCS);

you can use EXPECT_THAT with custom matches
EXPECT_THAT(BuildMI(*MBB, MBB->end(), MIMD, MCID)(), MyMatches);

another alternative:

 auto BuildDiPc = [&](...) -> pair<> {
    MachineInstrBuilder MIB = BuildMI(...)();
  return {MIB->getDebugLoc(), MIB->getPCSections()}
  };

EXPECT_EQ({DL, PC}. BuildDiPc(*MBB, MBB->end(), MIMD, MCID));
This revision is now accepted and ready to land.Sep 2 2022, 10:12 AM
melver updated this revision to Diff 457648.Sep 2 2022, 11:18 AM

Use EXPECT_THAT() with custom matcher for MIMetadata in test.

melver marked an inline comment as done.Sep 2 2022, 11:19 AM
melver added inline comments.
llvm/unittests/CodeGen/MachineInstrTest.cpp
463

Thanks, updated to use EXPECT_THAT.

melver marked an inline comment as done.Sep 2 2022, 11:19 AM
This revision was landed with ongoing or failed builds.Sep 7 2022, 2:24 AM
This revision was automatically updated to reflect the committed changes.