Skip to content

Commit

Permalink
[RegBankSelect] Improve the output of the debug messages.
Browse files Browse the repository at this point in the history
Add more information about mapping cost and chosen solution.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291629 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Quentin Colombet committed Jan 11, 2017
1 parent eb6ab04 commit 7249f50
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
14 changes: 14 additions & 0 deletions include/llvm/CodeGen/GlobalISel/RegBankSelect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -450,6 +451,18 @@ class RegBankSelect : public MachineFunctionPass {
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
Expand Down Expand Up @@ -626,6 +639,7 @@ class RegBankSelect : public MachineFunctionPass {
/// \endcode
bool runOnMachineFunction(MachineFunction &MF) override;
};

} // End namespace llvm.

#endif
39 changes: 32 additions & 7 deletions lib/CodeGen/GlobalISel/RegBankSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -476,15 +481,18 @@ 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.
if (Saturated)
break;
}
}
DEBUG(dbgs() << "Total cost is: " << Cost << "\n");
return Cost;
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

0 comments on commit 7249f50

Please sign in to comment.