Skip to content

Commit f94d1d2

Browse files
author
Jessica Paquette
committed
[MachineOutliner][NFC] Sink some candidate logic into OutlinedFunction
Just some simple gardening to improve clarity. Before, we had something along the lines of 1) Create a std::vector of Candidates 2) Create an OutlinedFunction 3) Create a std::vector of pointers to Candidates 4) Copy those over to the OutlinedFunction and the Candidate list Now, OutlinedFunctions create the Candidate pointers. They're still copied over to the main list of Candidates, but it makes it a bit clearer what's going on. llvm-svn: 337838
1 parent dc36389 commit f94d1d2

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

llvm/include/llvm/CodeGen/MachineOutliner.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,19 @@ struct OutlinedFunction {
209209
: NotOutlinedCost - OutlinedCost;
210210
}
211211

212-
OutlinedFunction(unsigned Name, unsigned OccurrenceCount,
212+
OutlinedFunction(unsigned Name, std::vector<Candidate> &Cands,
213213
const std::vector<unsigned> &Sequence, TargetCostInfo &TCI)
214-
: OccurrenceCount(OccurrenceCount), Name(Name), Sequence(Sequence),
215-
TCI(TCI) {}
214+
: Name(Name), Sequence(Sequence), TCI(TCI) {
215+
OccurrenceCount = Cands.size();
216+
for (Candidate &C : Cands)
217+
Candidates.push_back(std::make_shared<outliner::Candidate>(C));
218+
219+
unsigned B = getBenefit();
220+
for (std::shared_ptr<Candidate> &C : Candidates) {
221+
C->Benefit = B;
222+
C->TCI = TCI;
223+
}
224+
}
216225
};
217226
} // namespace outliner
218227
} // namespace llvm

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -916,12 +916,11 @@ unsigned MachineOutliner::findCandidates(
916916
std::vector<unsigned> Seq;
917917
for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++)
918918
Seq.push_back(ST.Str[i]);
919-
OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq.size(),
919+
OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq,
920920
Seq, TCI);
921-
unsigned Benefit = OF.getBenefit();
922921

923922
// Is it better to outline this candidate than not?
924-
if (Benefit < 1) {
923+
if (OF.getBenefit() < 1) {
925924
// Outlining this candidate would take more instructions than not
926925
// outlining.
927926
// Emit a remark explaining why we didn't outline this candidate.
@@ -958,19 +957,11 @@ unsigned MachineOutliner::findCandidates(
958957
if (StringLen > MaxLen)
959958
MaxLen = StringLen;
960959

961-
// At this point, the candidate class is seen as beneficial. Set their
962-
// benefit values and save them in the candidate list.
963-
std::vector<std::shared_ptr<Candidate>> CandidatesForFn;
964-
for (Candidate &C : CandidatesForRepeatedSeq) {
965-
C.Benefit = Benefit;
966-
C.TCI = TCI;
967-
std::shared_ptr<Candidate> Cptr = std::make_shared<Candidate>(C);
968-
CandidateList.push_back(Cptr);
969-
CandidatesForFn.push_back(Cptr);
970-
}
971-
960+
// The function is beneficial. Save its candidates to the candidate list
961+
// for pruning.
962+
for (std::shared_ptr<Candidate> &C : OF.Candidates)
963+
CandidateList.push_back(C);
972964
FunctionList.push_back(OF);
973-
FunctionList.back().Candidates = CandidatesForFn;
974965

975966
// Move to the next function.
976967
Parent.IsInTree = false;

0 commit comments

Comments
 (0)