]> granicus.if.org Git - llvm/commitdiff
[MachineOutliner][NFC] Sink some candidate logic into OutlinedFunction
authorJessica Paquette <jpaquette@apple.com>
Tue, 24 Jul 2018 17:36:13 +0000 (17:36 +0000)
committerJessica Paquette <jpaquette@apple.com>
Tue, 24 Jul 2018 17:36:13 +0000 (17:36 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337838 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineOutliner.h
lib/CodeGen/MachineOutliner.cpp

index 7847c9f017c40f085fa9fa50602a358749edf6d9..73913586719d38ec9bb786d11fb351e32f1a8b7c 100644 (file)
@@ -209,10 +209,19 @@ public:
                                             : NotOutlinedCost - OutlinedCost;
   }
 
-  OutlinedFunction(unsigned Name, unsigned OccurrenceCount,
+  OutlinedFunction(unsigned Name, std::vector<Candidate> &Cands,
                    const std::vector<unsigned> &Sequence, TargetCostInfo &TCI)
-      : OccurrenceCount(OccurrenceCount), Name(Name), Sequence(Sequence),
-        TCI(TCI) {}
+      : Name(Name), Sequence(Sequence), TCI(TCI) {
+    OccurrenceCount = Cands.size();
+    for (Candidate &C : Cands)
+      Candidates.push_back(std::make_shared<outliner::Candidate>(C));
+
+    unsigned B = getBenefit();
+    for (std::shared_ptr<Candidate> &C : Candidates) {
+      C->Benefit = B;
+      C->TCI = TCI;
+    }
+  }
 };
 } // namespace outliner
 } // namespace llvm
index 5a365f2a6578db314a40a082f9835ef3811f59e3..c576738cf7a65503a963c074827522275e1fe358 100644 (file)
@@ -916,12 +916,11 @@ unsigned MachineOutliner::findCandidates(
     std::vector<unsigned> 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<std::shared_ptr<Candidate>> CandidatesForFn;
-    for (Candidate &C : CandidatesForRepeatedSeq) {
-      C.Benefit = Benefit;
-      C.TCI = TCI;
-      std::shared_ptr<Candidate> Cptr = std::make_shared<Candidate>(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<Candidate> &C : OF.Candidates)
+      CandidateList.push_back(C);
     FunctionList.push_back(OF);
-    FunctionList.back().Candidates = CandidatesForFn;
 
     // Move to the next function.
     Parent.IsInTree = false;