diff options
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; } |