43 Commits

Author SHA1 Message Date
Roman Lebedev
6fe55f4897 [MCA] Add -summary-view option
Summary:
While that is indeed a quite interesting summary stat,
there are cases where it does not really add anything
other than consuming extra lines.

Declutters the output of D48190.

Reviewers: RKSimon, andreadb, courbet, craig.topper

Reviewed By: andreadb

Subscribers: javed.absar, gbedwell, llvm-commits

Differential Revision: https://reviews.llvm.org/D48209

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334833 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-15 14:01:43 +00:00
Andrea Di Biagio
10183d6bcd Revert: [llvm-mca] Flush the output stream before we start the analysis of a new code region. NFC
Not sure why, but it breaks buildbot clang-cmake-armv8-full.
It causes a failure in TEST 'Xray-armhf-linux :: TestCases/Posix/profiling-single-threaded.cc'.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334617 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 16:33:52 +00:00
Andrea Di Biagio
bc8a784b07 [llvm-mca] Flush the output stream before we start the analysis of a new code region. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334610 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-13 15:43:56 +00:00
Andrea Di Biagio
3d525a3f58 [llvm-mca] Print the "Block RThroughput" in the SummaryView.
This patch implements the "block reciprocal throughput" computation in the
SummaryView.

The block reciprocal throughput is computed as the MAX of:
  - NumMicroOps / DispatchWidth
  - Resource Cycles / #Units   (for every resource consumed).

The block throughput is bounded from above by the hardware dispatch throughput.
That is because the DispatchWidth is an upper bound on how many opcodes can be part
of a single dispatch group.

The block throughput is also limited by the amount of hardware parallelism. The
number of available resource units affects how the resource pressure is
distributed, and also how many blocks can be delivered every cycle.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333095 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-23 15:59:27 +00:00
Andrea Di Biagio
eb1647b75b [llvm-mca] Hide unrelated flags from the -help output.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332615 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-17 15:35:14 +00:00
Andrea Di Biagio
acf3f6ed48 [llvm-mca] add flag -all-views and flag -all-stats.
Flag -all-views enables all the views.
Flag -all-stats enables all the views that print hardware statistics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332602 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-17 12:27:03 +00:00
Matt Davis
1b9c943536 [llvm-mca] Introduce a pipeline Stage class and FetchStage.
Summary:
    This is just an idea, really two ideas.  I expect some push-back,
    but I realize that posting a diff is the most comprehensive way to express
    these concepts.

    This patch introduces a Stage class which represents the
    various stages of an instruction pipeline.  As a start, I have created a simple
    FetchStage that is based on existing logic for how MCA produces
    instructions, but now encapsulated in a Stage.  The idea should become more concrete
    once we introduce additional stages.  The idea being, that when a stage completes,
    the next stage in the pipeline will be executed.  Stages are chained together
    as a singly linked list to closely model a real pipeline. For now there is only one stage,
    so the stage-to-stage flow of instructions isn't immediately obvious.

    Eventually, Stage will also handle event notifications, but that functionality
    is not complete, and not destined for this patch.  Ideally, an interested party 
    can register for notifications from a particular stage.  Callbacks will be issued to
    these listeners at various points in the execution of the stage.  
    For now, eventing functionality remains similar to what it has been in mca::Backend. 
    We will be building-up the Stage class as we move on, such as adding debug output.

    This patch also removes the unique_ptr<Instruction> return value from
    InstrBuilder::createInstruction.  An Instruction pointer is still produced,
    but now it's up to the caller to decide how that item should be managed post-allocation
    (e.g., smart pointer).  This allows the Fetch stage to create instructions and
    manage the lifetime of those instructions as it wishes, and not have to be bound to any
    specific managed pointer type.  Other callers of createInstruction might have different 
    requirements, and thus can manage the pointer to fit their needs.  Another idea would be to push the
   ownership to the RCU. 

    Currently, the FetchStage will wrap the Instruction
    pointer in a shared_ptr.  This allows us to remove the Instruction container in
    Backend, which was probably going to disappear, or move, at some point anyways.
    Note that I did run these changes through valgrind, to make sure we are not leaking
    memory.  While the shared_ptr comes with some additional overhead it relieves us
    from having to manage a list of generated instructions, and/or make lookup calls
    to remove the instructions. 

    I realize that both the Stage class and the Instruction pointer management
    (mentioned directly above) are separate but related ideas, and probably should
    land as separate patches; I am happy to do that if either idea is decent.
    The main reason these two ideas are together is that
    Stage::execute() can mutate an InstRef. For the fetch stage, the InstRef is populated
    as the primary action of that stage (execute()).  I didn't want to change the Stage interface
    to support the idea of generating an instruction.  Ideally, instructions are to
    be pushed through the pipeline.  I didn't want to draw too much of a
    specialization just for the fetch stage.  Excuse the word-salad.

