diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -96,6 +96,10 @@ cl::desc("Enable the machine outliner on linkonceodr functions"), cl::init(false)); +static cl::opt Iterations( + "outlining-iteration", cl::init(1), cl::Hidden, + cl::desc("Total number of outlining iterations to perform")); + namespace { /// Represents an undefined index in the suffix tree. @@ -896,9 +900,13 @@ unsigned Name); /// Construct a suffix tree on the instructions in \p M and outline repeated - /// strings from that tree. + /// strings from that tree. This will be run doOutline on M Iterations times. bool runOnModule(Module &M) override; + /// Construct a suffix tree on the instructions in \p M and outline repeated + /// strings from that tree. This will do outlining on M once. + bool doOutline(Module &M); + /// Return a DISubprogram for OF if one exists, and null otherwise. Helper /// function for remark emission. DISubprogram *getSubprogramOrNull(const OutlinedFunction &OF) { @@ -1427,6 +1435,20 @@ if (M.empty()) return false; + if (Iterations > 1) { + bool Changed = false; + for (unsigned I = 0; I < Iterations; ++I) + if (doOutline(M)) + Changed = true; + else + return Changed; + return Changed; + } + + return doOutline(M); +} + +bool MachineOutliner::doOutline(Module &M) { MachineModuleInfo &MMI = getAnalysis().getMMI(); // If the user passed -enable-machine-outliner=always or