@@ -710,22 +710,28 @@ struct MachineOutliner : public ModulePass {
710
710
initializeMachineOutlinerPass (*PassRegistry::getPassRegistry ());
711
711
}
712
712
713
+ // / Remark output explaining that not outlining a set of candidates would be
714
+ // / better than outlining that set.
715
+ void emitNotOutliningCheaperRemark (
716
+ unsigned StringLen, std::vector<Candidate> &CandidatesForRepeatedSeq,
717
+ OutlinedFunction &OF);
718
+
713
719
// / Find all repeated substrings that satisfy the outlining cost model.
714
720
// /
715
721
// / If a substring appears at least twice, then it must be represented by
716
- // / an internal node which appears in at least two suffixes. Each suffix is
717
- // / represented by a leaf node. To do this, we visit each internal node in
718
- // / the tree, using the leaf children of each internal node. If an internal
719
- // / node represents a beneficial substring, then we use each of its leaf
720
- // / children to find the locations of its substring.
722
+ // / an internal node which appears in at least two suffixes. Each suffix
723
+ // / is represented by a leaf node. To do this, we visit each internal node
724
+ // / in the tree, using the leaf children of each internal node. If an
725
+ // / internal node represents a beneficial substring, then we use each of
726
+ // / its leaf children to find the locations of its substring.
721
727
// /
722
728
// / \param ST A suffix tree to query.
723
729
// / \param TII TargetInstrInfo for the target.
724
730
// / \param Mapper Contains outlining mapping information.
725
731
// / \param[out] CandidateList Filled with candidates representing each
726
732
// / beneficial substring.
727
- // / \param[out] FunctionList Filled with a list of \p OutlinedFunctions each
728
- // / type of candidate.
733
+ // / \param[out] FunctionList Filled with a list of \p OutlinedFunctions
734
+ // / each type of candidate.
729
735
// /
730
736
// / \returns The length of the longest candidate found.
731
737
unsigned
@@ -823,6 +829,36 @@ ModulePass *createMachineOutlinerPass(bool RunOnAllFunctions) {
823
829
INITIALIZE_PASS (MachineOutliner, DEBUG_TYPE, " Machine Function Outliner" , false ,
824
830
false )
825
831
832
+ void MachineOutliner::emitNotOutliningCheaperRemark(
833
+ unsigned StringLen, std::vector<Candidate> &CandidatesForRepeatedSeq,
834
+ OutlinedFunction &OF) {
835
+ Candidate &C = CandidatesForRepeatedSeq.front ();
836
+ MachineOptimizationRemarkEmitter MORE (*(C.getMF ()), nullptr );
837
+ MORE.emit ([&]() {
838
+ MachineOptimizationRemarkMissed R (DEBUG_TYPE, " NotOutliningCheaper" ,
839
+ C.front ()->getDebugLoc (), C.getMBB ());
840
+ R << " Did not outline " << NV (" Length" , StringLen) << " instructions"
841
+ << " from " << NV (" NumOccurrences" , CandidatesForRepeatedSeq.size ())
842
+ << " locations."
843
+ << " Bytes from outlining all occurrences ("
844
+ << NV (" OutliningCost" , OF.getOutliningCost ()) << " )"
845
+ << " >= Unoutlined instruction bytes ("
846
+ << NV (" NotOutliningCost" , OF.getNotOutlinedCost ()) << " )"
847
+ << " (Also found at: " ;
848
+
849
+ // Tell the user the other places the candidate was found.
850
+ for (unsigned i = 1 , e = CandidatesForRepeatedSeq.size (); i < e; i++) {
851
+ R << NV ((Twine (" OtherStartLoc" ) + Twine (i)).str (),
852
+ CandidatesForRepeatedSeq[i].front ()->getDebugLoc ());
853
+ if (i != e - 1 )
854
+ R << " , " ;
855
+ }
856
+
857
+ R << " )" ;
858
+ return R;
859
+ });
860
+ }
861
+
826
862
unsigned MachineOutliner::findCandidates (
827
863
SuffixTree &ST, const TargetInstrInfo &TII, InstructionMapper &Mapper,
828
864
std::vector<std::shared_ptr<Candidate>> &CandidateList,
@@ -916,41 +952,12 @@ unsigned MachineOutliner::findCandidates(
916
952
std::vector<unsigned > Seq;
917
953
for (unsigned i = Leaf->SuffixIdx ; i < Leaf->SuffixIdx + StringLen; i++)
918
954
Seq.push_back (ST.Str [i]);
919
- OutlinedFunction OF (FunctionList.size (), CandidatesForRepeatedSeq,
920
- Seq, TCI);
955
+ OutlinedFunction OF (FunctionList.size (), CandidatesForRepeatedSeq, Seq,
956
+ TCI);
921
957
922
958
// Is it better to outline this candidate than not?
923
959
if (OF.getBenefit () < 1 ) {
924
- // Outlining this candidate would take more instructions than not
925
- // outlining.
926
- // Emit a remark explaining why we didn't outline this candidate.
927
- Candidate &C = CandidatesForRepeatedSeq.front ();
928
- MachineOptimizationRemarkEmitter MORE (*(C.getMF ()), nullptr );
929
- MORE.emit ([&]() {
930
- MachineOptimizationRemarkMissed R (DEBUG_TYPE, " NotOutliningCheaper" ,
931
- C.front ()->getDebugLoc (), C.getMBB ());
932
- R << " Did not outline " << NV (" Length" , StringLen) << " instructions"
933
- << " from " << NV (" NumOccurrences" , CandidatesForRepeatedSeq.size ())
934
- << " locations."
935
- << " Bytes from outlining all occurrences ("
936
- << NV (" OutliningCost" , OF.getOutliningCost ()) << " )"
937
- << " >= Unoutlined instruction bytes ("
938
- << NV (" NotOutliningCost" , OF.getNotOutlinedCost ()) << " )"
939
- << " (Also found at: " ;
940
-
941
- // Tell the user the other places the candidate was found.
942
- for (unsigned i = 1 , e = CandidatesForRepeatedSeq.size (); i < e; i++) {
943
- R << NV ((Twine (" OtherStartLoc" ) + Twine (i)).str (),
944
- CandidatesForRepeatedSeq[i].front ()->getDebugLoc ());
945
- if (i != e - 1 )
946
- R << " , " ;
947
- }
948
-
949
- R << " )" ;
950
- return R;
951
- });
952
-
953
- // Move to the next candidate.
960
+ emitNotOutliningCheaperRemark (StringLen, CandidatesForRepeatedSeq, OF);
954
961
continue ;
955
962
}
956
963
0 commit comments