Reviewers: andreadb, courbet, RKSimon

Reviewed By: andreadb

Subscribers: llvm-commits, mgorny, javed.absar, tschuett, gbedwell

Differential Revision: https://reviews.llvm.org/D46741

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332390 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-15 20:21:04 +00:00
Andrea Di Biagio
d6075d034e [llvm-mca] removes flag -instruction-tables from the "View Options" category.
This patch also improves the description of a couple of flags in the view
options. With this change, the -help now specifies which views are enabled by
default.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331594 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-05 15:36:47 +00:00
Andrea Di Biagio
f6d466f5ba [llvm-mca] use colors for warnings and notes generated by InstrBuilder.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331517 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-04 13:52:12 +00:00
Andrea Di Biagio
0110ab1c05 [llvm-mca] Support for in-order CPU for -instruction-tables testing.
Added Intel Atom tests to verify that the tool correctly generates instruction
tables even if the CPU is in-order.

Fixes PR37282.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331169 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-30 12:05:34 +00:00
Filipe Cabecinhas
677f7d70cd [llvm-mca] Make ViewOptions static. NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330829 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25 14:39:16 +00:00
Andrea Di Biagio
a2dfca18bd [llvm-mca] Add a new option category for views.
With this patch, options to add/tweak views are all grouped together in the
-help output.

The new "View Options" category looks like this:

```
  View Options:

    -dispatch-stats                 - Print dispatch statistics
    -instruction-info               - Print the instruction info view
    -instruction-tables             - Print instruction tables
    -register-file-stats            - Print register file statistics
    -resource-pressure              - Print the resource pressure view
    -retire-stats                   - Print retire control unit statistics
    -scheduler-stats                - Print scheduler statistics
    -timeline                       - Print the timeline view
    -timeline-max-cycles=<uint>     - Maximum number of cycles in the timeline view. Defaults to 80 cycles
    -timeline-max-iterations=<uint> - Maximum number of iterations to print in timeline view
```


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330816 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25 11:33:14 +00:00
Andrea Di Biagio
b7acab1156 [llvm-mca] run clang-format on a bunch of files. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330811 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25 10:27:30 +00:00
Andrea Di Biagio
e508042fca [llvm-mca] Default to the native host cpu if flag -mcpu is not specified.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330809 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25 10:18:25 +00:00
Andrea Di Biagio
33b053f159 [llvm-mca] Remove unused flag -verbose. NFC
I forgot to remove it at r329794.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330757 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-24 19:14:56 +00:00
Andrea Di Biagio
9830843b26 [llvm-mca] Default the output asm dialect used by the instruction printer to the input asm dialect.
The instruction printer used by llvm-mca to generate the performance report now
defaults the output assembly format to the format used for the input assembly
file.

On x86, the asm format can be either AT&T or Intel, depending on the
presence/absence of directive `.intel_syntax`.

Users can still specify a different assembly dialect with the command line flag
-output-asm-variant=<uint>.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330733 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-24 16:19:08 +00:00
Jonas Devlieghere
ef2e5c92da [llvm-mca] Use WithColor for printing errors
Use convenience helpers in WithColor to print errors and notes.

Differential revision: https://reviews.llvm.org/D45666

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330267 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-18 15:26:51 +00:00
Rui Ueyama
0b9d56a30e Define InitLLVM to do common initialization all at once.
We have a few functions that virtually all command wants to run on
process startup/shutdown. This patch adds InitLLVM class to do that
all at once, so that we don't need to copy-n-paste boilerplate code
to each llvm command's main() function.

Differential Revision: https://reviews.llvm.org/D45602

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330046 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-13 18:26:06 +00:00
Andrea Di Biagio
ee869a8238 [llvm-mca] Minor code cleanup. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329796 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-11 12:31:44 +00:00
Andrea Di Biagio
900cf755f0 [llvm-mca] Renamed BackendStatistics to RetireControlUnitStatistics.
Also, removed flag -verbose in favor of flag -retire-stats.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329794 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-11 12:12:53 +00:00
Andrea Di Biagio
2d438c016c [llvm-mca] Move the logic that prints scheduler statistics from BackendStatistics to its own view.
Added flag -scheduler-stats to print scheduler related statistics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329792 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-11 11:37:46 +00:00
Andrea Di Biagio
955aba4f3b [llvm-mca] Move the logic that prints dispatch unit statistics from BackendStatistics to its own view.
This patch moves the logic that collects and analyzes dispatch events to the
DispatchStatistics view.

