Skip to content

Commit 276b4e9

Browse files
committed
[CodeGen] Utilizing register units based liveIns tracking
Currently, the machine basicblock does not fully utilizes the laneBitmask associated with physReg liveIns to check for the precise liveness. Conservatively, it acts fully correct now, only if all liveIns check for MBB is in form it defines it for itself. So, now with the use of register units tracking for MBB's liveIns , its possible to track & check liveness for all sorts of physRegs.
1 parent 4077882 commit 276b4e9

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

llvm/include/llvm/CodeGen/MachineBasicBlock.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H
1414
#define LLVM_CODEGEN_MACHINEBASICBLOCK_H
1515

16+
#include "llvm/ADT/BitVector.h"
1617
#include "llvm/ADT/DenseMapInfo.h"
1718
#include "llvm/ADT/GraphTraits.h"
1819
#include "llvm/ADT/SparseBitVector.h"
@@ -158,6 +159,7 @@ class MachineBasicBlock
158159

159160
MachineFunction *xParent;
160161
Instructions Insts;
162+
const TargetRegisterInfo *TRI;
161163

162164
/// Keep track of the predecessor / successor basic blocks.
163165
SmallVector<MachineBasicBlock *, 4> Predecessors;
@@ -177,6 +179,10 @@ class MachineBasicBlock
177179
using LiveInVector = std::vector<RegisterMaskPair>;
178180
LiveInVector LiveIns;
179181

182+
/// Keeps track of live register units for those physical registers which
183+
/// are livein of the basicblock.
184+
BitVector LiveInRegUnits;
185+
180186
/// Alignment of the basic block. One if the basic block does not need to be
181187
/// aligned.
182188
Align Alignment;
@@ -467,11 +473,17 @@ class MachineBasicBlock
467473
void addLiveIn(MCRegister PhysReg,
468474
LaneBitmask LaneMask = LaneBitmask::getAll()) {
469475
LiveIns.push_back(RegisterMaskPair(PhysReg, LaneMask));
476+
addLiveInRegUnit(PhysReg, LaneMask);
470477
}
471478
void addLiveIn(const RegisterMaskPair &RegMaskPair) {
472479
LiveIns.push_back(RegMaskPair);
480+
addLiveInRegUnit(RegMaskPair.PhysReg, RegMaskPair.LaneMask);
473481
}
474482

483+
// Sets the register units for Reg based on the LaneMask in the
484+
// LiveInRegUnits.
485+
void addLiveInRegUnit(MCRegister Reg, LaneBitmask LaneMask);
486+
475487
/// Sorts and uniques the LiveIns vector. It can be significantly faster to do
476488
/// this than repeatedly calling isLiveIn before calling addLiveIn for every
477489
/// LiveIn insertion.
@@ -493,6 +505,9 @@ class MachineBasicBlock
493505
void removeLiveIn(MCRegister Reg,
494506
LaneBitmask LaneMask = LaneBitmask::getAll());
495507

508+
/// Resets the register units from LiveInRegUnits for the specified regsiters.
509+
void removeLiveInRegUnit(MCRegister Reg);
510+
496511
/// Return true if the specified register is in the live in set.
497512
bool isLiveIn(MCRegister Reg,
498513
LaneBitmask LaneMask = LaneBitmask::getAll()) const;

llvm/lib/CodeGen/MachineBasicBlock.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "llvm/IR/ModuleSlotTracker.h"
3636
#include "llvm/MC/MCAsmInfo.h"
3737
#include "llvm/MC/MCContext.h"
38+
#include "llvm/MC/MCRegisterInfo.h"
3839
#include "llvm/Support/Debug.h"
3940
#include "llvm/Support/raw_ostream.h"
4041
#include "llvm/Target/TargetMachine.h"
@@ -51,10 +52,12 @@ static cl::opt<bool> PrintSlotIndexes(
5152
cl::init(true), cl::Hidden);
5253

