<div dir="auto">For the future: if you ar committing a patch on behalf of somebody else, you should set the ‘Author’ property using the following command:</div><div dir="auto"><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace"><br></span></div><div dir="auto"><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">‘git</span><span style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:13.300000190734863px"> </span><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">commit</span><span style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:13.300000190734863px"> </span><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">--amend</span><span style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;font-size:13.300000190734863px"> </span><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">--author’</span></div><div dir="auto"><span class="pre" style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace"><br></span></div><div dir="auto" style="background-color:rgba(0,0,0,0)!important;border-color:rgb(0,0,0)!important;color:rgb(0,0,0)!important"><font style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace;color:rgb(0,0,0)"><span style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace">(See </span></font><span style="font-family:Consolas,"Deja Vu Sans Mono","Bitstream Vera Sans Mono",monospace"><a href="https://llvm.org/docs/DeveloperPolicy.html#commit-messages">https://llvm.org/docs/DeveloperPolicy.html#commit-messages</a>)</span></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 21 Dec 2021 at 10:57, Djordje Todorovic via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><br>
Author: Djordje Todorovic<br>
Date: 2021-12-21T11:56:18+01:00<br>
New Revision: 0e343479a7ea9cabac8c467cd24bc3ed463b8786<br>
<br>
URL: <a href="https://github.com/llvm/llvm-project/commit/0e343479a7ea9cabac8c467cd24bc3ed463b8786" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/0e343479a7ea9cabac8c467cd24bc3ed463b8786</a><br>
DIFF: <a href="https://github.com/llvm/llvm-project/commit/0e343479a7ea9cabac8c467cd24bc3ed463b8786.diff" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/commit/0e343479a7ea9cabac8c467cd24bc3ed463b8786.diff</a><br>
<br>
LOG: [llvm-mca] Compare multiple files<br>
<br>
Script (llvm-mca-compare.py) uses llvm-mca tool to print<br>
statistics in console for multiple files.<br>
Script requires specified --llvm-mca-binary option (specified<br>
relative path to binary of llvm-mca).<br>
Options: --args [="-option1=<arg> -option2=<arg> ..."], -v or -h can also be used.<br>
<br>
The script is used as follows:<br>
$ llvm-project/llvm/utils/llvm-mca-compare.py file1.s --llvm-mca-binary=build/bin/llvm-mca<br>
<br>
Patch by Milica Matic <<a href="mailto:Milica.Matic@syrmia.com" target="_blank">Milica.Matic@syrmia.com</a>><br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D115138" rel="noreferrer" target="_blank">https://reviews.llvm.org/D115138</a><br>
<br>
Added: <br>
    llvm/utils/llvm-mca-compare.py<br>
