This is an archive of the discontinued LLVM Phabricator instance.

[llvm-mca] Move the AssembleInput logic into its own class.
ClosedPublic

Authored by mattd on Nov 6 2018, 1:12 PM.

Details

Summary

This patch introduces a CodeRegionGenerator class which is responsible for parsing some type of input and creating a 'CodeRegions' instance for use by llvm-mca. In the future, we will also have a CodeRegionGenerator subclass for converting an input object file into CodeRegions. For now, we only have the subclass for converting input assembly into CodeRegions.

This is mostly a NFC patch, as the logic remains close to the original, but now encapsulated in its own class and moved outside of llvm-mca.cpp.

Diff Detail

Repository
rL LLVM

Event Timeline

mattd created this revision.Nov 6 2018, 1:12 PM
mattd added a comment.Nov 6 2018, 10:03 PM

I started thinking about another way of organizing this patch, to reduce all of the potential extra files. I can only really see two CodeRegion generators: one for ASM input, and the other for object file input... once we add the binary support. Perhaps, we just have a CodeRegionGenerator.{h,cpp} and put the generators for ASM and object files in those instead of having separate header/implementations for ASM and Object files. Just a thought.

I like the patch, I only have cosmetic comments.

tools/llvm-mca/AsmCodeRegionGenerator.h
49 ↗(On Diff #172834)

this can be moved to the cpp file.

57 ↗(On Diff #172834)

ditto

tools/llvm-mca/CodeRegion.h
40 ↗(On Diff #172834)

why ?

130 ↗(On Diff #172834)

this is missing a virtual dtor (that you might want to use as anchor BTW).

tools/llvm-mca/llvm-mca.cpp
344 ↗(On Diff #172834)

Most tools do the initialization in the main, I'd rather keep this here rather than in AsmCodeRegionGenerator::AsmCodeRegionGenerator

I started thinking about another way of organizing this patch, to reduce all of the potential extra files. I can only really see two CodeRegion generators: one for ASM input, and the other for object file input... once we add the binary support. Perhaps, we just have a CodeRegionGenerator.{h,cpp} and put the generators for ASM and object files in those instead of having separate header/implementations for ASM and Object files. Just a thought.

Sounds reasonable to me.

andreadb added inline comments.Nov 7 2018, 3:47 AM
tools/llvm-mca/AsmCodeRegionGenerator.cpp
11 ↗(On Diff #172834)

This should be fixed. It is not declaring the assembly parse. It is declaring a "code region generator" for assemby code.

tools/llvm-mca/AsmCodeRegionGenerator.h
49 ↗(On Diff #172834)

I agree. I think you can probably move most of this implementation into the .cpp file. It would minimize the number of required includes.

98 ↗(On Diff #172834)

You should avoid this. I don't think it is okay to initialize assembly parsers multiple times.
Please remove this, and put it back into main.

tools/llvm-mca/CodeRegion.h
40 ↗(On Diff #172834)

I had the same question..

tools/llvm-mca/llvm-mca.cpp
44 ↗(On Diff #172834)

why do you need this?

mattd updated this revision to Diff 172979.Nov 7 2018, 10:13 AM

Thanks for the reviews. I've updated the patch per the feedback given.

  • Removed unnecessary header.
  • Fixed the header comment to be clearer in CodeRegionGenerators.{h,cpp}.
  • Created header and implementation files to describe the CodeRegionGenerators. The AsmCodeRegionGenerator lives in these now.
  • Added an anchor and virtual dtor to CodeRegionGenerators.
  • Moved the helper class from AsmCodeRegionGenerators into CodeRegionGenerators.cpp, and cleaned up the includes accordingly.
andreadb accepted this revision.Nov 7 2018, 10:34 AM

LGTM.

tools/llvm-mca/CodeRegionGenerator.cpp
34 ↗(On Diff #172979)

you can probably make this class final too.

This revision is now accepted and ready to land.Nov 7 2018, 10:34 AM
This revision was automatically updated to reflect the committed changes.