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