From e3d3b88cb985c6a1d975463a00a57925b0ed64d1 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 10 Dec 2014 01:12:30 +0000 Subject: [PATCH] Add a flag to enable/disable subregister liveness. llvm-svn: 223884 --- llvm/include/llvm/CodeGen/MachineRegisterInfo.h | 9 +++++++++ llvm/include/llvm/Target/TargetSubtargetInfo.h | 5 +++++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp | 8 ++++++++ llvm/lib/CodeGen/LiveRangeCalc.cpp | 5 +++-- llvm/lib/CodeGen/MachineRegisterInfo.cpp | 3 ++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h index ba86853..caa48a5 100644 --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -52,6 +52,9 @@ private: /// accurate when after this flag is cleared. bool TracksLiveness; + /// True if subregister liveness is tracked. + bool TracksSubRegLiveness; + /// VRegInfo - Information we keep for each virtual register. /// /// Each element in this list contains the register class of the vreg and the @@ -179,6 +182,12 @@ public: /// information. void invalidateLiveness() { TracksLiveness = false; } + bool tracksSubRegLiveness() const { return TracksSubRegLiveness; } + + void enableSubRegLiveness(bool Enable = true) { + TracksSubRegLiveness = Enable; + } + //===--------------------------------------------------------------------===// // Register Info //===--------------------------------------------------------------------===// diff --git a/llvm/include/llvm/Target/TargetSubtargetInfo.h b/llvm/include/llvm/Target/TargetSubtargetInfo.h index 80ff9e3..4ff88d0 100644 --- a/llvm/include/llvm/Target/TargetSubtargetInfo.h +++ b/llvm/include/llvm/Target/TargetSubtargetInfo.h @@ -168,6 +168,11 @@ public: virtual std::unique_ptr getCustomPBQPConstraints() const { return nullptr; } + + /// Enable tracking of subregister liveness in register allocator. + virtual bool enableSubRegLiveness() const { + return false; + } }; } // End llvm namespace diff --git a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp index 9f7d503..77e7149 100644 --- a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -63,6 +63,10 @@ static cl::opt EnablePrecomputePhysRegs( static bool EnablePrecomputePhysRegs = false; #endif // NDEBUG +static cl::opt EnableSubRegLiveness( + "enable-subreg-liveness", cl::Hidden, cl::init(true), + cl::desc("Enable subregister liveness tracking.")); + void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const { AU.setPreservesCFG(); AU.addRequired(); @@ -116,6 +120,10 @@ bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { AA = &getAnalysis(); Indexes = &getAnalysis(); DomTree = &getAnalysis(); + + if (EnableSubRegLiveness && MF->getSubtarget().enableSubRegLiveness()) + MRI->enableSubRegLiveness(true); + if (!LRCalc) LRCalc = new LiveRangeCalc(); diff --git a/llvm/lib/CodeGen/LiveRangeCalc.cpp b/llvm/lib/CodeGen/LiveRangeCalc.cpp index 4433fb1..daa1ee0 100644 --- a/llvm/lib/CodeGen/LiveRangeCalc.cpp +++ b/llvm/lib/CodeGen/LiveRangeCalc.cpp @@ -55,7 +55,7 @@ void LiveRangeCalc::createDeadDefs(LiveInterval &LI) { const MachineInstr *MI = MO.getParent(); SlotIndex Idx = getDefIndex(*Indexes, *MI, MO.isEarlyClobber()); unsigned SubReg = MO.getSubReg(); - if (SubReg != 0 || LI.hasSubRanges()) { + if (LI.hasSubRanges() || (SubReg != 0 && MRI->tracksSubRegLiveness())) { unsigned Mask = SubReg != 0 ? TRI.getSubRegIndexLaneMask(SubReg) : MRI->getMaxLaneMaskForVReg(Reg); @@ -179,7 +179,8 @@ void LiveRangeCalc::extendToUses(LiveInterval &LI) { continue; SlotIndex Idx = getUseIndex(*Indexes, MO); unsigned SubReg = MO.getSubReg(); - if (MO.isUse() && (LI.hasSubRanges() || SubReg != 0)) { + if (MO.isUse() && (LI.hasSubRanges() || + (MRI->tracksSubRegLiveness() && SubReg != 0))) { unsigned Mask = SubReg != 0 ? TRI.getSubRegIndexLaneMask(SubReg) : Mask = MRI->getMaxLaneMaskForVReg(Reg); diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp index c2fc4a7..aba9e5c 100644 --- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp +++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp @@ -24,7 +24,8 @@ using namespace llvm; void MachineRegisterInfo::Delegate::anchor() {} MachineRegisterInfo::MachineRegisterInfo(const MachineFunction *MF) - : MF(MF), TheDelegate(nullptr), IsSSA(true), TracksLiveness(true) { + : MF(MF), TheDelegate(nullptr), IsSSA(true), TracksLiveness(true), + TracksSubRegLiveness(false) { VRegInfo.reserve(256); RegAllocHints.reserve(256); UsedRegUnits.resize(getTargetRegisterInfo()->getNumRegUnits()); -- 2.7.4