Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
---
title: Running MCA with Arm assembly
title: Use LLVM Machine Code Analyzer to understand code performance

minutes_to_complete: 60

who_is_this_for: This is an introductory topic for Arm developers who want to diagnose performance issues of Arm programs using MCA and Compiler Explorer.
who_is_this_for: This is an introductory topic for Arm developers who want to diagnose performance issues of Arm programs using LLVM Machine Code Analyzer (MCA) and Compiler Explorer.

learning_objectives:
- Estimate the hardware resource pressure and the number of cycles taken to execute your code snippet using llvm-mca
- Understand how this estimate can help diagnose possible performance issues
- Use Compiler Explorer to run llvm-mca
- Estimate the hardware resource pressure and the number of cycles taken to execute your code snippet using llvm-mca.
- Understand how this estimate can help diagnose possible performance issues.
- Use Compiler Explorer to run llvm-mca.

prerequisites:
- Familiarity with Arm assembly
- clang compiler or access to Compiler Explorer
- Familiarity with Arm assembly.
- LLVM version 16 or newer (to include Neoverse V2 support).

author_primary: Rin Dobrescu

### Tags
skilllevels: Introductory
subjects: Performance
subjects: Performance and Architecture
armips:
- Neoverse
- Armv8
tools_software_languages:
- assembly
- llvm-mca
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
---
title: Using MCA with Compiler Explorer
title: Use MCA with Compiler Explorer
weight: 3
### FIXED, DO NOT MODIFY
layout: learningpathall
---

### What is Compiler Explorer?
Compiler Explorer is an interactive online compiler that lets you edit code in C/C++, Java, Python and many other programming languages. It then allows you to see what the code looks like after being compiled in real time. It supports multiple compilers and has many tools available, including llvm-mca.

Compiler Explorer is an interactive online compiler that lets you enter code in C/C++, Java, Python and many other programming languages. It allows you to see what the code looks like after being compiled in real time.

Compiler Explorer supports multiple compilers and has many tools available, including `llvm-mca`.

### Running MCA in Compiler Explorer
To access Compiler Explorer, open a browser and go to https://godbolt.org. This leads you to a page that looks as in Figure 1 below:

To access Compiler Explorer, open a browser and go to https://godbolt.org.

This leads you to the page shown below in Figure 1. Your view may be a slightly different.

![godbolt open alt-text#center](open.png "Figure 1. Compiler Explorer")

On the left side of the page is the source code. In Figure 1 it is set to C++, you can click on the programming language to select a different language for the source code. Now copy this code and use it as C++ source:
```
The left side of the page contains the source code. In Figure 1, the language is set to C++, but you can click on the programming language to select a different language for the source code.

Copy the code below and paste it into Compiler Explorer as C++ source code:

```C
int func(int a, int b, int c, int d, int e, int f) {
a = a + b;
a = a + c;
Expand All @@ -24,10 +34,28 @@ int func(int a, int b, int c, int d, int e, int f) {
}
```

On the right side of the page is the disassembly output from the compiler. You can change the compiler by clicking on it and selecting a different one. You can try this now and select `armv8-a clang(trunk)` as the compiler. Then add some compiler flags by typing `-O3` in the `Compiler options` box. You can view the full set of options passed to the compiler by clicking on the green tick next to the compiler. You can now add llvm-mca from the `Add tool` dropdown button, as shown in Figure 2 below:
The right side of the page contains the disassembly output from the compiler.

You can change the compiler by clicking on it and selecting a different one.

Select `armv8-a clang(trunk)` as the compiler to see Arm instructions.

Next, update the compiler flags by typing `-O3` in the `Compiler options` box.

You can view the full set of options passed to the compiler by clicking on the green tick next to the compiler.

Click the `Add tool` dropdown button to add `llvm-mca` as a tool as shown in Figure 2 below:

![tool mca alt-text#center](tool-mca.png "Figure 2. Assembly in Compiler Explorer")

To add more flags to `llvm-mca`, click on the `Arguments` button and type them in. Specify the CPU name to `llvm-mca` by using the `-mcpu` flag. To find what CPUs are supported you can check the [clang documentation](https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-print-supported-cpus). You can try this now and add `-mcpu=neoverse-v2`, as well as any other flags you choose to pass to `llvm-mca`. On the right side of the page is the output from running `llvm-mca` on the disassembly of the source code, as shown in Figure 3 below:
To add more flags to `llvm-mca`, click on the `Arguments` button and type them in.

Add `-mcpu=neoverse-v2`, as well as any other flags you choose to pass to `llvm-mca`.

To find what CPUs are supported you can check the [clang documentation](https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-print-supported-cpus).

The right side of the page now contains the output from running `llvm-mca` on the disassembly of the source code, as shown in Figure 3 below:

![argument mca alt-text#center](mca-arguments.png "Figure 3. MCA in Compiler Explorer")

You are now able to run `llvm-mca` using Compiler Explorer.
You are now able to run `llvm-mca` using Compiler Explorer. This is helpful when you want to try different compiler versions without installing them.
Loading