diff options
author | Puyan Lotfi <puyan@puyan.org> | 2020-04-29 03:33:47 -0400 |
---|---|---|
committer | Puyan Lotfi <puyan@puyan.org> | 2020-04-29 18:36:47 -0400 |
commit | ffd5e121d7444e93db02506b30719fd1df19a9f7 (patch) | |
tree | 1b2b71542a1b436c75f1ff0da8ec0bad14a61417 /llvm/lib/CodeGen/MachineOutliner.cpp | |
parent | 2c7ff270d28419cc038288f620e57ed1786053b2 (diff) | |
download | llvm-ffd5e121d7444e93db02506b30719fd1df19a9f7.zip llvm-ffd5e121d7444e93db02506b30719fd1df19a9f7.tar.gz llvm-ffd5e121d7444e93db02506b30719fd1df19a9f7.tar.bz2 |
[NFCi] Iterative Outliner + clang-format refactoring.
Prior to D69446 I had done some NFC cleanup to make landing an iterative
outliner a cleaner more straight-forward patch. Since then, it seems that has
landed but I noticed some ways it could be cleaned up. Specifically:
1) doOutline was meant to be the re-runable function, but instead
runOnceOnModule was created that just calls doOutline.
2) In D69446 we discussed that the flag allowing the re-run of the
outliner should be a flag to tell how many additional times to run
the outliner again, not the total number of times. I don't think it
makes sense to introduce a flag, but print an error if the flag is
set to 0.
This is an NFCi, the i being that I get rid of the way that the
machine-outline-runs flag could be used to tell the outliner to not run
at all, and because I renamed the flag to '-machine-outliner-reruns'.
Differential Revision: https://reviews.llvm.org/D79070
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 75 |
1 files changed, 36 insertions, 39 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index e15dcc3..dd1dd2c 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -97,12 +97,13 @@ static cl::opt<bool> EnableLinkOnceODROutlining( cl::desc("Enable the machine outliner on linkonceodr functions"), cl::init(false)); -// Set the number of times to repeatedly apply outlining. -// Defaults to 1, but more repetitions can save additional size. -static cl::opt<unsigned> - NumRepeat("machine-outline-runs", cl::Hidden, - cl::desc("The number of times to apply machine outlining"), - cl::init(1)); +/// Number of times to re-run the outliner. This is not the total number of runs +/// as the outliner will run at least one time. The default value is set to 0, +/// meaning the outliner will run one time and rerun zero times after that. +static cl::opt<unsigned> OutlinerReruns( + "machine-outliner-reruns", cl::init(0), cl::Hidden, + cl::desc( + "Number of times to rerun the outliner after the initial outline")); namespace { @@ -910,12 +911,9 @@ struct MachineOutliner : public ModulePass { InstructionMapper &Mapper, unsigned Name); - /// Calls runOnceOnModule NumRepeat times + /// Calls 'doOutline()' 1 + OutlinerReruns times. bool runOnModule(Module &M) override; - /// Calls 'doOutline()'. - bool runOnceOnModule(Module &M, unsigned Iter); - /// Construct a suffix tree on the instructions in \p M and outline repeated /// strings from that tree. bool doOutline(Module &M, unsigned &OutlinedFunctionNum); @@ -1306,8 +1304,9 @@ bool MachineOutliner::outline(Module &M, // implicit Last inst in outlined range <-- def to the call // instruction. Also remove call site information for outlined block // of code. The exposed uses need to be copied in the outlined range. - for (MachineBasicBlock::reverse_iterator Iter = EndIt.getReverse(), - Last = std::next(CallInst.getReverse()); + for (MachineBasicBlock::reverse_iterator + Iter = EndIt.getReverse(), + Last = std::next(CallInst.getReverse()); Iter != Last; Iter++) { MachineInstr *MI = &*Iter; for (MachineOperand &MOP : MI->operands()) { @@ -1333,10 +1332,10 @@ bool MachineOutliner::outline(Module &M, } for (const Register &I : DefRegs) - // If it's a def, add it to the call instruction. - CallInst->addOperand(MachineOperand::CreateReg( - I, true, /* isDef = true */ - true /* isImp = true */)); + // If it's a def, add it to the call instruction. + CallInst->addOperand( + MachineOperand::CreateReg(I, true, /* isDef = true */ + true /* isImp = true */)); for (const Register &I : UseRegs) // If it's a exposed use, add it to the call instruction. @@ -1487,19 +1486,31 @@ void MachineOutliner::emitInstrCountChangedRemark( } } -bool MachineOutliner::runOnceOnModule(Module &M, unsigned Iter) { +bool MachineOutliner::runOnModule(Module &M) { // Check if there's anything in the module. If it's empty, then there's // nothing to outline. if (M.empty()) return false; - OutlineRepeatedNum = Iter; - // Number to append to the current outlined function. unsigned OutlinedFunctionNum = 0; + OutlineRepeatedNum = 0; if (!doOutline(M, OutlinedFunctionNum)) return false; + + for (unsigned I = 0; I < OutlinerReruns; ++I) { + OutlinedFunctionNum = 0; + OutlineRepeatedNum++; + if (!doOutline(M, OutlinedFunctionNum)) { + LLVM_DEBUG({ + dbgs() << "Did not outline on iteration " << I + 2 << " out of " + << OutlinerReruns + 1 << "\n"; + }); + break; + } + } + return true; } @@ -1556,25 +1567,11 @@ bool MachineOutliner::doOutline(Module &M, unsigned &OutlinedFunctionNum) { if (ShouldEmitSizeRemarks && OutlinedSomething) emitInstrCountChangedRemark(M, MMI, FunctionToInstrCount); - return OutlinedSomething; -} + LLVM_DEBUG({ + if (!OutlinedSomething) + dbgs() << "Stopped outlining at iteration " << OutlineRepeatedNum + << " because no changes were found.\n"; + }); -// Apply machine outlining for NumRepeat times. -bool MachineOutliner::runOnModule(Module &M) { - if (NumRepeat < 1) - report_fatal_error("Expect NumRepeat for machine outlining " - "to be greater than or equal to 1!\n"); - - bool Changed = false; - for (unsigned I = 0; I < NumRepeat; I++) { - if (!runOnceOnModule(M, I)) { - LLVM_DEBUG(dbgs() << "Stopped outlining at iteration " << I - << " because no changes were found.\n";); - return Changed; - } - Changed = true; - } - LLVM_DEBUG(dbgs() << "Stopped outlining because iteration is " - "equal to " << NumRepeat << "\n";); - return Changed; + return OutlinedSomething; } |