@@ -620,10 +620,8 @@ struct InstructionMapper {
620
620
// / queried for candidates.
621
621
// /
622
622
// / \param MBB The \p MachineBasicBlock to be translated into integers.
623
- // / \param TRI \p TargetRegisterInfo for the module.
624
- // / \param TII \p TargetInstrInfo for the module.
623
+ // / \param TII \p TargetInstrInfo for the function.
625
624
void convertToUnsignedVec (MachineBasicBlock &MBB,
626
- const TargetRegisterInfo &TRI,
627
625
const TargetInstrInfo &TII) {
628
626
unsigned Flags = TII.getMachineOutlinerMBBFlags (MBB);
629
627
@@ -729,7 +727,6 @@ struct MachineOutliner : public ModulePass {
729
727
// / its leaf children to find the locations of its substring.
730
728
// /
731
729
// / \param ST A suffix tree to query.
732
- // / \param TII TargetInstrInfo for the target.
733
730
// / \param Mapper Contains outlining mapping information.
734
731
// / \param[out] CandidateList Filled with candidates representing each
735
732
// / beneficial substring.
@@ -738,7 +735,7 @@ struct MachineOutliner : public ModulePass {
738
735
// /
739
736
// / \returns The length of the longest candidate found.
740
737
unsigned
741
- findCandidates (SuffixTree &ST, const TargetInstrInfo &TII,
738
+ findCandidates (SuffixTree &ST,
742
739
InstructionMapper &Mapper,
743
740
std::vector<std::shared_ptr<Candidate>> &CandidateList,
744
741
std::vector<OutlinedFunction> &FunctionList);
@@ -770,14 +767,12 @@ struct MachineOutliner : public ModulePass {
770
767
// / \param[out] FunctionList Filled with functions corresponding to each type
771
768
// / of \p Candidate.
772
769
// / \param ST The suffix tree for the module.
773
- // / \param TII TargetInstrInfo for the module.
774
770
// /
775
771
// / \returns The length of the longest candidate found. 0 if there are none.
776
772
unsigned
777
773
buildCandidateList (std::vector<std::shared_ptr<Candidate>> &CandidateList,
778
774
std::vector<OutlinedFunction> &FunctionList,
779
- SuffixTree &ST, InstructionMapper &Mapper,
780
- const TargetInstrInfo &TII);
775
+ SuffixTree &ST, InstructionMapper &Mapper);
781
776
782
777
// / Helper function for pruneOverlaps.
783
778
// / Removes \p C from the candidate list, and updates its \p OutlinedFunction.
@@ -795,11 +790,9 @@ struct MachineOutliner : public ModulePass {
795
790
// / \param[in,out] FunctionList A list of functions to be outlined.
796
791
// / \param Mapper Contains instruction mapping info for outlining.
797
792
// / \param MaxCandidateLen The length of the longest candidate.
798
- // / \param TII TargetInstrInfo for the module.
799
793
void pruneOverlaps (std::vector<std::shared_ptr<Candidate>> &CandidateList,
800
794
std::vector<OutlinedFunction> &FunctionList,
801
- InstructionMapper &Mapper, unsigned MaxCandidateLen,
802
- const TargetInstrInfo &TII);
795
+ InstructionMapper &Mapper, unsigned MaxCandidateLen);
803
796
804
797
// / Construct a suffix tree on the instructions in \p M and outline repeated
805
798
// / strings from that tree.
@@ -892,7 +885,7 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
892
885
}
893
886
894
887
unsigned MachineOutliner::findCandidates (
895
- SuffixTree &ST, const TargetInstrInfo &TII, InstructionMapper &Mapper,
888
+ SuffixTree &ST, InstructionMapper &Mapper,
896
889
std::vector<std::shared_ptr<Candidate>> &CandidateList,
897
890
std::vector<OutlinedFunction> &FunctionList) {
898
891
CandidateList.clear ();
@@ -979,8 +972,16 @@ unsigned MachineOutliner::findCandidates(
979
972
// We've found something we might want to outline.
980
973
// Create an OutlinedFunction to store it and check if it'd be beneficial
981
974
// to outline.
975
+ if (CandidatesForRepeatedSeq.empty ())
976
+ continue ;
977
+
978
+ // Arbitrarily choose a TII from the first candidate.
979
+ // FIXME: Should getOutliningCandidateInfo move to TargetMachine?
980
+ const TargetInstrInfo *TII =
981
+ CandidatesForRepeatedSeq[0 ].getMF ()->getSubtarget ().getInstrInfo ();
982
+
982
983
OutlinedFunction OF =
983
- TII. getOutliningCandidateInfo (CandidatesForRepeatedSeq);
984
+ TII-> getOutliningCandidateInfo (CandidatesForRepeatedSeq);
984
985
985
986
// If we deleted every candidate, then there's nothing to outline.
986
987
if (OF.Candidates .empty ())
@@ -1036,7 +1037,7 @@ void MachineOutliner::prune(Candidate &C,
1036
1037
void MachineOutliner::pruneOverlaps (
1037
1038
std::vector<std::shared_ptr<Candidate>> &CandidateList,
1038
1039
std::vector<OutlinedFunction> &FunctionList, InstructionMapper &Mapper,
1039
- unsigned MaxCandidateLen, const TargetInstrInfo &TII ) {
1040
+ unsigned MaxCandidateLen) {
1040
1041
1041
1042
// Return true if this candidate became unbeneficial for outlining in a
1042
1043
// previous step.
@@ -1127,13 +1128,13 @@ void MachineOutliner::pruneOverlaps(
1127
1128
unsigned MachineOutliner::buildCandidateList (
1128
1129
std::vector<std::shared_ptr<Candidate>> &CandidateList,
1129
1130
std::vector<OutlinedFunction> &FunctionList, SuffixTree &ST,
1130
- InstructionMapper &Mapper, const TargetInstrInfo &TII ) {
1131
+ InstructionMapper &Mapper) {
1131
1132
1132
1133
std::vector<unsigned > CandidateSequence; // Current outlining candidate.
1133
1134
unsigned MaxCandidateLen = 0 ; // Length of the longest candidate.
1134
1135
1135
1136
MaxCandidateLen =
1136
- findCandidates (ST, TII, Mapper, CandidateList, FunctionList);
1137
+ findCandidates (ST, Mapper, CandidateList, FunctionList);
1137
1138
1138
1139
// Sort the candidates in decending order. This will simplify the outlining
1139
1140
// process when we have to remove the candidates from the mapping by
@@ -1339,10 +1340,6 @@ bool MachineOutliner::runOnModule(Module &M) {
1339
1340
return false ;
1340
1341
1341
1342
MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
1342
- const TargetSubtargetInfo &STI =
1343
- MMI.getOrCreateMachineFunction (*M.begin ()).getSubtarget ();
1344
- const TargetRegisterInfo *TRI = STI.getRegisterInfo ();
1345
- const TargetInstrInfo *TII = STI.getInstrInfo ();
1346
1343
1347
1344
// If the user passed -enable-machine-outliner=always or
1348
1345
// -enable-machine-outliner, the pass will run on all functions in the module.
@@ -1382,6 +1379,8 @@ bool MachineOutliner::runOnModule(Module &M) {
1382
1379
if (!MF)
1383
1380
continue ;
1384
1381
1382
+ const TargetInstrInfo *TII = MF->getSubtarget ().getInstrInfo ();
1383
+
1385
1384
if (!RunOnAllFunctions && !TII->shouldOutlineFromFunctionByDefault (*MF))
1386
1385
continue ;
1387
1386
@@ -1405,7 +1404,7 @@ bool MachineOutliner::runOnModule(Module &M) {
1405
1404
continue ;
1406
1405
1407
1406
// MBB is suitable for outlining. Map it to a list of unsigneds.
1408
- Mapper.convertToUnsignedVec (MBB, *TRI, * TII);
1407
+ Mapper.convertToUnsignedVec (MBB, *TII);
1409
1408
}
1410
1409
}
1411
1410
@@ -1416,10 +1415,10 @@ bool MachineOutliner::runOnModule(Module &M) {
1416
1415
1417
1416
// Find all of the outlining candidates.
1418
1417
unsigned MaxCandidateLen =
1419
- buildCandidateList (CandidateList, FunctionList, ST, Mapper, *TII );
1418
+ buildCandidateList (CandidateList, FunctionList, ST, Mapper);
1420
1419
1421
1420
// Remove candidates that overlap with other candidates.
1422
- pruneOverlaps (CandidateList, FunctionList, Mapper, MaxCandidateLen, *TII );
1421
+ pruneOverlaps (CandidateList, FunctionList, Mapper, MaxCandidateLen);
1423
1422
1424
1423
// Outline each of the candidates and return true if something was outlined.
1425
1424
bool OutlinedSomething = outline (M, CandidateList, FunctionList, Mapper);
0 commit comments