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