@@ -452,16 +452,19 @@ struct MachineOutliner : public ModulePass {
452
452
// / \param Mapper Contains outlining mapping information.
453
453
// / \param[out] FunctionList Filled with a list of \p OutlinedFunctions
454
454
// / each type of candidate.
455
- void findCandidates (InstructionMapper &Mapper,
456
- std::vector<OutlinedFunction> &FunctionList);
455
+ void
456
+ findCandidates (InstructionMapper &Mapper,
457
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
457
458
458
459
// / Replace the sequences of instructions represented by \p OutlinedFunctions
459
460
// / with calls to functions.
460
461
// /
461
462
// / \param M The module we are outlining from.
462
463
// / \param FunctionList A list of functions to be inserted into the module.
463
464
// / \param Mapper Contains the instruction mappings for the module.
464
- bool outline (Module &M, std::vector<OutlinedFunction> &FunctionList,
465
+ // / \param[out] OutlinedFunctionNum The outlined function number.
466
+ bool outline (Module &M,
467
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
465
468
InstructionMapper &Mapper, unsigned &OutlinedFunctionNum);
466
469
467
470
// / Creates a function for \p OF and inserts it into the module.
@@ -580,7 +583,8 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
580
583
}
581
584
582
585
void MachineOutliner::findCandidates (
583
- InstructionMapper &Mapper, std::vector<OutlinedFunction> &FunctionList) {
586
+ InstructionMapper &Mapper,
587
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
584
588
FunctionList.clear ();
585
589
SuffixTree ST (Mapper.UnsignedVec , OutlinerLeafDescendants);
586
590
@@ -682,7 +686,7 @@ void MachineOutliner::findCandidates(
682
686
continue ;
683
687
}
684
688
685
- FunctionList.push_back (*OF);
689
+ FunctionList.push_back (std::make_unique<OutlinedFunction>( *OF) );
686
690
}
687
691
}
688
692
@@ -827,71 +831,70 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
827
831
return &MF;
828
832
}
829
833
830
- bool MachineOutliner::outline (Module &M,
831
- std::vector<OutlinedFunction> &FunctionList,
832
- InstructionMapper &Mapper,
833
- unsigned &OutlinedFunctionNum) {
834
+ bool MachineOutliner::outline (
835
+ Module &M, std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
836
+ InstructionMapper &Mapper, unsigned &OutlinedFunctionNum) {
834
837
LLVM_DEBUG (dbgs () << " *** Outlining ***\n " );
835
838
LLVM_DEBUG (dbgs () << " NUMBER OF POTENTIAL FUNCTIONS: " << FunctionList.size ()
836
839
<< " \n " );
837
840
bool OutlinedSomething = false ;
838
841
839
842
// Sort by priority where priority := getNotOutlinedCost / getOutliningCost.
840
843
// The function with highest priority should be outlined first.
841
- stable_sort (FunctionList,
842
- []( const OutlinedFunction &LHS, const OutlinedFunction &RHS) {
843
- return LHS. getNotOutlinedCost () * RHS. getOutliningCost () >
844
- RHS. getNotOutlinedCost () * LHS. getOutliningCost ();
845
- });
844
+ stable_sort (FunctionList, []( const std::unique_ptr<OutlinedFunction> &LHS,
845
+ const std::unique_ptr< OutlinedFunction> &RHS) {
846
+ return LHS-> getNotOutlinedCost () * RHS-> getOutliningCost () >
847
+ RHS-> getNotOutlinedCost () * LHS-> getOutliningCost ();
848
+ });
846
849
847
850
// Walk over each function, outlining them as we go along. Functions are
848
851
// outlined greedily, based off the sort above.
849
852
auto *UnsignedVecBegin = Mapper.UnsignedVec .begin ();
850
853
LLVM_DEBUG (dbgs () << " WALKING FUNCTION LIST\n " );
851
- for (OutlinedFunction &OF : FunctionList) {
854
+ for (auto &OF : FunctionList) {
852
855
#ifndef NDEBUG
853
- auto NumCandidatesBefore = OF. Candidates .size ();
856
+ auto NumCandidatesBefore = OF-> Candidates .size ();
854
857
#endif
855
858
// If we outlined something that overlapped with a candidate in a previous
856
859
// step, then we can't outline from it.
857
- erase_if (OF. Candidates , [&UnsignedVecBegin](Candidate &C) {
860
+ erase_if (OF-> Candidates , [&UnsignedVecBegin](Candidate &C) {
858
861
return std::any_of (UnsignedVecBegin + C.getStartIdx (),
859
862
UnsignedVecBegin + C.getEndIdx () + 1 , [](unsigned I) {
860
863
return I == static_cast <unsigned >(-1 );
861
864
});
862
865
});
863
866
864
867
#ifndef NDEBUG
865
- auto NumCandidatesAfter = OF. Candidates .size ();
868
+ auto NumCandidatesAfter = OF-> Candidates .size ();
866
869
LLVM_DEBUG (dbgs () << " PRUNED: " << NumCandidatesBefore - NumCandidatesAfter
867
870
<< " /" << NumCandidatesBefore << " candidates\n " );
868
871
#endif
869
872
870
873
// If we made it unbeneficial to outline this function, skip it.
871
- if (OF. getBenefit () < OutlinerBenefitThreshold) {
872
- LLVM_DEBUG (dbgs () << " SKIP: Expected benefit (" << OF. getBenefit ()
874
+ if (OF-> getBenefit () < OutlinerBenefitThreshold) {
875
+ LLVM_DEBUG (dbgs () << " SKIP: Expected benefit (" << OF-> getBenefit ()
873
876
<< " B) < threshold (" << OutlinerBenefitThreshold
874
877
<< " B)\n " );
875
878
continue ;
876
879
}
877
880
878
- LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF. getBenefit ()
881
+ LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF-> getBenefit ()
879
882
<< " B) > threshold (" << OutlinerBenefitThreshold
880
883
<< " B)\n " );
881
884
882
885
// It's beneficial. Create the function and outline its sequence's
883
886
// occurrences.
884
- OF. MF = createOutlinedFunction (M, OF, Mapper, OutlinedFunctionNum);
885
- emitOutlinedFunctionRemark (OF);
887
+ OF-> MF = createOutlinedFunction (M, * OF, Mapper, OutlinedFunctionNum);
888
+ emitOutlinedFunctionRemark (* OF);
886
889
FunctionsCreated++;
887
890
OutlinedFunctionNum++; // Created a function, move to the next name.
888
- MachineFunction *MF = OF. MF ;
891
+ MachineFunction *MF = OF-> MF ;
889
892
const TargetSubtargetInfo &STI = MF->getSubtarget ();
890
893
const TargetInstrInfo &TII = *STI.getInstrInfo ();
891
894
892
895
// Replace occurrences of the sequence with calls to the new function.
893
896
LLVM_DEBUG (dbgs () << " CREATE OUTLINED CALLS\n " );
894
- for (Candidate &C : OF. Candidates ) {
897
+ for (Candidate &C : OF-> Candidates ) {
895
898
MachineBasicBlock &MBB = *C.getMBB ();
896
899
MachineBasicBlock::iterator StartIt = C.begin ();
897
900
MachineBasicBlock::iterator EndIt = std::prev (C.end ());
@@ -1183,7 +1186,7 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
1183
1186
1184
1187
// Prepare instruction mappings for the suffix tree.
1185
1188
populateMapper (Mapper, M, MMI);
1186
- std::vector<OutlinedFunction> FunctionList;
1189
+ std::vector<std::unique_ptr< OutlinedFunction> > FunctionList;
1187
1190
1188
1191
// Find all of the outlining candidates.
1189
1192
findCandidates (Mapper, FunctionList);
0 commit comments