2017-09-30 05:55:49 +08:00
|
|
|
//===- CalcSpillWeights.cpp -----------------------------------------------===//
|
2009-12-14 14:49:42 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-12-14 14:49:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/CalcSpillWeights.h"
|
2017-09-30 05:55:49 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include "llvm/CodeGen/LiveInterval.h"
|
2017-12-13 10:51:04 +08:00
|
|
|
#include "llvm/CodeGen/LiveIntervals.h"
|
2009-12-14 14:49:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2017-09-30 05:55:49 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2009-12-14 14:49:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2017-09-30 05:55:49 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2009-12-14 14:49:42 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-08 09:01:31 +08:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/CodeGen/VirtRegMap.h"
|
2009-12-14 14:49:42 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-09-30 05:55:49 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <tuple>
|
|
|
|
|
2009-12-14 14:49:42 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 10:02:50 +08:00
|
|
|
#define DEBUG_TYPE "calcspillweights"
|
|
|
|
|
2020-09-30 00:09:25 +08:00
|
|
|
void VirtRegAuxInfo::calculateSpillWeightsAndHints() {
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "********** Compute Spill Weights **********\n"
|
|
|
|
<< "********** Function: " << MF.getName() << '\n');
|
2009-12-14 14:49:42 +08:00
|
|
|
|
2012-06-21 05:25:05 +08:00
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
2020-09-30 00:09:25 +08:00
|
|
|
for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
|
|
|
|
unsigned Reg = Register::index2VirtReg(I);
|
2012-06-21 05:25:05 +08:00
|
|
|
if (MRI.reg_nodbg_empty(Reg))
|
|
|
|
continue;
|
2020-09-30 00:09:25 +08:00
|
|
|
calculateSpillWeightAndHint(LIS.getInterval(Reg));
|
2009-12-14 14:49:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-10 08:02:26 +08:00
|
|
|
// Return the preferred allocation register for reg, given a COPY instruction.
|
2020-10-10 03:18:52 +08:00
|
|
|
static Register copyHint(const MachineInstr *MI, unsigned Reg,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const MachineRegisterInfo &MRI) {
|
|
|
|
unsigned Sub, HSub;
|
|
|
|
Register HReg;
|
|
|
|
if (MI->getOperand(0).getReg() == Reg) {
|
|
|
|
Sub = MI->getOperand(0).getSubReg();
|
|
|
|
HReg = MI->getOperand(1).getReg();
|
|
|
|
HSub = MI->getOperand(1).getSubReg();
|
2010-08-10 08:02:26 +08:00
|
|
|
} else {
|
2020-10-10 03:18:52 +08:00
|
|
|
Sub = MI->getOperand(1).getSubReg();
|
|
|
|
HReg = MI->getOperand(0).getReg();
|
|
|
|
HSub = MI->getOperand(0).getSubReg();
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
if (!HReg)
|
2010-08-10 08:02:26 +08:00
|
|
|
return 0;
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
if (Register::isVirtualRegister(HReg))
|
|
|
|
return Sub == HSub ? HReg : Register();
|
2010-08-10 08:02:26 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
const TargetRegisterClass *rc = MRI.getRegClass(Reg);
|
|
|
|
Register CopiedPReg = (HSub ? TRI.getSubReg(HReg, HSub) : HReg);
|
2017-12-05 18:52:24 +08:00
|
|
|
if (rc->contains(CopiedPReg))
|
|
|
|
return CopiedPReg;
|
|
|
|
|
|
|
|
// Check if reg:sub matches so that a super register could be hinted.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (Sub)
|
|
|
|
return TRI.getMatchingSuperReg(CopiedPReg, Sub, rc);
|
2010-08-10 08:02:26 +08:00
|
|
|
|
2017-12-05 18:52:24 +08:00
|
|
|
return 0;
|
2009-12-14 14:49:42 +08:00
|
|
|
}
|
2010-08-10 08:02:26 +08:00
|
|
|
|
2012-06-05 09:06:12 +08:00
|
|
|
// Check if all values in LI are rematerializable
|
|
|
|
static bool isRematerializable(const LiveInterval &LI,
|
|
|
|
const LiveIntervals &LIS,
|
2015-08-10 19:59:44 +08:00
|
|
|
VirtRegMap *VRM,
|
2012-06-05 09:06:12 +08:00
|
|
|
const TargetInstrInfo &TII) {
|
2020-09-16 05:54:38 +08:00
|
|
|
unsigned Reg = LI.reg();
|
2015-08-10 19:59:44 +08:00
|
|
|
unsigned Original = VRM ? VRM->getOriginal(Reg) : 0;
|
2012-06-05 09:06:12 +08:00
|
|
|
for (LiveInterval::const_vni_iterator I = LI.vni_begin(), E = LI.vni_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
const VNInfo *VNI = *I;
|
|
|
|
if (VNI->isUnused())
|
|
|
|
continue;
|
|
|
|
if (VNI->isPHIDef())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MachineInstr *MI = LIS.getInstructionFromIndex(VNI->def);
|
|
|
|
assert(MI && "Dead valno in interval");
|
|
|
|
|
2015-08-10 19:59:44 +08:00
|
|
|
// Trace copies introduced by live range splitting. The inline
|
|
|
|
// spiller can rematerialize through these copies, so the spill
|
|
|
|
// weight must reflect this.
|
|
|
|
if (VRM) {
|
|
|
|
while (MI->isFullCopy()) {
|
|
|
|
// The copy destination must match the interval register.
|
|
|
|
if (MI->getOperand(0).getReg() != Reg)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the source register.
|
|
|
|
Reg = MI->getOperand(1).getReg();
|
|
|
|
|
|
|
|
// If the original (pre-splitting) registers match this
|
|
|
|
// copy came from a split.
|
2019-08-02 07:27:28 +08:00
|
|
|
if (!Register::isVirtualRegister(Reg) ||
|
2015-08-10 19:59:44 +08:00
|
|
|
VRM->getOriginal(Reg) != Original)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Follow the copy live-in value.
|
|
|
|
const LiveInterval &SrcLI = LIS.getInterval(Reg);
|
|
|
|
LiveQueryResult SrcQ = SrcLI.Query(VNI->def);
|
|
|
|
VNI = SrcQ.valueIn();
|
|
|
|
assert(VNI && "Copy from non-existing value");
|
|
|
|
if (VNI->isPHIDef())
|
|
|
|
return false;
|
|
|
|
MI = LIS.getInstructionFromIndex(VNI->def);
|
|
|
|
assert(MI && "Dead valno in interval");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:01:54 +08:00
|
|
|
if (!TII.isTriviallyReMaterializable(*MI, LIS.getAliasAnalysis()))
|
2012-06-05 09:06:12 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
void VirtRegAuxInfo::calculateSpillWeightAndHint(LiveInterval &LI) {
|
|
|
|
float Weight = weightCalcHelper(LI);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
// Check if unspillable.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (Weight < 0)
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
return;
|
2020-10-10 03:18:52 +08:00
|
|
|
LI.setWeight(Weight);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
}
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
float VirtRegAuxInfo::futureWeight(LiveInterval &LI, SlotIndex Start,
|
|
|
|
SlotIndex End) {
|
|
|
|
return weightCalcHelper(LI, &Start, &End);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
}
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
float VirtRegAuxInfo::weightCalcHelper(LiveInterval &LI, SlotIndex *Start,
|
|
|
|
SlotIndex *End) {
|
|
|
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
|
|
|
const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
|
|
|
|
MachineBasicBlock *MBB = nullptr;
|
|
|
|
MachineLoop *Loop = nullptr;
|
|
|
|
bool IsExiting = false;
|
|
|
|
float TotalWeight = 0;
|
|
|
|
unsigned NumInstr = 0; // Number of instructions using li
|
|
|
|
SmallPtrSet<MachineInstr *, 8> Visited;
|
|
|
|
|
|
|
|
std::pair<unsigned, unsigned> TargetHint = MRI.getRegAllocationHint(LI.reg());
|
|
|
|
|
|
|
|
if (LI.isSpillable() && VRM) {
|
|
|
|
Register Reg = LI.reg();
|
[CalcSpillWeights] Propagate the fact that a live-interval is not spillable
When we calculate the weight of a live-interval, add some code to
check if the original live-interval was markied as not spillable and
if so, progagate that information down to the new interval.
Previously we would just recompute a weight for the new interval,
thus, we could in theory just spill live-intervals marked as not
spillable by just splitting them. That goes against the spirit of
a non-spillable live-interval.
E.g., previously we could do:
v1 = // v1 must not be spilled
...
= v1
Split:
v1 = // v1 must not be spilled
...
v2 = v1 // v2 can be spilled
...
v3 = v2 // v3 can be spilled
= v3
There's no test case for that one as we would need to split a
non-spillable live-interval without using LiveRangeEdit to see this
happening.
RegAlloc inserts non-spillable intervals only as part of the spilling
mechanism, thus at this point the intervals are not splittable anymore.
On top of that, RegAlloc uses the LiveRangeEdit API, which already
properly propagate that information.
In other words, this could only happen if a target was to mark
a live-interval as not spillable before register allocation and
split it without using LRE, e.g., through
LiveIntervals::splitSeparateComponent.
2020-07-16 08:26:37 +08:00
|
|
|
Register Original = VRM->getOriginal(Reg);
|
|
|
|
const LiveInterval &OrigInt = LIS.getInterval(Original);
|
|
|
|
// li comes from a split of OrigInt. If OrigInt was marked
|
|
|
|
// as not spillable, make sure the new interval is marked
|
|
|
|
// as not spillable as well.
|
|
|
|
if (!OrigInt.isSpillable())
|
2020-10-10 03:18:52 +08:00
|
|
|
LI.markNotSpillable();
|
[CalcSpillWeights] Propagate the fact that a live-interval is not spillable
When we calculate the weight of a live-interval, add some code to
check if the original live-interval was markied as not spillable and
if so, progagate that information down to the new interval.
Previously we would just recompute a weight for the new interval,
thus, we could in theory just spill live-intervals marked as not
spillable by just splitting them. That goes against the spirit of
a non-spillable live-interval.
E.g., previously we could do:
v1 = // v1 must not be spilled
...
= v1
Split:
v1 = // v1 must not be spilled
...
v2 = v1 // v2 can be spilled
...
v3 = v2 // v3 can be spilled
= v3
There's no test case for that one as we would need to split a
non-spillable live-interval without using LiveRangeEdit to see this
happening.
RegAlloc inserts non-spillable intervals only as part of the spilling
mechanism, thus at this point the intervals are not splittable anymore.
On top of that, RegAlloc uses the LiveRangeEdit API, which already
properly propagate that information.
In other words, this could only happen if a target was to mark
a live-interval as not spillable before register allocation and
split it without using LRE, e.g., through
LiveIntervals::splitSeparateComponent.
2020-07-16 08:26:37 +08:00
|
|
|
}
|
|
|
|
|
2011-03-30 05:20:19 +08:00
|
|
|
// Don't recompute spill weight for an unspillable register.
|
2020-10-10 03:18:52 +08:00
|
|
|
bool IsSpillable = LI.isSpillable();
|
2011-03-30 05:20:19 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
bool IsLocalSplitArtifact = Start && End;
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
|
|
|
|
// Do not update future local split artifacts.
|
2020-10-10 03:18:52 +08:00
|
|
|
bool ShouldUpdateLI = !IsLocalSplitArtifact;
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
if (IsLocalSplitArtifact) {
|
|
|
|
MachineBasicBlock *localMBB = LIS.getMBBFromIndex(*End);
|
|
|
|
assert(localMBB == LIS.getMBBFromIndex(*Start) &&
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
"start and end are expected to be in the same basic block");
|
|
|
|
|
|
|
|
// Local split artifact will have 2 additional copy instructions and they
|
|
|
|
// will be in the same BB.
|
|
|
|
// localLI = COPY other
|
|
|
|
// ...
|
|
|
|
// other = COPY localLI
|
2020-10-10 03:18:52 +08:00
|
|
|
TotalWeight += LiveIntervals::getSpillWeight(true, false, &MBFI, localMBB);
|
|
|
|
TotalWeight += LiveIntervals::getSpillWeight(false, true, &MBFI, localMBB);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
NumInstr += 2;
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
}
|
|
|
|
|
2017-12-05 18:52:24 +08:00
|
|
|
// CopyHint is a sortable hint derived from a COPY instruction.
|
|
|
|
struct CopyHint {
|
|
|
|
unsigned Reg;
|
|
|
|
float Weight;
|
|
|
|
bool IsPhys;
|
2018-10-05 22:23:11 +08:00
|
|
|
CopyHint(unsigned R, float W, bool P) :
|
|
|
|
Reg(R), Weight(W), IsPhys(P) {}
|
2017-12-05 18:52:24 +08:00
|
|
|
bool operator<(const CopyHint &rhs) const {
|
|
|
|
// Always prefer any physreg hint.
|
|
|
|
if (IsPhys != rhs.IsPhys)
|
|
|
|
return (IsPhys && !rhs.IsPhys);
|
|
|
|
if (Weight != rhs.Weight)
|
|
|
|
return (Weight > rhs.Weight);
|
2018-10-05 22:23:11 +08:00
|
|
|
return Reg < rhs.Reg; // Tie-breaker.
|
2017-12-05 18:52:24 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
std::set<CopyHint> CopyHints;
|
|
|
|
|
2020-03-17 23:16:39 +08:00
|
|
|
for (MachineRegisterInfo::reg_instr_nodbg_iterator
|
2020-10-10 03:18:52 +08:00
|
|
|
I = MRI.reg_instr_nodbg_begin(LI.reg()),
|
|
|
|
E = MRI.reg_instr_nodbg_end();
|
2020-03-17 23:16:39 +08:00
|
|
|
I != E;) {
|
2020-10-10 03:18:52 +08:00
|
|
|
MachineInstr *MI = &*(I++);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
|
|
|
|
// For local split artifacts, we are interested only in instructions between
|
|
|
|
// the expected start and end of the range.
|
2020-10-10 03:18:52 +08:00
|
|
|
SlotIndex SI = LIS.getInstructionIndex(*MI);
|
|
|
|
if (IsLocalSplitArtifact && ((SI < *Start) || (SI > *End)))
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
continue;
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
NumInstr++;
|
|
|
|
if (MI->isIdentityCopy() || MI->isImplicitDef())
|
2010-08-10 08:02:26 +08:00
|
|
|
continue;
|
2020-10-10 03:18:52 +08:00
|
|
|
if (!Visited.insert(MI).second)
|
2010-08-10 08:02:26 +08:00
|
|
|
continue;
|
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
float Weight = 1.0f;
|
|
|
|
if (IsSpillable) {
|
2011-03-30 05:20:19 +08:00
|
|
|
// Get loop info for mi.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (MI->getParent() != MBB) {
|
|
|
|
MBB = MI->getParent();
|
|
|
|
Loop = Loops.getLoopFor(MBB);
|
|
|
|
IsExiting = Loop ? Loop->isLoopExiting(MBB) : false;
|
2011-03-30 05:20:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate instr weight.
|
2020-10-10 03:18:52 +08:00
|
|
|
bool Reads, Writes;
|
|
|
|
std::tie(Reads, Writes) = MI->readsWritesVirtualRegister(LI.reg());
|
|
|
|
Weight = LiveIntervals::getSpillWeight(Writes, Reads, &MBFI, *MI);
|
2011-03-30 05:20:19 +08:00
|
|
|
|
|
|
|
// Give extra weight to what looks like a loop induction variable update.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (Writes && IsExiting && LIS.isLiveOutOfMBB(LI, MBB))
|
|
|
|
Weight *= 3;
|
2011-03-30 05:20:19 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
TotalWeight += Weight;
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get allocation hints from copies.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (!MI->isCopy())
|
2010-08-10 08:02:26 +08:00
|
|
|
continue;
|
2020-10-10 03:18:52 +08:00
|
|
|
Register hint = copyHint(MI, LI.reg(), TRI, MRI);
|
2010-08-10 08:02:26 +08:00
|
|
|
if (!hint)
|
|
|
|
continue;
|
2014-04-22 01:57:01 +08:00
|
|
|
// Force hweight onto the stack so that x86 doesn't add hidden precision,
|
|
|
|
// making the comparison incorrectly pass (i.e., 1 > 1 == true??).
|
|
|
|
//
|
|
|
|
// FIXME: we probably shouldn't use floats at all.
|
2020-10-10 03:18:52 +08:00
|
|
|
volatile float HWeight = Hint[hint] += Weight;
|
|
|
|
if (Register::isVirtualRegister(hint) || MRI.isAllocatable(hint))
|
2019-08-02 07:27:28 +08:00
|
|
|
CopyHints.insert(
|
2020-10-10 03:18:52 +08:00
|
|
|
CopyHint(hint, HWeight, Register::isPhysicalRegister(hint)));
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|
|
|
|
|
2011-04-27 02:52:36 +08:00
|
|
|
Hint.clear();
|
2010-08-10 08:02:26 +08:00
|
|
|
|
2017-12-05 18:52:24 +08:00
|
|
|
// Pass all the sorted copy hints to mri.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (ShouldUpdateLI && CopyHints.size()) {
|
2017-12-05 18:52:24 +08:00
|
|
|
// Remove a generic hint if previously added by target.
|
|
|
|
if (TargetHint.first == 0 && TargetHint.second)
|
2020-10-10 03:18:52 +08:00
|
|
|
MRI.clearSimpleHint(LI.reg());
|
2017-12-05 18:52:24 +08:00
|
|
|
|
2018-10-03 20:51:19 +08:00
|
|
|
std::set<unsigned> HintedRegs;
|
2017-12-05 18:52:24 +08:00
|
|
|
for (auto &Hint : CopyHints) {
|
2018-10-03 20:51:19 +08:00
|
|
|
if (!HintedRegs.insert(Hint.Reg).second ||
|
|
|
|
(TargetHint.first != 0 && Hint.Reg == TargetHint.second))
|
|
|
|
// Don't add the same reg twice or the target-type hint again.
|
2017-12-05 18:52:24 +08:00
|
|
|
continue;
|
2020-10-10 03:18:52 +08:00
|
|
|
MRI.addRegAllocationHint(LI.reg(), Hint.Reg);
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
}
|
2017-12-05 18:52:24 +08:00
|
|
|
|
|
|
|
// Weakly boost the spill weight of hinted registers.
|
2020-10-10 03:18:52 +08:00
|
|
|
TotalWeight *= 1.01F;
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|
|
|
|
|
2011-03-30 05:20:19 +08:00
|
|
|
// If the live interval was already unspillable, leave it that way.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (!IsSpillable)
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
return -1.0;
|
2011-03-30 05:20:19 +08:00
|
|
|
|
2016-02-09 06:52:51 +08:00
|
|
|
// Mark li as unspillable if all live ranges are tiny and the interval
|
|
|
|
// is not live at any reg mask. If the interval is live at a reg mask
|
|
|
|
// spilling may be required.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (ShouldUpdateLI && LI.isZeroLength(LIS.getSlotIndexes()) &&
|
|
|
|
!LI.isLiveAtIndexes(LIS.getRegMaskSlots())) {
|
|
|
|
LI.markNotSpillable();
|
Add logic to greedy reg alloc to avoid bad eviction chains
This fixes bugzilla 26810
https://bugs.llvm.org/show_bug.cgi?id=26810
This is intended to prevent sequences like:
movl %ebp, 8(%esp) # 4-byte Spill
movl %ecx, %ebp
movl %ebx, %ecx
movl %edi, %ebx
movl %edx, %edi
cltd
idivl %esi
movl %edi, %edx
movl %ebx, %edi
movl %ecx, %ebx
movl %ebp, %ecx
movl 16(%esp), %ebp # 4 - byte Reload
Such sequences are created in 2 scenarios:
Scenario #1:
vreg0 is evicted from physreg0 by vreg1
Evictee vreg0 is intended for region splitting with split candidate physreg0 (the reg vreg0 was evicted from)
Region splitting creates a local interval because of interference with the evictor vreg1 (normally region spliiting creates 2 interval, the "by reg" and "by stack" intervals. Local interval created when interference occurs.)
one of the split intervals ends up evicting vreg2 from physreg1
Evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
Scenario #2
vreg0 is evicted from physreg0 by vreg1
vreg2 is evicted from physreg2 by vreg3 etc
Evictee vreg0 is intended for region splitting with split candidate physreg1
Region splitting creates a local interval because of interference with the evictor vreg1
one of the split intervals ends up evicting back original evictor vreg1 from physreg0 (the reg vreg0 was evicted from)
Another evictee vreg2 is intended for region splitting with split candidate physreg1
one of the split intervals ends up evicting vreg3 from physreg2 etc.. until someone spills
As compile time was a concern, I've added a flag to control weather we do cost calculations for local intervals we expect to be created (it's on by default for X86 target, off for the rest).
Differential Revision: https://reviews.llvm.org/D35816
Change-Id: Id9411ff7bbb845463d289ba2ae97737a1ee7cc39
llvm-svn: 316295
2017-10-23 01:59:38 +08:00
|
|
|
return -1.0;
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// If all of the definitions of the interval are re-materializable,
|
2012-06-05 09:06:12 +08:00
|
|
|
// it is a preferred candidate for spilling.
|
2010-08-10 08:02:26 +08:00
|
|
|
// FIXME: this gets much more complicated once we support non-trivial
|
|
|
|
// re-materialization.
|
2020-10-10 03:18:52 +08:00
|
|
|
if (isRematerializable(LI, LIS, VRM, *MF.getSubtarget().getInstrInfo()))
|
|
|
|
TotalWeight *= 0.5F;
|
2010-08-10 08:02:26 +08:00
|
|
|
|
2020-10-10 03:18:52 +08:00
|
|
|
if (IsLocalSplitArtifact)
|
|
|
|
return normalize(TotalWeight, Start->distance(*End), NumInstr);
|
|
|
|
return normalize(TotalWeight, LI.getSize(), NumInstr);
|
2010-08-10 08:02:26 +08:00
|
|
|
}
|