diff options
| author | Jessica Paquette <jpaquette@apple.com> | 2017-10-17 21:11:58 +0000 |
|---|---|---|
| committer | Jessica Paquette <jpaquette@apple.com> | 2017-10-17 21:11:58 +0000 |
| commit | 60d31fc3a90afbfd26398cbf820641287a52e6cb (patch) | |
| tree | 3339d36da501346ff873784824541428d16abc09 /llvm/lib/CodeGen | |
| parent | 8e61b3e50ca81efa93da7a6df174db91101ff064 (diff) | |
| download | bcm5719-llvm-60d31fc3a90afbfd26398cbf820641287a52e6cb.tar.gz bcm5719-llvm-60d31fc3a90afbfd26398cbf820641287a52e6cb.zip | |
[MachineOutliner][NFC] Clean up prune logic a bit
Move the prune logic in pruneOverlaps to a new function, prune. This lets us
reuse the prune functionality. Makes the code a bit more readable. It'll also
make it easier to emit remarks/debug statements for pruned functions.
llvm-svn: 316031
Diffstat (limited to 'llvm/lib/CodeGen')
| -rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index b60740320b8..8c268cf32d8 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -164,9 +164,7 @@ public: TargetInstrInfo::MachineOutlinerInfo MInfo; /// Return the number of candidates for this \p OutlinedFunction. - unsigned getOccurrenceCount() { - return OccurrenceCount; - } + unsigned getOccurrenceCount() { return OccurrenceCount; } /// Decrement the occurrence count of this OutlinedFunction and return the /// new count. @@ -848,6 +846,10 @@ struct MachineOutliner : public ModulePass { SuffixTree &ST, InstructionMapper &Mapper, const TargetInstrInfo &TII); + /// Helper function for pruneOverlaps. + /// Removes \p C from the candidate list, and updates its \p OutlinedFunction. + void prune(Candidate &C, std::vector<OutlinedFunction> &FunctionList); + /// \brief Remove any overlapping candidates that weren't handled by the /// suffix tree's pruning method. /// @@ -1017,6 +1019,25 @@ MachineOutliner::findCandidates(SuffixTree &ST, const TargetInstrInfo &TII, return MaxLen; } +// Remove C from the candidate space, and update its OutlinedFunction. +void MachineOutliner::prune(Candidate &C, + std::vector<OutlinedFunction> &FunctionList) { + // Get the OutlinedFunction associated with this Candidate. + OutlinedFunction &F = FunctionList[C.FunctionIdx]; + + // Update C's associated function's occurrence count. + F.decrement(); + + // Remove C from the CandidateList. + C.InCandidateList = false; + + DEBUG(dbgs() << "- Removed a Candidate \n"; + dbgs() << "--- Num fns left for candidate: " << F.getOccurrenceCount() + << "\n"; + dbgs() << "--- Candidate's functions's benefit: " << F.getBenefit() + << "\n";); +} + void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList, std::vector<OutlinedFunction> &FunctionList, InstructionMapper &Mapper, @@ -1025,18 +1046,15 @@ void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList, // Return true if this candidate became unbeneficial for outlining in a // previous step. - auto ShouldSkipCandidate = [&FunctionList](Candidate &C) { + auto ShouldSkipCandidate = [&FunctionList, this](Candidate &C) { // Check if the candidate was removed in a previous step. if (!C.InCandidateList) return true; // C must be alive. Check if we should remove it. - OutlinedFunction &F = FunctionList[C.FunctionIdx]; - - if (F.getBenefit() < 1) { - F.decrement(); - C.InCandidateList = false; + if (FunctionList[C.FunctionIdx].getBenefit() < 1) { + prune(C, FunctionList); return true; } @@ -1044,25 +1062,6 @@ void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList, return false; }; - // Remove C from the candidate space, and update its OutlinedFunction. - auto Prune = [&FunctionList](Candidate &C) { - - // Get the OutlinedFunction associated with this Candidate. - OutlinedFunction &F = FunctionList[C.FunctionIdx]; - - // Update C's associated function's occurrence count. - F.decrement(); - - // Remove C from the CandidateList. - C.InCandidateList = false; - - DEBUG(dbgs() << "- Removed a Candidate \n"; - dbgs() << "--- Num fns left for candidate: " << F.getOccurrenceCount() - << "\n"; - dbgs() << "--- Candidate's functions's benefit: " << F.getBenefit() - << "\n";); - }; - // TODO: Experiment with interval trees or other interval-checking structures // to lower the time complexity of this function. // TODO: Can we do better than the simple greedy choice? @@ -1116,13 +1115,17 @@ void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList, // // Approximate this by picking the one which would have saved us the // most instructions before any pruning. - if (C1.Benefit >= C2.Benefit) { - Prune(C2); - } else { - Prune(C1); - // C1 is out, so we don't have to compare it against anyone else. + + // Is C2 a better candidate? + if (C2.Benefit > C1.Benefit) { + // Yes, so prune C1. Since C1 is dead, we don't have to compare it + // against anything anymore, so break. + prune(C1, FunctionList); break; } + + // Prune C2 and move on to the next candidate. + prune(C2, FunctionList); } } } |

