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