1 //===--------------------- InstructionInfoView.cpp --------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file implements the InstructionInfoView API.
12 //===----------------------------------------------------------------------===//
14 #include "Views/InstructionInfoView.h"
19 void InstructionInfoView::printView(raw_ostream
&OS
) const {
21 raw_string_ostream
TempStream(Buffer
);
22 const MCSchedModel
&SM
= STI
.getSchedModel();
24 std::string Instruction
;
25 raw_string_ostream
InstrStream(Instruction
);
27 TempStream
<< "\n\nInstruction Info:\n";
28 TempStream
<< "[1]: #uOps\n[2]: Latency\n[3]: RThroughput\n"
29 << "[4]: MayLoad\n[5]: MayStore\n[6]: HasSideEffects (U)\n\n";
31 TempStream
<< "[1] [2] [3] [4] [5] [6] Instructions:\n";
32 for (const MCInst
&Inst
: Source
) {
33 const MCInstrDesc
&MCDesc
= MCII
.get(Inst
.getOpcode());
35 // Obtain the scheduling class information from the instruction.
36 unsigned SchedClassID
= MCDesc
.getSchedClass();
37 unsigned CPUID
= SM
.getProcessorID();
39 // Try to solve variant scheduling classes.
40 while (SchedClassID
&& SM
.getSchedClassDesc(SchedClassID
)->isVariant())
41 SchedClassID
= STI
.resolveVariantSchedClass(SchedClassID
, &Inst
, CPUID
);
43 const MCSchedClassDesc
&SCDesc
= *SM
.getSchedClassDesc(SchedClassID
);
44 unsigned NumMicroOpcodes
= SCDesc
.NumMicroOps
;
45 unsigned Latency
= MCSchedModel::computeInstrLatency(STI
, SCDesc
);
46 // Add extra latency due to delays in the forwarding data paths.
47 Latency
+= MCSchedModel::getForwardingDelayCycles(
48 STI
.getReadAdvanceEntries(SCDesc
));
49 Optional
<double> RThroughput
=
50 MCSchedModel::getReciprocalThroughput(STI
, SCDesc
);
52 TempStream
<< ' ' << NumMicroOpcodes
<< " ";
53 if (NumMicroOpcodes
< 10)
55 else if (NumMicroOpcodes
< 100)
57 TempStream
<< Latency
<< " ";
60 else if (Latency
< 100)
63 if (RThroughput
.hasValue()) {
64 double RT
= RThroughput
.getValue();
65 TempStream
<< format("%.2f", RT
) << ' ';
73 TempStream
<< (MCDesc
.mayLoad() ? " * " : " ");
74 TempStream
<< (MCDesc
.mayStore() ? " * " : " ");
75 TempStream
<< (MCDesc
.hasUnmodeledSideEffects() ? " U " : " ");
77 MCIP
.printInst(&Inst
, InstrStream
, "", STI
);
80 // Consume any tabs or spaces at the beginning of the string.
81 StringRef
Str(Instruction
);
83 TempStream
<< " " << Str
<< '\n';