forked from OSchip/llvm-project
[StackColoring] Remap PseudoSourceValue frame indices via MachineFunction::getPSVManager()
Reviewed By: dantrushin Differential Revision: https://reviews.llvm.org/D73063
This commit is contained in:
parent
2e667d07c7
commit
7a8b0b1595
|
@ -93,7 +93,7 @@ public:
|
||||||
/// A specialized PseudoSourceValue for holding FixedStack values, which must
|
/// A specialized PseudoSourceValue for holding FixedStack values, which must
|
||||||
/// include a frame index.
|
/// include a frame index.
|
||||||
class FixedStackPseudoSourceValue : public PseudoSourceValue {
|
class FixedStackPseudoSourceValue : public PseudoSourceValue {
|
||||||
int FI;
|
const int FI;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
|
explicit FixedStackPseudoSourceValue(int FI, const TargetInstrInfo &TII)
|
||||||
|
@ -112,7 +112,6 @@ public:
|
||||||
void printCustom(raw_ostream &OS) const override;
|
void printCustom(raw_ostream &OS) const override;
|
||||||
|
|
||||||
int getFrameIndex() const { return FI; }
|
int getFrameIndex() const { return FI; }
|
||||||
void setFrameIndex(int FI) { this->FI = FI; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class CallEntryPseudoSourceValue : public PseudoSourceValue {
|
class CallEntryPseudoSourceValue : public PseudoSourceValue {
|
||||||
|
|
|
@ -960,6 +960,7 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap all instructions to the new stack slots.
|
// Remap all instructions to the new stack slots.
|
||||||
|
std::vector<std::vector<MachineMemOperand *>> SSRefs(MFI->getObjectIndexEnd());
|
||||||
for (MachineBasicBlock &BB : *MF)
|
for (MachineBasicBlock &BB : *MF)
|
||||||
for (MachineInstr &I : BB) {
|
for (MachineInstr &I : BB) {
|
||||||
// Skip lifetime markers. We'll remove them soon.
|
// Skip lifetime markers. We'll remove them soon.
|
||||||
|
@ -1025,13 +1026,14 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
|
||||||
SmallVector<MachineMemOperand *, 2> NewMMOs;
|
SmallVector<MachineMemOperand *, 2> NewMMOs;
|
||||||
bool ReplaceMemOps = false;
|
bool ReplaceMemOps = false;
|
||||||
for (MachineMemOperand *MMO : I.memoperands()) {
|
for (MachineMemOperand *MMO : I.memoperands()) {
|
||||||
|
// Collect MachineMemOperands which reference
|
||||||
|
// FixedStackPseudoSourceValues with old frame indices.
|
||||||
if (const auto *FSV = dyn_cast_or_null<FixedStackPseudoSourceValue>(
|
if (const auto *FSV = dyn_cast_or_null<FixedStackPseudoSourceValue>(
|
||||||
MMO->getPseudoValue())) {
|
MMO->getPseudoValue())) {
|
||||||
int FI = FSV->getFrameIndex();
|
int FI = FSV->getFrameIndex();
|
||||||
auto To = SlotRemap.find(FI);
|
auto To = SlotRemap.find(FI);
|
||||||
if (To != SlotRemap.end())
|
if (To != SlotRemap.end())
|
||||||
const_cast<FixedStackPseudoSourceValue *>(FSV)->setFrameIndex(
|
SSRefs[FI].push_back(MMO);
|
||||||
To->second);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this memory location can be a slot remapped here,
|
// If this memory location can be a slot remapped here,
|
||||||
|
@ -1071,6 +1073,14 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
|
||||||
I.setMemRefs(*MF, NewMMOs);
|
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.
|
// Update the location of C++ catch objects for the MSVC personality routine.
|
||||||
if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
|
if (WinEHFuncInfo *EHInfo = MF->getWinEHFuncInfo())
|
||||||
for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
|
for (WinEHTryBlockMapEntry &TBME : EHInfo->TryBlockMap)
|
||||||
|
|
|
@ -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>'
|
; ModuleID = '<stdin>'
|
||||||
source_filename = "<stdin>"
|
source_filename = "<stdin>"
|
||||||
|
|
Loading…
Reference in New Issue