[llvm-mca] Fix JSON format for multiple regions

Instead of printing each region individually when using JSON format,
this patch creates a JSON object which is updated with the values of
each region, printing them at the end. New test is added for JSON output
with multiple regions.

Bug: https://bugs.llvm.org/show_bug.cgi?id=51008

Reviewed By: andreadb

Differential Revision: https://reviews.llvm.org/D105618
This commit is contained in:
Marcos Horro 2021-07-09 17:58:57 +02:00
parent c282d55a38
commit b11d31eb73
7 changed files with 482 additions and 168 deletions

View File

@ -0,0 +1,288 @@
# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py
# Verify that we create proper JSON for the MCA views TimelineView, ResourcePressureview,
# InstructionInfoView and SummaryView.
# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=haswell --json --timeline-max-iterations=1 --timeline --all-stats --all-views < %s | FileCheck %s
# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=haswell --json --timeline-max-iterations=1 --timeline --all-stats --all-views -o %t.json < %s
# RUN: cat %t.json \
# RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
# RUN: | FileCheck %s
# LLVM-MCA-BEGIN foo
add %eax, %eax
# LLVM-MCA-BEGIN bar
add %ebx, %ebx
add %ecx, %ecx
# LLVM-MCA-END bar
add %edx, %edx
# LLVM-MCA-END foo
# CHECK: {
# CHECK-NEXT: "Resources": {
# CHECK-NEXT: "CPUName": "haswell",
# CHECK-NEXT: "Resources": [
# CHECK-NEXT: "HWDivider",
# CHECK-NEXT: "HWFPDivider",
# CHECK-NEXT: "HWPort0",
# CHECK-NEXT: "HWPort1",
# CHECK-NEXT: "HWPort2",
# CHECK-NEXT: "HWPort3",
# CHECK-NEXT: "HWPort4",
# CHECK-NEXT: "HWPort5",
# CHECK-NEXT: "HWPort6",
# CHECK-NEXT: "HWPort7"
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "bar": {
# CHECK-NEXT: "DispatchStatistics": {
# CHECK-NEXT: "GROUP": 0,
# CHECK-NEXT: "LQ": 0,
# CHECK-NEXT: "RAT": 0,
# CHECK-NEXT: "RCU": 0,
# CHECK-NEXT: "SCHEDQ": 41,
# CHECK-NEXT: "SQ": 0,
# CHECK-NEXT: "USH": 0
# CHECK-NEXT: },
# CHECK-NEXT: "InstructionInfoView": {
# CHECK-NEXT: "InstructionList": [
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 0,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 1,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "Instructions": [
# CHECK-NEXT: "addl\t%ebx, %ebx",
# CHECK-NEXT: "addl\t%ecx, %ecx"
# CHECK-NEXT: ],
# CHECK-NEXT: "ResourcePressureView": {
# CHECK-NEXT: "ResourcePressureInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 0,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 0,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 1,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 1,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 0.5
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "SummaryView": {
# CHECK-NEXT: "BlockRThroughput": 0.5,
# CHECK-NEXT: "DispatchWidth": 4,
# CHECK-NEXT: "IPC": 1.941747572815534,
# CHECK-NEXT: "Instructions": 200,
# CHECK-NEXT: "Iterations": 100,
# CHECK-NEXT: "TotalCycles": 103,
# CHECK-NEXT: "TotaluOps": 200,
# CHECK-NEXT: "uOpsPerCycle": 1.941747572815534
# CHECK-NEXT: },
# CHECK-NEXT: "TimelineView": {
# CHECK-NEXT: "TimelineInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: },
# CHECK-NEXT: "foo": {
# CHECK-NEXT: "DispatchStatistics": {
# CHECK-NEXT: "GROUP": 0,
# CHECK-NEXT: "LQ": 0,
# CHECK-NEXT: "RAT": 0,
# CHECK-NEXT: "RCU": 0,
# CHECK-NEXT: "SCHEDQ": 0,
# CHECK-NEXT: "SQ": 0,
# CHECK-NEXT: "USH": 0
# CHECK-NEXT: },
# CHECK-NEXT: "InstructionInfoView": {
# CHECK-NEXT: "InstructionList": [
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 0,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 1,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 2,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 3,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "Instructions": [
# CHECK-NEXT: "addl\t%eax, %eax",
# CHECK-NEXT: "addl\t%ebx, %ebx",
# CHECK-NEXT: "addl\t%ecx, %ecx",
# CHECK-NEXT: "addl\t%edx, %edx"
# CHECK-NEXT: ],
# CHECK-NEXT: "ResourcePressureView": {
# CHECK-NEXT: "ResourcePressureInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 0,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 1,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 3,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "SummaryView": {
# CHECK-NEXT: "BlockRThroughput": 1,
# CHECK-NEXT: "DispatchWidth": 4,
# CHECK-NEXT: "IPC": 3.883495145631068,
# CHECK-NEXT: "Instructions": 400,
# CHECK-NEXT: "Iterations": 100,
# CHECK-NEXT: "TotalCycles": 103,
# CHECK-NEXT: "TotaluOps": 400,
# CHECK-NEXT: "uOpsPerCycle": 3.883495145631068
# CHECK-NEXT: },
# CHECK-NEXT: "TimelineView": {
# CHECK-NEXT: "TimelineInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: }
# CHECK-NEXT: }

View File

@ -14,162 +14,162 @@ add %ecx, %ecx
add %edx, %edx
# CHECK: {
# CHECK-NEXT: "DispatchStatistics": {
# CHECK-NEXT: "GROUP": 0,
# CHECK-NEXT: "LQ": 0,
# CHECK-NEXT: "RAT": 0,
# CHECK-NEXT: "RCU": 0,
# CHECK-NEXT: "SCHEDQ": 0,
# CHECK-NEXT: "SQ": 0,
# CHECK-NEXT: "USH": 0
# CHECK-NEXT: },
# CHECK-NEXT: "InstructionInfoView": {
# CHECK-NEXT: "InstructionList": [
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 0,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 1,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 2,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 3,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: }
# CHECK-NEXT: "Resources": {
# CHECK-NEXT: "CPUName": "haswell",
# CHECK-NEXT: "Resources": [
# CHECK-NEXT: "HWDivider",
# CHECK-NEXT: "HWFPDivider",
# CHECK-NEXT: "HWPort0",
# CHECK-NEXT: "HWPort1",
# CHECK-NEXT: "HWPort2",
# CHECK-NEXT: "HWPort3",
# CHECK-NEXT: "HWPort4",
# CHECK-NEXT: "HWPort5",
# CHECK-NEXT: "HWPort6",
# CHECK-NEXT: "HWPort7"
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "Instructions and CPU resources": {
# CHECK-NEXT: "main": {
# CHECK-NEXT: "DispatchStatistics": {
# CHECK-NEXT: "GROUP": 0,
# CHECK-NEXT: "LQ": 0,
# CHECK-NEXT: "RAT": 0,
# CHECK-NEXT: "RCU": 0,
# CHECK-NEXT: "SCHEDQ": 0,
# CHECK-NEXT: "SQ": 0,
# CHECK-NEXT: "USH": 0
# CHECK-NEXT: },
# CHECK-NEXT: "InstructionInfoView": {
# CHECK-NEXT: "InstructionList": [
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 0,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 1,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 2,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "Instruction": 3,
# CHECK-NEXT: "Latency": 1,
# CHECK-NEXT: "NumMicroOpcodes": 1,
# CHECK-NEXT: "RThroughput": 0.25,
# CHECK-NEXT: "hasUnmodeledSideEffects": false,
# CHECK-NEXT: "mayLoad": false,
# CHECK-NEXT: "mayStore": false
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "Instructions": [
# CHECK-NEXT: "addl\t%eax, %eax",
# CHECK-NEXT: "addl\t%ebx, %ebx",
# CHECK-NEXT: "addl\t%ecx, %ecx",
# CHECK-NEXT: "addl\t%edx, %edx"
# CHECK-NEXT: ],
# CHECK-NEXT: "Resources": {
# CHECK-NEXT: "CPUName": "haswell",
# CHECK-NEXT: "Resources": [
# CHECK-NEXT: "HWDivider",
# CHECK-NEXT: "HWFPDivider",
# CHECK-NEXT: "HWPort0",
# CHECK-NEXT: "HWPort1",
# CHECK-NEXT: "HWPort2",
# CHECK-NEXT: "HWPort3",
# CHECK-NEXT: "HWPort4",
# CHECK-NEXT: "HWPort5",
# CHECK-NEXT: "HWPort6",
# CHECK-NEXT: "HWPort7"
# CHECK-NEXT: "ResourcePressureView": {
# CHECK-NEXT: "ResourcePressureInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 0,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 1,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 3,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "SummaryView": {
# CHECK-NEXT: "BlockRThroughput": 1,
# CHECK-NEXT: "DispatchWidth": 4,
# CHECK-NEXT: "IPC": 3.883495145631068,
# CHECK-NEXT: "Instructions": 400,
# CHECK-NEXT: "Iterations": 100,
# CHECK-NEXT: "TotalCycles": 103,
# CHECK-NEXT: "TotaluOps": 400,
# CHECK-NEXT: "uOpsPerCycle": 3.883495145631068
# CHECK-NEXT: },
# CHECK-NEXT: "TimelineView": {
# CHECK-NEXT: "TimelineInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: },
# CHECK-NEXT: "ResourcePressureView": {
# CHECK-NEXT: "ResourcePressureInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 0,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 1,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 2,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 3,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 2,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 3,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 7,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "InstructionIndex": 4,
# CHECK-NEXT: "ResourceIndex": 8,
# CHECK-NEXT: "ResourceUsage": 1
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: },
# CHECK-NEXT: "SummaryView": {
# CHECK-NEXT: "BlockRThroughput": 1,
# CHECK-NEXT: "DispatchWidth": 4,
# CHECK-NEXT: "IPC": 3.883495145631068,
# CHECK-NEXT: "Instructions": 400,
# CHECK-NEXT: "Iterations": 100,
# CHECK-NEXT: "TotalCycles": 103,
# CHECK-NEXT: "TotaluOps": 400,
# CHECK-NEXT: "uOpsPerCycle": 3.883495145631068
# CHECK-NEXT: },
# CHECK-NEXT: "TimelineView": {
# CHECK-NEXT: "TimelineInfo": [
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: },
# CHECK-NEXT: {
# CHECK-NEXT: "CycleDispatched": 0,
# CHECK-NEXT: "CycleExecuted": 2,
# CHECK-NEXT: "CycleIssued": 1,
# CHECK-NEXT: "CycleReady": 0,
# CHECK-NEXT: "CycleRetired": 3
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: }
# CHECK-NEXT: }

View File

@ -17,19 +17,21 @@
namespace llvm {
namespace mca {
json::Object PipelinePrinter::getJSONReportRegion() const {
json::Object JO;
for (const auto &V : Views) {
if (V->isSerializable()) {
JO.try_emplace(V->getNameAsString().str(), V->toJSON());
}
}
return JO;
}
void PipelinePrinter::printReport(llvm::raw_ostream &OS) const {
json::Object JO;
for (const auto &V : Views) {
if ((OutputKind == View::OK_JSON)) {
if (V->isSerializable()) {
JO.try_emplace(V->getNameAsString().str(), V->toJSON());
}
} else {
V->printView(OS);
}
V->printView(OS);
}
if (OutputKind == View::OK_JSON)
OS << formatv("{0:2}", json::Value(std::move(JO))) << "\n";
}
} // namespace mca.
} // namespace llvm

View File

@ -48,6 +48,7 @@ public:
}
void printReport(llvm::raw_ostream &OS) const;
json::Object getJSONReportRegion() const;
};
} // namespace mca
} // namespace llvm

