[MachineOutliner][NFC] Move decrement logic to OutlinedFunction

This commit moves the decrement logic for outlined functions into the class,
and makes OccurrenceCount private. It can now be accessed via
getOccurrenceCount().

This makes it more difficult to accidentally introduce bugs by incorrectly
decrementing the occurrence count on OutlinedFunctions.

llvm-svn: 316020
This commit is contained in:
Jessica Paquette 2017-10-17 19:03:23 +00:00
parent c9ab4c2634
commit 85af63d044
1 changed files with 26 additions and 16 deletions

View File

@ -144,6 +144,11 @@ public:
/// class of candidate.
struct OutlinedFunction {
private:
/// The number of candidates for this \p OutlinedFunction.
unsigned OccurrenceCount = 0;
public:
/// The actual outlined function created.
/// This is initialized after we go through and create the actual function.
MachineFunction *MF = nullptr;
@ -151,9 +156,6 @@ struct OutlinedFunction {
/// A number assigned to this function which appears at the end of its name.
unsigned Name;
/// The number of candidates for this OutlinedFunction.
unsigned OccurrenceCount = 0;
/// \brief The sequence of integers corresponding to the instructions in this
/// function.
std::vector<unsigned> Sequence;
@ -161,6 +163,19 @@ struct OutlinedFunction {
/// Contains all target-specific information for this \p OutlinedFunction.
TargetInstrInfo::MachineOutlinerInfo MInfo;
/// Return the number of candidates for this \p OutlinedFunction.
unsigned getOccurrenceCount() {
return OccurrenceCount;
}
/// Decrement the occurrence count of this OutlinedFunction and return the
/// new count.
unsigned decrement() {
assert(OccurrenceCount > 0 && "Can't decrement an empty function!");
OccurrenceCount--;
return getOccurrenceCount();
}
/// \brief Return the number of instructions it would take to outline this
/// function.
unsigned getOutliningCost() {
@ -180,7 +195,7 @@ struct OutlinedFunction {
OutlinedFunction(unsigned Name, unsigned OccurrenceCount,
const std::vector<unsigned> &Sequence,
TargetInstrInfo::MachineOutlinerInfo &MInfo)
: Name(Name), OccurrenceCount(OccurrenceCount), Sequence(Sequence),
: OccurrenceCount(OccurrenceCount), Name(Name), Sequence(Sequence),
MInfo(MInfo) {}
};
@ -963,7 +978,7 @@ MachineOutliner::findCandidates(SuffixTree &ST, const TargetInstrInfo &TII,
<< " Instructions from outlining all occurrences ("
<< NV("OutliningCost", OF.getOutliningCost()) << ")"
<< " >= Unoutlined instruction count ("
<< NV("NotOutliningCost", StringLen * OF.OccurrenceCount) << ")"
<< NV("NotOutliningCost", StringLen * OF.getOccurrenceCount()) << ")"
<< " (Also found at: ";
// Tell the user the other places the candidate was found.
@ -1016,14 +1031,11 @@ void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList,
if (!C.InCandidateList)
return true;
// Check if C's associated function is still beneficial after previous
// pruning steps.
// C must be alive. Check if we should remove it.
OutlinedFunction &F = FunctionList[C.FunctionIdx];
if (F.OccurrenceCount < 2 || F.getBenefit() < 1) {
assert(F.OccurrenceCount > 0 &&
"Can't remove OutlinedFunction with no occurrences!");
F.OccurrenceCount--;
if (F.getBenefit() < 1) {
F.decrement();
C.InCandidateList = false;
return true;
}
@ -1039,15 +1051,13 @@ void MachineOutliner::pruneOverlaps(std::vector<Candidate> &CandidateList,
OutlinedFunction &F = FunctionList[C.FunctionIdx];
// Update C's associated function's occurrence count.
assert(F.OccurrenceCount > 0 &&
"Can't remove OutlinedFunction with no occurrences!");
F.OccurrenceCount--;
F.decrement();
// Remove C from the CandidateList.
C.InCandidateList = false;
DEBUG(dbgs() << "- Removed a Candidate \n";
dbgs() << "--- Num fns left for candidate: " << F.OccurrenceCount
dbgs() << "--- Num fns left for candidate: " << F.getOccurrenceCount()
<< "\n";
dbgs() << "--- Candidate's functions's benefit: " << F.getBenefit()
<< "\n";);
@ -1208,7 +1218,7 @@ bool MachineOutliner::outline(Module &M,
OutlinedFunction &OF = FunctionList[C.FunctionIdx];
// Was its OutlinedFunction made unbeneficial during pruneOverlaps?
if (OF.OccurrenceCount < 2 || OF.getBenefit() < 1)
if (OF.getBenefit() < 1)
continue;
// If not, then outline it.