Matt Davis | 712db51 | 2018-06-18 21:38:38 +0000 | [diff] [blame] | 1 | //===--------------------- InstructionInfoView.cpp --------------*- C++ -*-===// |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// |
Matt Davis | 712db51 | 2018-06-18 21:38:38 +0000 | [diff] [blame] | 10 | /// This file implements the InstructionInfoView API. |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Matt Davis | 10aa09f | 2018-08-24 20:24:53 +0000 | [diff] [blame] | 14 | #include "Views/InstructionInfoView.h" |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 15 | |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 16 | namespace llvm { |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 17 | namespace mca { |
| 18 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 19 | void InstructionInfoView::printView(raw_ostream &OS) const { |
| 20 | std::string Buffer; |
| 21 | raw_string_ostream TempStream(Buffer); |
| 22 | const MCSchedModel &SM = STI.getSchedModel(); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 23 | |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 24 | std::string Instruction; |
| 25 | raw_string_ostream InstrStream(Instruction); |
| 26 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 27 | TempStream << "\n\nInstruction Info:\n"; |
| 28 | TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n" |
Andrea Di Biagio | d2e2c05 | 2018-07-11 12:44:44 +0000 | [diff] [blame] | 29 | << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects (U)\n\n"; |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 30 | |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 31 | TempStream << "[1] [2] [3] [4] [5] [6] Instructions:\n"; |
Andrea Di Biagio | 7be45b0f | 2018-10-24 15:06:27 +0000 | [diff] [blame] | 32 | for (const MCInst &Inst : Source) { |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 33 | const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode()); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 34 | |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 35 | // Obtain the scheduling class information from the instruction. |
| 36 | unsigned SchedClassID = MCDesc.getSchedClass(); |
| 37 | unsigned CPUID = SM.getProcessorID(); |
| 38 | |
| 39 | // Try to solve variant scheduling classes. |
| 40 | while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant()) |
| 41 | SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &Inst, CPUID); |
| 42 | |
| 43 | const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 44 | unsigned NumMicroOpcodes = SCDesc.NumMicroOps; |
| 45 | unsigned Latency = MCSchedModel::computeInstrLatency(STI, SCDesc); |
Andrea Di Biagio | d768d35 | 2019-01-23 16:35:07 +0000 | [diff] [blame] | 46 | // Add extra latency due to delays in the forwarding data paths. |
| 47 | Latency += MCSchedModel::getForwardingDelayCycles( |
| 48 | STI.getReadAdvanceEntries(SCDesc)); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 49 | Optional<double> RThroughput = |
| 50 | MCSchedModel::getReciprocalThroughput(STI, SCDesc); |
| 51 | |
| 52 | TempStream << ' ' << NumMicroOpcodes << " "; |
| 53 | if (NumMicroOpcodes < 10) |
| 54 | TempStream << " "; |
| 55 | else if (NumMicroOpcodes < 100) |
| 56 | TempStream << ' '; |
| 57 | TempStream << Latency << " "; |
| 58 | if (Latency < 10) |
| 59 | TempStream << " "; |
| 60 | else if (Latency < 100) |
| 61 | TempStream << ' '; |
| 62 | |
| 63 | if (RThroughput.hasValue()) { |
| 64 | double RT = RThroughput.getValue(); |
| 65 | TempStream << format("%.2f", RT) << ' '; |
| 66 | if (RT < 10.0) |
| 67 | TempStream << " "; |
| 68 | else if (RT < 100.0) |
| 69 | TempStream << ' '; |
| 70 | } else { |
| 71 | TempStream << " - "; |
| 72 | } |
| 73 | TempStream << (MCDesc.mayLoad() ? " * " : " "); |
| 74 | TempStream << (MCDesc.mayStore() ? " * " : " "); |
Andrea Di Biagio | d2e2c05 | 2018-07-11 12:44:44 +0000 | [diff] [blame] | 75 | TempStream << (MCDesc.hasUnmodeledSideEffects() ? " U " : " "); |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 76 | |
| 77 | MCIP.printInst(&Inst, InstrStream, "", STI); |
| 78 | InstrStream.flush(); |
| 79 | |
| 80 | // Consume any tabs or spaces at the beginning of the string. |
| 81 | StringRef Str(Instruction); |
| 82 | Str = Str.ltrim(); |
| 83 | TempStream << " " << Str << '\n'; |
| 84 | Instruction = ""; |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | TempStream.flush(); |
| 88 | OS << Buffer; |
| 89 | } |
| 90 | } // namespace mca. |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 91 | } // namespace llvm |