This is an archive of the discontinued LLVM Phabricator instance.

[TargetInstrInfo] Add new hook: getMemOpBaseRegImmOfs.
ClosedPublic

Authored by sanjoy on Jun 2 2015, 2:37 PM.

Details

Summary

NFC: no-one uses getMemOpBaseRegImmOfs yet.

Add new hook TargetInstrInfo::getMemOpBaseRegImmOfs and implement for
x86. The implementation only handles a few easy cases now and will be
made more sophisticated in the future.

getMemOpBaseRegImmOfs, like getLdStBaseRegImmOfs, parses a memory
accessing instruction and tries to recover the memory being accessed as
a base pointer with a constant offset.

getMemOpBaseRegImmOfs is different from getLdStBaseRegImmOfs in the
sense that it also parses instructions that are not just loads and
stores, like "addl %ecx, (%rdi)" on x86.

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 27008.Jun 2 2015, 2:37 PM
sanjoy retitled this revision from to [TargetInstrInfo] Add new hook: getMemOpBaseRegImmOfs..
sanjoy updated this object.
sanjoy edited the test plan for this revision. (Show Details)
sanjoy added reviewers: atrick, reames.
sanjoy added a subscriber: Unknown Object (MLST).
sanjoy added a reviewer: ab.Jun 5 2015, 9:13 AM
ab added inline comments.Jun 8 2015, 9:56 AM
include/llvm/Target/TargetInstrInfo.h
838–841

Seems to me this should just reuse getLdStBaseRegImmOfs. Judging by the user of that callback, the MachineScheduler, whether a load/store was folded or standalone isn't interesting.

Though if you override that for X86, it means the scheduler behavior might change, which is a whole 'nother can of worms.

Andy knows best; +Matthias, who I believe has been looking into the scheduler.

lib/Target/X86/X86InstrInfo.cpp
3973–3992

How about using X86II::getMemoryOperandNo() ?

isLoadingOp can be inferred from MC flags (MayLoad, or !MayStore, depending on what you're interested in).

ab added a reviewer: MatzeB.Jun 8 2015, 9:56 AM
sanjoy added inline comments.Jun 8 2015, 11:17 AM
include/llvm/Target/TargetInstrInfo.h
838–841

Though if you override that for X86, it means the scheduler behavior might change, which is a whole 'nother can of worms.

The only user of getLdStBaseRegImmOfs is LoadClusterMotion. LoadClusterMotion kicks in only if TargetInstrInfo::enableClusterLoads returns true, and it returns false for x86. So I think overriding getLdStBaseRegImmOfs for x86 should also be a NFC.

I did not override getLdStBaseRegImmOfs because the name seems to imply that we're parsing a load or a store; but I suppose just adding a clear comment should be fine here.

lib/Target/X86/X86InstrInfo.cpp
3973–3992

How about using X86II::getMemoryOperandNo() ?

Perfect, thanks for pointing that out!

MatzeB edited edge metadata.Jun 8 2015, 1:20 PM

Comment added below. Maybe you could comment on what you plan to use this for and hold off the commit until the using code is ready as well.

include/llvm/Target/TargetInstrInfo.h
838–841

I'd also recommend to not introduce a new API here, getLdStBaseRegImmOfs() is just too similar and as you already found, it won't change anything on X86.
It's of course sensible to rename the function. I would maybe not talk about folding in the comment but just about memory addressing modes (doesn't matter how they were produced).
Personally I would also prefer a "MachineInstr &" argument to indicate that nullptr is not a valid input but seeing that most other API here is using a pointer, I would be fine with the pointer version for consistency as well...

atrick edited edge metadata.Jun 9 2015, 3:17 PM

I agree. Convert getLdStBaseRegImmOfs into getMemOpBaseRegImmOfs. There is already a hook for shouldClusterLoads, so there's no reason to filter loads/stores in that API.

sanjoy added a comment.Jun 9 2015, 6:36 PM

Comment added below. Maybe you could comment on what you plan to use this for and hold off the commit until the using code is ready as well.

The motivation for this is http://reviews.llvm.org/D10201. I don't plan to check this in now, it will go in together with D10201.

sanjoy updated this revision to Diff 27422.Jun 9 2015, 6:37 PM
sanjoy edited edge metadata.

Address review:

  • unify with getLdStBaseRegImmOfs
  • use getMemoryOperandNo
MatzeB accepted this revision.Jun 9 2015, 6:42 PM
MatzeB edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jun 9 2015, 6:42 PM
atrick accepted this revision.Jun 12 2015, 4:46 PM
atrick edited edge metadata.

LGTM too.

This revision was automatically updated to reflect the committed changes.