Skip to content

Commit ea11f47

Browse files
committed
Split LiveRangeCalc in LiveRangeCalc/LiveIntervalCalc. NFC
Summary: Refactor LiveRangeCalc such that it is now split into two classes The objective is to split all the "register specific" logic away from LiveRangeCalc. The two new classes created are: - LiveRangeCalc - is meant as a generic class to compute and modify live ranges in a generic way. This class should deal only with SlotIndices and VNInfo objects. - LiveIntervalCals - is meant to be equivalent to the old LiveRangeCalc. It computes the liveness virtual registers tracked by a LiveInterval object. With this refactoring LiveRangeCalc can be used to implement tracking of liveness of LiveRanges that represent other things than just registers. Subscribers: MatzeB, qcolombet, mgorny, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76584
1 parent 882ba48 commit ea11f47

File tree

11 files changed

+365
-253
lines changed

11 files changed

+365
-253
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===- LiveIntervalCalc.h - Calculate live intervals -----------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// The LiveIntervalCalc class is an extension of LiveRangeCalc targeted to the
10+
// computation and modification of the LiveInterval variants of LiveRanges.
11+
// LiveIntervals are meant to track liveness of registers and stack slots and
12+
// LiveIntervalCalc adds to LiveRangeCalc all the machinery requied to
13+
// construct the liveness of virtual registers tracked by a LiveInterval.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#ifndef LLVM_LIB_CODEGEN_LIVEINTERVALCALC_H
18+
#define LLVM_LIB_CODEGEN_LIVEINTERVALCALC_H
19+
20+
#include "llvm/ADT/ArrayRef.h"
21+
#include "llvm/ADT/BitVector.h"
22+
#include "llvm/ADT/DenseMap.h"
23+
#include "llvm/ADT/IndexedMap.h"
24+
#include "llvm/ADT/SmallVector.h"
25+
#include "llvm/CodeGen/LiveInterval.h"
26+
#include "llvm/CodeGen/LiveRangeCalc.h"
27+
#include "llvm/CodeGen/MachineBasicBlock.h"
28+
#include "llvm/CodeGen/SlotIndexes.h"
29+
#include "llvm/MC/LaneBitmask.h"
30+
#include <utility>
31+
32+
namespace llvm {
33+
34+
template <class NodeT> class DomTreeNodeBase;
35+
class MachineDominatorTree;
36+
class MachineFunction;
37+
class MachineRegisterInfo;
38+
39+
using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
40+
41+
class LiveIntervalCalc : public LiveRangeCalc {
42+
/// Extend the live range of @p LR to reach all uses of Reg.
43+
///
44+
/// If @p LR is a main range, or if @p LI is null, then all uses must be
45+
/// jointly dominated by the definitions from @p LR. If @p LR is a subrange
46+
/// of the live interval @p LI, corresponding to lane mask @p LaneMask,
47+
/// all uses must be jointly dominated by the definitions from @p LR
48+
/// together with definitions of other lanes where @p LR becomes undefined
49+
/// (via <def,read-undef> operands).
50+
/// If @p LR is a main range, the @p LaneMask should be set to ~0, i.e.
51+
/// LaneBitmask::getAll().
52+
void extendToUses(LiveRange &LR, Register Reg, LaneBitmask LaneMask,
53+
LiveInterval *LI = nullptr);
54+
55+
public:
56+
LiveIntervalCalc() = default;
57+
58+
/// createDeadDefs - Create a dead def in LI for every def operand of Reg.
59+
/// Each instruction defining Reg gets a new VNInfo with a corresponding
60+
/// minimal live range.
61+
void createDeadDefs(LiveRange &LR, Register Reg);
62+
63+
/// Extend the live range of @p LR to reach all uses of Reg.
64+
///
65+
/// All uses must be jointly dominated by existing liveness. PHI-defs are
66+
/// inserted as needed to preserve SSA form.
67+
void extendToUses(LiveRange &LR, MCRegister PhysReg) {
68+
extendToUses(LR, PhysReg, LaneBitmask::getAll());
69+
}
70+
71+
/// Calculates liveness for the register specified in live interval @p LI.
72+
/// Creates subregister live ranges as needed if subreg liveness tracking is
73+
/// enabled.
74+
void calculate(LiveInterval &LI, bool TrackSubRegs);
75+
76+
/// For live interval \p LI with correct SubRanges construct matching
77+
/// information for the main live range. Expects the main live range to not
78+
/// have any segments or value numbers.
79+
void constructMainRangeFromSubranges(LiveInterval &LI);
80+
};
81+
82+
} // end namespace llvm
83+
84+
#endif // LLVM_LIB_CODEGEN_LIVEINTERVALCALC_H

