[RegBankSelect] Look for the best mapping in greedy mode.

The Fast mode takes the first mapping, the greedy mode loops over all
the possible mapping for an instruction and choose the cheaper one.
Test case will come with target specific code, since we currently do not
have instructions that have several mappings.

llvm-svn: 270249
This commit is contained in:
Quentin Colombet 2016-05-20 18:37:33 +00:00
parent 64c9e1227e
commit 79fe1bea6b
2 changed files with 45 additions and 10 deletions

View File

@ -525,6 +525,13 @@ private:
RegBankSelect::RepairingPlacement &RepairPt,
const iterator_range<SmallVectorImpl<unsigned>::iterator> &NewVRegs);
/// Find the best mapping for \p MI from \p PossibleMappings.
/// \return a reference on the best mapping in \p PossibleMappings.
RegisterBankInfo::InstructionMapping &
findBestMapping(MachineInstr &MI,
RegisterBankInfo::InstructionMappings &PossibleMappings,
SmallVectorImpl<RepairingPlacement> &RepairPts);
/// Compute the cost of mapping \p MI with \p InstrMapping and
/// compute the repairing placement for such mapping in \p
/// RepairPts.

View File

@ -136,6 +136,27 @@ void RegBankSelect::repairReg(
// Legalize NewInstrs if need be.
}
RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
MachineInstr &MI, RegisterBankInfo::InstructionMappings &PossibleMappings,
SmallVectorImpl<RepairingPlacement> &RepairPts) {
RegisterBankInfo::InstructionMapping *BestMapping = nullptr;
MappingCost Cost = MappingCost::ImpossibleCost();
SmallVector<RepairingPlacement, 4> LocalRepairPts;
for (RegisterBankInfo::InstructionMapping &CurMapping : PossibleMappings) {
MappingCost CurCost = computeMapping(MI, CurMapping, LocalRepairPts, &Cost);
if (CurCost < Cost) {
Cost = CurCost;
BestMapping = &CurMapping;
RepairPts.clear();
for (RepairingPlacement &RepairPt : LocalRepairPts)
RepairPts.emplace_back(std::move(RepairPt));
}
}
assert(BestMapping && "No suitable mapping for instruction");
return *BestMapping;
}
void RegBankSelect::tryAvoidingSplit(
RegBankSelect::RepairingPlacement &RepairPt, const MachineOperand &MO,
const RegisterBankInfo::ValueMapping &ValMapping) const {
@ -433,22 +454,29 @@ void RegBankSelect::applyMapping(
void RegBankSelect::assignInstr(MachineInstr &MI) {
DEBUG(dbgs() << "Assign: " << MI);
RegisterBankInfo::InstructionMapping DefaultMapping =
RBI->getInstrMapping(MI);
// Remember the repairing placement for all the operands.
SmallVector<RepairingPlacement, 4> RepairPts;
MappingCost DefaultCost = computeMapping(MI, DefaultMapping, RepairPts);
(void)DefaultCost;
assert(DefaultCost != MappingCost::ImpossibleCost() &&
"Default mapping is not suited");
RegisterBankInfo::InstructionMapping BestMapping;
if (OptMode == RegBankSelect::Mode::Fast) {
BestMapping = RBI->getInstrMapping(MI);
MappingCost DefaultCost = computeMapping(MI, BestMapping, RepairPts);
(void)DefaultCost;
assert(DefaultCost != MappingCost::ImpossibleCost() &&
"Default mapping is not suited");
} else {
RegisterBankInfo::InstructionMappings PossibleMappings =
RBI->getInstrPossibleMappings(MI);
assert(!PossibleMappings.empty() &&
"Do not know how to map this instruction");
BestMapping = std::move(findBestMapping(MI, PossibleMappings, RepairPts));
}
// Make sure the mapping is valid for MI.
assert(DefaultMapping.verify(MI) && "Invalid instruction mapping");
assert(BestMapping.verify(MI) && "Invalid instruction mapping");
DEBUG(dbgs() << "Mapping: " << DefaultMapping << '\n');
DEBUG(dbgs() << "Mapping: " << BestMapping << '\n');
applyMapping(MI, DefaultMapping, RepairPts);
applyMapping(MI, BestMapping, RepairPts);
DEBUG(dbgs() << "Assigned: " << MI);
}