1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

[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.

llvm-svn: 359481
This commit is contained in:
Daniel Sanders 2019-04-29 18:45:59 +00:00
parent 22b0cb9706
commit 43994e0ea0
3 changed files with 63 additions and 6 deletions

View File

@ -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;

View File

@ -88,12 +88,15 @@ namespace {
class LegalizerWorkListManager : public GISelChangeObserver {
InstListTy &InstList;
ArtifactListTy &ArtifactList;
#ifndef NDEBUG
SmallVector<MachineInstr *, 4> 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<MachineInstr *, 4> DeadInstructions;
if (ArtCombiner.tryCombineInstruction(MI, DeadInstructions,
WrapperObserver)) {
WorkListObserver.printNewInstrs();
for (auto *DeadMI : DeadInstructions) {
LLVM_DEBUG(dbgs() << *DeadMI << "Is dead\n");
RemoveDeadInstFromLists(DeadMI);

View File

@ -42,6 +42,45 @@ cl::opt<bool> 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<unsigned, LLT> 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");