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 "Views/InstructionInfoView.h"
20 void InstructionInfoView::printView(raw_ostream &OS) const {
22 raw_string_ostream TempStream(Buffer);
23 const MCSchedModel &SM = STI.getSchedModel();
25 std::string Instruction;
26 raw_string_ostream InstrStream(Instruction);
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";
32 TempStream << "[1] [2] [3] [4] [5] [6] Instructions:\n";
33 for (const MCInst &Inst : Source) {
34 const MCInstrDesc &MCDesc = MCII.get(Inst.getOpcode());
36 // Obtain the scheduling class information from the instruction.
37 unsigned SchedClassID = MCDesc.getSchedClass();
38 unsigned CPUID = SM.getProcessorID();
40 // Try to solve variant scheduling classes.
41 while (SchedClassID && SM.getSchedClassDesc(SchedClassID)->isVariant())
42 SchedClassID = STI.resolveVariantSchedClass(SchedClassID, &Inst, CPUID);
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);
50 TempStream << ' ' << NumMicroOpcodes << " ";
51 if (NumMicroOpcodes < 10)
53 else if (NumMicroOpcodes < 100)
55 TempStream << Latency << " ";
58 else if (Latency < 100)
61 if (RThroughput.hasValue()) {
62 double RT = RThroughput.getValue();
63 TempStream << format("%.2f", RT) << ' ';
71 TempStream << (MCDesc.mayLoad() ? " * " : " ");
72 TempStream << (MCDesc.mayStore() ? " * " : " ");
73 TempStream << (MCDesc.hasUnmodeledSideEffects() ? " U " : " ");
75 MCIP.printInst(&Inst, InstrStream, "", STI);
78 // Consume any tabs or spaces at the beginning of the string.
79 StringRef Str(Instruction);
81 TempStream << " " << Str << '\n';