This is an archive of the discontinued LLVM Phabricator instance.

[llvm-mca][NFC] Refactor instruction printing
AcceptedPublic

Authored by wolfgangp on Aug 21 2020, 7:26 PM.

Details

Summary

There are several places where views generate an ASCII form of a machine instruction. Use a helper function.

This is another preparatory patch for JSON generation.

Diff Detail

Event Timeline

wolfgangp created this revision.Aug 21 2020, 7:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 21 2020, 7:26 PM
Herald added a subscriber: gbedwell. · View Herald Transcript
wolfgangp requested review of this revision.Aug 21 2020, 7:26 PM

I believe this is going to regress normal codepath in terms of avoidable memory allocations.

llvm/tools/llvm-mca/Views/InstructionInfoView.cpp
23–24

I believe this change is going to cause many new allocations.

llvm/tools/llvm-mca/Views/ResourcePressureView.cpp
154–155

Same.

llvm/tools/llvm-mca/Views/TimelineView.cpp
186–187

Same

295–297

Same

lebedev.ri requested changes to this revision.Aug 22 2020, 2:01 PM

(marking as reviewed)

This revision now requires changes to proceed.Aug 22 2020, 2:01 PM

Here is another proposal: We're using statics for the Instruction string and the stream to write it and return a reference to it.
The users all immediately write the string to a different stream. This should have even fewer allocations than the original code.

This is not MT-capable but I don't think this is a requirement for printing views.

wolfgangp marked 4 inline comments as done.Aug 24 2020, 10:42 AM
wolfgangp updated this revision to Diff 287525.Aug 24 2020, 5:24 PM

After some consultation with @andreadb this is some more extensive refactoring:
We create a new base class InstructionView that is meant for views that deal with individual instructions (e.g. print them). The 3 members MCIP (the instruction printer), STI (subtarget info) and Source (the array of machine instructions) live there and can be accessed via getters (they could be made protected as well). Printing the instructions is effected by using a string member in the new base class (which must be mutable along with its associated stream).

All this has the effect that only views that we don't use any globals for instruction printing while simplifying the code.

andreadb accepted this revision.Aug 25 2020, 1:06 AM

Looks good to me module a few nits (see below).

llvm/tools/llvm-mca/Views/View.h
38

Remove this comment.

47

Please add a virtual destructor.

virtual ~InstructionView() = defalt
51–57

Please move this definition to View.cpp.

andreadb added inline comments.Aug 25 2020, 1:38 AM
llvm/tools/llvm-mca/Views/BottleneckAnalysis.cpp
311

Remove const.

504

Remove const.

llvm/tools/llvm-mca/Views/InstructionInfoView.cpp
24

Remove const.

llvm/tools/llvm-mca/Views/ResourcePressureView.cpp
55

Remove const.

136

Remove const.

157

Remove const

llvm/tools/llvm-mca/Views/TimelineView.cpp
283

Remove const.

llvm/tools/llvm-mca/Views/View.h
36

Don't need const. It is not a mutable array.

45

Remove const.

61

Don't need const for this. ArrayRef is already a constant reference.

lebedev.ri accepted this revision.Aug 25 2020, 6:19 AM

Looks better i guess, thanks.
Did't measure if there are any effects on memory consumption.

This revision is now accepted and ready to land.Aug 25 2020, 6:19 AM
lebedev.ri resigned from this revision.Jan 12 2023, 5:43 PM

This review seems to be stuck/dead, consider abandoning if no longer relevant.

Herald added a project: Restricted Project. · View Herald TranscriptJan 12 2023, 5:43 PM
Herald added a subscriber: StephenFan. · View Herald Transcript