From f94d1d29c1eab9ac1afba8a6e2200a990fafa232 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Tue, 24 Jul 2018 17:36:13 +0000 Subject: [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 --- llvm/lib/CodeGen/MachineOutliner.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index 5a365f2a657..c576738cf7a 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -916,12 +916,11 @@ unsigned MachineOutliner::findCandidates( std::vector Seq; for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++) Seq.push_back(ST.Str[i]); - OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq.size(), + OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq, Seq, TCI); - unsigned Benefit = OF.getBenefit(); // Is it better to outline this candidate than not? - if (Benefit < 1) { + if (OF.getBenefit() < 1) { // Outlining this candidate would take more instructions than not // outlining. // Emit a remark explaining why we didn't outline this candidate. @@ -958,19 +957,11 @@ unsigned MachineOutliner::findCandidates( if (StringLen > MaxLen) MaxLen = StringLen; - // At this point, the candidate class is seen as beneficial. Set their - // benefit values and save them in the candidate list. - std::vector> CandidatesForFn; - for (Candidate &C : CandidatesForRepeatedSeq) { - C.Benefit = Benefit; - C.TCI = TCI; - std::shared_ptr Cptr = std::make_shared(C); - CandidateList.push_back(Cptr); - CandidatesForFn.push_back(Cptr); - } - + // The function is beneficial. Save its candidates to the candidate list + // for pruning. + for (std::shared_ptr &C : OF.Candidates) + CandidateList.push_back(C); FunctionList.push_back(OF); - FunctionList.back().Candidates = CandidatesForFn; // Move to the next function. Parent.IsInTree = false; -- cgit v1.2.3