1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[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
This commit is contained in:
Jessica Paquette 2017-10-17 21:11:58 +00:00
parent 86baa0793e
commit 037bbeb19c

View File

@ -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);
}
}
}