Skip to content

Commit edbf06a

Browse files
committed
[AsmPrinter] Remove hidden flag -print-schedule.
This patch removes hidden codegen flag -print-schedule effectively reverting the logic originally committed as r300311 (https://llvm.org/viewvc/llvm-project?view=revision&revision=300311). Flag -print-schedule was originally introduced by r300311 to address PR32216 (https://bugs.llvm.org/show_bug.cgi?id=32216). That bug was about adding "Better testing of schedule model instruction latencies/throughputs". These days, we can use llvm-mca to test scheduling models. So there is no longer a need for flag -print-schedule in LLVM. The main use case for PR32216 is now addressed by llvm-mca. Flag -print-schedule is mainly used for debugging purposes, and it is only actually used by x86 specific tests. We already have extensive (latency and throughput) tests under "test/tools/llvm-mca" for X86 processor models. That means, most (if not all) existing -print-schedule tests for X86 are redundant. When flag -print-schedule was first added to LLVM, several files had to be modified; a few APIs gained new arguments (see for example method MCAsmStreamer::EmitInstruction), and MCSubtargetInfo/TargetSubtargetInfo gained a couple of getSchedInfoStr() methods. Method getSchedInfoStr() had to originally work for both MCInst and MachineInstr. The original implmentation of getSchedInfoStr() introduced a subtle layering violation (reported as PR37160 and then fixed/worked-around by r330615). In retrospect, that new API could have been designed more optimally. We can always query MCSchedModel to get the latency and throughput. More importantly, the "sched-info" string should not have been generated by the subtarget. Note, r317782 fixed an issue where "print-schedule" didn't work very well in the presence of inline assembly. That commit is also reverted by this change. Differential Revision: https://reviews.llvm.org/D57244 llvm-svn: 353043
1 parent fb222aa commit edbf06a

File tree

79 files changed

+2485
-129452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2485
-129452
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ class AsmPrinter : public MachineFunctionPass {
121121
using GOTEquivUsePair = std::pair<const GlobalVariable *, unsigned>;
122122
MapVector<const MCSymbol *, GOTEquivUsePair> GlobalGOTEquivs;
123123

124-
/// Enable print [latency:throughput] in output.
125-
bool EnablePrintSchedInfo = false;
126-
127124
private:
128125
MCSymbol *CurrentFnBegin = nullptr;
129126
MCSymbol *CurrentFnEnd = nullptr;

llvm/include/llvm/CodeGen/TargetSubtargetInfo.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
189189
/// TargetLowering preference). It does not yet disable the postRA scheduler.
190190
virtual bool enableMachineScheduler() const;
191191

192-
/// Support printing of [latency:throughput] comment in output .S file.
193-
virtual bool supportPrintSchedInfo() const { return false; }
194-
195192
/// True if the machine scheduler should disable the TLI preference
196193
/// for preRA scheduling with the source level scheduler.
197194
virtual bool enableMachineSchedDefaultSched() const { return true; }
@@ -285,10 +282,6 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
285282
/// possible.
286283
virtual bool enableSubRegLiveness() const { return false; }
287284

288-
/// Returns string representation of scheduler comment
289-
std::string getSchedInfoStr(const MachineInstr &MI) const;
290-
std::string getSchedInfoStr(MCInst const &MCI) const override;
291-
292285
/// This is called after a .mir file was loaded.
293286
virtual void mirFileLoaded(MachineFunction &MF) const;
294287
};

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ class MCObjectStreamer : public MCStreamer {
115115
void EmitSLEB128Value(const MCExpr *Value) override;
116116
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
117117
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
118-
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
119-
bool = false) override;
118+
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
120119

121120
/// Emit an instruction to a special fragment, because this instruction
122121
/// can change its size during relaxation.

llvm/include/llvm/MC/MCParser/MCAsmParser.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,6 @@ class MCAsmParser {
129129
/// Flag tracking whether any errors have been encountered.
130130
bool HadError = false;
131131

132-
/// Enable print [latency:throughput] in output file.
133-
bool EnablePrintSchedInfo = false;
134-
135132
bool ShowParsedOperands = false;
136133

137134
public:
@@ -165,9 +162,6 @@ class MCAsmParser {
165162
bool getShowParsedOperands() const { return ShowParsedOperands; }
166163
void setShowParsedOperands(bool Value) { ShowParsedOperands = Value; }
167164

168-
void setEnablePrintSchedInfo(bool Value) { EnablePrintSchedInfo = Value; }
169-
bool shouldPrintSchedInfo() const { return EnablePrintSchedInfo; }
170-
171165
/// Run the parser on the input source buffer.
172166
virtual bool Run(bool NoInitialTextSection, bool NoFinalize = false) = 0;
173167

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -952,9 +952,7 @@ class MCStreamer {
952952
virtual void EmitAddrsigSym(const MCSymbol *Sym) {}
953953

954954
/// Emit the given \p Instruction into the current section.
955-
/// PrintSchedInfo == true then schedul comment should be added to output
956-
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
957-
bool PrintSchedInfo = false);
955+
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
958956

959957
/// Set the bundle alignment mode from now on in the section.
960958
/// The argument is the power of 2 to which the alignment is set. The

llvm/include/llvm/MC/MCSubtargetInfo.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,6 @@ class MCSubtargetInfo {
180180
auto Found = std::lower_bound(ProcDesc.begin(), ProcDesc.end(), CPU);
181181
return Found != ProcDesc.end() && StringRef(Found->Key) == CPU;
182182
}
183-
184-
/// Returns string representation of scheduler comment
185-
virtual std::string getSchedInfoStr(MCInst const &MCI) const {
186-
return {};
187-
}
188183
};
189184

190185
} // end namespace llvm

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include "llvm/CodeGen/TargetLowering.h"
6060
#include "llvm/CodeGen/TargetOpcodes.h"
6161
#include "llvm/CodeGen/TargetRegisterInfo.h"
62-
#include "llvm/CodeGen/TargetSubtargetInfo.h"
6362
#include "llvm/IR/BasicBlock.h"
6463
#include "llvm/IR/Comdat.h"
6564
#include "llvm/IR/Constant.h"
@@ -142,10 +141,6 @@ static const char *const CodeViewLineTablesGroupDescription =
142141

143142
STATISTIC(EmittedInsts, "Number of machine instrs printed");
144143

145-
static cl::opt<bool>
146-
PrintSchedule("print-schedule", cl::Hidden, cl::init(false),
147-
cl::desc("Print 'sched: [latency:throughput]' in .s output"));
148-
149144
char AsmPrinter::ID = 0;
150145

151146
using gcp_map_type = DenseMap<GCStrategy *, std::unique_ptr<GCMetadataPrinter>>;
@@ -746,18 +741,14 @@ void AsmPrinter::EmitFunctionEntryLabel() {
746741
}
747742

748743
/// emitComments - Pretty-print comments for instructions.
749-
/// It returns true iff the sched comment was emitted.
750-
/// Otherwise it returns false.
751-
static bool emitComments(const MachineInstr &MI, raw_ostream &CommentOS,
752-
AsmPrinter *AP) {
744+
static void emitComments(const MachineInstr &MI, raw_ostream &CommentOS) {
753745
const MachineFunction *MF = MI.getMF();
754746
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
755747

756748
// Check for spills and reloads
757749
int FI;
758750

759751
const MachineFrameInfo &MFI = MF->getFrameInfo();
760-
bool Commented = false;
761752

762753
auto getSize =
763754
[&MFI](const SmallVectorImpl<const MachineMemOperand *> &Accesses) {
@@ -777,43 +768,24 @@ static bool emitComments(const MachineInstr &MI, raw_ostream &CommentOS,
777768
if (TII->isLoadFromStackSlotPostFE(MI, FI)) {
778769
if (MFI.isSpillSlotObjectIndex(FI)) {
779770
MMO = *MI.memoperands_begin();
780-
CommentOS << MMO->getSize() << "-byte Reload";
781-
Commented = true;
771+
CommentOS << MMO->getSize() << "-byte Reload\n";
782772
}
783773
} else if (TII->hasLoadFromStackSlot(MI, Accesses)) {
784-
if (auto Size = getSize(Accesses)) {
785-
CommentOS << Size << "-byte Folded Reload";
786-
Commented = true;
787-
}
774+
if (auto Size = getSize(Accesses))
775+
CommentOS << Size << "-byte Folded Reload\n";
788776
} else if (TII->isStoreToStackSlotPostFE(MI, FI)) {
789777
if (MFI.isSpillSlotObjectIndex(FI)) {
790778
MMO = *MI.memoperands_begin();
791-
CommentOS << MMO->getSize() << "-byte Spill";
792-
Commented = true;
779+
CommentOS << MMO->getSize() << "-byte Spill\n";
793780
}
794781
} else if (TII->hasStoreToStackSlot(MI, Accesses)) {
795-
if (auto Size = getSize(Accesses)) {
796-
CommentOS << Size << "-byte Folded Spill";
797-
Commented = true;
798-
}
782+
if (auto Size = getSize(Accesses))
783+
CommentOS << Size << "-byte Folded Spill\n";
799784
}
800785

801786
// Check for spill-induced copies
802-
if (MI.getAsmPrinterFlag(MachineInstr::ReloadReuse)) {
803-
Commented = true;
804-
CommentOS << " Reload Reuse";
805-
}
806-
807-
if (Commented) {
808-
if (AP->EnablePrintSchedInfo) {
809-
// If any comment was added above and we need sched info comment then add
810-
// this new comment just after the above comment w/o "\n" between them.
811-
CommentOS << " " << MF->getSubtarget().getSchedInfoStr(MI) << "\n";
812-
return true;
813-
}
814-
CommentOS << "\n";
815-
}
816-
return false;
787+
if (MI.getAsmPrinterFlag(MachineInstr::ReloadReuse))
788+
CommentOS << " Reload Reuse\n";
817789
}
818790

819791
/// emitImplicitDef - This method emits the specified machine instruction
@@ -1101,10 +1073,8 @@ void AsmPrinter::EmitFunctionBody() {
11011073
}
11021074
}
11031075

1104-
if (isVerbose() && emitComments(MI, OutStreamer->GetCommentOS(), this)) {
1105-
MachineInstr *MIP = const_cast<MachineInstr *>(&MI);
1106-
MIP->setAsmPrinterFlag(MachineInstr::NoSchedComment);
1107-
}
1076+
if (isVerbose())
1077+
emitComments(MI, OutStreamer->GetCommentOS());
11081078

11091079
switch (MI.getOpcode()) {
11101080
case TargetOpcode::CFI_INSTRUCTION:
@@ -1636,11 +1606,6 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
16361606
}
16371607

16381608
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE();
1639-
1640-
const TargetSubtargetInfo &STI = MF.getSubtarget();
1641-
EnablePrintSchedInfo = PrintSchedule.getNumOccurrences()
1642-
? PrintSchedule
1643-
: STI.supportPrintSchedInfo();
16441609
}
16451610

16461611
namespace {

llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/CodeGen/MachineModuleInfo.h"
1919
#include "llvm/CodeGen/TargetInstrInfo.h"
2020
#include "llvm/CodeGen/TargetRegisterInfo.h"
21-
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2221
#include "llvm/IR/Constants.h"
2322
#include "llvm/IR/DataLayout.h"
2423
#include "llvm/IR/InlineAsm.h"
@@ -154,7 +153,6 @@ void AsmPrinter::EmitInlineAsm(StringRef Str, const MCSubtargetInfo &STI,
154153
" we don't have an asm parser for this target\n");
155154
Parser->setAssemblerDialect(Dialect);
156155
Parser->setTargetParser(*TAP.get());
157-
Parser->setEnablePrintSchedInfo(EnablePrintSchedInfo);
158156
// Enable lexing Masm binary and hex integer literals in intel inline
159157
// assembly.
160158
if (Dialect == InlineAsm::AD_Intel)

llvm/lib/CodeGen/MachineCombiner.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,13 @@ bool MachineCombiner::combineInstructions(MachineBasicBlock *MBB) {
558558
continue;
559559

560560
LLVM_DEBUG(if (dump_intrs) {
561-
dbgs() << "\tFor the Pattern (" << (int)P << ") these instructions could be removed\n";
562-
for (auto const *InstrPtr : DelInstrs) {
563-
dbgs() << "\t\t" << STI->getSchedInfoStr(*InstrPtr) << ": ";
561+
dbgs() << "\tFor the Pattern (" << (int)P
562+
<< ") these instructions could be removed\n";
563+
for (auto const *InstrPtr : DelInstrs)
564564
InstrPtr->print(dbgs(), false, false, false, TII);
565-
}
566565
dbgs() << "\tThese instructions could replace the removed ones\n";
567-
for (auto const *InstrPtr : InsInstrs) {
568-
dbgs() << "\t\t" << STI->getSchedInfoStr(*InstrPtr) << ": ";
566+
for (auto const *InstrPtr : InsInstrs)
569567
InstrPtr->print(dbgs(), false, false, false, TII);
570-
}
571568
});
572569

573570
bool SubstituteAlways = false;

llvm/lib/CodeGen/TargetSubtargetInfo.cpp

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "llvm/CodeGen/TargetSubtargetInfo.h"
14-
#include "llvm/ADT/Optional.h"
15-
#include "llvm/CodeGen/MachineInstr.h"
16-
#include "llvm/CodeGen/TargetInstrInfo.h"
17-
#include "llvm/CodeGen/TargetSchedule.h"
18-
#include "llvm/MC/MCInst.h"
19-
#include "llvm/Support/Format.h"
20-
#include "llvm/Support/raw_ostream.h"
21-
#include <string>
2214

2315
using namespace llvm;
2416

@@ -66,64 +58,4 @@ bool TargetSubtargetInfo::useAA() const {
6658
return false;
6759
}
6860

69-
static std::string createSchedInfoStr(unsigned Latency, double RThroughput) {
70-
static const char *SchedPrefix = " sched: [";
71-
std::string Comment;
72-
raw_string_ostream CS(Comment);
73-
if (RThroughput != 0.0)
74-
CS << SchedPrefix << Latency << format(":%2.2f", RThroughput)
75-
<< "]";
76-
else
77-
CS << SchedPrefix << Latency << ":?]";
78-
CS.flush();
79-
return Comment;
80-
}
81-
82-
/// Returns string representation of scheduler comment
83-
std::string TargetSubtargetInfo::getSchedInfoStr(const MachineInstr &MI) const {
84-
if (MI.isPseudo() || MI.isTerminator())
85-
return std::string();
86-
// We don't cache TSchedModel because it depends on TargetInstrInfo
87-
// that could be changed during the compilation
88-
TargetSchedModel TSchedModel;
89-
TSchedModel.init(this);
90-
unsigned Latency = TSchedModel.computeInstrLatency(&MI);
91-
92-
// Add extra latency due to forwarding delays.
93-
const MCSchedClassDesc &SCDesc = *TSchedModel.resolveSchedClass(&MI);
94-
Latency +=
95-
MCSchedModel::getForwardingDelayCycles(getReadAdvanceEntries(SCDesc));
96-
97-
double RThroughput = TSchedModel.computeReciprocalThroughput(&MI);
98-
return createSchedInfoStr(Latency, RThroughput);
99-
}
100-
101-
/// Returns string representation of scheduler comment
102-
std::string TargetSubtargetInfo::getSchedInfoStr(MCInst const &MCI) const {
103-
// We don't cache TSchedModel because it depends on TargetInstrInfo
104-
// that could be changed during the compilation
105-
TargetSchedModel TSchedModel;
106-
TSchedModel.init(this);
107-
unsigned Latency;
108-
if (TSchedModel.hasInstrSchedModel()) {
109-
Latency = TSchedModel.computeInstrLatency(MCI);
110-
// Add extra latency due to forwarding delays.
111-
const MCSchedModel &SM = *TSchedModel.getMCSchedModel();
112-
unsigned SClassID = getInstrInfo()->get(MCI.getOpcode()).getSchedClass();
113-
while (SM.getSchedClassDesc(SClassID)->isVariant())
114-
SClassID = resolveVariantSchedClass(SClassID, &MCI, SM.ProcID);
115-
const MCSchedClassDesc &SCDesc = *SM.getSchedClassDesc(SClassID);
116-
Latency +=
117-
MCSchedModel::getForwardingDelayCycles(getReadAdvanceEntries(SCDesc));
118-
} else if (TSchedModel.hasInstrItineraries()) {
119-
auto *ItinData = TSchedModel.getInstrItineraries();
120-
Latency = ItinData->getStageLatency(
121-
getInstrInfo()->get(MCI.getOpcode()).getSchedClass());
122-
} else
123-
return std::string();
124-
double RThroughput = TSchedModel.computeReciprocalThroughput(MCI);
125-
return createSchedInfoStr(Latency, RThroughput);
126-
}
127-
128-
void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const {
129-
}
61+
void TargetSubtargetInfo::mirFileLoaded(MachineFunction &MF) const { }

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ class MCAsmStreamer final : public MCStreamer {
107107
void AddComment(const Twine &T, bool EOL = true) override;
108108

109109
/// Add a comment showing the encoding of an instruction.
110-
/// If PrintSchedInfo is true, then the comment sched:[x:y] will be added to
111-
/// the output if supported by the target.
112-
void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &,
113-
bool PrintSchedInfo);
110+
void AddEncodingComment(const MCInst &Inst, const MCSubtargetInfo &);
114111

115112
/// Return a raw_ostream that comments can be written to.
116113
/// Unlike AddComment, you are required to terminate comments with \n if you
@@ -311,8 +308,7 @@ class MCAsmStreamer final : public MCStreamer {
311308
void emitCGProfileEntry(const MCSymbolRefExpr *From,
312309
const MCSymbolRefExpr *To, uint64_t Count) override;
313310

314-
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI,
315-
bool PrintSchedInfo) override;
311+
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
316312

317313
void EmitBundleAlignMode(unsigned AlignPow2) override;
318314
void EmitBundleLock(bool AlignToEnd) override;
@@ -1739,8 +1735,7 @@ void MCAsmStreamer::emitCGProfileEntry(const MCSymbolRefExpr *From,
17391735
}
17401736

17411737
void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
1742-
const MCSubtargetInfo &STI,
1743-
bool PrintSchedInfo) {
1738+
const MCSubtargetInfo &STI) {
17441739
raw_ostream &OS = GetCommentOS();
17451740
SmallString<256> Code;
17461741
SmallVector<MCFixup, 4> Fixups;
@@ -1819,11 +1814,7 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
18191814
}
18201815
}
18211816
}
1822-
OS << "]";
1823-
// If we are not going to add fixup or schedule comments after this point
1824-
// then we have to end the current comment line with "\n".
1825-
if (Fixups.size() || !PrintSchedInfo)
1826-
OS << "\n";
1817+
OS << "]\n";
18271818

18281819
for (unsigned i = 0, e = Fixups.size(); i != e; ++i) {
18291820
MCFixup &F = Fixups[i];
@@ -1835,18 +1826,15 @@ void MCAsmStreamer::AddEncodingComment(const MCInst &Inst,
18351826
}
18361827

18371828
void MCAsmStreamer::EmitInstruction(const MCInst &Inst,
1838-
const MCSubtargetInfo &STI,
1839-
bool PrintSchedInfo) {
1829+
const MCSubtargetInfo &STI) {
18401830
assert(getCurrentSectionOnly() &&
18411831
"Cannot emit contents before setting section!");
18421832

18431833
// Show the encoding in a comment if we have a code emitter.
1844-
AddEncodingComment(Inst, STI, PrintSchedInfo);
1834+
AddEncodingComment(Inst, STI);
18451835

18461836
// Show the MCInst if enabled.
18471837
if (ShowInst) {
1848-
if (PrintSchedInfo)
1849-
GetCommentOS() << "\n";
18501838
Inst.dump_pretty(GetCommentOS(), InstPrinter.get(), "\n ");
18511839
GetCommentOS() << "\n";
18521840
}
@@ -1856,12 +1844,6 @@ void MCAsmStreamer::EmitInstruction(const MCInst &Inst,
18561844
else
18571845
InstPrinter->printInst(&Inst, OS, "", STI);
18581846

1859-
if (PrintSchedInfo) {
1860-
std::string SI = STI.getSchedInfoStr(Inst);
1861-
if (!SI.empty())
1862-
GetCommentOS() << SI;
1863-
}
1864-
18651847
StringRef Comments = CommentToEmit;
18661848
if (Comments.size() && Comments.back() != '\n')
18671849
GetCommentOS() << "\n";

0 commit comments

Comments
 (0)