This is an archive of the discontinued LLVM Phabricator instance.

[MCA] Allow mca::Instruction-s to be recycled and reused
ClosedPublic

Authored by myhsu on Jun 5 2022, 9:21 PM.

Details

Summary

This patch introduces a new feature that allows InstrBuilder to reuse mca::Instruction recycled from IncrementalSourceMgr. This significantly reduces the memory footprint.
Note that we're only recycling instructions that have static InstrDesc and no variadic operands.

This is patch 2/2 of MCA Daemon's upstreaming efforts.

Diff Detail

Event Timeline

myhsu created this revision.Jun 5 2022, 9:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2022, 9:21 PM
myhsu requested review of this revision.Jun 5 2022, 9:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2022, 9:21 PM

Hi Min,

I left a few comments below.

Thanks for the patch!

-Andrea

llvm/include/llvm/MCA/IncrementalSourceMgr.h
87–114

Could you please move these definitions to a IncrementalSourceMgr.cpp ?

llvm/include/llvm/MCA/InstrBuilder.h
25

I really don't think that we should use system_error.

74

Would it be more readable if we defined that type with a using InstRecycleCallback = ...?

That way, you may not need to use decltype at line 101.

llvm/include/llvm/MCA/Instruction.h
571

Personally, I prefer that we don't touch that method. What about adding a
void clearOptimizableMove() ?

647–657

Please move this definition to Instruction.cpp

llvm/lib/MCA/InstrBuilder.cpp
542–544

I wonder if instead we should add a bitfield bool IsRecyclable : 1 to struct InstrDesc.

By default, it would be set to false.

That way, you don't need to change these signatures, and you can still retrieve that information automatically. It might make the rest of the logic a bit more readable/self documenting.

myhsu updated this revision to Diff 436969.Jun 14 2022, 4:24 PM
myhsu marked 6 inline comments as done.

Addressed feedbacks.

myhsu added inline comments.Jun 14 2022, 4:24 PM
llvm/lib/MCA/InstrBuilder.cpp
542–544

yeah that definitely sounds more elegant

Hi Min,

Patch looks good modulo a minor nit (see my comment below).

Thanks!
-Andrea

llvm/include/llvm/MCA/IncrementalSourceMgr.h
46–59

I suggest to use a using for that type, and then use that new type definition in setOnInstFreedCallback (instead of using decltype).

Something like this:

using InstFreedCallbackTy = llvm::function_ref<void(Instruction *)>;
myhsu updated this revision to Diff 437330.Jun 15 2022, 2:03 PM
myhsu marked an inline comment as done.

Use type alias for instruction recycling callback function type.

myhsu added a comment.Jun 23 2022, 9:47 AM

a gentle ping

andreadb accepted this revision.Jun 23 2022, 11:23 AM

a gentle ping

LGTM

Thanks!

This revision is now accepted and ready to land.Jun 23 2022, 11:23 AM
This revision was landed with ongoing or failed builds.Jun 24 2022, 3:41 PM
This revision was automatically updated to reflect the committed changes.