-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[StackColoring] Delete dead stack slots #72633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
24f1b7a
delete dead stack slots (#104)
mohammed-nurulhoque cc6ae37
Fix Debug Info after removing stack slot
mohammed-nurulhoque dda2242
use-opaque-pointer
mohammed-nurulhoque 81309b7
check debuginfo is stack slot
mohammed-nurulhoque 80a04b1
simplify test case
mohammed-nurulhoque 71f88f6
fix formatting
mohammed-nurulhoque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -899,6 +899,15 @@ 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()) | ||
|
@@ -1249,8 +1258,15 @@ bool StackColoring::runOnMachineFunction(MachineFunction &Func) { | |
|
||
// Do not bother looking at empty intervals. | ||
for (unsigned I = 0; I < NumSlots; ++I) { | ||
if (Intervals[SortedSlots[I]]->empty()) | ||
int Slot = SortedSlots[I]; | ||
if (Intervals[Slot]->empty()) { | ||
if (InterestingSlots.test(Slot) && !ConservativeSlots.test(Slot)) { | ||
RemovedSlots += 1; | ||
ReducedSize += MFI->getObjectSize(Slot); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reduced size thing doesn't account for alignment but I guess this is only used for debug printing and was never accurate |
||
MFI->RemoveStackObject(Slot); | ||
} | ||
SortedSlots[I] = -1; | ||
} | ||
} | ||
|
||
// This is a simple greedy algorithm for merging allocas. First, sort the | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \ | ||
; RUN: | FileCheck %s | ||
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \ | ||
; RUN: | FileCheck %s | ||
|
||
; Remove the lifetime-marked alloca, but not the unmarked one. | ||
define signext i32 @f1() nounwind { | ||
; CHECK-LABEL: f1: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: addi sp, sp, -32 | ||
; CHECK-NEXT: li a0, 0 | ||
; CHECK-NEXT: addi sp, sp, 32 | ||
; CHECK-NEXT: ret | ||
%1 = alloca [32 x i8], align 4 | ||
%2 = alloca [32 x i8], align 4 | ||
%3 = getelementptr inbounds [32 x i8], ptr %1, i64 0, i64 0 | ||
call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) | ||
call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) | ||
ret i32 0 | ||
} | ||
|
||
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) | ||
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.