[PATCH] D73063: [StackColoring] Remap PseudoSourceValue frame indices via MachineFunction::getPSVManager()
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 20 11:50:17 PST 2020
MaskRay created this revision.
MaskRay added reviewers: Bdragon28, dantrushin.
Herald added subscribers: llvm-commits, jsji, hiraditya, nemanjai.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73063
Files:
llvm/include/llvm/CodeGen/PseudoSourceValue.h
llvm/lib/CodeGen/StackColoring.cpp
llvm/test/CodeGen/PowerPC/stack-coloring-vararg.mir
Index: llvm/test/CodeGen/PowerPC/stack-coloring-vararg.mir
===================================================================
--- llvm/test/CodeGen/PowerPC/stack-coloring-vararg.mir
+++ llvm/test/CodeGen/PowerPC/stack-coloring-vararg.mir
@@ -1,4 +1,16 @@
-# RUN: llc -o - %s -start-before=stack-coloring
+# RUN: llc -run-pass=stack-coloring %s -o - | FileCheck %s
+
+## Test %stack.1 is merged into %stack.0 and there is no MemoryMemOperand
+## referencing %stack.1. This regression test is sensitive to the StackColoring
+## algorithm. Please adjust or delete this test if the merging strategy
+## changes.
+
+# CHECK: {{^}}stack:
+# CHECK-NEXT: - { id: 0,
+# CHECK-NOT: - { id: 1,
+# CHECK: - { id: 2,
+# CHECK-NOT: %stack.1
+
--- |
; ModuleID = '<stdin>'
source_filename = "<stdin>"
Index: llvm/lib/CodeGen/StackColoring.cpp
===================================================================
--- llvm/lib/CodeGen/StackColoring.cpp
+++ llvm/lib/CodeGen/StackColoring.cpp
@@ -960,6 +960,7 @@
}
// Remap all instructions to the new stack slots.
+ std::vector<std::vector<MachineMemOperand *>> SSRefs(MFI->getObjectIndexEnd());
for (MachineBasicBlock &BB : *MF)
for (MachineInstr &I : BB) {
// Skip lifetime markers. We'll remove them soon.
@@ -1030,8 +1031,7 @@
int FI = FSV->getFrameIndex();
auto To = SlotRemap.find(FI);
if (To != SlotRemap.end())
- const_cast<FixedStackPseudoSourceValue *>(FSV)->setFrameIndex(
- To->second);
+ SSRefs[FI].push_back(MMO);
}
// If this memory location can be a slot remapped here,
@@ -1071,6 +1071,14 @@
I.setMemRefs(*MF, NewMMOs);
}
+ // Rewrite MachineMemOperands that reference old frame indices.
+ for (auto E : enumerate(SSRefs)) {
+ const PseudoSourceValue *NewSV =
+ MF->getPSVManager().getFixedStack(SlotRemap[E.index()]);
+ for (MachineMemOperand *Ref : E.value())
+ Ref->setValue(NewSV);
+ }
+
// Update the location of C++ catch objects for the MSVC personality routine.
if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
Index: llvm/include/llvm/CodeGen/PseudoSourceValue.h
===================================================================
--- llvm/include/llvm/CodeGen/PseudoSourceValue.h
+++ llvm/include/llvm/CodeGen/PseudoSourceValue.h
@@ -93,7 +93,7 @@
/// A specialized PseudoSourceValue for holding FixedStack values, which must
/// include a frame index.
class FixedStackPseudoSourceValue : public PseudoSourceValue {
- int FI;
+ const int FI;
public:
explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
@@ -112,7 +112,6 @@
void printCustom(raw_ostream &OS) const override;
int getFrameIndex() const { return FI; }
- void setFrameIndex(int FI) { this->FI = FI; }
};
class CallEntryPseudoSourceValue : public PseudoSourceValue {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73063.239187.patch
Type: text/x-patch
Size: 2968 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200120/ad90f348/attachment.bin>
More information about the llvm-commits
mailing list