[llvm] r348428 - [MachineOutliner][NFC] Remove buildCandidateList and replace with findCandidates

Jessica Paquette via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 5 15:39:07 PST 2018


Author: paquette
Date: Wed Dec  5 15:39:07 2018
New Revision: 348428

URL: http://llvm.org/viewvc/llvm-project?rev=348428&view=rev
Log:
[MachineOutliner][NFC] Remove buildCandidateList and replace with findCandidates

More refactoring.

Since the pruning logic has changed, and the candidate list is gone,
everything can be sunk into findCandidates.

We no longer need to keep track of the length of the longest substring, so we
can drop all of that logic as well.

After this, we just find all of the candidates and move to outlining.

Modified:
    llvm/trunk/lib/CodeGen/MachineOutliner.cpp

Modified: llvm/trunk/lib/CodeGen/MachineOutliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineOutliner.cpp?rev=348428&r1=348427&r2=348428&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineOutliner.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineOutliner.cpp Wed Dec  5 15:39:07 2018
@@ -874,7 +874,8 @@ struct MachineOutliner : public ModulePa
   /// Remark output explaining that a function was outlined.
   void emitOutlinedFunctionRemark(OutlinedFunction &OF);
 
-  /// Find all repeated substrings that satisfy the outlining cost model.
+  /// Find all repeated substrings that satisfy the outlining cost model by
+  /// constructing a suffix tree.
   ///
   /// If a substring appears at least twice, then it must be represented by
   /// an internal node which appears in at least two suffixes. Each suffix
@@ -883,16 +884,13 @@ struct MachineOutliner : public ModulePa
   /// internal node represents a beneficial substring, then we use each of
   /// its leaf children to find the locations of its substring.
   ///
-  /// \param ST A suffix tree to query.
   /// \param Mapper Contains outlining mapping information.
   /// \param[out] FunctionList Filled with a list of \p OutlinedFunctions
   /// each type of candidate.
   ///
   /// \returns The length of the longest candidate found.
-  unsigned
-  findCandidates(SuffixTree &ST,
-                 InstructionMapper &Mapper,
-                 std::vector<OutlinedFunction> &FunctionList);
+  void findCandidates(InstructionMapper &Mapper,
+                      std::vector<OutlinedFunction> &FunctionList);
 
   /// Replace the sequences of instructions represented by \p OutlinedFunctions
   /// with calls to functions.
@@ -908,21 +906,6 @@ struct MachineOutliner : public ModulePa
                                           InstructionMapper &Mapper,
                                           unsigned Name);
 
-  /// Find potential outlining candidates.
-  ///
-  /// For each type of potential candidate, also build an \p OutlinedFunction
-  /// struct containing the information to build the function for that
-  /// candidate.
-  ///
-  /// \param[out] FunctionList Filled with functions corresponding to each type
-  /// of \p Candidate.
-  /// \param Mapper Contains the instruction mappings for the module.
-  ///
-  /// \returns The length of the longest candidate found. 0 if there are none.
-  unsigned
-  buildCandidateList(std::vector<OutlinedFunction> &FunctionList,
-                     InstructionMapper &Mapper);
-
   /// Construct a suffix tree on the instructions in \p M and outline repeated
   /// strings from that tree.
   bool runOnModule(Module &M) override;
@@ -1031,11 +1014,11 @@ void MachineOutliner::emitOutlinedFuncti
   MORE.emit(R);
 }
 
-unsigned MachineOutliner::findCandidates(
-    SuffixTree &ST, InstructionMapper &Mapper,
-    std::vector<OutlinedFunction> &FunctionList) {
+void
+MachineOutliner::findCandidates(InstructionMapper &Mapper,
+                                std::vector<OutlinedFunction> &FunctionList) {
   FunctionList.clear();
-  unsigned MaxLen = 0;
+  SuffixTree ST(Mapper.UnsignedVec);
 
   // First, find dall of the repeated substrings in the tree of minimum length
   // 2.
@@ -1110,27 +1093,8 @@ unsigned MachineOutliner::findCandidates
       continue;
     }
 
-    if (StringLen > MaxLen)
-      MaxLen = StringLen;
-
     FunctionList.push_back(OF);
   }
-
-  return MaxLen;
-}
-
-unsigned MachineOutliner::buildCandidateList(
-    std::vector<OutlinedFunction> &FunctionList,
-    InstructionMapper &Mapper) {
-  // Construct a suffix tree and use it to find candidates.
-  SuffixTree ST(Mapper.UnsignedVec);
-
-  std::vector<unsigned> CandidateSequence; // Current outlining candidate.
-  unsigned MaxCandidateLen = 0;            // Length of the longest candidate.
-
-  MaxCandidateLen = findCandidates(ST, Mapper, FunctionList);
-
-  return MaxCandidateLen;
 }
 
 MachineFunction *
@@ -1494,7 +1458,7 @@ bool MachineOutliner::runOnModule(Module
   std::vector<OutlinedFunction> FunctionList;
 
   // Find all of the outlining candidates.
-  buildCandidateList(FunctionList, Mapper);
+  findCandidates(Mapper, FunctionList);
 
   // If we've requested size remarks, then collect the MI counts of every
   // function before outlining, and the MI counts after outlining.




More information about the llvm-commits mailing list