@@ -456,16 +456,19 @@ struct MachineOutliner : public ModulePass {
456
456
// / \param Mapper Contains outlining mapping information.
457
457
// / \param[out] FunctionList Filled with a list of \p OutlinedFunctions
458
458
// / each type of candidate.
459
- void findCandidates (InstructionMapper &Mapper,
460
- std::vector<OutlinedFunction> &FunctionList);
459
+ void
460
+ findCandidates (InstructionMapper &Mapper,
461
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList);
461
462
462
463
// / Replace the sequences of instructions represented by \p OutlinedFunctions
463
464
// / with calls to functions.
464
465
// /
465
466
// / \param M The module we are outlining from.
466
467
// / \param FunctionList A list of functions to be inserted into the module.
467
468
// / \param Mapper Contains the instruction mappings for the module.
468
- bool outline (Module &M, std::vector<OutlinedFunction> &FunctionList,
469
+ // / \param[out] OutlinedFunctionNum The outlined function number.
470
+ bool outline (Module &M,
471
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList,
469
472
InstructionMapper &Mapper, unsigned &OutlinedFunctionNum);
470
473
471
474
// / Creates a function for \p OF and inserts it into the module.
@@ -583,7 +586,8 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
583
586
}
584
587
585
588
void MachineOutliner::findCandidates (
586
- InstructionMapper &Mapper, std::vector<OutlinedFunction> &FunctionList) {
589
+ InstructionMapper &Mapper,
590
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
587
591
FunctionList.clear ();
588
592
SuffixTree ST (Mapper.UnsignedVec , OutlinerLeafDescendants);
589
593
@@ -684,7 +688,7 @@ void MachineOutliner::findCandidates(
684
688
continue ;
685
689
}
686
690
687
- FunctionList.push_back (*OF);
691
+ FunctionList.push_back (std::make_unique<OutlinedFunction>( *OF) );
688
692
}
689
693
}
690
694
@@ -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 ());
@@ -1180,7 +1183,7 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
1180
1183
1181
1184
// Prepare instruction mappings for the suffix tree.
1182
1185
populateMapper (Mapper, M);
1183
- std::vector<OutlinedFunction> FunctionList;
1186
+ std::vector<std::unique_ptr< OutlinedFunction> > FunctionList;
1184
1187
1185
1188
// Find all of the outlining candidates.
1186
1189
findCandidates (Mapper, FunctionList);
0 commit comments