1 //===--------------------- InstructionInfoView.cpp --------------*- C++ -*-===// 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 /// 11 /// This file implements the InstructionInfoView API. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #include "InstructionInfoView.h" 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(); 25 unsigned Instructions = Source.size(); 26 27 std::string Instruction; 28 raw_string_ostream InstrStream(Instruction); 29 30 TempStream << "\n\nInstruction Info:\n"; 31 TempStream << "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n" 32 << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects (U)\n\n"; 33 34 TempStream << "[1] [2] [3] [4] [5] [6] Instructions:\n"; 35 for (unsigned I = 0, E = Instructions; I < E; ++I) { 36 const MCInst &Inst = Source.getMCInstFromIndex(I); 37 const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode()); 38 39 // Obtain the scheduling class information from the instruction. 40 unsigned SchedClassID = MCDesc.getSchedClass(); 41 unsigned CPUID = SM.getProcessorID(); 42 43 // Try to solve variant scheduling classes. 44 while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant()) 45 SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &Inst, CPUID); 46 47 const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SchedClassID); 48 unsigned NumMicroOpcodes = SCDesc.NumMicroOps; 49 unsigned Latency = MCSchedModel::computeInstrLatency(STI, SCDesc); 50 Optional<double> RThroughput = 51 MCSchedModel::getReciprocalThroughput(STI, SCDesc); 52 53 TempStream << ' ' << NumMicroOpcodes << " "; 54 if (NumMicroOpcodes < 10) 55 TempStream << " "; 56 else if (NumMicroOpcodes < 100) 57 TempStream << ' '; 58 TempStream << Latency << " "; 59 if (Latency < 10) 60 TempStream << " "; 61 else if (Latency < 100) 62 TempStream << ' '; 63 64 if (RThroughput.hasValue()) { 65 double RT = RThroughput.getValue(); 66 TempStream << format("%.2f", RT) << ' '; 67 if (RT < 10.0) 68 TempStream << " "; 69 else if (RT < 100.0) 70 TempStream << ' '; 71 } else { 72 TempStream << " - "; 73 } 74 TempStream << (MCDesc.mayLoad() ? " * " : " "); 75 TempStream << (MCDesc.mayStore() ? " * " : " "); 76 TempStream << (MCDesc.hasUnmodeledSideEffects() ? " U " : " "); 77 78 MCIP.printInst(&Inst, InstrStream, "", STI); 79 InstrStream.flush(); 80 81 // Consume any tabs or spaces at the beginning of the string. 82 StringRef Str(Instruction); 83 Str = Str.ltrim(); 84 TempStream << " " << Str << '\n'; 85 Instruction = ""; 86 } 87 88 TempStream.flush(); 89 OS << Buffer; 90 } 91 } // namespace mca. 92