@@ -446,16 +446,19 @@ struct MachineOutliner : public ModulePass {
446446 // / \param Mapper Contains outlining mapping information.
447447 // / \param[out] FunctionList Filled with a list of \p OutlinedFunctions
448448 // / each type of candidate.
449- void findCandidates (InstructionMapper &Mapper,
450- std::vector<OutlinedFunction> &FunctionList);
449+ void
450+ findCandidates (InstructionMapper &Mapper,
451+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
451452
452453 // / Replace the sequences of instructions represented by \p OutlinedFunctions
453454 // / with calls to functions.
454455 // /
455456 // / \param M The module we are outlining from.
456457 // / \param FunctionList A list of functions to be inserted into the module.
457458 // / \param Mapper Contains the instruction mappings for the module.
458- bool outline (Module &M, std::vector<OutlinedFunction> &FunctionList,
459+ // / \param[out] OutlinedFunctionNum The outlined function number.
460+ bool outline (Module &M,
461+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
459462 InstructionMapper &Mapper, unsigned &OutlinedFunctionNum);
460463
461464 // / Creates a function for \p OF and inserts it into the module.
@@ -574,7 +577,8 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
574577}
575578
576579void MachineOutliner::findCandidates (
577- InstructionMapper &Mapper, std::vector<OutlinedFunction> &FunctionList) {
580+ InstructionMapper &Mapper,
581+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
578582 FunctionList.clear ();
579583 SuffixTree ST (Mapper.UnsignedVec );
580584
@@ -674,7 +678,7 @@ void MachineOutliner::findCandidates(
674678 continue ;
675679 }
676680
677- FunctionList.push_back (*OF);
681+ FunctionList.push_back (std::make_unique<OutlinedFunction>( *OF) );
678682 }
679683}
680684
@@ -819,69 +823,68 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
819823 return &MF;
820824}
821825
822- bool MachineOutliner::outline (Module &M,
823- std::vector<OutlinedFunction> &FunctionList,
824- InstructionMapper &Mapper,
825- unsigned &OutlinedFunctionNum) {
826+ bool MachineOutliner::outline (
827+ Module &M, std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
828+ InstructionMapper &Mapper, unsigned &OutlinedFunctionNum) {
826829 LLVM_DEBUG (dbgs () << " *** Outlining ***\n " );
827830 LLVM_DEBUG (dbgs () << " NUMBER OF POTENTIAL FUNCTIONS: " << FunctionList.size ()
828831 << " \n " );
829832 bool OutlinedSomething = false ;
830833
831834 // Sort by benefit. The most beneficial functions should be outlined first.
832- stable_sort (FunctionList,
833- []( const OutlinedFunction &LHS, const OutlinedFunction &RHS) {
834- return LHS. getBenefit () > RHS. getBenefit ();
835- });
835+ stable_sort (FunctionList, []( const std::unique_ptr<OutlinedFunction> &LHS,
836+ const std::unique_ptr< OutlinedFunction> &RHS) {
837+ return LHS-> getBenefit () > RHS-> getBenefit ();
838+ });
836839
837840 // Walk over each function, outlining them as we go along. Functions are
838841 // outlined greedily, based off the sort above.
839842 auto *UnsignedVecBegin = Mapper.UnsignedVec .begin ();
840843 LLVM_DEBUG (dbgs () << " WALKING FUNCTION LIST\n " );
841- for (OutlinedFunction &OF : FunctionList) {
844+ for (auto &OF : FunctionList) {
842845#ifndef NDEBUG
843- auto NumCandidatesBefore = OF. Candidates .size ();
846+ auto NumCandidatesBefore = OF-> Candidates .size ();
844847#endif
845848 // If we outlined something that overlapped with a candidate in a previous
846849 // step, then we can't outline from it.
847- erase_if (OF. Candidates , [&UnsignedVecBegin](Candidate &C) {
850+ erase_if (OF-> Candidates , [&UnsignedVecBegin](Candidate &C) {
848851 return std::any_of (UnsignedVecBegin + C.getStartIdx (),
849852 UnsignedVecBegin + C.getEndIdx () + 1 , [](unsigned I) {
850853 return I == static_cast <unsigned >(-1 );
851854 });
852855 });
853856
854857#ifndef NDEBUG
855- auto NumCandidatesAfter = OF. Candidates .size ();
858+ auto NumCandidatesAfter = OF-> Candidates .size ();
856859 LLVM_DEBUG (dbgs () << " PRUNED: " << NumCandidatesBefore - NumCandidatesAfter
857860 << " /" << NumCandidatesBefore << " candidates\n " );
858861#endif
859862
860863 // If we made it unbeneficial to outline this function, skip it.
861- if (OF. getBenefit () < OutlinerBenefitThreshold) {
862- LLVM_DEBUG (dbgs () << " SKIP: Expected benefit (" << OF. getBenefit ()
864+ if (OF-> getBenefit () < OutlinerBenefitThreshold) {
865+ LLVM_DEBUG (dbgs () << " SKIP: Expected benefit (" << OF-> getBenefit ()
863866 << " B) < threshold (" << OutlinerBenefitThreshold
864867 << " B)\n " );
865868 continue ;
866869 }
867870
868- LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF. getBenefit ()
871+ LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF-> getBenefit ()
869872 << " B) > threshold (" << OutlinerBenefitThreshold
870873 << " B)\n " );
871874
872875 // It's beneficial. Create the function and outline its sequence's
873876 // occurrences.
874- OF. MF = createOutlinedFunction (M, OF, Mapper, OutlinedFunctionNum);
875- emitOutlinedFunctionRemark (OF);
877+ OF-> MF = createOutlinedFunction (M, * OF, Mapper, OutlinedFunctionNum);
878+ emitOutlinedFunctionRemark (* OF);
876879 FunctionsCreated++;
877880 OutlinedFunctionNum++; // Created a function, move to the next name.
878- MachineFunction *MF = OF. MF ;
881+ MachineFunction *MF = OF-> MF ;
879882 const TargetSubtargetInfo &STI = MF->getSubtarget ();
880883 const TargetInstrInfo &TII = *STI.getInstrInfo ();
881884
882885 // Replace occurrences of the sequence with calls to the new function.
883886 LLVM_DEBUG (dbgs () << " CREATE OUTLINED CALLS\n " );
884- for (Candidate &C : OF. Candidates ) {
887+ for (Candidate &C : OF-> Candidates ) {
885888 MachineBasicBlock &MBB = *C.getMBB ();
886889 MachineBasicBlock::iterator StartIt = C.begin ();
887890 MachineBasicBlock::iterator EndIt = std::prev (C.end ());
@@ -1173,7 +1176,7 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
11731176
11741177 // Prepare instruction mappings for the suffix tree.
11751178 populateMapper (Mapper, M, MMI);
1176- std::vector<OutlinedFunction> FunctionList;
1179+ std::vector<std::unique_ptr< OutlinedFunction> > FunctionList;
11771180
11781181 // Find all of the outlining candidates.
11791182 findCandidates (Mapper, FunctionList);
0 commit comments