Skip to content

Commit a51fc8d

Browse files
committed
[MachineOuliner][NFC] Refactoring code to make outline rerunning a cleaner diff.
I want to add the ability to rerun the outliner in certain cases, and I thought this could be an NFC change that could make a subsequent change that allows for rerunning the outliner a cleaner diff. Differential Revision: https://reviews.llvm.org/D69482
1 parent e3a45a2 commit a51fc8d

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -888,16 +888,20 @@ struct MachineOutliner : public ModulePass {
888888
/// \param FunctionList A list of functions to be inserted into the module.
889889
/// \param Mapper Contains the instruction mappings for the module.
890890
bool outline(Module &M, std::vector<OutlinedFunction> &FunctionList,
891-
InstructionMapper &Mapper);
891+
InstructionMapper &Mapper,
892+
unsigned &OutlinedFunctionNum);
892893

893894
/// Creates a function for \p OF and inserts it into the module.
894895
MachineFunction *createOutlinedFunction(Module &M, OutlinedFunction &OF,
895896
InstructionMapper &Mapper,
896897
unsigned Name);
897898

899+
/// Calls 'doOutline()'.
900+
bool runOnModule(Module &M) override;
901+
898902
/// Construct a suffix tree on the instructions in \p M and outline repeated
899903
/// strings from that tree.
900-
bool runOnModule(Module &M) override;
904+
bool doOutline(Module &M, unsigned &OutlinedFunctionNum);
901905

902906
/// Return a DISubprogram for OF if one exists, and null otherwise. Helper
903907
/// function for remark emission.
@@ -1190,13 +1194,11 @@ MachineOutliner::createOutlinedFunction(Module &M, OutlinedFunction &OF,
11901194

11911195
bool MachineOutliner::outline(Module &M,
11921196
std::vector<OutlinedFunction> &FunctionList,
1193-
InstructionMapper &Mapper) {
1197+
InstructionMapper &Mapper,
1198+
unsigned &OutlinedFunctionNum) {
11941199

11951200
bool OutlinedSomething = false;
11961201

1197-
// Number to append to the current outlined function.
1198-
unsigned OutlinedFunctionNum = 0;
1199-
12001202
// Sort by benefit. The most beneficial functions should be outlined first.
12011203
llvm::stable_sort(FunctionList, [](const OutlinedFunction &LHS,
12021204
const OutlinedFunction &RHS) {
@@ -1427,6 +1429,15 @@ bool MachineOutliner::runOnModule(Module &M) {
14271429
if (M.empty())
14281430
return false;
14291431

1432+
// Number to append to the current outlined function.
1433+
unsigned OutlinedFunctionNum = 0;
1434+
1435+
if (!doOutline(M, OutlinedFunctionNum))
1436+
return false;
1437+
return true;
1438+
}
1439+
1440+
bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) {
14301441
MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
14311442

14321443
// If the user passed -enable-machine-outliner=always or
@@ -1470,7 +1481,8 @@ bool MachineOutliner::runOnModule(Module &M) {
14701481
initSizeRemarkInfo(M, MMI, FunctionToInstrCount);
14711482

14721483
// Outline each of the candidates and return true if something was outlined.
1473-
bool OutlinedSomething = outline(M, FunctionList, Mapper);
1484+
bool OutlinedSomething =
1485+
outline(M, FunctionList, Mapper, OutlinedFunctionNum);
14741486

14751487
// If we outlined something, we definitely changed the MI count of the
14761488
// module. If we've asked for size remarks, then output them.

0 commit comments

Comments
 (0)