diff options
author | Quentin Colombet <qcolombet@apple.com> | 2016-05-20 18:37:33 +0000 |
---|---|---|
committer | Quentin Colombet <qcolombet@apple.com> | 2016-05-20 18:37:33 +0000 |
commit | 79fe1bea6bde1a937c6469cb1735a6cf6e493c46 (patch) | |
tree | 4a3ec9705308467108d5d263c5cf7d345ff8c4cf /llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp | |
parent | 64c9e1227ec59b2bb147ec53769042bd7d7e5cea (diff) | |
download | bcm5719-llvm-79fe1bea6bde1a937c6469cb1735a6cf6e493c46.tar.gz bcm5719-llvm-79fe1bea6bde1a937c6469cb1735a6cf6e493c46.zip |
[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
Diffstat (limited to 'llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp | 48 |
1 files changed, 38 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp index 152fc0c306c..4dc2bd8c81a 100644 --- a/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp +++ b/llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp @@ -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); } |