Added flag -dispatch-stats to print statistics related to the dispatch logic.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329708 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-10 14:55:14 +00:00
Fangrui Song
b5f3ce829b [llvm-mca] Fix MCACommentConsumer
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329592 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 17:06:57 +00:00
Andrea Di Biagio
aae4cd3ca1 [llvm-mca] Add the ability to mark regions of code for analysis (PR36875)
This patch teaches llvm-mca how to parse code comments in search for special
"markers" used to select regions of code.

Example:

# LLVM-MCA-BEGIN My Code Region
  ....
# LLVM-MCA-END

The MCAsmLexer now delegates to an object of class MCACommentParser (i.e. an
AsmCommentConsumer) the parsing of code comments to search for begin/end code
region markers.

A comment starting with substring "LLVM-MCA-BEGIN" marks the beginning of a new
region of code.  A comment starting with substring "LLVM-MCA-END" marks the end
of the last region.

This implementation doesn't allow regions to overlap. Each region can have a
optional description; internally, each region is identified by a range of source
code locations (SMLoc).

MCInst objects are added to a region R only if the source location for the
MCInst is in the range of locations specified by R.

By default, the tool allocates an implicit "Default" code region which contains
every source location.  See new tests llvm-mca-marker-*.s for a few examples.

A new Backend object is created for every region. So, the analysis is conducted
on every parsed code region.  The final report is the union of the reports
generated for every code region.  Note that empty regions are skipped.

Special "[#] Code Region - ..." strings are used in the report to mark the
portion which is specific to a code region only. For example, see
llvm-mca-markers-5.s.

Differential Revision: https://reviews.llvm.org/D45433


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329590 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-09 16:39:52 +00:00
Andrea Di Biagio
2785576ecb [llvm-mca] Simplify code. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329532 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-08 15:10:19 +00:00
Andrea Di Biagio
370e64a807 [llvm-mca] Remove flag -max-retire-per-cycle, and update the docs.
This is done in preparation for D45259.
With D45259, models can specify the size of the reorder buffer, and the retire
throughput directly via tablegen.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329274 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-05 11:36:50 +00:00
Andrea Di Biagio
6ea791d917 [llvm-mca] Move the logic that prints register file statistics to its own view. NFCI
Before this patch, the "BackendStatistics" view was responsible for printing the
register file usage (as well as many other statistics).

Now users can enable register file usage statistics using the command line flag
`-register-file-stats`. By default, the tool doesn't print register file
statistics.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@329083 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-03 16:46:23 +00:00
Andrea Di Biagio
7fa3ae5ae3 [llvm-mca] Fix how views are added to the InstructionTables.
This should fix the stack-use-after-scope reported by the asan buildbots after
revision 328493.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328499 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-26 14:25:52 +00:00
Andrea Di Biagio
fafdf4a29c [llvm-mca] Add a flag -instruction-info to enable/disable the instruction info view.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328493 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-26 13:44:54 +00:00
Andrea Di Biagio
181ce9f609 [llvm-mca] Add flag -instruction-tables to print the theoretical resource pressure distribution for instructions (PR36874)
The goal of this patch is to address most of PR36874.  To fully fix PR36874 we
need to split the "InstructionInfo" view from the "SummaryView". That would make
easy to check the latency and rthroughput as well.

The patch reuses all the logic from ResourcePressureView to print out the
"instruction tables".

We have an entry for every instruction in the input sequence. Each entry reports
the theoretical resource pressure distribution. Resource pressure is uniformly
distributed across all the processor resource units of a group.

At the moment, the backend pipeline is not configurable, so the only way to fix
this is by creating a different driver that simply sends instruction events to
the resource pressure view.  That means, we don't use the Backend interface.
Instead, it is simpler to just have a different code-path for when flag
-instruction-tables is specified.

Once Clement addresses bug 36663, then we can port the "instruction tables"
logic into a stage of our configurable pipeline.

Updated the BtVer2 test cases (thanks Simon for the help). Now we pass flag
-instruction-tables to each modified test.

