Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions llvm/lib/CodeGen/ReachingDefAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,9 @@ void ReachingDefAnalysis::processDefs(MachineInstr *MI) {
assert(FrameIndex >= 0 && "Can't handle negative frame indicies yet!");
if (!isFIDef(*MI, FrameIndex, TII))
continue;
if (MBBFrameObjsReachingDefs.contains(MBBNumber)) {
auto Frame2InstrIdx = MBBFrameObjsReachingDefs[MBBNumber];
if (Frame2InstrIdx.count(FrameIndex - ObjectIndexBegin) > 0)
Frame2InstrIdx[FrameIndex - ObjectIndexBegin].push_back(CurInstr);
else
Frame2InstrIdx[FrameIndex - ObjectIndexBegin] = {CurInstr};
} else {
MBBFrameObjsReachingDefs[MBBNumber] = {
{FrameIndex - ObjectIndexBegin, {CurInstr}}};
}

int Key = FrameIndex - ObjectIndexBegin;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to normalize the FrameIndex. Can't we use it as the key directly?

MBBFrameObjsReachingDefs[MBBNumber][Key].push_back(CurInstr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A map of maps is a kind of silly data structure. You can make the key a std::pair and use a single level map. Unless we need to be able to easily access the inner map for a single basic block.

}
if (!isValidRegDef(MO))
continue;
Expand Down Expand Up @@ -348,8 +341,19 @@ int ReachingDefAnalysis::getReachingDef(MachineInstr *MI, Register Reg) const {

if (Reg.isStack()) {
int FrameIndex = Reg.stackSlotIndex();
for (int Def : MBBFrameObjsReachingDefs.lookup(MBBNumber).lookup(
FrameIndex - ObjectIndexBegin)) {
int Key = FrameIndex - ObjectIndexBegin;

// Check that there was a reaching def.
auto Lookup1 = MBBFrameObjsReachingDefs.find(MBBNumber);
if (Lookup1 == MBBFrameObjsReachingDefs.end())
return LatestDef;
auto &InnerMap = Lookup1->second;
auto Lookup2 = InnerMap.find(Key);
if (Lookup2 == InnerMap.end())
return LatestDef;
auto &Defs = Lookup2->second;

for (int Def : Defs) {
if (Def >= InstId)
break;
DefRes = Def;
Expand Down
37 changes: 37 additions & 0 deletions llvm/test/CodeGen/RISCV/rda-stack.mir
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,40 @@ body: |
$x10 = LD %stack.0, 0 :: (load (s64))
PseudoRET implicit $x10
...
---
name: test4
tracksRegLiveness: true
stack:
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
- { id: 1, name: '', type: default, offset: 0, size: 4, alignment: 4,
stack-id: default, callee-saved-register: '', callee-saved-restored: true,
debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
body: |
; CHECK: RDA results for test4
; CHECK-NEXT: $x10:{ }
; CHECK-NEXT: %stack.0:{ }
; CHECK-NEXT: 0: SD $x10, %stack.0, 0 :: (store (s64))
; CHECK-EMPTY:
; CHECK-NEXT: $x11:{ }
; CHECK-NEXT: %stack.0:{ 0 }
; CHECK-NEXT: 1: SD $x11, %stack.0, 0 :: (store (s64))
; CHECK-EMPTY:
; CHECK-NEXT: $x10:{ }
; CHECK-NEXT: %stack.1:{ }
; CHECK-NEXT: 2: SD $x10, %stack.1, 0 :: (store (s64))
; CHECK-EMPTY:
; CHECK-NEXT: $x11:{ }
; CHECK-NEXT: %stack.1:{ 2 }
; CHECK-NEXT: 3: SD $x11, %stack.1, 0 :: (store (s64))
; CHECK-EMPTY:
; CHECK-NEXT: 4: PseudoRET
bb.0.entry:
liveins: $x10, $x11
SD $x10, %stack.0, 0 :: (store (s64))
SD $x11, %stack.0, 0 :: (store (s64))
SD $x10, %stack.1, 0 :: (store (s64))
SD $x11, %stack.1, 0 :: (store (s64))
PseudoRET
...