llvm/include/llvm/CodeGen/LiveIntervals.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace llvm {
4141
extern cl::opt<bool> UseSegmentSetForPhysRegs;
4242

4343
class BitVector;
44-
class LiveRangeCalc;
44+
class LiveIntervalCalc;
4545
class MachineBlockFrequencyInfo;
4646
class MachineDominatorTree;
4747
class MachineFunction;
@@ -59,7 +59,7 @@ class VirtRegMap;
5959
AliasAnalysis *AA;
6060
SlotIndexes* Indexes;
6161
MachineDominatorTree *DomTree = nullptr;
62-
LiveRangeCalc *LRCalc = nullptr;
62+
LiveIntervalCalc *LICalc = nullptr;
6363

6464
/// Special pool allocator for VNInfo's (LiveInterval val#).
6565
VNInfo::Allocator VNInfoAllocator;

llvm/include/llvm/CodeGen/LiveRangeCalc.h

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
//===- LiveRangeCalc.h - Calculate live ranges ------------------*- C++ -*-===//
1+
//===- LiveRangeCalc.h - Calculate live ranges -----------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// The LiveRangeCalc class can be used to compute live ranges from scratch. It
10-
// caches information about values in the CFG to speed up repeated operations
11-
// on the same live range. The cache can be shared by non-overlapping live
12-
// ranges. SplitKit uses that when computing the live range of split products.
9+
// The LiveRangeCalc class can be used to implement the computation of
10+
// live ranges from scratch.
11+
// It caches information about values in the CFG to speed up repeated
12+
// operations on the same live range. The cache can be shared by
13+
// non-overlapping live ranges. SplitKit uses that when computing the live
14+
// range of split products.
1315
//
1416
// A low-level interface is available to clients that know where a variable is
1517
// live, but don't know which value it has as every point. LiveRangeCalc will
1618
// propagate values down the dominator tree, and even insert PHI-defs where
17-
// needed. SplitKit uses this faster interface when possible.
19+
// needed. SplitKit uses this faster interface when possible.
1820
//
1921
//===----------------------------------------------------------------------===//
2022

@@ -159,18 +161,14 @@ class LiveRangeCalc {
159161
/// the given @p LiveOuts.
160162
void updateFromLiveIns();
161163

162-
/// Extend the live range of @p LR to reach all uses of Reg.
163-
///
164-
/// If @p LR is a main range, or if @p LI is null, then all uses must be
165-
/// jointly dominated by the definitions from @p LR. If @p LR is a subrange
166-
/// of the live interval @p LI, corresponding to lane mask @p LaneMask,
167-
/// all uses must be jointly dominated by the definitions from @p LR
168-
/// together with definitions of other lanes where @p LR becomes undefined
169-
/// (via <def,read-undef> operands).
170-
/// If @p LR is a main range, the @p LaneMask should be set to ~0, i.e.
171-
/// LaneBitmask::getAll().
172-
void extendToUses(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask,
173-
LiveInterval *LI = nullptr);
164+
protected:
165+
/// Some getters to expose in a read-only way some private fields to
166+
/// subclasses.
167+
const MachineFunction *getMachineFunction() { return MF; }
168+
const MachineRegisterInfo *getRegInfo() const { return MRI; }
169+
SlotIndexes *getIndexes() { return Indexes; }
170+
MachineDominatorTree *getDomTree() { return DomTree; }
171+
VNInfo::Allocator *getVNAlloc() { return Alloc; }
174172

175173
/// Reset Map and Seen fields.
176174
void resetLiveOutMap();
@@ -210,29 +208,6 @@ class LiveRangeCalc {
210208
void extend(LiveRange &LR, SlotIndex Use, unsigned PhysReg,
211209
ArrayRef<SlotIndex> Undefs);
212210

213-
/// createDeadDefs - Create a dead def in LI for every def operand of Reg.
214-
/// Each instruction defining Reg gets a new VNInfo with a corresponding
215-
/// minimal live range.
216-
void createDeadDefs(LiveRange &LR, unsigned Reg);
217-
218-
/// Extend the live range of @p LR to reach all uses of Reg.
219-
///
220-
/// All uses must be jointly dominated by existing liveness. PHI-defs are
221-
/// inserted as needed to preserve SSA form.
222-
void extendToUses(LiveRange &LR, unsigned PhysReg) {
223-
extendToUses(LR, PhysReg, LaneBitmask::getAll());
224-
}
225-
226-
/// Calculates liveness for the register specified in live interval @p LI.
227-
/// Creates subregister live ranges as needed if subreg liveness tracking is
228-
/// enabled.
229-
void calculate(LiveInterval &LI, bool TrackSubRegs);
230-
231-
/// For live interval \p LI with correct SubRanges construct matching
232-
/// information for the main live range. Expects the main live range to not
233-
/// have any segments or value numbers.
234-
void constructMainRangeFromSubranges(LiveInterval &LI);
235-
236211
//===--------------------------------------------------------------------===//
237212
// Low-level interface.
238213
//===--------------------------------------------------------------------===//

llvm/lib/CodeGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ add_llvm_component_library(LLVMCodeGen
5656
LiveIntervalUnion.cpp
5757
LivePhysRegs.cpp
5858
LiveRangeCalc.cpp
59+
LiveIntervalCalc.cpp
5960
LiveRangeEdit.cpp
6061
LiveRangeShrink.cpp
6162
LiveRegMatrix.cpp

llvm/lib/CodeGen/InlineSpiller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include "llvm/ADT/Statistic.h"
2424
#include "llvm/Analysis/AliasAnalysis.h"
2525
#include "llvm/CodeGen/LiveInterval.h"
26+
#include "llvm/CodeGen/LiveIntervalCalc.h"
2627
#include "llvm/CodeGen/LiveIntervals.h"
27-
#include "llvm/CodeGen/LiveRangeCalc.h"
2828
#include "llvm/CodeGen/LiveRangeEdit.h"
2929
#include "llvm/CodeGen/LiveStacks.h"
3030
#include "llvm/CodeGen/MachineBasicBlock.h"

0 commit comments

Comments
 (0)