mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-27 12:26:08 +00:00
This patch fixes a problem which arose when using the Post-RA scheduler
on X86 Atom. Some of our tests failed because the tail merging part of the BranchFolding pass was creating new basic blocks which did not contain live-in information. When the anti-dependency code in the Post-RA scheduler ran, it would sometimes rename the register containing the function return value because the fact that the return value was live-in to the subsequent block had been lost. To fix this, it is necessary to run the RegisterScavenging code in the BranchFolding pass. This patch makes sure that the register scavenging code is invoked in the X86 subtarget only when post-RA scheduling is being done. Post RA scheduling in the X86 subtarget is only done for Atom. This patch adds a new function to the TargetRegisterClass to control whether or not live-ins should be preserved during branch folding. This is necessary in order for the anti-dependency optimizations done during the PostRASchedulerList pass to work properly when doing Post-RA scheduling for the X86 in general and for the Intel Atom in particular. The patch adds and invokes the new function trackLivenessAfterRegAlloc() instead of using the existing requiresRegisterScavenging(). It changes BranchFolding.cpp to call trackLivenessAfterRegAlloc() instead of requiresRegisterScavenging(). It changes the all the targets that implemented requiresRegisterScavenging() to also implement trackLivenessAfterRegAlloc(). It adds an assertion in the Post RA scheduler to make sure that post RA liveness information is available when it is needed. It changes the X86 break-anti-dependencies test to use –mcpu=atom, in order to avoid running into the added assertion. Finally, this patch restores the use of anti-dependency checking (which was turned off temporarily for the 3.1 release) for Intel Atom in the Post RA scheduler. Patch by Andy Zhang! Thanks to Jakob and Anton for their reviews. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155395 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -612,6 +612,12 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// trackLivenessAfterRegAlloc - returns true if the live-ins should be tracked
|
||||||
|
/// after register allocation.
|
||||||
|
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// needsStackRealignment - true if storage within the function requires the
|
/// needsStackRealignment - true if storage within the function requires the
|
||||||
/// stack pointer to be aligned more than the normal calling convention calls
|
/// stack pointer to be aligned more than the normal calling convention calls
|
||||||
/// for.
|
/// for.
|
||||||
|
@@ -188,7 +188,7 @@ bool BranchFolder::OptimizeFunction(MachineFunction &MF,
|
|||||||
|
|
||||||
// Use a RegScavenger to help update liveness when required.
|
// Use a RegScavenger to help update liveness when required.
|
||||||
MachineRegisterInfo &MRI = MF.getRegInfo();
|
MachineRegisterInfo &MRI = MF.getRegInfo();
|
||||||
if (MRI.tracksLiveness() && TRI->requiresRegisterScavenging(MF))
|
if (MRI.tracksLiveness() && TRI->trackLivenessAfterRegAlloc(MF))
|
||||||
RS = new RegScavenger();
|
RS = new RegScavenger();
|
||||||
else
|
else
|
||||||
MRI.invalidateLiveness();
|
MRI.invalidateLiveness();
|
||||||
|
@@ -206,6 +206,10 @@ SchedulePostRATDList::SchedulePostRATDList(
|
|||||||
const InstrItineraryData *InstrItins = TM.getInstrItineraryData();
|
const InstrItineraryData *InstrItins = TM.getInstrItineraryData();
|
||||||
HazardRec =
|
HazardRec =
|
||||||
TM.getInstrInfo()->CreateTargetPostRAHazardRecognizer(InstrItins, this);
|
TM.getInstrInfo()->CreateTargetPostRAHazardRecognizer(InstrItins, this);
|
||||||
|
|
||||||
|
assert((AntiDepMode == TargetSubtargetInfo::ANTIDEP_NONE ||
|
||||||
|
MRI.tracksLiveness()) &&
|
||||||
|
"Live-ins must be accurate for anti-dependency breaking");
|
||||||
AntiDepBreak =
|
AntiDepBreak =
|
||||||
((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ?
|
((AntiDepMode == TargetSubtargetInfo::ANTIDEP_ALL) ?
|
||||||
(AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) :
|
(AntiDepBreaker *)new AggressiveAntiDepBreaker(MF, RCI, CriticalPathRCs) :
|
||||||
|
@@ -711,6 +711,11 @@ requiresRegisterScavenging(const MachineFunction &MF) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ARMBaseRegisterInfo::
|
||||||
|
trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool ARMBaseRegisterInfo::
|
bool ARMBaseRegisterInfo::
|
||||||
requiresFrameIndexScavenging(const MachineFunction &MF) const {
|
requiresFrameIndexScavenging(const MachineFunction &MF) const {
|
||||||
return true;
|
return true;
|
||||||
|
@@ -173,6 +173,8 @@ public:
|
|||||||
|
|
||||||
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
||||||
|
|
||||||
|
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const;
|
||||||
|
|
||||||
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
|
virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
|
||||||
|
|
||||||
virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const;
|
virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const;
|
||||||
|
@@ -63,6 +63,11 @@ namespace llvm {
|
|||||||
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
|
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const
|
||||||
{ return true; }
|
{ return true; }
|
||||||
|
|
||||||
|
//! Enable tracking of liveness after register allocation, since register
|
||||||
|
// scavenging is enabled.
|
||||||
|
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const
|
||||||
|
{ return true; }
|
||||||
|
|
||||||
//! Return the reserved registers
|
//! Return the reserved registers
|
||||||
BitVector getReservedRegs(const MachineFunction &MF) const;
|
BitVector getReservedRegs(const MachineFunction &MF) const;
|
||||||
|
|
||||||
|
@@ -73,6 +73,10 @@ struct HexagonRegisterInfo : public HexagonGenRegisterInfo {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Debug information queries.
|
// Debug information queries.
|
||||||
unsigned getRARegister() const;
|
unsigned getRARegister() const;
|
||||||
unsigned getFrameRegister(const MachineFunction &MF) const;
|
unsigned getFrameRegister(const MachineFunction &MF) const;
|
||||||
|
@@ -136,6 +136,11 @@ MipsRegisterInfo::requiresRegisterScavenging(const MachineFunction &MF) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MipsRegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// This function eliminate ADJCALLSTACKDOWN,
|
// This function eliminate ADJCALLSTACKDOWN,
|
||||||
// ADJCALLSTACKUP pseudo instructions
|
// ADJCALLSTACKUP pseudo instructions
|
||||||
void MipsRegisterInfo::
|
void MipsRegisterInfo::
|
||||||
|
@@ -49,6 +49,8 @@ struct MipsRegisterInfo : public MipsGenRegisterInfo {
|
|||||||
|
|
||||||
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
||||||
|
|
||||||
|
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const;
|
||||||
|
|
||||||
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||||
MachineBasicBlock &MBB,
|
MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const;
|
MachineBasicBlock::iterator I) const;
|
||||||
|
@@ -89,6 +89,12 @@ PPCRegisterInfo::PPCRegisterInfo(const PPCSubtarget &ST,
|
|||||||
ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; ImmToIdxMap[PPC::STD_32] = PPC::STDX_32;
|
ImmToIdxMap[PPC::ADDI8] = PPC::ADD8; ImmToIdxMap[PPC::STD_32] = PPC::STDX_32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PPCRegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return requiresRegisterScavenging(MF);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// getPointerRegClass - Return the register class to use to hold pointers.
|
/// getPointerRegClass - Return the register class to use to hold pointers.
|
||||||
/// This is used for addressing modes.
|
/// This is used for addressing modes.
|
||||||
const TargetRegisterClass *
|
const TargetRegisterClass *
|
||||||
|
@@ -50,6 +50,8 @@ public:
|
|||||||
/// FIXME (64-bit): Should be inlined.
|
/// FIXME (64-bit): Should be inlined.
|
||||||
bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
||||||
|
|
||||||
|
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const;
|
||||||
|
|
||||||
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||||
MachineBasicBlock &MBB,
|
MachineBasicBlock &MBB,
|
||||||
MachineBasicBlock::iterator I) const;
|
MachineBasicBlock::iterator I) const;
|
||||||
|
@@ -90,6 +90,12 @@ int X86RegisterInfo::getCompactUnwindRegNum(unsigned RegNum, bool isEH) const {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
X86RegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
// Only enable when post-RA scheduling is enabled and this is needed.
|
||||||
|
return TM.getSubtargetImpl()->postRAScheduler();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
X86RegisterInfo::getSEHRegNum(unsigned i) const {
|
X86RegisterInfo::getSEHRegNum(unsigned i) const {
|
||||||
int reg = X86_MC::getX86RegNum(i);
|
int reg = X86_MC::getX86RegNum(i);
|
||||||
|
@@ -65,7 +65,8 @@ public:
|
|||||||
int getCompactUnwindRegNum(unsigned RegNum, bool isEH) const;
|
int getCompactUnwindRegNum(unsigned RegNum, bool isEH) const;
|
||||||
|
|
||||||
/// Code Generation virtual methods...
|
/// Code Generation virtual methods...
|
||||||
///
|
///
|
||||||
|
virtual bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const;
|
||||||
|
|
||||||
/// getMatchingSuperRegClass - Return a subclass of the specified register
|
/// getMatchingSuperRegClass - Return a subclass of the specified register
|
||||||
/// class A so that each register in it has a sub-register of the
|
/// class A so that each register in it has a sub-register of the
|
||||||
|
@@ -424,9 +424,7 @@ bool X86Subtarget::enablePostRAScheduler(
|
|||||||
CodeGenOpt::Level OptLevel,
|
CodeGenOpt::Level OptLevel,
|
||||||
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
||||||
RegClassVector& CriticalPathRCs) const {
|
RegClassVector& CriticalPathRCs) const {
|
||||||
//TODO: change back to ANTIDEP_CRITICAL when the
|
Mode = TargetSubtargetInfo::ANTIDEP_CRITICAL;
|
||||||
// X86 subtarget properly sets up post RA liveness.
|
|
||||||
Mode = TargetSubtargetInfo::ANTIDEP_NONE;
|
|
||||||
CriticalPathRCs.clear();
|
CriticalPathRCs.clear();
|
||||||
return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
|
return PostRAScheduler && OptLevel >= CodeGenOpt::Default;
|
||||||
}
|
}
|
||||||
|
@@ -307,6 +307,8 @@ public:
|
|||||||
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
TargetSubtargetInfo::AntiDepBreakMode& Mode,
|
||||||
RegClassVector& CriticalPathRCs) const;
|
RegClassVector& CriticalPathRCs) const;
|
||||||
|
|
||||||
|
bool postRAScheduler() const { return PostRAScheduler; }
|
||||||
|
|
||||||
/// getInstrItins = Return the instruction itineraries based on the
|
/// getInstrItins = Return the instruction itineraries based on the
|
||||||
/// subtarget selection.
|
/// subtarget selection.
|
||||||
const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
|
const InstrItineraryData &getInstrItineraryData() const { return InstrItins; }
|
||||||
|
@@ -91,6 +91,11 @@ XCoreRegisterInfo::requiresRegisterScavenging(const MachineFunction &MF) const {
|
|||||||
return TFI->hasFP(MF);
|
return TFI->hasFP(MF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
XCoreRegisterInfo::trackLivenessAfterRegAlloc(const MachineFunction &MF) const {
|
||||||
|
return requiresRegisterScavenging(MF);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
XCoreRegisterInfo::useFPForScavengingIndex(const MachineFunction &MF) const {
|
XCoreRegisterInfo::useFPForScavengingIndex(const MachineFunction &MF) const {
|
||||||
return false;
|
return false;
|
||||||
|
@@ -50,6 +50,8 @@ public:
|
|||||||
|
|
||||||
bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
bool requiresRegisterScavenging(const MachineFunction &MF) const;
|
||||||
|
|
||||||
|
bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const;
|
||||||
|
|
||||||
bool useFPForScavengingIndex(const MachineFunction &MF) const;
|
bool useFPForScavengingIndex(const MachineFunction &MF) const;
|
||||||
|
|
||||||
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
void eliminateCallFramePseudoInstr(MachineFunction &MF,
|
||||||
|
@@ -1,9 +1,6 @@
|
|||||||
; XFAIL: *
|
|
||||||
; RUN: llc <%s -O2 -mcpu=atom -march=x86 -relocation-model=static | FileCheck -check-prefix=atom %s
|
; RUN: llc <%s -O2 -mcpu=atom -march=x86 -relocation-model=static | FileCheck -check-prefix=atom %s
|
||||||
; RUN: llc <%s -O2 -mcpu=core2 -march=x86 -relocation-model=static | FileCheck %s
|
; RUN: llc <%s -O2 -mcpu=core2 -march=x86 -relocation-model=static | FileCheck %s
|
||||||
;
|
;
|
||||||
; FIXME: Atom's scheduler is temporarily disabled.
|
|
||||||
; XFAIL: *
|
|
||||||
|
|
||||||
@a = common global i32 0, align 4
|
@a = common global i32 0, align 4
|
||||||
@b = common global i32 0, align 4
|
@b = common global i32 0, align 4
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
; Without list-burr scheduling we may not see the difference in codegen here.
|
; Without list-burr scheduling we may not see the difference in codegen here.
|
||||||
; RUN: llc < %s -march=x86-64 -post-RA-scheduler -pre-RA-sched=list-burr -break-anti-dependencies=none > %t
|
; Use a subtarget that has post-RA scheduling enabled because the anti-dependency
|
||||||
|
; breaker requires liveness information to be kept.
|
||||||
|
; RUN: llc < %s -march=x86-64 -mcpu=atom -post-RA-scheduler -pre-RA-sched=list-burr -break-anti-dependencies=none > %t
|
||||||
; RUN: grep {%xmm0} %t | count 14
|
; RUN: grep {%xmm0} %t | count 14
|
||||||
; RUN: not grep {%xmm1} %t
|
; RUN: not grep {%xmm1} %t
|
||||||
; RUN: llc < %s -march=x86-64 -post-RA-scheduler -break-anti-dependencies=critical > %t
|
; RUN: llc < %s -march=x86-64 -mcpu=atom -post-RA-scheduler -break-anti-dependencies=critical > %t
|
||||||
; RUN: grep {%xmm0} %t | count 7
|
; RUN: grep {%xmm0} %t | count 7
|
||||||
; RUN: grep {%xmm1} %t | count 7
|
; RUN: grep {%xmm1} %t | count 7
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user