Skip to content

Commit eb99767

Browse files
committed
Comment
1 parent ddc96e9 commit eb99767

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

llvm/lib/Target/RISCV/RISCVLiveVariables.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
// The pass computes liveness information for virtual and physical registers
1111
// in RISC-V machine functions, optimized for RV64 (64-bit RISC-V architecture).
1212
//
13-
// The analysis performs a backward dataflow analysis to compute:
14-
// - Live-in sets: Registers that are live at the entry of a basic block
15-
// - Live-out sets: Registers that are live at the exit of a basic block
16-
// - Kill points: Instructions where a register's last use occurs
17-
// - Def points: Instructions where a register is defined
13+
// The analysis performs a backward dataflow analysis to compute
14+
// liveness information. Also updates the kill flags on register operands.
15+
// There is also a verification step to ensure consistency with MBB live-ins.
1816
//
1917
//===----------------------------------------------------------------------===//
2018

@@ -50,6 +48,10 @@ static cl::opt<bool> UpdateKills("riscv-liveness-update-kills",
5048
cl::desc("Update kill flags"), cl::init(false),
5149
cl::Hidden);
5250

51+
static cl::opt<unsigned> MaxVRegs("riscv-liveness-max-vregs",
52+
cl::desc("Maximum VRegs to track"),
53+
cl::init(1024), cl::Hidden);
54+
5355
namespace {
5456

5557
/// LivenessInfo - Stores liveness information for a basic block
@@ -158,21 +160,16 @@ FunctionPass *llvm::createRISCVLiveVariablesPass(bool PreRegAlloc) {
158160
bool RISCVLiveVariables::isTrackableRegister(
159161
Register Reg, const TargetRegisterInfo *TRI,
160162
const MachineRegisterInfo *MRI) const {
161-
// Track virtual registers
163+
// Track all virtual registers but only allocatable physical registers.
164+
// 1. General purpose registers (X0-X31)
165+
// 2. Floating point registers (F0-F31)
166+
// 3. Vector registers if present
167+
162168
if (Reg.isVirtual())
163169
return true;
164170

165-
// For physical registers, only track allocatable ones
166-
if (Reg.isPhysical()) {
167-
// Check if register is allocatable
168-
if (!TRI->isInAllocatableClass(Reg))
169-
return false;
170-
171-
// Track general purpose registers (X0-X31)
172-
// Track floating point registers (F0-F31)
173-
// Track vector registers for RVV if present
174-
return true;
175-
}
171+
if (Reg.isPhysical())
172+
return TRI->isInAllocatableClass(Reg);
176173

177174
return false;
178175
}
@@ -194,8 +191,7 @@ void RISCVLiveVariables::processInstruction(const MachineInstr &MI,
194191
continue;
195192

196193
if (MO.isUse()) {
197-
// This is a use - only add to Use set if not already defined in this
198-
// block
194+
// Only add to Use set if not already defined in this block.
199195
if (Info.Gen.find(Reg) == Info.Gen.end()) {
200196
Info.Use.insert(Reg);
201197

@@ -477,7 +473,7 @@ bool RISCVLiveVariables::runOnMachineFunction(MachineFunction &MF) {
477473
// TODO: Update live-in/live-out sets of MBBs
478474

479475
// Step 3: Mark kill flags on operands
480-
if (UpdateKills)
476+
if (UpdateKills && MaxVRegs >= RegCounter)
481477
markKills(MF);
482478

483479
LLVM_DEBUG({

llvm/test/CodeGen/RISCV/live-variables-loops.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,4 @@ loop:
159159

160160
exit:
161161
ret i64 %sum.next
162-
}
162+
}

0 commit comments

Comments
 (0)