View File

@ -28,14 +28,15 @@ StringRef InstructionView::printInstructionString(const llvm::MCInst &MCI) const
}
json::Value InstructionView::toJSON() const {
json::Object JO;
json::Array SourceInfo;
for (const auto &MCI : getSource()) {
StringRef Instruction = printInstructionString(MCI);
SourceInfo.push_back(Instruction.str());
}
JO.try_emplace("Instructions", std::move(SourceInfo));
return SourceInfo;
}
json::Object InstructionView::getJSONResources() const {
json::Array Resources;
const MCSchedModel &SM = STI.getSchedModel();
for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) {
@ -52,9 +53,7 @@ json::Value InstructionView::toJSON() const {
Resources.push_back(ResNameStream.str());
}
}
JO.try_emplace("Resources", json::Object({{"CPUName", MCPU}, {"Resources", std::move(Resources)}}));
return JO;
return json::Object({{"CPUName", MCPU}, {"Resources", std::move(Resources)}});
}
} // namespace mca
} // namespace llvm

View File

@ -45,7 +45,7 @@ public:
virtual ~InstructionView() = default;
StringRef getNameAsString() const override {
return "Instructions and CPU resources";
return "Instructions";
}
// Return a reference to a string representing a given machine instruction.
// The result should be used or copied before the next call to
@ -56,6 +56,7 @@ public:
llvm::MCInstPrinter &getInstPrinter() const { return MCIP; }
llvm::ArrayRef<llvm::MCInst> getSource() const { return Source; }
json::Value toJSON() const override;
json::Object getJSONResources() const;
virtual void printViewJSON(llvm::raw_ostream &OS) override {
json::Value JV = toJSON();
OS << formatv("{0:2}", JV) << "\n";

View File

@ -523,6 +523,7 @@ int main(int argc, char **argv) {
*STI, *MRI, mc::InitMCTargetOptionsFromFlags()));
assert(MAB && "Unable to create asm backend!");
json::Object JSONOutput;
for (const std::unique_ptr<mca::CodeRegion> &Region : Regions) {
// Skip empty code regions.
if (Region->empty())
@ -530,7 +531,8 @@ int main(int argc, char **argv) {
// Don't print the header of this region if it is the default region, and
// it doesn't have an end location.
if (Region->startLoc().isValid() || Region->endLoc().isValid()) {
if (!PrintJson &&
(Region->startLoc().isValid() || Region->endLoc().isValid())) {
TOF->os() << "\n[" << RegionIdx++ << "] Code Region";
StringRef Desc = Region->getDescription();
if (!Desc.empty())
@ -590,7 +592,14 @@ int main(int argc, char **argv) {
if (!runPipeline(*P))
return 1;
Printer.printReport(TOF->os());
if (PrintJson) {
JSONOutput.try_emplace(!Region->getDescription().empty()
? Region->getDescription().str()
: "main",
Printer.getJSONReportRegion());
} else {
Printer.printReport(TOF->os());
}
continue;
}
@ -610,9 +619,13 @@ int main(int argc, char **argv) {
// When we output JSON, we add a view that contains the instructions
// and CPU resource information.
if (PrintJson)
Printer.addView(
std::make_unique<mca::InstructionView>(*STI, *IP, Insts, MCPU));
if (PrintJson) {
auto IV = std::make_unique<mca::InstructionView>(*STI, *IP, Insts, MCPU);
if (JSONOutput.find("Resources") == JSONOutput.end()) {
JSONOutput.try_emplace("Resources", IV->getJSONResources());
}
Printer.addView(std::move(IV));
}
if (PrintSummaryView)
Printer.addView(
@ -659,12 +672,22 @@ int main(int argc, char **argv) {
if (!runPipeline(*P))
return 1;
Printer.printReport(TOF->os());
if (PrintJson) {
JSONOutput.try_emplace(!Region->getDescription().empty()
? Region->getDescription().str()
: "main",
Printer.getJSONReportRegion());
} else {
Printer.printReport(TOF->os());
}
// Clear the InstrBuilder internal state in preparation for another round.
IB.clear();
}
if (PrintJson)
TOF->os() << formatv("{0:2}", json::Value(std::move(JSONOutput))) << "\n";
TOF->keep();
return 0;
}