@@ -446,16 +446,19 @@ struct MachineOutliner : public ModulePass {
446
446
// / \param Mapper Contains outlining mapping information.
447
447
// / \param[out] FunctionList Filled with a list of \p OutlinedFunctions
448
448
// / 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);
451
452
452
453
// / Replace the sequences of instructions represented by \p OutlinedFunctions
453
454
// / with calls to functions.
454
455
// /
455
456
// / \param M The module we are outlining from.
456
457
// / \param FunctionList A list of functions to be inserted into the module.
457
458
// / \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,
459
462
InstructionMapper &Mapper, unsigned &OutlinedFunctionNum);
460
463
461
464
// / Creates a function for \p OF and inserts it into the module.
@@ -574,7 +577,8 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
574
577
}
575
578
576
579
void MachineOutliner::findCandidates (
577
- InstructionMapper &Mapper, std::vector<OutlinedFunction> &FunctionList) {
580
+ InstructionMapper &Mapper,
581
+ std::vector<std::unique_ptr<OutlinedFunction>> &FunctionList) {
578
582
FunctionList.clear ();
579
583
SuffixTree ST (Mapper.UnsignedVec );
580
584
@@ -674,7 +678,7 @@ void MachineOutliner::findCandidates(
674
678
continue ;
675
679
}
676
680
677
- FunctionList.push_back (*OF);
681
+ FunctionList.push_back (std::make_unique<OutlinedFunction>( *OF) );
678
682
}
679
683
}
680
684
@@ -819,69 +823,68 @@ MachineFunction *MachineOutliner::createOutlinedFunction(
819
823
return &MF;
820
824
}
821
825
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) {
826
829
LLVM_DEBUG (dbgs () << " *** Outlining ***\n " );
827
830
LLVM_DEBUG (dbgs () << " NUMBER OF POTENTIAL FUNCTIONS: " << FunctionList.size ()
828
831
<< " \n " );
829
832
bool OutlinedSomething = false ;
830
833
831
834
// 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
+ });
836
839
837
840
// Walk over each function, outlining them as we go along. Functions are
838
841
// outlined greedily, based off the sort above.
839
842
auto *UnsignedVecBegin = Mapper.UnsignedVec .begin ();
840
843
LLVM_DEBUG (dbgs () << " WALKING FUNCTION LIST\n " );
841
- for (OutlinedFunction &OF : FunctionList) {
844
+ for (auto &OF : FunctionList) {
842
845
#ifndef NDEBUG
843
- auto NumCandidatesBefore = OF. Candidates .size ();
846
+ auto NumCandidatesBefore = OF-> Candidates .size ();
844
847
#endif
845
848
// If we outlined something that overlapped with a candidate in a previous
846
849
// step, then we can't outline from it.
847
- erase_if (OF. Candidates , [&UnsignedVecBegin](Candidate &C) {
850
+ erase_if (OF-> Candidates , [&UnsignedVecBegin](Candidate &C) {
848
851
return std::any_of (UnsignedVecBegin + C.getStartIdx (),
849
852
UnsignedVecBegin + C.getEndIdx () + 1 , [](unsigned I) {
850
853
return I == static_cast <unsigned >(-1 );
851
854
});
852
855
});
853
856
854
857
#ifndef NDEBUG
855
- auto NumCandidatesAfter = OF. Candidates .size ();
858
+ auto NumCandidatesAfter = OF-> Candidates .size ();
856
859
LLVM_DEBUG (dbgs () << " PRUNED: " << NumCandidatesBefore - NumCandidatesAfter
857
860
<< " /" << NumCandidatesBefore << " candidates\n " );
858
861
#endif
859
862
860
863
// 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 ()
863
866
<< " B) < threshold (" << OutlinerBenefitThreshold
864
867
<< " B)\n " );
865
868
continue ;
866
869
}
867
870
868
- LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF. getBenefit ()
871
+ LLVM_DEBUG (dbgs () << " OUTLINE: Expected benefit (" << OF-> getBenefit ()
869
872
<< " B) > threshold (" << OutlinerBenefitThreshold
870
873
<< " B)\n " );
871
874
872
875
// It's beneficial. Create the function and outline its sequence's
873
876
// occurrences.
874
- OF. MF = createOutlinedFunction (M, OF, Mapper, OutlinedFunctionNum);
875
- emitOutlinedFunctionRemark (OF);
877
+ OF-> MF = createOutlinedFunction (M, * OF, Mapper, OutlinedFunctionNum);
878
+ emitOutlinedFunctionRemark (* OF);
876
879
FunctionsCreated++;
877
880
OutlinedFunctionNum++; // Created a function, move to the next name.
878
- MachineFunction *MF = OF. MF ;
881
+ MachineFunction *MF = OF-> MF ;
879
882
const TargetSubtargetInfo &STI = MF->getSubtarget ();
880
883
const TargetInstrInfo &TII = *STI.getInstrInfo ();
881
884
882
885
// Replace occurrences of the sequence with calls to the new function.
883
886
LLVM_DEBUG (dbgs () << " CREATE OUTLINED CALLS\n " );
884
- for (Candidate &C : OF. Candidates ) {
887
+ for (Candidate &C : OF-> Candidates ) {
885
888
MachineBasicBlock &MBB = *C.getMBB ();
886
889
MachineBasicBlock::iterator StartIt = C.begin ();
887
890
MachineBasicBlock::iterator EndIt = std::prev (C.end ());
@@ -1173,7 +1176,7 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
1173
1176
1174
1177
// Prepare instruction mappings for the suffix tree.
1175
1178
populateMapper (Mapper, M, MMI);
1176
- std::vector<OutlinedFunction> FunctionList;
1179
+ std::vector<std::unique_ptr< OutlinedFunction> > FunctionList;
1177
1180
1178
1181
// Find all of the outlining candidates.
1179
1182
findCandidates (Mapper, FunctionList);
0 commit comments