Skip to content

Commit

Permalink
Revert "[StackColoring] Delete dead stack slots (#75351)"
Browse files Browse the repository at this point in the history
This reverts commit 08b306d.
  • Loading branch information
ilovepi committed Dec 15, 2023
1 parent 59f7f35 commit 6e99603
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 48 deletions.
20 changes: 2 additions & 18 deletions llvm/lib/CodeGen/StackColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,6 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
unsigned FixedMemOp = 0;
unsigned FixedDbg = 0;

// Remove debug information for deleted slots.
erase_if(MF->getVariableDbgInfo(), [&](auto &VI) {
if (!VI.inStackSlot())
return false;
int Slot = VI.getStackSlot();
return Slot >= 0 && Intervals[Slot]->empty() &&
InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot);
});

// Remap debug information that refers to stack slots.
for (auto &VI : MF->getVariableDbgInfo()) {
if (!VI.Var || !VI.inStackSlot())
Expand Down Expand Up @@ -1259,15 +1250,8 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) {

// Do not bother looking at empty intervals.
for (unsigned I = 0; I < NumSlots; ++I) {
int Slot = SortedSlots[I];
if (Intervals[Slot]->empty()) {
if (InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot)) {
RemovedSlots += 1;
ReducedSize += MFI->getObjectSize(Slot);
MFI->RemoveStackObject(Slot);
}
if (Intervals[SortedSlots[I]]->empty())
SortedSlots[I] = -1;
}
}

// This is a simple greedy algorithm for merging allocas. First, sort the
Expand Down Expand Up @@ -1355,7 +1339,7 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) {

// Scan the entire function and update all machine operands that use frame
// indices to use the remapped frame index.
if (RemovedSlots > 0) {
if (!SlotRemap.empty()) {
expungeSlotMap(SlotRemap, NumSlots);
remapInstructions(SlotRemap);
}
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/PowerPC/aix32-cc-abi-vaarg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ entry:

; 32BIT-LABEL: stack:
; 32BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 4, alignment: 4,
; 32BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 4, alignment: 4,
; 32BIT-DAG: - { id: 2, name: '', type: default, offset: 0, size: 8, alignment: 8,
; 32BIT-DAG: - { id: 3, name: '', type: default, offset: 0, size: 8, alignment: 8,

Expand Down
8 changes: 6 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix64-cc-abi-vaarg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@
; 64BIT-LABEL: fixedStack:
; 64BIT-DAG: - { id: 0, type: default, offset: 112, size: 8, alignment: 16, stack-id: default,

; 64BIT-LABEL: stack: []
; 64BIT-LABEL: stack:
; 64BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 8, alignment: 8,
; 64BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 8, alignment: 8,

; 64BIT-LABEL: body: |
; 64BIT-DAG: liveins: $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10
Expand Down Expand Up @@ -303,7 +305,9 @@
; 64BIT-LABEL: fixedStack:
; 64BIT-DAG: - { id: 0, type: default, offset: 152, size: 8

; 64BIT-LABEL: stack: []
; 64BIT-LABEL: stack:
; 64BIT-DAG: - { id: 0, name: arg1, type: default, offset: 0, size: 8
; 64BIT-DAG: - { id: 1, name: arg2, type: default, offset: 0, size: 8

; 64BIT-LABEL: body: |
; 64BIT-DAG: liveins: $f1, $f2, $f3, $f4, $f5, $f6, $f7, $f8, $f9, $f10, $f11, $f12, $f13
Expand Down
25 changes: 0 additions & 25 deletions llvm/test/CodeGen/RISCV/dead-stack-slot.ll

This file was deleted.

2 changes: 1 addition & 1 deletion llvm/test/CodeGen/X86/StackColoring-tbaa.mir
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ body: |
; CHECK: [[LEA64r:%[0-9]+]]:gr64 = nuw LEA64r %stack.1.agg, 1, $noreg, 24, $noreg
; CHECK-NEXT: CMP8mi %stack.1.agg, 1, $noreg, 47, $noreg, 0, implicit-def $eflags :: (dereferenceable load (s8) from %ir.a22, !tbaa !2)
; CHECK-NEXT: [[CMOV64rm:%[0-9]+]]:gr64 = CMOV64rm [[LEA64r]], %stack.1.agg, 1, $noreg, 24, $noreg, 8, implicit $eflags :: (dereferenceable load (s64) from %ir.a2)
; CHECK-NEXT: [[MOV8rm:%[0-9]+]]:gr8 = MOV8rm killed [[CMOV64rm]], 1, $noreg, 16, $noreg :: (load (s8) from %ir.add.ptr.i)
; CHECK-NEXT: [[MOV8rm:%[0-9]+]]:gr8 = MOV8rm killed [[CMOV64rm]], 1, $noreg, 16, $noreg :: (load (s8) from %ir.add.ptr.i, !tbaa !2)
; CHECK-NEXT: $al = COPY [[MOV8rm]]
; CHECK-NEXT: RET 0, $al
LIFETIME_START %stack.0.padding
Expand Down
24 changes: 22 additions & 2 deletions llvm/test/DebugInfo/COFF/lexicalblock.ll
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,32 @@
; CHECK: LocalSym {
; CHECK: VarName: localA
; CHECK: }
; CHECK: LocalSym {
; CHECK: VarName: localB
; CHECK: }
; CHECK: BlockSym {
; CHECK: Kind: S_BLOCK32 {{.*}}
; CHECK: BlockName:
; CHECK: }
; CHECK: LocalSym {
; CHECK: VarName: localB
; CHECK: ScopeEndSym {
; CHECK: Kind: S_END {{.*}}
; CHECK: }
; CHECK: BlockSym {
; CHECK: Kind: S_BLOCK32 {{.*}}
; CHECK: BlockName:
; CHECK: }
; CHECK: ScopeEndSym {
; CHECK: Kind: S_END {{.*}}
; CHECK: }
; CHECK: BlockSym {
; CHECK: Kind: S_BLOCK32 {{.*}}
; CHECK: BlockName:
; CHECK: }
; CHECK: ScopeEndSym {
; CHECK: }
; CHECK: BlockSym {
; CHECK: Kind: S_BLOCK32 {{.*}}
; CHECK: BlockName:
; CHECK: }
; CHECK: ScopeEndSym {
; CHECK: Kind: S_END {{.*}}
Expand Down

0 comments on commit 6e99603

Please sign in to comment.