1 //===--------------------- InstructionInfoView.cpp --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file implements the InstructionInfoView API.
13 //===----------------------------------------------------------------------===//
15 #include "InstructionInfoView.h"
21 void InstructionInfoView::printView(raw_ostream &OS) const {
23 raw_string_ostream TempStream(Buffer);
24 const MCSchedModel &SM = STI.getSchedModel();
25 unsigned Instructions = Source.size();
27 std::string Instruction;
28 raw_string_ostream InstrStream(Instruction);
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";
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());
39 // Obtain the scheduling class information from the instruction.
40 unsigned SchedClassID = MCDesc.getSchedClass();
41 unsigned CPUID = SM.getProcessorID();
43 // Try to solve variant scheduling classes.
44 while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant())
45 SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &Inst, CPUID);
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);
53 TempStream << ' ' << NumMicroOpcodes << " ";
54 if (NumMicroOpcodes < 10)
56 else if (NumMicroOpcodes < 100)
58 TempStream << Latency << " ";
61 else if (Latency < 100)
64 if (RThroughput.hasValue()) {
65 double RT = RThroughput.getValue();
66 TempStream << format("%.2f", RT) << ' ';
74 TempStream << (MCDesc.mayLoad() ? " * " : " ");
75 TempStream << (MCDesc.mayStore() ? " * " : " ");
76 TempStream << (MCDesc.hasUnmodeledSideEffects() ? " U " : " ");
78 MCIP.printInst(&Inst, InstrStream, "", STI);
81 // Consume any tabs or spaces at the beginning of the string.
82 StringRef Str(Instruction);
84 TempStream << " " << Str << '\n';