diff --git a/llvm/include/llvm/CodeGen/TailDuplicator.h b/llvm/include/llvm/CodeGen/TailDuplicator.h index 6e2860d3ff21..17412f1b022e 100644 --- a/llvm/include/llvm/CodeGen/TailDuplicator.h +++ b/llvm/include/llvm/CodeGen/TailDuplicator.h @@ -34,6 +34,7 @@ class TailDuplicator { const MachineModuleInfo *MMI; MachineRegisterInfo *MRI; bool PreRegAlloc; + unsigned TailDupSize; // A list of virtual registers for which to update SSA form. SmallVector SSAUpdateVRs; @@ -45,8 +46,11 @@ class TailDuplicator { DenseMap SSAUpdateVals; public: + /// Prepare to run on a specific machine function. + /// @param TailDupSize - Maxmimum size of blocks to tail-duplicate. void initMF(MachineFunction &MF, const MachineModuleInfo *MMI, - const MachineBranchProbabilityInfo *MBPI); + const MachineBranchProbabilityInfo *MBPI, + unsigned TailDupSize = 0); bool tailDuplicateBlocks(MachineFunction &MF); static bool isSimpleBB(MachineBasicBlock *TailBB); bool shouldTailDuplicate(const MachineFunction &MF, bool IsSimple, diff --git a/llvm/lib/CodeGen/TailDuplicator.cpp b/llvm/lib/CodeGen/TailDuplicator.cpp index ec8e48d0de06..a93d13c65cee 100644 --- a/llvm/lib/CodeGen/TailDuplicator.cpp +++ b/llvm/lib/CodeGen/TailDuplicator.cpp @@ -57,12 +57,14 @@ static cl::opt TailDupLimit("tail-dup-limit", cl::init(~0U), namespace llvm { void TailDuplicator::initMF(MachineFunction &MF, const MachineModuleInfo *MMIin, - const MachineBranchProbabilityInfo *MBPIin) { + const MachineBranchProbabilityInfo *MBPIin, + unsigned TailDupSizeIn) { TII = MF.getSubtarget().getInstrInfo(); TRI = MF.getSubtarget().getRegisterInfo(); MRI = &MF.getRegInfo(); MMI = MMIin; MBPI = MBPIin; + TailDupSize = TailDupSizeIn; assert(MBPI != nullptr && "Machine Branch Probability Info required"); @@ -511,12 +513,14 @@ bool TailDuplicator::shouldTailDuplicate(const MachineFunction &MF, // duplicate only one, because one branch instruction can be eliminated to // compensate for the duplication. unsigned MaxDuplicateCount; - if (TailDuplicateSize.getNumOccurrences() == 0 && - // FIXME: Use Function::optForSize(). + if (TailDupSize == 0 && + TailDuplicateSize.getNumOccurrences() == 0 && MF.getFunction()->optForSize()) MaxDuplicateCount = 1; - else + else if (TailDupSize == 0) MaxDuplicateCount = TailDuplicateSize; + else + MaxDuplicateCount = TailDupSize; // If the block to be duplicated ends in an unanalyzable fallthrough, don't // duplicate it.