diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-04-21 17:40:41 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-04-22 14:19:26 -0700 |
commit | 1a78b0bd3829381e7be627b459c22083bf4671d4 (patch) | |
tree | 852144562cb6e25f36e812093487a19623171c9a /llvm/lib/CodeGen/MachineOutliner.cpp | |
parent | 3ceea67c091d556ec672e65ec4e9d72997e76807 (diff) | |
download | llvm-1a78b0bd3829381e7be627b459c22083bf4671d4.zip llvm-1a78b0bd3829381e7be627b459c22083bf4671d4.tar.gz llvm-1a78b0bd3829381e7be627b459c22083bf4671d4.tar.bz2 |
[MachineOutliner] Teach outliner to set live-ins
Preserving liveness can be useful even late in the pipeline, if we're
doing substantial optimization work afterwards. (See, for example,
D76065.) Teach MachineOutliner how to correctly set live-ins on the
basic block in outlined functions.
Differential Revision: https://reviews.llvm.org/D78605
Diffstat (limited to 'llvm/lib/CodeGen/MachineOutliner.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineOutliner.cpp | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp index bd30bd4..e15dcc3 100644 --- a/llvm/lib/CodeGen/MachineOutliner.cpp +++ b/llvm/lib/CodeGen/MachineOutliner.cpp @@ -1178,12 +1178,35 @@ MachineFunction *MachineOutliner::createOutlinedFunction( MBB.insert(MBB.end(), NewMI); } - TII.buildOutlinedFrame(MBB, MF, OF); - - // Outlined functions shouldn't preserve liveness. - MF.getProperties().reset(MachineFunctionProperties::Property::TracksLiveness); + // Set normal properties for a late MachineFunction. + MF.getProperties().reset(MachineFunctionProperties::Property::IsSSA); + MF.getProperties().set(MachineFunctionProperties::Property::NoPHIs); + MF.getProperties().set(MachineFunctionProperties::Property::NoVRegs); + MF.getProperties().set(MachineFunctionProperties::Property::TracksLiveness); MF.getRegInfo().freezeReservedRegs(MF); + // Compute live-in set for outlined fn + const MachineRegisterInfo &MRI = MF.getRegInfo(); + const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo(); + LivePhysRegs LiveIns(TRI); + for (auto &Cand : OF.Candidates) { + // Figure out live-ins at the first instruction. + MachineBasicBlock &OutlineBB = *Cand.front()->getParent(); + LivePhysRegs CandLiveIns(TRI); + CandLiveIns.addLiveOuts(OutlineBB); + for (const MachineInstr &MI : + reverse(make_range(Cand.front(), OutlineBB.end()))) + CandLiveIns.stepBackward(MI); + + // The live-in set for the outlined function is the union of the live-ins + // from all the outlining points. + for (MCPhysReg Reg : make_range(CandLiveIns.begin(), CandLiveIns.end())) + LiveIns.addReg(Reg); + } + addLiveIns(MBB, LiveIns); + + TII.buildOutlinedFrame(MBB, MF, OF); + // If there's a DISubprogram associated with this outlined function, then // emit debug info for the outlined function. if (DISubprogram *SP = getSubprogramOrNull(OF)) { |