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 | cbec9af | 2019-08-09 11:26:27 +0000 | [diff] [blame^] | 15 | #include "llvm/Support/FormattedStream.h" |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 16 | |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 17 | namespace llvm { |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 18 | namespace mca { |
| 19 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 20 | void InstructionInfoView::printView(raw_ostream &OS) const { |
| 21 | std::string Buffer; |
| 22 | raw_string_ostream TempStream(Buffer); |
| 23 | const MCSchedModel &SM = STI.getSchedModel(); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 24 | |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 25 | std::string Instruction; |
| 26 | raw_string_ostream InstrStream(Instruction); |
| 27 | |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 28 | TempStream << "\n\nInstruction Info:\n"; |
| 29 | TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n" |
Andrea Di Biagio | cbec9af | 2019-08-09 11:26:27 +0000 | [diff] [blame^] | 30 | << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects (U)\n"; |
| 31 | if (PrintEncodings) { |
| 32 | TempStream << "[7]: Encoding Size\n"; |
| 33 | TempStream << "\n[1] [2] [3] [4] [5] [6] [7] " |
| 34 | << "Encodings: Instructions:\n"; |
| 35 | } else { |
| 36 | TempStream << "\n[1] [2] [3] [4] [5] [6] Instructions:\n"; |
| 37 | } |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 38 | |
Andrea Di Biagio | cbec9af | 2019-08-09 11:26:27 +0000 | [diff] [blame^] | 39 | for (unsigned I = 0, E = Source.size(); I < E; ++I) { |
| 40 | const MCInst &Inst = Source[I]; |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 41 | const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode()); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 42 | |
Andrea Di Biagio | 39e5a56 | 2018-06-04 15:43:09 +0000 | [diff] [blame] | 43 | // Obtain the scheduling class information from the instruction. |
| 44 | unsigned SchedClassID = MCDesc.getSchedClass(); |
| 45 | unsigned CPUID = SM.getProcessorID(); |
| 46 | |
| 47 | // Try to solve variant scheduling classes. |
| 48 | while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant()) |
| 49 | SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &Inst, CPUID); |
| 50 | |
| 51 | const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 52 | unsigned NumMicroOpcodes = SCDesc.NumMicroOps; |
| 53 | unsigned Latency = MCSchedModel::computeInstrLatency(STI, SCDesc); |
Andrea Di Biagio | d768d35 | 2019-01-23 16:35:07 +0000 | [diff] [blame] | 54 | // Add extra latency due to delays in the forwarding data paths. |
| 55 | Latency += MCSchedModel::getForwardingDelayCycles( |
| 56 | STI.getReadAdvanceEntries(SCDesc)); |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 57 | Optional<double> RThroughput = |
| 58 | MCSchedModel::getReciprocalThroughput(STI, SCDesc); |
| 59 | |
| 60 | TempStream << ' ' << NumMicroOpcodes << " "; |
| 61 | if (NumMicroOpcodes < 10) |
| 62 | TempStream << " "; |
| 63 | else if (NumMicroOpcodes < 100) |
| 64 | TempStream << ' '; |
| 65 | TempStream << Latency << " "; |
| 66 | if (Latency < 10) |
| 67 | TempStream << " "; |
| 68 | else if (Latency < 100) |
| 69 | TempStream << ' '; |
| 70 | |
| 71 | if (RThroughput.hasValue()) { |
| 72 | double RT = RThroughput.getValue(); |
| 73 | TempStream << format("%.2f", RT) << ' '; |
| 74 | if (RT < 10.0) |
| 75 | TempStream << " "; |
| 76 | else if (RT < 100.0) |
| 77 | TempStream << ' '; |
| 78 | } else { |
| 79 | TempStream << " - "; |
| 80 | } |
| 81 | TempStream << (MCDesc.mayLoad() ? " * " : " "); |
| 82 | TempStream << (MCDesc.mayStore() ? " * " : " "); |
Andrea Di Biagio | cbec9af | 2019-08-09 11:26:27 +0000 | [diff] [blame^] | 83 | TempStream << (MCDesc.hasUnmodeledSideEffects() ? " U " : " "); |
| 84 | |
| 85 | if (PrintEncodings) { |
| 86 | StringRef Encoding(CE.getEncoding(I)); |
| 87 | unsigned EncodingSize = Encoding.size(); |
| 88 | TempStream << " " << EncodingSize |
| 89 | << (EncodingSize < 10 ? " " : " "); |
| 90 | TempStream.flush(); |
| 91 | formatted_raw_ostream FOS(TempStream); |
| 92 | for (unsigned i = 0, e = Encoding.size(); i != e; ++i) |
| 93 | FOS << format("%02x ", (uint8_t)Encoding[i]); |
| 94 | FOS.PadToColumn(30); |
| 95 | FOS.flush(); |
| 96 | } |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 97 | |
| 98 | MCIP.printInst(&Inst, InstrStream, "", STI); |
| 99 | InstrStream.flush(); |
| 100 | |
| 101 | // Consume any tabs or spaces at the beginning of the string. |
| 102 | StringRef Str(Instruction); |
| 103 | Str = Str.ltrim(); |
Andrea Di Biagio | cbec9af | 2019-08-09 11:26:27 +0000 | [diff] [blame^] | 104 | TempStream << Str << '\n'; |
Andrea Di Biagio | a7c3c45 | 2018-05-15 15:18:05 +0000 | [diff] [blame] | 105 | Instruction = ""; |
Andrea Di Biagio | df5d948 | 2018-03-23 19:40:04 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | TempStream.flush(); |
| 109 | OS << Buffer; |
| 110 | } |
| 111 | } // namespace mca. |
Fangrui Song | 5a8fd65 | 2018-10-30 15:56:08 +0000 | [diff] [blame] | 112 | } // namespace llvm |