Differential Revision: https://reviews.llvm.org/D44839


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328487 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-26 12:04:53 +00:00
Andrea Di Biagio
add7b3e24e [llvm-mca] run clang-format on all files.
This also addresses Simon's review comment in D44839.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328428 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-24 16:05:36 +00:00
Andrea Di Biagio
3b9d2408db [llvm-mca] Split the InstructionInfoView from the SummaryView.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328358 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-23 19:40:04 +00:00
Andrea Di Biagio
8a63941a9f [llvm-mca] Pass the InstrBuilder to the constructor of Backend.
This is done in preparation for the fix for PR36784.
No functional change.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328306 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-23 11:50:43 +00:00
Andrea Di Biagio
10ba818f3b [llvm-mca] Add flag -resource-pressure to enable/disable printing of the resource pressure view.
By default, the tool always enables the resource pressure view.
This flag lets user specify whether they want to add that view or not.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328305 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-23 11:33:09 +00:00
Andrea Di Biagio
280f00a153 [llvm-mca] Simplify code. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328187 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-22 10:19:20 +00:00
Andrea Di Biagio
2ff763c8ed [llvm-mca] Move the logic that computes the register file usage to the BackendStatistics view.
With this patch, the "instruction dispatched" event now provides information
related to the number of microarchitectural registers used in each register
file. Similarly, the "instruction retired" event is now able to tell how may
registers are freed in each register file.

Currently, the BackendStatistics view is the only consumer of register
usage/pressure information. BackendStatistics uses that info to print out a few
general statistics (i.e. max number of mappings used; total mapping created).
Before this patch, the BackendStatistics was forced to query the Backend to
obtain the register pressure information.

This helps removes that dependency. Now views are completely independent from
the Backend.  As a consequence, it should be easier to address PR36663 and
further modularize the pipeline.

Added a couple of test cases in the BtVer2 specific directory.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328129 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 18:11:05 +00:00
Andrea Di Biagio
115a8a95af [llvm-mca] Remove method getSchedModel() from the Backend.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327756 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-16 22:21:52 +00:00
Andrea Di Biagio
04be4f5879 [llvm-mca] Remove the logic that computes the reciprocal throughput, and make the SummaryView independent from the Backend. NFCI
Since r327420, the tool can query the MCSchedModel interface to obtain the
reciprocal throughput information.
As a consequence, method `ResourceManager::getRThroughput`, and
method `Backend::getRThroughput` are no longer needed.

This patch simplifies the code by removing the custom RThroughput computation.
This patch also refactors class SummaryView by removing the dependency with
the Backend object.

No functional change intended.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327425 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-13 17:24:32 +00:00
Andrea Di Biagio
80f8cd5c84 [llvm-mca] Views are now independent from resource masks. NFCI
This change removes method Backend::getProcResourceMasks() and simplifies some
logic in the Views. This effectively removes yet another dependency between the
views and the Backend.
No functional change intended.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327214 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-10 16:55:07 +00:00
Andrea Di Biagio
7ebbb195b1 [llvm-mca] Move the logic that prints the summary into its own view. NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327128 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-09 13:52:03 +00:00
Andrea Di Biagio
163bd8a42d [llvm-mca] Run clang-format on the source code. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327125 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-09 12:50:42 +00:00
Andrea Di Biagio
6b07e2fa92 [llvm-mca] Unify the API for the various views. NFCI
This allows the customization of the performance report.

Users can specify their own custom sequence of views.
Each view contributes a portion of the performance report generated by the
BackendPrinter.

Internally, class BackendPrinter keeps a sequence of views; views are printed
out in sequence when method 'printReport()' is called. 

This patch addresses one of the two review comments from Clement in D43951.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327018 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-08 16:08:43 +00:00
Andrea Di Biagio
29b29cc6a9 [llvm-mca] LLVM Machine Code Analyzer.
llvm-mca is an LLVM based performance analysis tool that can be used to
statically measure the performance of code, and to help triage potential
problems with target scheduling models.

llvm-mca uses information which is already available in LLVM (e.g. scheduling
models) to statically measure the performance of machine code in a specific cpu.
Performance is measured in terms of throughput as well as processor resource
consumption. The tool currently works for processors with an out-of-order
backend, for which there is a scheduling model available in LLVM.

The main goal of this tool is not just to predict the performance of the code
when run on the target, but also help with diagnosing potential performance
issues.

Given an assembly code sequence, llvm-mca estimates the IPC (instructions per
cycle), as well as hardware resources pressure. The analysis and reporting style
were mostly inspired by the IACA tool from Intel.

This patch is related to the RFC on llvm-dev visible at this link:
http://lists.llvm.org/pipermail/llvm-dev/2018-March/121490.html

Differential Revision: https://reviews.llvm.org/D43951


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326998 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-08 13:05:02 +00:00