<br>
Modified: <br>
<br>
<br>
Removed: <br>
<br>
<br>
<br>
################################################################################<br>
diff  --git a/llvm/utils/llvm-mca-compare.py b/llvm/utils/llvm-mca-compare.py<br>
new file mode 100755<br>
index 0000000000000..72c875d424422<br>
--- /dev/null<br>
+++ b/llvm/utils/llvm-mca-compare.py<br>
@@ -0,0 +1,279 @@<br>
+#!/usr/bin/env python3<br>
+<br>
+import argparse<br>
+import sys<br>
+from json import loads<br>
+from subprocess import Popen, PIPE<br>
+<br>
+# Holds code regions statistics.<br>
+class Summary:<br>
+    def __init__(<br>
+        self,<br>
+        name,<br>
+        block_rthroughput,<br>
+        dispatch_width,<br>
+        ipc,<br>
+        instructions,<br>
+        iterations,<br>
+        total_cycles,<br>
+        total_uops,<br>
+        uops_per_cycle,<br>
+        iteration_resource_pressure,<br>
+        name_target_info_resources,<br>
+    ):<br>
+        <a href="http://self.name" rel="noreferrer" target="_blank">self.name</a> = name<br>
+        self.block_rthroughput = block_rthroughput<br>
+        self.dispatch_width = dispatch_width<br>
+        self.ipc = ipc<br>
+        self.instructions = instructions<br>
+        self.iterations = iterations<br>
+        self.total_cycles = total_cycles<br>
+        self.total_uops = total_uops<br>
+        self.uops_per_cycle = uops_per_cycle<br>
+        self.iteration_resource_pressure = iteration_resource_pressure<br>
+        self.name_target_info_resources = name_target_info_resources<br>
+<br>
+<br>
+# Parse the program arguments.<br>
+def parse_program_args(parser):<br>
+    parser.add_argument(<br>
+        "file_names",<br>
+        nargs="+",<br>
+        type=str,<br>
+        help="Names of files which llvm-mca tool process.",<br>
+    )<br>
+    parser.add_argument(<br>
+        "--llvm-mca-binary",<br>
+        nargs=1,<br>
+        required=True,<br>
+        type=str,<br>
+        action="store",<br>
+        metavar="[=<path to llvm-mca>]",<br>
+        help="Specified relative path to binary of llvm-mca.",<br>
+    )<br>
+    parser.add_argument(<br>
+        "--args",<br>
+        nargs=1,<br>
+        type=str,<br>
+        action="store",<br>
+        metavar="[='-option1=<arg> -option2=<arg> ...']",<br>
+        default=["-"],<br>
+        help="Forward options to lvm-mca tool.",<br>
+    )<br>
+    parser.add_argument(<br>
+        "-v",<br>
+        action="store_true",<br>
+        default=False,<br>
+        help="More details about the running lvm-mca tool.",<br>
+    )<br>
+    return parser.parse_args()<br>
+<br>
+<br>
+# Returns the name of the file to be analyzed from the path it is on.<br>
+def get_filename_from_path(path):<br>
+    index_of_slash = path.rfind("/")<br>
+    return path[(index_of_slash + 1) : len(path)]<br>
+<br>
+<br>
+# Returns the results of the running llvm-mca tool for the input file.<br>
+def run_llvm_mca_tool(opts, file_name):<br>
+    # Get the path of the llvm-mca binary file.<br>
+    llvm_mca_cmd = opts.llvm_mca_binary[0]<br>
+<br>
+    # The statistics llvm-mca options.<br>
+    if opts.args[0] != "-":<br>
+        llvm_mca_cmd += " " + opts.args[0]<br>
+    llvm_mca_cmd += " -json"<br>
+<br>
+    # Set file which llvm-mca tool will process.<br>
+    llvm_mca_cmd += " " + file_name<br>
+<br>
+    if opts.v:<br>
+        print("run: $ " + llvm_mca_cmd + "\n")<br>
+<br>
+    # Generate the stats with the llvm-mca.<br>
+    subproc = Popen(<br>
+        llvm_mca_cmd.split(" "),<br>
+        stdin=PIPE,<br>
+        stdout=PIPE,<br>
+        stderr=PIPE,<br>
+        universal_newlines=True,<br>
+    )<br>
+<br>
+    cmd_stdout, cmd_stderr = subproc.communicate()<br>
+<br>
+    try:<br>
+        json_parsed = loads(cmd_stdout)<br>
+    except:<br>
+        print("error: No valid llvm-mca statistics found.")<br>
+        print(cmd_stderr)<br>
+        sys.exit(1)<br>
+<br>
+    if opts.v:<br>
+        print("Simulation Parameters: ")<br>
+        simulation_parameters = json_parsed["SimulationParameters"]<br>
+        for key in simulation_parameters:<br>
+            print(key, ":", simulation_parameters[key])<br>
+        print("\n")<br>
+<br>
+    code_regions_len = len(json_parsed["CodeRegions"])<br>
+    array_of_code_regions = [None] * code_regions_len<br>
+<br>
+    for i in range(code_regions_len):<br>
+        code_region_instructions_len = len(<br>
+            json_parsed["CodeRegions"][i]["Instructions"]<br>
+        )<br>
+        target_info_resources_len = len(json_parsed["TargetInfo"]["Resources"])<br>
+        iteration_resource_pressure = ["-" for k in range(target_info_resources_len)]<br>
+        resource_pressure_info = json_parsed["CodeRegions"][i]["ResourcePressureView"][<br>
+            "ResourcePressureInfo"<br>
+        ]<br>
+<br>
+        name_target_info_resources = [" "] + json_parsed["TargetInfo"]["Resources"]<br>
+<br>
+        for s in range(len(resource_pressure_info)):<br>
+            obj_of_resource_pressure_info = resource_pressure_info[s]<br>
+            if (<br>
+                obj_of_resource_pressure_info["InstructionIndex"]<br>
+                == code_region_instructions_len<br>
+            ):<br>
+                iteration_resource_pressure[<br>
+                    obj_of_resource_pressure_info["ResourceIndex"]<br>
+                ] = str(round(obj_of_resource_pressure_info["ResourceUsage"], 2))<br>
+<br>
+        array_of_code_regions[i] = Summary(<br>
+            file_name,<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["BlockRThroughput"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["DispatchWidth"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["IPC"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["Instructions"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["Iterations"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["TotalCycles"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["TotaluOps"],<br>
+            json_parsed["CodeRegions"][i]["SummaryView"]["uOpsPerCycle"],<br>
+            iteration_resource_pressure,<br>
+            name_target_info_resources,<br>
+        )<br>
+<br>
+    return array_of_code_regions<br>
+<br>
+<br>
+# Print statistics in console for single file or for multiple files.<br>
+def console_print_results(matrix_of_code_regions, opts):<br>
+    try:<br>
+        import termtables as tt<br>
+    except ImportError:<br>
+        print("error: termtables not found.")<br>
+        sys.exit(1)<br>
+<br>
+    headers_names = [None] * (len(opts.file_names) + 1)<br>
+    headers_names[0] = " "<br>
+<br>
+    max_code_regions = 0<br>
+<br>
+    print("Input files:")<br>
+    for i in range(len(matrix_of_code_regions)):<br>
+        if max_code_regions < len(matrix_of_code_regions[i]):<br>
+            max_code_regions = len(matrix_of_code_regions[i])<br>
+        print("[f" + str(i + 1) + "]: " + get_filename_from_path(opts.file_names[i]))<br>
+        headers_names[i + 1] = "[f" + str(i + 1) + "]: "<br>
+<br>
+    print("\nITERATIONS: " + str(matrix_of_code_regions[0][0].iterations) + "\n")<br>
+<br>
+    for i in range(max_code_regions):<br>
+<br>
+        print(<br>
+            "\n-----------------------------------------\nCode region: "<br>
+            + str(i + 1)<br>
+            + "\n"<br>
+        )<br>
+<br>
+        table_values = [<br>
+            [[None] for i in range(len(matrix_of_code_regions) + 1)] for j in range(7)<br>
+        ]<br>
+<br>
+        table_values[0][0] = "Instructions: "<br>
+        table_values[1][0] = "Total Cycles: "<br>
+        table_values[2][0] = "Total uOps: "<br>
+        table_values[3][0] = "Dispatch Width: "<br>
+        table_values[4][0] = "uOps Per Cycle: "<br>
+        table_values[5][0] = "IPC: "<br>
+        table_values[6][0] = "Block RThroughput: "<br>
+<br>
+        for j in range(len(matrix_of_code_regions)):<br>
+            if len(matrix_of_code_regions[j]) > i:<br>
+                table_values[0][j + 1] = str(matrix_of_code_regions[j][i].instructions)<br>
+                table_values[1][j + 1] = str(matrix_of_code_regions[j][i].total_cycles)<br>
+                table_values[2][j + 1] = str(matrix_of_code_regions[j][i].total_uops)<br>
+                table_values[3][j + 1] = str(<br>
+                    matrix_of_code_regions[j][i].dispatch_width<br>
+                )<br>
+                table_values[4][j + 1] = str(<br>
+                    round(matrix_of_code_regions[j][i].uops_per_cycle, 2)<br>
+                )<br>
+                table_values[5][j + 1] = str(round(matrix_of_code_regions[j][i].ipc, 2))<br>
+                table_values[6][j + 1] = str(<br>
+                    round(matrix_of_code_regions[j][i].block_rthroughput, 2)<br>
+                )<br>
+            else:<br>
+                table_values[0][j + 1] = "-"<br>
+                table_values[1][j + 1] = "-"<br>
+                table_values[2][j + 1] = "-"<br>
+                table_values[3][j + 1] = "-"<br>
+                table_values[4][j + 1] = "-"<br>
+                table_values[5][j + 1] = "-"<br>
+                table_values[6][j + 1] = "-"<br>
+<br>
+        tt.print(<br>
+            table_values,<br>
+            header=headers_names,<br>
+            style=tt.styles.ascii_thin_double,<br>
+            padding=(0, 1),<br>
+        )<br>
+<br>
+        print("\nResource pressure per iteration: \n")<br>
+<br>
+        table_values = [<br>
+            [<br>
+                [None]<br>
+                for i in range(<br>
+                    len(matrix_of_code_regions[0][0].iteration_resource_pressure) + 1<br>
+                )<br>
+            ]<br>
+            for j in range(len(matrix_of_code_regions) + 1)<br>
+        ]<br>
+<br>
+        table_values[0] = matrix_of_code_regions[0][0].name_target_info_resources<br>
+<br>
+        for j in range(len(matrix_of_code_regions)):<br>
+            if len(matrix_of_code_regions[j]) > i:<br>
+                table_values[j + 1] = [<br>
+                    "[f" + str(j + 1) + "]: "<br>
+                ] + matrix_of_code_regions[j][i].iteration_resource_pressure<br>
+            else:<br>
+                table_values[j + 1] = ["[f" + str(j + 1) + "]: "] + len(<br>
+                    matrix_of_code_regions[0][0].iteration_resource_pressure<br>
+                ) * ["-"]<br>
+<br>
+        tt.print(<br>
+            table_values,<br>
+            style=tt.styles.ascii_thin_double,<br>
+            padding=(0, 1),<br>
+        )<br>
+        print("\n")<br>
+<br>
+<br>
+def Main():<br>
+    parser = argparse.ArgumentParser()<br>
+    opts = parse_program_args(parser)<br>
+<br>
+    matrix_of_code_regions = [None] * len(opts.file_names)<br>
+<br>
+    for i in range(len(opts.file_names)):<br>
+        matrix_of_code_regions[i] = run_llvm_mca_tool(opts, opts.file_names[i])<br>
+    console_print_results(matrix_of_code_regions, opts)<br>
+<br>
+<br>
+if __name__ == "__main__":<br>
+    Main()<br>
+    sys.exit(0)<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>