Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit a390496

Browse files
author
Eli Friedman
committed
[MachineOutliner] Clean up subtarget handling.
Call shouldOutlineFromFunctionByDefault, isFunctionSafeToOutlineFrom, getOutliningType, and getMachineOutlinerMBBFlags using the correct TargetInstrInfo. And don't create a MachineFunction for a function declaration. The call to getOutliningCandidateInfo is still a little weird, but at least the weirdness is explicitly called out. Differential Revision: https://reviews.llvm.org/D49880 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338465 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 6baa465 commit a390496

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

lib/CodeGen/MachineOutliner.cpp

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,8 @@ struct InstructionMapper {
620620
/// queried for candidates.
621621
///
622622
/// \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.
625624
void convertToUnsignedVec(MachineBasicBlock &MBB,
626-
const TargetRegisterInfo &TRI,
627625
const TargetInstrInfo &TII) {
628626
unsigned Flags = TII.getMachineOutlinerMBBFlags(MBB);
629627

@@ -729,7 +727,6 @@ struct MachineOutliner : public ModulePass {
729727
/// its leaf children to find the locations of its substring.
730728
///
731729
/// \param ST A suffix tree to query.
732-
/// \param TII TargetInstrInfo for the target.
733730
/// \param Mapper Contains outlining mapping information.
734731
/// \param[out] CandidateList Filled with candidates representing each
735732
/// beneficial substring.
@@ -738,7 +735,7 @@ struct MachineOutliner : public ModulePass {
738735
///
739736
/// \returns The length of the longest candidate found.
740737
unsigned
741-
findCandidates(SuffixTree &ST, const TargetInstrInfo &TII,
738+
findCandidates(SuffixTree &ST,
742739
InstructionMapper &Mapper,
743740
std::vector<std::shared_ptr<Candidate>> &CandidateList,
744741
std::vector<OutlinedFunction> &FunctionList);
@@ -770,14 +767,12 @@ struct MachineOutliner : public ModulePass {
770767
/// \param[out] FunctionList Filled with functions corresponding to each type
771768
/// of \p Candidate.
772769
/// \param ST The suffix tree for the module.
773-
/// \param TII TargetInstrInfo for the module.
774770
///
775771
/// \returns The length of the longest candidate found. 0 if there are none.
776772
unsigned
777773
buildCandidateList(std::vector<std::shared_ptr<Candidate>> &CandidateList,
778774
std::vector<OutlinedFunction> &FunctionList,
779-
SuffixTree &ST, InstructionMapper &Mapper,
780-
const TargetInstrInfo &TII);
775+
SuffixTree &ST, InstructionMapper &Mapper);
781776

782777
/// Helper function for pruneOverlaps.
783778
/// Removes \p C from the candidate list, and updates its \p OutlinedFunction.
@@ -795,11 +790,9 @@ struct MachineOutliner : public ModulePass {
795790
/// \param[in,out] FunctionList A list of functions to be outlined.
796791
/// \param Mapper Contains instruction mapping info for outlining.
797792
/// \param MaxCandidateLen The length of the longest candidate.
798-
/// \param TII TargetInstrInfo for the module.
799793
void pruneOverlaps(std::vector<std::shared_ptr<Candidate>> &CandidateList,
800794
std::vector<OutlinedFunction> &FunctionList,
801-
InstructionMapper &Mapper, unsigned MaxCandidateLen,
802-
const TargetInstrInfo &TII);
795+
InstructionMapper &Mapper, unsigned MaxCandidateLen);
803796

804797
/// Construct a suffix tree on the instructions in \p M and outline repeated
805798
/// strings from that tree.
@@ -892,7 +885,7 @@ void MachineOutliner::emitOutlinedFunctionRemark(OutlinedFunction &OF) {
892885
}
893886

894887
unsigned MachineOutliner::findCandidates(
895-
SuffixTree &ST, const TargetInstrInfo &TII, InstructionMapper &Mapper,
888+
SuffixTree &ST, InstructionMapper &Mapper,
896889
std::vector<std::shared_ptr<Candidate>> &CandidateList,
897890
std::vector<OutlinedFunction> &FunctionList) {
898891
CandidateList.clear();
@@ -979,8 +972,16 @@ unsigned MachineOutliner::findCandidates(
979972
// We've found something we might want to outline.
980973
// Create an OutlinedFunction to store it and check if it'd be beneficial
981974
// 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+
982983
OutlinedFunction OF =
983-
TII.getOutliningCandidateInfo(CandidatesForRepeatedSeq);
984+
TII->getOutliningCandidateInfo(CandidatesForRepeatedSeq);
984985

985986
// If we deleted every candidate, then there's nothing to outline.
986987
if (OF.Candidates.empty())
@@ -1036,7 +1037,7 @@ void MachineOutliner::prune(Candidate &C,
10361037
void MachineOutliner::pruneOverlaps(
10371038
std::vector<std::shared_ptr<Candidate>> &CandidateList,
10381039
std::vector<OutlinedFunction> &FunctionList, InstructionMapper &Mapper,
1039-
unsigned MaxCandidateLen, const TargetInstrInfo &TII) {
1040+
unsigned MaxCandidateLen) {
10401041

10411042
// Return true if this candidate became unbeneficial for outlining in a
10421043
// previous step.
@@ -1127,13 +1128,13 @@ void MachineOutliner::pruneOverlaps(
11271128
unsigned MachineOutliner::buildCandidateList(
11281129
std::vector<std::shared_ptr<Candidate>> &CandidateList,
11291130
std::vector<OutlinedFunction> &FunctionList, SuffixTree &ST,
1130-
InstructionMapper &Mapper, const TargetInstrInfo &TII) {
1131+
InstructionMapper &Mapper) {
11311132

11321133
std::vector<unsigned> CandidateSequence; // Current outlining candidate.
11331134
unsigned MaxCandidateLen = 0; // Length of the longest candidate.
11341135

11351136
MaxCandidateLen =
1136-
findCandidates(ST, TII, Mapper, CandidateList, FunctionList);
1137+
findCandidates(ST, Mapper, CandidateList, FunctionList);
11371138

11381139
// Sort the candidates in decending order. This will simplify the outlining
11391140
// process when we have to remove the candidates from the mapping by
@@ -1339,10 +1340,6 @@ bool MachineOutliner::runOnModule(Module &M) {
13391340
return false;
13401341

13411342
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();
13461343

13471344
// If the user passed -enable-machine-outliner=always or
13481345
// -enable-machine-outliner, the pass will run on all functions in the module.
@@ -1382,6 +1379,8 @@ bool MachineOutliner::runOnModule(Module &M) {
13821379
if (!MF)
13831380
continue;
13841381

1382+
const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo();
1383+
13851384
if (!RunOnAllFunctions && !TII->shouldOutlineFromFunctionByDefault(*MF))
13861385
continue;
13871386

@@ -1405,7 +1404,7 @@ bool MachineOutliner::runOnModule(Module &M) {
14051404
continue;
14061405

14071406
// MBB is suitable for outlining. Map it to a list of unsigneds.
1408-
Mapper.convertToUnsignedVec(MBB, *TRI, *TII);
1407+
Mapper.convertToUnsignedVec(MBB, *TII);
14091408
}
14101409
}
14111410

@@ -1416,10 +1415,10 @@ bool MachineOutliner::runOnModule(Module &M) {
14161415

14171416
// Find all of the outlining candidates.
14181417
unsigned MaxCandidateLen =
1419-
buildCandidateList(CandidateList, FunctionList, ST, Mapper, *TII);
1418+
buildCandidateList(CandidateList, FunctionList, ST, Mapper);
14201419

14211420
// Remove candidates that overlap with other candidates.
1422-
pruneOverlaps(CandidateList, FunctionList, Mapper, MaxCandidateLen, *TII);
1421+
pruneOverlaps(CandidateList, FunctionList, Mapper, MaxCandidateLen);
14231422

14241423
// Outline each of the candidates and return true if something was outlined.
14251424
bool OutlinedSomething = outline(M, CandidateList, FunctionList, Mapper);

0 commit comments

Comments
 (0)