From: Daniel Sanders Date: Mon, 29 Apr 2019 18:45:59 +0000 (+0000) Subject: [globalisel] Improve Legalizer debug output X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8488f421468a7076cf1763d1f4374ad258b4c927;p=llvm [globalisel] Improve Legalizer debug output * LegalizeAction should be printed by name rather than number * Newly created instructions are incomplete at the point the observer first sees them. They are therefore recorded in a small vector and printed just before the legalizer moves on to another instruction. By this point, the instruction must be complete. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359481 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h index 6e4c9674519..d38dbf9e0d1 100644 --- a/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ b/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -92,6 +92,7 @@ enum LegalizeAction : std::uint8_t { UseLegacyRules, }; } // end namespace LegalizeActions +raw_ostream &operator<<(raw_ostream &OS, LegalizeActions::LegalizeAction Action); using LegalizeActions::LegalizeAction; diff --git a/lib/CodeGen/GlobalISel/Legalizer.cpp b/lib/CodeGen/GlobalISel/Legalizer.cpp index 52a6bb66570..9efeeb4c5a3 100644 --- a/lib/CodeGen/GlobalISel/Legalizer.cpp +++ b/lib/CodeGen/GlobalISel/Legalizer.cpp @@ -88,12 +88,15 @@ namespace { class LegalizerWorkListManager : public GISelChangeObserver { InstListTy &InstList; ArtifactListTy &ArtifactList; +#ifndef NDEBUG + SmallVector NewMIs; +#endif public: LegalizerWorkListManager(InstListTy &Insts, ArtifactListTy &Arts) : InstList(Insts), ArtifactList(Arts) {} - void createdInstr(MachineInstr &MI) override { + void createdOrChangedInstr(MachineInstr &MI) { // Only legalize pre-isel generic instructions. // Legalization process could generate Target specific pseudo // instructions with generic types. Don't record them @@ -103,7 +106,20 @@ public: else InstList.insert(&MI); } + } + + void createdInstr(MachineInstr &MI) override { LLVM_DEBUG(dbgs() << ".. .. New MI: " << MI); + LLVM_DEBUG(NewMIs.push_back(&MI)); + createdOrChangedInstr(MI); + } + + void printNewInstrs() { + LLVM_DEBUG({ + for (const auto *MI : NewMIs) + dbgs() << ".. .. New MI: " << *MI; + NewMIs.clear(); + }); } void erasingInstr(MachineInstr &MI) override { @@ -120,7 +136,7 @@ public: // When insts change, we want to revisit them to legalize them again. // We'll consider them the same as created. LLVM_DEBUG(dbgs() << ".. .. Changed MI: " << MI); - createdInstr(MI); + createdOrChangedInstr(MI); } }; } // namespace @@ -213,6 +229,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) { "unable to legalize instruction", MI); return false; } + WorkListObserver.printNewInstrs(); Changed |= Res == LegalizerHelper::Legalized; } while (!ArtifactList.empty()) { @@ -227,6 +244,7 @@ bool Legalizer::runOnMachineFunction(MachineFunction &MF) { SmallVector DeadInstructions; if (ArtCombiner.tryCombineInstruction(MI, DeadInstructions, WrapperObserver)) { + WorkListObserver.printNewInstrs(); for (auto *DeadMI : DeadInstructions) { LLVM_DEBUG(dbgs() << *DeadMI << "Is dead\n"); RemoveDeadInstFromLists(DeadMI); diff --git a/lib/CodeGen/GlobalISel/LegalizerInfo.cpp b/lib/CodeGen/GlobalISel/LegalizerInfo.cpp index 17609175951..0010ca72d76 100644 --- a/lib/CodeGen/GlobalISel/LegalizerInfo.cpp +++ b/lib/CodeGen/GlobalISel/LegalizerInfo.cpp @@ -42,6 +42,45 @@ cl::opt llvm::DisableGISelLegalityCheck( cl::desc("Don't verify that MIR is fully legal between GlobalISel passes"), cl::Hidden); +raw_ostream &llvm::operator<<(raw_ostream &OS, LegalizeAction Action) { + switch (Action) { + case Legal: + OS << "Legal"; + break; + case NarrowScalar: + OS << "NarrowScalar"; + break; + case WidenScalar: + OS << "WidenScalar"; + break; + case FewerElements: + OS << "FewerElements"; + break; + case MoreElements: + OS << "MoreElements"; + break; + case Lower: + OS << "Lower"; + break; + case Libcall: + OS << "Libcall"; + break; + case Custom: + OS << "Custom"; + break; + case Unsupported: + OS << "Unsupported"; + break; + case NotFound: + OS << "NotFound"; + break; + case UseLegacyRules: + OS << "UseLegacyRules"; + break; + } + return OS; +} + raw_ostream &LegalityQuery::print(raw_ostream &OS) const { OS << Opcode << ", Tys={"; for (const auto &Type : Types) { @@ -149,7 +188,7 @@ LegalizeActionStep LegalizeRuleSet::apply(const LegalityQuery &Query) const { if (Rule.match(Query)) { LLVM_DEBUG(dbgs() << ".. match\n"); std::pair Mutation = Rule.determineMutation(Query); - LLVM_DEBUG(dbgs() << ".. .. " << (unsigned)Rule.getAction() << ", " + LLVM_DEBUG(dbgs() << ".. .. " << Rule.getAction() << ", " << Mutation.first << ", " << Mutation.second << "\n"); assert(mutationIsSane(Rule, Query, Mutation) && "legality mutation invalid for match"); @@ -402,9 +441,8 @@ LegalizerInfo::getAction(const LegalityQuery &Query) const { for (unsigned i = 0; i < Query.Types.size(); ++i) { auto Action = getAspectAction({Query.Opcode, i, Query.Types[i]}); if (Action.first != Legal) { - LLVM_DEBUG(dbgs() << ".. (legacy) Type " << i - << " Action=" << (unsigned)Action.first << ", " - << Action.second << "\n"); + LLVM_DEBUG(dbgs() << ".. (legacy) Type " << i << " Action=" + << Action.first << ", " << Action.second << "\n"); return {Action.first, i, Action.second}; } else LLVM_DEBUG(dbgs() << ".. (legacy) Type " << i << " Legal\n");