5354
MachineBasicBlock::MachineBasicBlock(MachineFunction &MF, const BasicBlock *B)
54-
: BB(B), Number(-1), xParent(&MF) {
55+
: BB(B), Number(-1), xParent(&MF),
56+
TRI(MF.getSubtarget().getRegisterInfo()) {
5557
Insts.Parent = this;
5658
if (B)
5759
IrrLoopHeaderWeight = B->getIrrLoopHeaderWeight();
60+
LiveInRegUnits.resize(TRI->getNumRegUnits());
5861
}
5962

6063
MachineBasicBlock::~MachineBasicBlock() = default;
@@ -597,28 +600,47 @@ void MachineBasicBlock::printAsOperand(raw_ostream &OS,
597600
printName(OS, 0);
598601
}
599602

603+
void MachineBasicBlock::addLiveInRegUnit(MCRegister Reg, LaneBitmask LaneMask) {
604+
for (MCRegUnitMaskIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) {
605+
LaneBitmask UnitMask = (*Unit).second;
606+
if ((UnitMask & LaneMask).any())
607+
LiveInRegUnits.set((*Unit).first);
608+
}
609+
}
610+
600611
void MachineBasicBlock::removeLiveIn(MCRegister Reg, LaneBitmask LaneMask) {
601612
LiveInVector::iterator I = find_if(
602613
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
603614
if (I == LiveIns.end())
604615
return;
605616

606617
I->LaneMask &= ~LaneMask;
607-
if (I->LaneMask.none())
618+
if (I->LaneMask.none()) {
608619
LiveIns.erase(I);
620+
removeLiveInRegUnit(I->PhysReg);
621+
}
609622
}
610623

611624
MachineBasicBlock::livein_iterator
612625
MachineBasicBlock::removeLiveIn(MachineBasicBlock::livein_iterator I) {
613626
// Get non-const version of iterator.
614627
LiveInVector::iterator LI = LiveIns.begin() + (I - LiveIns.begin());
628+
removeLiveInRegUnit(LI->PhysReg);
615629
return LiveIns.erase(LI);
616630
}
617631

632+
void MachineBasicBlock::removeLiveInRegUnit(MCRegister Reg) {
633+
for (MCRegUnit Unit : TRI->regunits(Reg))
634+
LiveInRegUnits.reset(Unit);
635+
}
636+
618637
bool MachineBasicBlock::isLiveIn(MCRegister Reg, LaneBitmask LaneMask) const {
619-
livein_iterator I = find_if(
620-
LiveIns, [Reg](const RegisterMaskPair &LI) { return LI.PhysReg == Reg; });
621-
return I != livein_end() && (I->LaneMask & LaneMask).any();
638+
for (MCRegUnitMaskIterator Unit(Reg, TRI); Unit.isValid(); ++Unit) {
639+
LaneBitmask UnitMask = (*Unit).second;
640+
if ((UnitMask & LaneMask).any() && LiveInRegUnits.test((*Unit).first))
641+
return true;
642+
}
643+
return false;
622644
}
623645

624646
void MachineBasicBlock::sortUniqueLiveIns() {
@@ -1767,12 +1789,14 @@ MachineBasicBlock::getEndClobberMask(const TargetRegisterInfo *TRI) const {
17671789

17681790
void MachineBasicBlock::clearLiveIns() {
17691791
LiveIns.clear();
1792+
LiveInRegUnits.reset();
17701793
}
17711794

17721795
void MachineBasicBlock::clearLiveIns(
17731796
std::vector<RegisterMaskPair> &OldLiveIns) {
17741797
assert(OldLiveIns.empty() && "Vector must be empty");
17751798
std::swap(LiveIns, OldLiveIns);
1799+
LiveInRegUnits.reset();
17761800
}
17771801

17781802
MachineBasicBlock::livein_iterator MachineBasicBlock::livein_begin() const {

llvm/test/CodeGen/ARM/aes-erratum-fix.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ define arm_aapcs_vfpcc void @aese_via_call2(half %0, ptr %1) nounwind {
6868
; CHECK-FIX-NEXT: push {r4, lr}
6969
; CHECK-FIX-NEXT: mov r4, r0
7070
; CHECK-FIX-NEXT: bl get_inputf16
71-
; CHECK-FIX-NEXT: vorr q0, q0, q0
7271
; CHECK-FIX-NEXT: vld1.64 {d16, d17}, [r4]
72+
; CHECK-FIX-NEXT: vorr q0, q0, q0
7373
; CHECK-FIX-NEXT: aese.8 q8, q0
7474
; CHECK-FIX-NEXT: aesmc.8 q8, q8
7575
; CHECK-FIX-NEXT: vst1.64 {d16, d17}, [r4]
@@ -89,8 +89,8 @@ define arm_aapcs_vfpcc void @aese_via_call3(float %0, ptr %1) nounwind {
8989
; CHECK-FIX-NEXT: push {r4, lr}
9090
; CHECK-FIX-NEXT: mov r4, r0
9191
; CHECK-FIX-NEXT: bl get_inputf32
92-
; CHECK-FIX-NEXT: vorr q0, q0, q0
9392
; CHECK-FIX-NEXT: vld1.64 {d16, d17}, [r4]
93+
; CHECK-FIX-NEXT: vorr q0, q0, q0
9494
; CHECK-FIX-NEXT: aese.8 q8, q0
9595
; CHECK-FIX-NEXT: aesmc.8 q8, q8
9696
; CHECK-FIX-NEXT: vst1.64 {d16, d17}, [r4]
@@ -2222,8 +2222,8 @@ define arm_aapcs_vfpcc void @aesd_via_call2(half %0, ptr %1) nounwind {
22222222
; CHECK-FIX-NEXT: push {r4, lr}
22232223
; CHECK-FIX-NEXT: mov r4, r0
22242224
; CHECK-FIX-NEXT: bl get_inputf16
2225-
; CHECK-FIX-NEXT: vorr q0, q0, q0
22262225
; CHECK-FIX-NEXT: vld1.64 {d16, d17}, [r4]
2226+
; CHECK-FIX-NEXT: vorr q0, q0, q0
22272227
; CHECK-FIX-NEXT: aesd.8 q8, q0
22282228
; CHECK-FIX-NEXT: aesimc.8 q8, q8
22292229
; CHECK-FIX-NEXT: vst1.64 {d16, d17}, [r4]
@@ -2243,8 +2243,8 @@ define arm_aapcs_vfpcc void @aesd_via_call3(float %0, ptr %1) nounwind {
22432243
; CHECK-FIX-NEXT: push {r4, lr}
22442244
; CHECK-FIX-NEXT: mov r4, r0
22452245
; CHECK-FIX-NEXT: bl get_inputf32
2246-
; CHECK-FIX-NEXT: vorr q0, q0, q0
22472246
; CHECK-FIX-NEXT: vld1.64 {d16, d17}, [r4]
2247+
; CHECK-FIX-NEXT: vorr q0, q0, q0
22482248
; CHECK-FIX-NEXT: aesd.8 q8, q0
22492249
; CHECK-FIX-NEXT: aesimc.8 q8, q8
22502250
; CHECK-FIX-NEXT: vst1.64 {d16, d17}, [r4]

0 commit comments

Comments
 (0)