From 7c489ab36564ddde3fa672aff52cfcae06517dfc Mon Sep 17 00:00:00 2001 From: Andrew Trick Date: Mon, 14 Oct 2013 20:45:17 +0000 Subject: Use a SparseSet in LiveRegUnits. Some clients may add block live ins and may track liveness over a large scope. This guarantees an efficient implementation in all cases with no memory allocation/deallocation, independent of the number of target registers. It could be slightly less convenient but is fine in the expected case. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192622 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LiveRegUnits.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/llvm/CodeGen/LiveRegUnits.h b/include/llvm/CodeGen/LiveRegUnits.h index 0c6df8838e..1e24e695a1 100644 --- a/include/llvm/CodeGen/LiveRegUnits.h +++ b/include/llvm/CodeGen/LiveRegUnits.h @@ -17,9 +17,9 @@ #ifndef LLVM_CODEGEN_LIVEREGUNITS_H #define LLVM_CODEGEN_LIVEREGUNITS_H -#include "llvm/ADT/SmallSet.h" +#include "llvm/ADT/SparseSet.h" #include "llvm/CodeGen/MachineBasicBlock.h" -#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/Target/TargetRegisterInfo.h" #include namespace llvm { @@ -29,17 +29,23 @@ class MachineInstr; /// A set of live register units with functions to track liveness when walking /// backward/forward through a basic block. class LiveRegUnits { - SmallSet LiveUnits; + SparseSet LiveUnits; + LiveRegUnits(const LiveRegUnits&) LLVM_DELETED_FUNCTION; + LiveRegUnits &operator=(const LiveRegUnits&) LLVM_DELETED_FUNCTION; public: /// \brief Constructs a new empty LiveRegUnits set. LiveRegUnits() {} - /// \brief Constructs a new LiveRegUnits set by copying @p Other. - LiveRegUnits(const LiveRegUnits &Other) - : LiveUnits(Other.LiveUnits) { + void init(const TargetRegisterInfo *TRI) { + LiveUnits.clear(); + LiveUnits.setUniverse(TRI->getNumRegs()); } + void clear() { LiveUnits.clear(); } + + bool empty() const { return LiveUnits.empty(); } + /// \brief Adds a register to the set. void addReg(unsigned Reg, const MCRegisterInfo &MCRI) { for (MCRegUnitIterator RUnits(Reg, &MCRI); RUnits.isValid(); ++RUnits) @@ -73,7 +79,7 @@ public: /// instruction(bundle): Remove killed-uses, add defs. void stepForward(const MachineInstr &MI, const MCRegisterInfo &MCRI); - /// Adds all registers in the live-in list of block @p BB. + /// \brief Adds all registers in the live-in list of block @p BB. void addLiveIns(const MachineBasicBlock &BB, const MCRegisterInfo &MCRI); }; -- cgit v1.2.3