forked from OSchip/llvm-project
[RegBankSelect] Improve the output of the debug messages.
Add more information about mapping cost and chosen solution. llvm-svn: 291629
This commit is contained in:
parent
7f41c4d802
commit
0b63b31b2e
|
@ -76,6 +76,7 @@ class MachineBlockFrequencyInfo;
|
|||
class MachineRegisterInfo;
|
||||
class TargetPassConfig;
|
||||
class TargetRegisterInfo;
|
||||
class raw_ostream;
|
||||
|
||||
/// This pass implements the reg bank selector pass used in the GlobalISel
|
||||
/// pipeline. At the end of this pass, all register operands have been assigned
|
||||
|
@ -450,6 +451,18 @@ private:
|
|||
bool operator>(const MappingCost &Cost) const {
|
||||
return *this != Cost && Cost < *this;
|
||||
}
|
||||
|
||||
/// Print this on dbgs() stream.
|
||||
void dump() const;
|
||||
|
||||
/// Print this on \p OS;
|
||||
void print(raw_ostream &OS) const;
|
||||
|
||||
/// Overload the stream operator for easy debug printing.
|
||||
friend raw_ostream &operator<<(raw_ostream &OS, const MappingCost &Cost) {
|
||||
Cost.print(OS);
|
||||
return OS;
|
||||
}
|
||||
};
|
||||
|
||||
/// Interface to the target lowering info related
|
||||
|
@ -626,6 +639,7 @@ public:
|
|||
/// \endcode
|
||||
bool runOnMachineFunction(MachineFunction &MF) override;
|
||||
};
|
||||
|
||||
} // End namespace llvm.
|
||||
|
||||
#endif
|
||||
|
|
|
@ -223,6 +223,7 @@ RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
|
|||
for (RegisterBankInfo::InstructionMapping &CurMapping : PossibleMappings) {
|
||||
MappingCost CurCost = computeMapping(MI, CurMapping, LocalRepairPts, &Cost);
|
||||
if (CurCost < Cost) {
|
||||
DEBUG(dbgs() << "New best: " << CurCost << '\n');
|
||||
Cost = CurCost;
|
||||
BestMapping = &CurMapping;
|
||||
RepairPts.clear();
|
||||
|
@ -377,8 +378,10 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
|
|||
DEBUG(dbgs() << "Evaluating mapping cost for: " << MI);
|
||||
DEBUG(dbgs() << "With: " << InstrMapping << '\n');
|
||||
RepairPts.clear();
|
||||
if (BestCost && Cost > *BestCost)
|
||||
if (BestCost && Cost > *BestCost) {
|
||||
DEBUG(dbgs() << "Mapping is too expensive from the start\n");
|
||||
return Cost;
|
||||
}
|
||||
|
||||
// Moreover, to realize this mapping, the register bank of each operand must
|
||||
// match this mapping. In other words, we may need to locally reassign the
|
||||
|
@ -392,17 +395,17 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
|
|||
unsigned Reg = MO.getReg();
|
||||
if (!Reg)
|
||||
continue;
|
||||
DEBUG(dbgs() << "Opd" << OpIdx);
|
||||
DEBUG(dbgs() << "Opd" << OpIdx << '\n');
|
||||
const RegisterBankInfo::ValueMapping &ValMapping =
|
||||
InstrMapping.getOperandMapping(OpIdx);
|
||||
// If Reg is already properly mapped, this is free.
|
||||
bool Assign;
|
||||
if (assignmentMatch(Reg, ValMapping, Assign)) {
|
||||
DEBUG(dbgs() << " is free (match).\n");
|
||||
DEBUG(dbgs() << "=> is free (match).\n");
|
||||
continue;
|
||||
}
|
||||
if (Assign) {
|
||||
DEBUG(dbgs() << " is free (simple assignment).\n");
|
||||
DEBUG(dbgs() << "=> is free (simple assignment).\n");
|
||||
RepairPts.emplace_back(RepairingPlacement(MI, OpIdx, *TRI, *this,
|
||||
RepairingPlacement::Reassign));
|
||||
continue;
|
||||
|
@ -420,8 +423,10 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
|
|||
tryAvoidingSplit(RepairPt, MO, ValMapping);
|
||||
|
||||
// Check that the materialization of the repairing is possible.
|
||||
if (!RepairPt.canMaterialize())
|
||||
if (!RepairPt.canMaterialize()) {
|
||||
DEBUG(dbgs() << "Mapping involves impossible repairing\n");
|
||||
return MappingCost::ImpossibleCost();
|
||||
}
|
||||
|
||||
// Account for the split cost and repair cost.
|
||||
// Unless the cost is already saturated or we do not care about the cost.
|
||||
|
@ -476,8 +481,10 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
|
|||
|
||||
// Stop looking into what it takes to repair, this is already
|
||||
// too expensive.
|
||||
if (BestCost && Cost > *BestCost)
|
||||
if (BestCost && Cost > *BestCost) {
|
||||
DEBUG(dbgs() << "Mapping is too expensive, stop processing\n");
|
||||
return Cost;
|
||||
}
|
||||
|
||||
// No need to accumulate more cost information.
|
||||
// We need to still gather the repairing information though.
|
||||
|
@ -485,6 +492,7 @@ RegBankSelect::MappingCost RegBankSelect::computeMapping(
|
|||
break;
|
||||
}
|
||||
}
|
||||
DEBUG(dbgs() << "Total cost is: " << Cost << "\n");
|
||||
return Cost;
|
||||
}
|
||||
|
||||
|
@ -550,7 +558,7 @@ bool RegBankSelect::assignInstr(MachineInstr &MI) {
|
|||
// Make sure the mapping is valid for MI.
|
||||
assert(BestMapping.verify(MI) && "Invalid instruction mapping");
|
||||
|
||||
DEBUG(dbgs() << "Mapping: " << BestMapping << '\n');
|
||||
DEBUG(dbgs() << "Best Mapping: " << BestMapping << '\n');
|
||||
|
||||
// After this call, MI may not be valid anymore.
|
||||
// Do not use it.
|
||||
|
@ -959,3 +967,20 @@ bool RegBankSelect::MappingCost::operator==(const MappingCost &Cost) const {
|
|||
return LocalCost == Cost.LocalCost && NonLocalCost == Cost.NonLocalCost &&
|
||||
LocalFreq == Cost.LocalFreq;
|
||||
}
|
||||
|
||||
void RegBankSelect::MappingCost::dump() const {
|
||||
print(dbgs());
|
||||
dbgs() << '\n';
|
||||
}
|
||||
|
||||
void RegBankSelect::MappingCost::print(raw_ostream &OS) const {
|
||||
if (*this == ImpossibleCost()) {
|
||||
OS << "impossible";
|
||||
return;
|
||||
}
|
||||
if (isSaturated()) {
|
||||
OS << "saturated";
|
||||
return;
|
||||
}
|
||||
OS << LocalFreq << " * " << LocalCost << " + " << NonLocalCost;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue