Skip to content

Commit 1cc52a0

Browse files
author
Jessica Paquette
committed
[MachineOutliner][NFC] Move missed opt remark into its own function
Having the missed remark code in the middle of `findCandidates` made the function hard to follow. This yanks that out into a new function, `emitNotOutliningCheaperRemark`. llvm-svn: 337839
1 parent f94d1d2 commit 1cc52a0

File tree

1 file changed

+46
-39
lines changed

1 file changed

+46
-39
lines changed

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -710,22 +710,28 @@ struct MachineOutliner : public ModulePass {
710710
initializeMachineOutlinerPass(*PassRegistry::getPassRegistry());
711711
}
712712

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+
713719
/// Find all repeated substrings that satisfy the outlining cost model.
714720
///
715721
/// 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.
721727
///
722728
/// \param ST A suffix tree to query.
723729
/// \param TII TargetInstrInfo for the target.
724730
/// \param Mapper Contains outlining mapping information.
725731
/// \param[out] CandidateList Filled with candidates representing each
726732
/// 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.
729735
///
730736
/// \returns The length of the longest candidate found.
731737
unsigned
@@ -823,6 +829,36 @@ ModulePass *createMachineOutlinerPass(bool RunOnAllFunctions) {
823829
INITIALIZE_PASS(MachineOutliner, DEBUG_TYPE, "Machine Function Outliner", false,
824830
false)
825831

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+
826862
unsigned MachineOutliner::findCandidates(
827863
SuffixTree &ST, const TargetInstrInfo &TII, InstructionMapper &Mapper,
828864
std::vector<std::shared_ptr<Candidate>> &CandidateList,
@@ -916,41 +952,12 @@ unsigned MachineOutliner::findCandidates(
916952
std::vector<unsigned> Seq;
917953
for (unsigned i = Leaf->SuffixIdx; i < Leaf->SuffixIdx + StringLen; i++)
918954
Seq.push_back(ST.Str[i]);
919-
OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq,
920-
Seq, TCI);
955+
OutlinedFunction OF(FunctionList.size(), CandidatesForRepeatedSeq, Seq,
956+
TCI);
921957

922958
// Is it better to outline this candidate than not?
923959
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);
954961
continue;
955962
}
956963

0 commit comments

Comments
 (0)