This is an archive of the discontinued LLVM Phabricator instance.

Extract helper function to merge MemoryOperand lists [NFC]
ClosedPublic

Authored by reames on Dec 23 2015, 12:39 PM.

Details

Summary

In the discussion on http://reviews.llvm.org/D15730, Andy pointed out we had a utility function for merging MMO lists. Since it turned we actually had two copies and there's another review in progress (http://reviews.llvm.org/D15230) which needs the same, extract it into a utility function and clean up the interfaces to make it easier to use with a MachineInstBuilder.

I introduced a pair here to track size and allocation together. I think we should probably move in the direction of the MachineOperandsRef helper class, but I'm leaving that for further work. I want to get the poison state introduced before I make major changes to the interface.

Diff Detail

Repository
rL LLVM

Event Timeline

reames updated this revision to Diff 43555.Dec 23 2015, 12:39 PM
reames retitled this revision from to Extract helper function to merge MemoryOperand lists [NFC].
reames updated this object.
reames added a subscriber: llvm-commits.
sanjoy edited edge metadata.Dec 23 2015, 3:42 PM

Minor drive-by comments.

include/llvm/CodeGen/MachineInstr.h
1186 ↗(On Diff #43555)

Why std::pair (as opposed to two separate arguments)?

include/llvm/CodeGen/MachineInstrBuilder.h
165 ↗(On Diff #43555)

Please double check, but this line looks like it is too long.

(I'd just run clang-format on the diff before checking in)

reames added inline comments.Dec 23 2015, 3:46 PM
include/llvm/CodeGen/MachineInstr.h
1186 ↗(On Diff #43555)

Because it groups the array descriptor (base, and length) into a single value. It also allows me to write setMemRefs(I->mergeMemRefsWith(*I2)) which wouldn't be possible otherwise.

flyingforyou added inline comments.Dec 23 2015, 8:18 PM
lib/CodeGen/MachineInstr.cpp
884 ↗(On Diff #43555)

We might update NumMemRefs in this function. Right?

reames added inline comments.Dec 23 2015, 8:25 PM
lib/CodeGen/MachineInstr.cpp
884 ↗(On Diff #43555)

Sorry, what? Oh, I see what you're getting at. Yes, MemEnd-MemBegin should be equal to numMemRefs. I copied the code and didn't notice the confusing name and missing assert. Will add.

reames updated this revision to Diff 43939.Jan 4 2016, 4:12 PM
reames edited edge metadata.

address review comments to date

flyingforyou added inline comments.Jan 4 2016, 7:50 PM
lib/CodeGen/MachineInstr.cpp
884 ↗(On Diff #43939)

I mean NumMemRefs is in MachineInstr.

If MI1's MMOs count is 1, Other MI's MMOs count is 2, we should update MI1's MMOs count(NumMemRefs) 3.
concatenateMemOperands assume that MI1's MMOs count is zero. But If we want to make interface about merging MMOs, we might update NumMemRefs.

reames added inline comments.Jan 5 2016, 11:16 AM
lib/CodeGen/MachineInstr.cpp
884 ↗(On Diff #43939)

I'm really confused by your comment. My best guess is that you are misreading the code. This function does not update the memref information on the current instruction. It produces a new set of memrefs (in the return value) which can be set on an instruction.

atrick accepted this revision.Jan 5 2016, 2:39 PM
atrick edited edge metadata.

LGTM!

This revision is now accepted and ready to land.Jan 5 2016, 2:39 PM
flyingforyou added inline comments.Jan 5 2016, 4:19 PM
lib/CodeGen/MachineInstr.cpp
884 ↗(On Diff #43939)

Thanks for explain.

I expect that this function can merge own and other's memref information.
Is this better way for the function?

This revision was automatically updated to reflect the committed changes.