[llvm] r270304 - [RegBankSelect] Compute the repairing cost for copies.
Quentin Colombet via llvm-commits
llvm-commits at lists.llvm.org
Fri May 20 18:43:26 PDT 2016
Author: qcolombet
Date: Fri May 20 20:43:25 2016
New Revision: 270304
URL: http://llvm.org/viewvc/llvm-project?rev=270304&view=rev
Log:
[RegBankSelect] Compute the repairing cost for copies.
Prior to this patch, we were using 1 for all the repairing costs.
Now, we use the information from the target to get this information.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h?rev=270304&r1=270303&r2=270304&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/RegBankSelect.h Fri May 20 20:43:25 2016
@@ -525,6 +525,15 @@ private:
RegBankSelect::RepairingPlacement &RepairPt,
const iterator_range<SmallVectorImpl<unsigned>::iterator> &NewVRegs);
+ /// Return the cost of the instruction needed to map \p MO to \p ValMapping.
+ /// The cost is free of basic block frequencies.
+ /// \pre MO.isReg()
+ /// \pre MO is assigned to a register bank.
+ /// \pre ValMapping is a valid mapping for MO.
+ uint64_t
+ getRepairCost(const MachineOperand &MO,
+ const RegisterBankInfo::ValueMapping &ValMapping) const;
+
/// Find the best mapping for \p MI from \p PossibleMappings.
/// \return a reference on the best mapping in \p PossibleMappings.
RegisterBankInfo::InstructionMapping &
Modified: llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp?rev=270304&r1=270303&r2=270304&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/RegBankSelect.cpp Fri May 20 20:43:25 2016
@@ -136,6 +136,44 @@ void RegBankSelect::repairReg(
// Legalize NewInstrs if need be.
}
+uint64_t RegBankSelect::getRepairCost(
+ const MachineOperand &MO,
+ const RegisterBankInfo::ValueMapping &ValMapping) const {
+ assert(MO.isReg() && "We should only repair register operand");
+ assert(!ValMapping.BreakDown.empty() && "Nothing to map??");
+
+ bool IsSameNumOfValues = ValMapping.BreakDown.size() == 1;
+ const RegisterBank *CurRegBank = RBI->getRegBank(MO.getReg(), *MRI, *TRI);
+ // If MO does not have a register bank, we should have just been
+ // able to set one unless we have to break the value down.
+ assert((!IsSameNumOfValues || CurRegBank) && "We should not have to repair");
+ // Def: Val <- NewDefs
+ // Same number of values: copy
+ // Different number: Val = build_sequence Defs1, Defs2, ...
+ // Use: NewSources <- Val.
+ // Same number of values: copy.
+ // Different number: Src1, Src2, ... =
+ // extract_value Val, Src1Begin, Src1Len, Src2Begin, Src2Len, ...
+ // We should remember that this value is available somewhere else to
+ // coalesce the value.
+
+ if (IsSameNumOfValues) {
+ const RegisterBank *DesiredRegBrank = ValMapping.BreakDown[0].RegBank;
+ // If we repair a definition, swap the source and destination for
+ // the repairing.
+ if (MO.isDef())
+ std::swap(CurRegBank, DesiredRegBrank);
+ unsigned Cost = RBI->copyCost(*DesiredRegBrank, *CurRegBank);
+ // TODO: use a dedicated constant for ImpossibleCost.
+ if (Cost != UINT_MAX)
+ return Cost;
+ assert(false && "Legalization not available yet");
+ // Return the legalization cost of that repairing.
+ }
+ assert(false && "Complex repairing not implemented yet");
+ return 1;
+}
+
RegisterBankInfo::InstructionMapping &RegBankSelect::findBestMapping(
MachineInstr &MI, RegisterBankInfo::InstructionMappings &PossibleMappings,
SmallVectorImpl<RepairingPlacement> &RepairPts) {
@@ -320,18 +358,6 @@ RegBankSelect::MappingCost RegBankSelect
continue;
}
- // TODO:
- // Ask the repairing module how much it would cost to get this mapping.
- // Use: NewSources <- Val.
- // Same size: copy.
- // Different size: Src1, Src2, ... =
- // extract_value Val, Src1Begin, Src1Len, Src2Begin, Src2Len, ...
- // Def: Val <- NewDefs
- // Same size: copy
- // Different size: Val = build_sequence Defs1, Defs2, ...
- // We should remember that this value is available somewhere else to
- // coalesce the value.
-
// Find the insertion point for the repairing code.
RepairPts.emplace_back(
RepairingPlacement(MI, OpIdx, *TRI, *this, RepairingPlacement::Insert));
@@ -356,9 +382,8 @@ RegBankSelect::MappingCost RegBankSelect
// Thus, if we end up here this information should be here.
assert(MBFI && MBPI && "Cost computation requires MBFI and MBPI");
- // Sums up the repairing cost of at each insertion point.
- // TODO: Get the actual repairing cost.
- uint64_t RepairCost = 1;
+ // Sums up the repairing cost of MO at each insertion point.
+ uint64_t RepairCost = getRepairCost(MO, ValMapping);
// Bias used for splitting: 5%.
const uint64_t PercentageForBias = 5;
uint64_t Bias = (RepairCost * PercentageForBias + 99) / 100;
More information about the llvm-commits
mailing list