-
Notifications
You must be signed in to change notification settings - Fork 15k
[llvm] Support multiple save/restore points in mir #119357
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
[llvm] Support multiple save/restore points in mir #119357
Conversation
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-backend-webassembly Author: Elizaveta Noskova (enoskova-sc) ChangesCurrently mir supports only one save and one restore point specification:
This patch provide possibility to have multiple save and multiple restore points in mir:
Shrink-Wrap points split Part 3. Part 1: #117862 Patch is 276.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119357.diff 340 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index 09a6ca936fe1f4..be8a8e593ef922 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
namespace llvm {
namespace yaml {
+struct SRPEntry {
+ StringValue Point;
+
+ bool operator==(const SRPEntry &Other) const { return Point == Other.Point; }
+};
+
+using SaveRestorePoints = std::vector<SRPEntry>;
+
+template <> struct MappingTraits<SRPEntry> {
+ static void mapping(IO &YamlIO, SRPEntry &Entry) {
+ YamlIO.mapRequired("point", Entry.Point);
+ }
+};
+
template <> struct MappingTraits<MachineJumpTable> {
static void mapping(IO &YamlIO, MachineJumpTable &JT) {
YamlIO.mapRequired("kind", JT.Kind);
@@ -618,6 +632,14 @@ template <> struct MappingTraits<MachineJumpTable> {
}
};
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SRPEntry)
+
+namespace llvm {
+namespace yaml {
+
/// Serializable representation of MachineFrameInfo.
///
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
@@ -645,8 +667,8 @@ struct MachineFrameInfo {
bool HasTailCall = false;
bool IsCalleeSavedInfoValid = false;
unsigned LocalFrameSize = 0;
- StringValue SavePoint;
- StringValue RestorePoint;
+ SaveRestorePoints SavePoints;
+ SaveRestorePoints RestorePoints;
bool operator==(const MachineFrameInfo &Other) const {
return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
@@ -667,7 +689,8 @@ struct MachineFrameInfo {
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
HasTailCall == Other.HasTailCall &&
LocalFrameSize == Other.LocalFrameSize &&
- SavePoint == Other.SavePoint && RestorePoint == Other.RestorePoint &&
+ SavePoints == Other.SavePoints &&
+ RestorePoints == Other.RestorePoints &&
IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
}
};
@@ -699,10 +722,12 @@ template <> struct MappingTraits<MachineFrameInfo> {
YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
false);
YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
- YamlIO.mapOptional("savePoint", MFI.SavePoint,
- StringValue()); // Don't print it out when it's empty.
- YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
- StringValue()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "savePoints", MFI.SavePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "restorePoints", MFI.RestorePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
}
};
diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h
index 74cf94398736dd..88800d91ef51a9 100644
--- a/llvm/include/llvm/CodeGen/MachineDominators.h
+++ b/llvm/include/llvm/CodeGen/MachineDominators.h
@@ -185,6 +185,11 @@ class MachineDominatorTree : public DomTreeBase<MachineBasicBlock> {
return Base::findNearestCommonDominator(A, B);
}
+ /// Returns the nearest common dominator of the given blocks.
+ /// If that tree node is a virtual root, a nullptr will be returned.
+ MachineBasicBlock *
+ findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
+
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
applySplitCriticalEdges();
return Base::getNode(BB);
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index e2543f883f91ce..f7c1e162d2a96e 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -124,6 +124,10 @@ class MIRParserImpl {
bool initializeFrameInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
+ bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS,
+ const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints);
+
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
@@ -832,18 +836,9 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
MFI.setHasTailCall(YamlMFI.HasTailCall);
MFI.setCalleeSavedInfoValid(YamlMFI.IsCalleeSavedInfoValid);
MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
- if (!YamlMFI.SavePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
- return true;
- MFI.setSavePoint(MBB);
- }
- if (!YamlMFI.RestorePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
- return true;
- MFI.setRestorePoint(MBB);
- }
+ initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, true /*IsSavePoints*/);
+ initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints,
+ false /*IsSavePoints*/);
std::vector<CalleeSavedInfo> CSIInfo;
// Initialize the fixed frame objects.
@@ -1058,8 +1053,28 @@ bool MIRParserImpl::initializeConstantPool(PerFunctionMIParsingState &PFS,
return false;
}
-bool MIRParserImpl::initializeJumpTableInfo(PerFunctionMIParsingState &PFS,
- const yaml::MachineJumpTable &YamlJTI) {
+bool MIRParserImpl::initializeSaveRestorePoints(
+ PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints) {
+ MachineFunction &MF = PFS.MF;
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+
+ if (!YamlSRP.empty()) {
+ const auto &Entry = YamlSRP.front();
+ const auto &MBBSource = Entry.Point;
+ MachineBasicBlock *MBB = nullptr;
+ if (parseMBBReference(PFS, MBB, MBBSource.Value))
+ return true;
+ if (IsSavePoints)
+ MFI.setSavePoint(MBB);
+ else
+ MFI.setRestorePoint(MBB);
+ }
+ return false;
+}
+
+bool MIRParserImpl::initializeJumpTableInfo(
+ PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI) {
MachineJumpTableInfo *JTI = PFS.MF.getOrCreateJumpTableInfo(YamlJTI.Kind);
for (const auto &Entry : YamlJTI.Entries) {
std::vector<MachineBasicBlock *> Blocks;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index c8f6341c1224d2..2d0728a6452808 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -118,6 +118,8 @@ class MIRPrinter {
const TargetRegisterInfo *TRI);
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
const MachineFrameInfo &MFI);
+ void convert(ModuleSlotTracker &MST, yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SaveRestorePoint);
void convert(yaml::MachineFunction &MF,
const MachineConstantPool &ConstantPool);
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
@@ -392,14 +394,10 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
YamlMFI.HasTailCall = MFI.hasTailCall();
YamlMFI.IsCalleeSavedInfoValid = MFI.isCalleeSavedInfoValid();
YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
- if (MFI.getSavePoint()) {
- raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
- StrOS << printMBBReference(*MFI.getSavePoint());
- }
- if (MFI.getRestorePoint()) {
- raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
- StrOS << printMBBReference(*MFI.getRestorePoint());
- }
+ if (MFI.getSavePoint())
+ convert(MST, YamlMFI.SavePoints, MFI.getSavePoint());
+ if (MFI.getRestorePoint())
+ convert(MST, YamlMFI.RestorePoints, MFI.getRestorePoint());
}
void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
@@ -618,6 +616,18 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
}
}
+void MIRPrinter::convert(ModuleSlotTracker &MST,
+ yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SRP) {
+ std::string Str;
+ yaml::SRPEntry Entry;
+ raw_string_ostream StrOS(Str);
+ StrOS << printMBBReference(*SRP);
+ Entry.Point = StrOS.str();
+ Str.clear();
+ YamlSRP.push_back(Entry);
+}
+
void MIRPrinter::convert(ModuleSlotTracker &MST,
yaml::MachineJumpTable &YamlJTI,
const MachineJumpTableInfo &JTI) {
diff --git a/llvm/lib/CodeGen/MachineDominators.cpp b/llvm/lib/CodeGen/MachineDominators.cpp
index a2cc8fdfa7c9f9..384f90c6da66c0 100644
--- a/llvm/lib/CodeGen/MachineDominators.cpp
+++ b/llvm/lib/CodeGen/MachineDominators.cpp
@@ -189,3 +189,19 @@ void MachineDominatorTree::applySplitCriticalEdges() const {
NewBBs.clear();
CriticalEdgesToSplit.clear();
}
+
+MachineBasicBlock *MachineDominatorTree::findNearestCommonDominator(
+ ArrayRef<MachineBasicBlock *> Blocks) const {
+ assert(!Blocks.empty());
+
+ MachineBasicBlock *NCD = Blocks.front();
+ for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ NCD = Base::findNearestCommonDominator(NCD, BB);
+
+ // Stop when the root is reached.
+ if (Base::isVirtualRoot(Base::getNode(NCD)))
+ return nullptr;
+ }
+
+ return NCD;
+}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index deb0b627225c64..0de1f1d821a6e2 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1607,6 +1607,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
int FrameIdx = MFI.CreateFixedSpillStackObject(Size, Offset);
assert(FrameIdx < 0);
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
continue;
}
}
@@ -1623,6 +1625,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
if ((unsigned)FrameIdx > MaxCSFrameIndex)
MaxCSFrameIndex = FrameIdx;
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
}
// Allocate a fixed object that covers the full push or libcall size.
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
index d52ef0f3da74c7..2e8f3c460b2fe7 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
@@ -86,8 +86,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
index ba621cf77f9aed..07e80538e793f5 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
@@ -59,8 +59,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 16
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, type: default, offset: -16, size: 16,
diff --git a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
index 16e2de751381ad..31589a86599ff3 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
@@ -157,8 +157,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/aarch64st1.mir b/llvm/test/CodeGen/AArch64/aarch64st1.mir
index 22a024d37bc64f..439db1e97aa794 100644
--- a/llvm/test/CodeGen/AArch64/aarch64st1.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64st1.mir
@@ -58,8 +58,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
index 31fa3832367bec..6851fdba1239a4 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
@@ -80,8 +80,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 30000
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: p, type: default, offset: -30016, size: 30000, alignment: 1,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
index a24972d1388320..fe5c90a5e6dc54 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
@@ -47,8 +47,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup.mir b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
index f522df6bb3fa06..dd75cec7f6e0be 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
@@ -65,8 +65,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -248,8 +248,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -403,8 +403,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
index 1c4447bffd8729..85f8abcbf7fe60 100644
--- a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
+++ b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
@@ -6,17 +6,23 @@
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
; CHECK: name: compiler_pop_stack
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: compiler_pop_stack_no_memoperands
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: f
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.2'
- ; CHECK-NEXT: restorePoint: '%bb.4'
- ; CHECK-NEXT: stack:
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.2'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.4'
+ ; CHECK: stack:
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"
diff --git a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
index a7f67f8b682c3c..6324db0cb2c0ff 100644
--- a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
+++ b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
@@ -105,8 +105,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
index f9878adfe5e448..3c98a1a128413e 100644
--- a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
+++ b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
@@ -75,8 +75,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: true
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
entry_values: []
diff --git a/llvm/test/CodeGen/AArch64/irg-nomem.mir b/llvm/test/CodeGen/AArch64/irg-nomem.mir
index 3b000fafbed46f..78438151405e66 100644
--- a/llvm/test/CodeGen/AArch64/irg-nomem.mir
+++ b/llvm/test/CodeGen/AArch64/irg-nomem.mir
@@ -47,8 +47,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
index a2532a854923f5..81cf5953895cab 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
+++ b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
@@ -92,8 +92,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
index f1f9e5fbc9b087..b431de2d9b35b3 100644
--- a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
+++ b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
@@ -103,8 +103,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -216,8 +216,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -327,8 +327,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
diff --git a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
index 612453ab53f438..4be16228814a3b 100644
--- a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
+++ b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
@@ -120,8 +120,10 @@ frameInfo:
adjustsStack: true
hasC...
[truncated]
|
@llvm/pr-subscribers-backend-aarch64 Author: Elizaveta Noskova (enoskova-sc) ChangesCurrently mir supports only one save and one restore point specification:
This patch provide possibility to have multiple save and multiple restore points in mir:
Shrink-Wrap points split Part 3. Part 1: #117862 Patch is 276.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119357.diff 340 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index 09a6ca936fe1f4..be8a8e593ef922 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
namespace llvm {
namespace yaml {
+struct SRPEntry {
+ StringValue Point;
+
+ bool operator==(const SRPEntry &Other) const { return Point == Other.Point; }
+};
+
+using SaveRestorePoints = std::vector<SRPEntry>;
+
+template <> struct MappingTraits<SRPEntry> {
+ static void mapping(IO &YamlIO, SRPEntry &Entry) {
+ YamlIO.mapRequired("point", Entry.Point);
+ }
+};
+
template <> struct MappingTraits<MachineJumpTable> {
static void mapping(IO &YamlIO, MachineJumpTable &JT) {
YamlIO.mapRequired("kind", JT.Kind);
@@ -618,6 +632,14 @@ template <> struct MappingTraits<MachineJumpTable> {
}
};
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SRPEntry)
+
+namespace llvm {
+namespace yaml {
+
/// Serializable representation of MachineFrameInfo.
///
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
@@ -645,8 +667,8 @@ struct MachineFrameInfo {
bool HasTailCall = false;
bool IsCalleeSavedInfoValid = false;
unsigned LocalFrameSize = 0;
- StringValue SavePoint;
- StringValue RestorePoint;
+ SaveRestorePoints SavePoints;
+ SaveRestorePoints RestorePoints;
bool operator==(const MachineFrameInfo &Other) const {
return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
@@ -667,7 +689,8 @@ struct MachineFrameInfo {
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
HasTailCall == Other.HasTailCall &&
LocalFrameSize == Other.LocalFrameSize &&
- SavePoint == Other.SavePoint && RestorePoint == Other.RestorePoint &&
+ SavePoints == Other.SavePoints &&
+ RestorePoints == Other.RestorePoints &&
IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
}
};
@@ -699,10 +722,12 @@ template <> struct MappingTraits<MachineFrameInfo> {
YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
false);
YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
- YamlIO.mapOptional("savePoint", MFI.SavePoint,
- StringValue()); // Don't print it out when it's empty.
- YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
- StringValue()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "savePoints", MFI.SavePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "restorePoints", MFI.RestorePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
}
};
diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h
index 74cf94398736dd..88800d91ef51a9 100644
--- a/llvm/include/llvm/CodeGen/MachineDominators.h
+++ b/llvm/include/llvm/CodeGen/MachineDominators.h
@@ -185,6 +185,11 @@ class MachineDominatorTree : public DomTreeBase<MachineBasicBlock> {
return Base::findNearestCommonDominator(A, B);
}
+ /// Returns the nearest common dominator of the given blocks.
+ /// If that tree node is a virtual root, a nullptr will be returned.
+ MachineBasicBlock *
+ findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
+
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
applySplitCriticalEdges();
return Base::getNode(BB);
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index e2543f883f91ce..f7c1e162d2a96e 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -124,6 +124,10 @@ class MIRParserImpl {
bool initializeFrameInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
+ bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS,
+ const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints);
+
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
@@ -832,18 +836,9 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
MFI.setHasTailCall(YamlMFI.HasTailCall);
MFI.setCalleeSavedInfoValid(YamlMFI.IsCalleeSavedInfoValid);
MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
- if (!YamlMFI.SavePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
- return true;
- MFI.setSavePoint(MBB);
- }
- if (!YamlMFI.RestorePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
- return true;
- MFI.setRestorePoint(MBB);
- }
+ initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, true /*IsSavePoints*/);
+ initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints,
+ false /*IsSavePoints*/);
std::vector<CalleeSavedInfo> CSIInfo;
// Initialize the fixed frame objects.
@@ -1058,8 +1053,28 @@ bool MIRParserImpl::initializeConstantPool(PerFunctionMIParsingState &PFS,
return false;
}
-bool MIRParserImpl::initializeJumpTableInfo(PerFunctionMIParsingState &PFS,
- const yaml::MachineJumpTable &YamlJTI) {
+bool MIRParserImpl::initializeSaveRestorePoints(
+ PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints) {
+ MachineFunction &MF = PFS.MF;
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+
+ if (!YamlSRP.empty()) {
+ const auto &Entry = YamlSRP.front();
+ const auto &MBBSource = Entry.Point;
+ MachineBasicBlock *MBB = nullptr;
+ if (parseMBBReference(PFS, MBB, MBBSource.Value))
+ return true;
+ if (IsSavePoints)
+ MFI.setSavePoint(MBB);
+ else
+ MFI.setRestorePoint(MBB);
+ }
+ return false;
+}
+
+bool MIRParserImpl::initializeJumpTableInfo(
+ PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI) {
MachineJumpTableInfo *JTI = PFS.MF.getOrCreateJumpTableInfo(YamlJTI.Kind);
for (const auto &Entry : YamlJTI.Entries) {
std::vector<MachineBasicBlock *> Blocks;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index c8f6341c1224d2..2d0728a6452808 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -118,6 +118,8 @@ class MIRPrinter {
const TargetRegisterInfo *TRI);
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
const MachineFrameInfo &MFI);
+ void convert(ModuleSlotTracker &MST, yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SaveRestorePoint);
void convert(yaml::MachineFunction &MF,
const MachineConstantPool &ConstantPool);
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
@@ -392,14 +394,10 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
YamlMFI.HasTailCall = MFI.hasTailCall();
YamlMFI.IsCalleeSavedInfoValid = MFI.isCalleeSavedInfoValid();
YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
- if (MFI.getSavePoint()) {
- raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
- StrOS << printMBBReference(*MFI.getSavePoint());
- }
- if (MFI.getRestorePoint()) {
- raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
- StrOS << printMBBReference(*MFI.getRestorePoint());
- }
+ if (MFI.getSavePoint())
+ convert(MST, YamlMFI.SavePoints, MFI.getSavePoint());
+ if (MFI.getRestorePoint())
+ convert(MST, YamlMFI.RestorePoints, MFI.getRestorePoint());
}
void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
@@ -618,6 +616,18 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
}
}
+void MIRPrinter::convert(ModuleSlotTracker &MST,
+ yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SRP) {
+ std::string Str;
+ yaml::SRPEntry Entry;
+ raw_string_ostream StrOS(Str);
+ StrOS << printMBBReference(*SRP);
+ Entry.Point = StrOS.str();
+ Str.clear();
+ YamlSRP.push_back(Entry);
+}
+
void MIRPrinter::convert(ModuleSlotTracker &MST,
yaml::MachineJumpTable &YamlJTI,
const MachineJumpTableInfo &JTI) {
diff --git a/llvm/lib/CodeGen/MachineDominators.cpp b/llvm/lib/CodeGen/MachineDominators.cpp
index a2cc8fdfa7c9f9..384f90c6da66c0 100644
--- a/llvm/lib/CodeGen/MachineDominators.cpp
+++ b/llvm/lib/CodeGen/MachineDominators.cpp
@@ -189,3 +189,19 @@ void MachineDominatorTree::applySplitCriticalEdges() const {
NewBBs.clear();
CriticalEdgesToSplit.clear();
}
+
+MachineBasicBlock *MachineDominatorTree::findNearestCommonDominator(
+ ArrayRef<MachineBasicBlock *> Blocks) const {
+ assert(!Blocks.empty());
+
+ MachineBasicBlock *NCD = Blocks.front();
+ for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ NCD = Base::findNearestCommonDominator(NCD, BB);
+
+ // Stop when the root is reached.
+ if (Base::isVirtualRoot(Base::getNode(NCD)))
+ return nullptr;
+ }
+
+ return NCD;
+}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index deb0b627225c64..0de1f1d821a6e2 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1607,6 +1607,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
int FrameIdx = MFI.CreateFixedSpillStackObject(Size, Offset);
assert(FrameIdx < 0);
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
continue;
}
}
@@ -1623,6 +1625,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
if ((unsigned)FrameIdx > MaxCSFrameIndex)
MaxCSFrameIndex = FrameIdx;
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
}
// Allocate a fixed object that covers the full push or libcall size.
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
index d52ef0f3da74c7..2e8f3c460b2fe7 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
@@ -86,8 +86,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
index ba621cf77f9aed..07e80538e793f5 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
@@ -59,8 +59,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 16
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, type: default, offset: -16, size: 16,
diff --git a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
index 16e2de751381ad..31589a86599ff3 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
@@ -157,8 +157,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/aarch64st1.mir b/llvm/test/CodeGen/AArch64/aarch64st1.mir
index 22a024d37bc64f..439db1e97aa794 100644
--- a/llvm/test/CodeGen/AArch64/aarch64st1.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64st1.mir
@@ -58,8 +58,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
index 31fa3832367bec..6851fdba1239a4 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
@@ -80,8 +80,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 30000
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: p, type: default, offset: -30016, size: 30000, alignment: 1,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
index a24972d1388320..fe5c90a5e6dc54 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
@@ -47,8 +47,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup.mir b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
index f522df6bb3fa06..dd75cec7f6e0be 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
@@ -65,8 +65,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -248,8 +248,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -403,8 +403,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
index 1c4447bffd8729..85f8abcbf7fe60 100644
--- a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
+++ b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
@@ -6,17 +6,23 @@
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
; CHECK: name: compiler_pop_stack
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: compiler_pop_stack_no_memoperands
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: f
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.2'
- ; CHECK-NEXT: restorePoint: '%bb.4'
- ; CHECK-NEXT: stack:
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.2'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.4'
+ ; CHECK: stack:
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"
diff --git a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
index a7f67f8b682c3c..6324db0cb2c0ff 100644
--- a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
+++ b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
@@ -105,8 +105,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
index f9878adfe5e448..3c98a1a128413e 100644
--- a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
+++ b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
@@ -75,8 +75,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: true
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
entry_values: []
diff --git a/llvm/test/CodeGen/AArch64/irg-nomem.mir b/llvm/test/CodeGen/AArch64/irg-nomem.mir
index 3b000fafbed46f..78438151405e66 100644
--- a/llvm/test/CodeGen/AArch64/irg-nomem.mir
+++ b/llvm/test/CodeGen/AArch64/irg-nomem.mir
@@ -47,8 +47,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
index a2532a854923f5..81cf5953895cab 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
+++ b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
@@ -92,8 +92,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
index f1f9e5fbc9b087..b431de2d9b35b3 100644
--- a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
+++ b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
@@ -103,8 +103,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -216,8 +216,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -327,8 +327,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
diff --git a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
index 612453ab53f438..4be16228814a3b 100644
--- a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
+++ b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
@@ -120,8 +120,10 @@ frameInfo:
adjustsStack: true
hasC...
[truncated]
|
@llvm/pr-subscribers-backend-nvptx Author: Elizaveta Noskova (enoskova-sc) ChangesCurrently mir supports only one save and one restore point specification:
This patch provide possibility to have multiple save and multiple restore points in mir:
Shrink-Wrap points split Part 3. Part 1: #117862 Patch is 276.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119357.diff 340 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index 09a6ca936fe1f4..be8a8e593ef922 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
namespace llvm {
namespace yaml {
+struct SRPEntry {
+ StringValue Point;
+
+ bool operator==(const SRPEntry &Other) const { return Point == Other.Point; }
+};
+
+using SaveRestorePoints = std::vector<SRPEntry>;
+
+template <> struct MappingTraits<SRPEntry> {
+ static void mapping(IO &YamlIO, SRPEntry &Entry) {
+ YamlIO.mapRequired("point", Entry.Point);
+ }
+};
+
template <> struct MappingTraits<MachineJumpTable> {
static void mapping(IO &YamlIO, MachineJumpTable &JT) {
YamlIO.mapRequired("kind", JT.Kind);
@@ -618,6 +632,14 @@ template <> struct MappingTraits<MachineJumpTable> {
}
};
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SRPEntry)
+
+namespace llvm {
+namespace yaml {
+
/// Serializable representation of MachineFrameInfo.
///
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
@@ -645,8 +667,8 @@ struct MachineFrameInfo {
bool HasTailCall = false;
bool IsCalleeSavedInfoValid = false;
unsigned LocalFrameSize = 0;
- StringValue SavePoint;
- StringValue RestorePoint;
+ SaveRestorePoints SavePoints;
+ SaveRestorePoints RestorePoints;
bool operator==(const MachineFrameInfo &Other) const {
return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
@@ -667,7 +689,8 @@ struct MachineFrameInfo {
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
HasTailCall == Other.HasTailCall &&
LocalFrameSize == Other.LocalFrameSize &&
- SavePoint == Other.SavePoint && RestorePoint == Other.RestorePoint &&
+ SavePoints == Other.SavePoints &&
+ RestorePoints == Other.RestorePoints &&
IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
}
};
@@ -699,10 +722,12 @@ template <> struct MappingTraits<MachineFrameInfo> {
YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
false);
YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
- YamlIO.mapOptional("savePoint", MFI.SavePoint,
- StringValue()); // Don't print it out when it's empty.
- YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
- StringValue()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "savePoints", MFI.SavePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "restorePoints", MFI.RestorePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
}
};
diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h
index 74cf94398736dd..88800d91ef51a9 100644
--- a/llvm/include/llvm/CodeGen/MachineDominators.h
+++ b/llvm/include/llvm/CodeGen/MachineDominators.h
@@ -185,6 +185,11 @@ class MachineDominatorTree : public DomTreeBase<MachineBasicBlock> {
return Base::findNearestCommonDominator(A, B);
}
+ /// Returns the nearest common dominator of the given blocks.
+ /// If that tree node is a virtual root, a nullptr will be returned.
+ MachineBasicBlock *
+ findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
+
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
applySplitCriticalEdges();
return Base::getNode(BB);
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index e2543f883f91ce..f7c1e162d2a96e 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -124,6 +124,10 @@ class MIRParserImpl {
bool initializeFrameInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
+ bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS,
+ const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints);
+
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
@@ -832,18 +836,9 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
MFI.setHasTailCall(YamlMFI.HasTailCall);
MFI.setCalleeSavedInfoValid(YamlMFI.IsCalleeSavedInfoValid);
MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
- if (!YamlMFI.SavePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
- return true;
- MFI.setSavePoint(MBB);
- }
- if (!YamlMFI.RestorePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
- return true;
- MFI.setRestorePoint(MBB);
- }
+ initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, true /*IsSavePoints*/);
+ initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints,
+ false /*IsSavePoints*/);
std::vector<CalleeSavedInfo> CSIInfo;
// Initialize the fixed frame objects.
@@ -1058,8 +1053,28 @@ bool MIRParserImpl::initializeConstantPool(PerFunctionMIParsingState &PFS,
return false;
}
-bool MIRParserImpl::initializeJumpTableInfo(PerFunctionMIParsingState &PFS,
- const yaml::MachineJumpTable &YamlJTI) {
+bool MIRParserImpl::initializeSaveRestorePoints(
+ PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints) {
+ MachineFunction &MF = PFS.MF;
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+
+ if (!YamlSRP.empty()) {
+ const auto &Entry = YamlSRP.front();
+ const auto &MBBSource = Entry.Point;
+ MachineBasicBlock *MBB = nullptr;
+ if (parseMBBReference(PFS, MBB, MBBSource.Value))
+ return true;
+ if (IsSavePoints)
+ MFI.setSavePoint(MBB);
+ else
+ MFI.setRestorePoint(MBB);
+ }
+ return false;
+}
+
+bool MIRParserImpl::initializeJumpTableInfo(
+ PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI) {
MachineJumpTableInfo *JTI = PFS.MF.getOrCreateJumpTableInfo(YamlJTI.Kind);
for (const auto &Entry : YamlJTI.Entries) {
std::vector<MachineBasicBlock *> Blocks;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index c8f6341c1224d2..2d0728a6452808 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -118,6 +118,8 @@ class MIRPrinter {
const TargetRegisterInfo *TRI);
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
const MachineFrameInfo &MFI);
+ void convert(ModuleSlotTracker &MST, yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SaveRestorePoint);
void convert(yaml::MachineFunction &MF,
const MachineConstantPool &ConstantPool);
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
@@ -392,14 +394,10 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
YamlMFI.HasTailCall = MFI.hasTailCall();
YamlMFI.IsCalleeSavedInfoValid = MFI.isCalleeSavedInfoValid();
YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
- if (MFI.getSavePoint()) {
- raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
- StrOS << printMBBReference(*MFI.getSavePoint());
- }
- if (MFI.getRestorePoint()) {
- raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
- StrOS << printMBBReference(*MFI.getRestorePoint());
- }
+ if (MFI.getSavePoint())
+ convert(MST, YamlMFI.SavePoints, MFI.getSavePoint());
+ if (MFI.getRestorePoint())
+ convert(MST, YamlMFI.RestorePoints, MFI.getRestorePoint());
}
void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
@@ -618,6 +616,18 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
}
}
+void MIRPrinter::convert(ModuleSlotTracker &MST,
+ yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SRP) {
+ std::string Str;
+ yaml::SRPEntry Entry;
+ raw_string_ostream StrOS(Str);
+ StrOS << printMBBReference(*SRP);
+ Entry.Point = StrOS.str();
+ Str.clear();
+ YamlSRP.push_back(Entry);
+}
+
void MIRPrinter::convert(ModuleSlotTracker &MST,
yaml::MachineJumpTable &YamlJTI,
const MachineJumpTableInfo &JTI) {
diff --git a/llvm/lib/CodeGen/MachineDominators.cpp b/llvm/lib/CodeGen/MachineDominators.cpp
index a2cc8fdfa7c9f9..384f90c6da66c0 100644
--- a/llvm/lib/CodeGen/MachineDominators.cpp
+++ b/llvm/lib/CodeGen/MachineDominators.cpp
@@ -189,3 +189,19 @@ void MachineDominatorTree::applySplitCriticalEdges() const {
NewBBs.clear();
CriticalEdgesToSplit.clear();
}
+
+MachineBasicBlock *MachineDominatorTree::findNearestCommonDominator(
+ ArrayRef<MachineBasicBlock *> Blocks) const {
+ assert(!Blocks.empty());
+
+ MachineBasicBlock *NCD = Blocks.front();
+ for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ NCD = Base::findNearestCommonDominator(NCD, BB);
+
+ // Stop when the root is reached.
+ if (Base::isVirtualRoot(Base::getNode(NCD)))
+ return nullptr;
+ }
+
+ return NCD;
+}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index deb0b627225c64..0de1f1d821a6e2 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1607,6 +1607,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
int FrameIdx = MFI.CreateFixedSpillStackObject(Size, Offset);
assert(FrameIdx < 0);
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
continue;
}
}
@@ -1623,6 +1625,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
if ((unsigned)FrameIdx > MaxCSFrameIndex)
MaxCSFrameIndex = FrameIdx;
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
}
// Allocate a fixed object that covers the full push or libcall size.
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
index d52ef0f3da74c7..2e8f3c460b2fe7 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
@@ -86,8 +86,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
index ba621cf77f9aed..07e80538e793f5 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
@@ -59,8 +59,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 16
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, type: default, offset: -16, size: 16,
diff --git a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
index 16e2de751381ad..31589a86599ff3 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
@@ -157,8 +157,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/aarch64st1.mir b/llvm/test/CodeGen/AArch64/aarch64st1.mir
index 22a024d37bc64f..439db1e97aa794 100644
--- a/llvm/test/CodeGen/AArch64/aarch64st1.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64st1.mir
@@ -58,8 +58,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
index 31fa3832367bec..6851fdba1239a4 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
@@ -80,8 +80,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 30000
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: p, type: default, offset: -30016, size: 30000, alignment: 1,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
index a24972d1388320..fe5c90a5e6dc54 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
@@ -47,8 +47,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup.mir b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
index f522df6bb3fa06..dd75cec7f6e0be 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
@@ -65,8 +65,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -248,8 +248,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -403,8 +403,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
index 1c4447bffd8729..85f8abcbf7fe60 100644
--- a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
+++ b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
@@ -6,17 +6,23 @@
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
; CHECK: name: compiler_pop_stack
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: compiler_pop_stack_no_memoperands
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: f
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.2'
- ; CHECK-NEXT: restorePoint: '%bb.4'
- ; CHECK-NEXT: stack:
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.2'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.4'
+ ; CHECK: stack:
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"
diff --git a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
index a7f67f8b682c3c..6324db0cb2c0ff 100644
--- a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
+++ b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
@@ -105,8 +105,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
index f9878adfe5e448..3c98a1a128413e 100644
--- a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
+++ b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
@@ -75,8 +75,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: true
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
entry_values: []
diff --git a/llvm/test/CodeGen/AArch64/irg-nomem.mir b/llvm/test/CodeGen/AArch64/irg-nomem.mir
index 3b000fafbed46f..78438151405e66 100644
--- a/llvm/test/CodeGen/AArch64/irg-nomem.mir
+++ b/llvm/test/CodeGen/AArch64/irg-nomem.mir
@@ -47,8 +47,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
index a2532a854923f5..81cf5953895cab 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
+++ b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
@@ -92,8 +92,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
index f1f9e5fbc9b087..b431de2d9b35b3 100644
--- a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
+++ b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
@@ -103,8 +103,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -216,8 +216,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -327,8 +327,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
diff --git a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
index 612453ab53f438..4be16228814a3b 100644
--- a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
+++ b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
@@ -120,8 +120,10 @@ frameInfo:
adjustsStack: true
hasC...
[truncated]
|
@llvm/pr-subscribers-backend-powerpc Author: Elizaveta Noskova (enoskova-sc) ChangesCurrently mir supports only one save and one restore point specification:
This patch provide possibility to have multiple save and multiple restore points in mir:
Shrink-Wrap points split Part 3. Part 1: #117862 Patch is 276.31 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/119357.diff 340 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/MIRYamlMapping.h b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
index 09a6ca936fe1f4..be8a8e593ef922 100644
--- a/llvm/include/llvm/CodeGen/MIRYamlMapping.h
+++ b/llvm/include/llvm/CodeGen/MIRYamlMapping.h
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
namespace llvm {
namespace yaml {
+struct SRPEntry {
+ StringValue Point;
+
+ bool operator==(const SRPEntry &Other) const { return Point == Other.Point; }
+};
+
+using SaveRestorePoints = std::vector<SRPEntry>;
+
+template <> struct MappingTraits<SRPEntry> {
+ static void mapping(IO &YamlIO, SRPEntry &Entry) {
+ YamlIO.mapRequired("point", Entry.Point);
+ }
+};
+
template <> struct MappingTraits<MachineJumpTable> {
static void mapping(IO &YamlIO, MachineJumpTable &JT) {
YamlIO.mapRequired("kind", JT.Kind);
@@ -618,6 +632,14 @@ template <> struct MappingTraits<MachineJumpTable> {
}
};
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SRPEntry)
+
+namespace llvm {
+namespace yaml {
+
/// Serializable representation of MachineFrameInfo.
///
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
@@ -645,8 +667,8 @@ struct MachineFrameInfo {
bool HasTailCall = false;
bool IsCalleeSavedInfoValid = false;
unsigned LocalFrameSize = 0;
- StringValue SavePoint;
- StringValue RestorePoint;
+ SaveRestorePoints SavePoints;
+ SaveRestorePoints RestorePoints;
bool operator==(const MachineFrameInfo &Other) const {
return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
@@ -667,7 +689,8 @@ struct MachineFrameInfo {
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
HasTailCall == Other.HasTailCall &&
LocalFrameSize == Other.LocalFrameSize &&
- SavePoint == Other.SavePoint && RestorePoint == Other.RestorePoint &&
+ SavePoints == Other.SavePoints &&
+ RestorePoints == Other.RestorePoints &&
IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
}
};
@@ -699,10 +722,12 @@ template <> struct MappingTraits<MachineFrameInfo> {
YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
false);
YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
- YamlIO.mapOptional("savePoint", MFI.SavePoint,
- StringValue()); // Don't print it out when it's empty.
- YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
- StringValue()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "savePoints", MFI.SavePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
+ YamlIO.mapOptional(
+ "restorePoints", MFI.RestorePoints,
+ SaveRestorePoints()); // Don't print it out when it's empty.
}
};
diff --git a/llvm/include/llvm/CodeGen/MachineDominators.h b/llvm/include/llvm/CodeGen/MachineDominators.h
index 74cf94398736dd..88800d91ef51a9 100644
--- a/llvm/include/llvm/CodeGen/MachineDominators.h
+++ b/llvm/include/llvm/CodeGen/MachineDominators.h
@@ -185,6 +185,11 @@ class MachineDominatorTree : public DomTreeBase<MachineBasicBlock> {
return Base::findNearestCommonDominator(A, B);
}
+ /// Returns the nearest common dominator of the given blocks.
+ /// If that tree node is a virtual root, a nullptr will be returned.
+ MachineBasicBlock *
+ findNearestCommonDominator(ArrayRef<MachineBasicBlock *> Blocks) const;
+
MachineDomTreeNode *operator[](MachineBasicBlock *BB) const {
applySplitCriticalEdges();
return Base::getNode(BB);
diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
index e2543f883f91ce..f7c1e162d2a96e 100644
--- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
+++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp
@@ -124,6 +124,10 @@ class MIRParserImpl {
bool initializeFrameInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
+ bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS,
+ const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints);
+
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS,
const yaml::MachineFunction &YamlMF);
@@ -832,18 +836,9 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
MFI.setHasTailCall(YamlMFI.HasTailCall);
MFI.setCalleeSavedInfoValid(YamlMFI.IsCalleeSavedInfoValid);
MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
- if (!YamlMFI.SavePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
- return true;
- MFI.setSavePoint(MBB);
- }
- if (!YamlMFI.RestorePoint.Value.empty()) {
- MachineBasicBlock *MBB = nullptr;
- if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
- return true;
- MFI.setRestorePoint(MBB);
- }
+ initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, true /*IsSavePoints*/);
+ initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints,
+ false /*IsSavePoints*/);
std::vector<CalleeSavedInfo> CSIInfo;
// Initialize the fixed frame objects.
@@ -1058,8 +1053,28 @@ bool MIRParserImpl::initializeConstantPool(PerFunctionMIParsingState &PFS,
return false;
}
-bool MIRParserImpl::initializeJumpTableInfo(PerFunctionMIParsingState &PFS,
- const yaml::MachineJumpTable &YamlJTI) {
+bool MIRParserImpl::initializeSaveRestorePoints(
+ PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRP,
+ bool IsSavePoints) {
+ MachineFunction &MF = PFS.MF;
+ MachineFrameInfo &MFI = MF.getFrameInfo();
+
+ if (!YamlSRP.empty()) {
+ const auto &Entry = YamlSRP.front();
+ const auto &MBBSource = Entry.Point;
+ MachineBasicBlock *MBB = nullptr;
+ if (parseMBBReference(PFS, MBB, MBBSource.Value))
+ return true;
+ if (IsSavePoints)
+ MFI.setSavePoint(MBB);
+ else
+ MFI.setRestorePoint(MBB);
+ }
+ return false;
+}
+
+bool MIRParserImpl::initializeJumpTableInfo(
+ PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI) {
MachineJumpTableInfo *JTI = PFS.MF.getOrCreateJumpTableInfo(YamlJTI.Kind);
for (const auto &Entry : YamlJTI.Entries) {
std::vector<MachineBasicBlock *> Blocks;
diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp
index c8f6341c1224d2..2d0728a6452808 100644
--- a/llvm/lib/CodeGen/MIRPrinter.cpp
+++ b/llvm/lib/CodeGen/MIRPrinter.cpp
@@ -118,6 +118,8 @@ class MIRPrinter {
const TargetRegisterInfo *TRI);
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
const MachineFrameInfo &MFI);
+ void convert(ModuleSlotTracker &MST, yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SaveRestorePoint);
void convert(yaml::MachineFunction &MF,
const MachineConstantPool &ConstantPool);
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
@@ -392,14 +394,10 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
YamlMFI.HasTailCall = MFI.hasTailCall();
YamlMFI.IsCalleeSavedInfoValid = MFI.isCalleeSavedInfoValid();
YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
- if (MFI.getSavePoint()) {
- raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
- StrOS << printMBBReference(*MFI.getSavePoint());
- }
- if (MFI.getRestorePoint()) {
- raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
- StrOS << printMBBReference(*MFI.getRestorePoint());
- }
+ if (MFI.getSavePoint())
+ convert(MST, YamlMFI.SavePoints, MFI.getSavePoint());
+ if (MFI.getRestorePoint())
+ convert(MST, YamlMFI.RestorePoints, MFI.getRestorePoint());
}
void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
@@ -618,6 +616,18 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
}
}
+void MIRPrinter::convert(ModuleSlotTracker &MST,
+ yaml::SaveRestorePoints &YamlSRP,
+ MachineBasicBlock *SRP) {
+ std::string Str;
+ yaml::SRPEntry Entry;
+ raw_string_ostream StrOS(Str);
+ StrOS << printMBBReference(*SRP);
+ Entry.Point = StrOS.str();
+ Str.clear();
+ YamlSRP.push_back(Entry);
+}
+
void MIRPrinter::convert(ModuleSlotTracker &MST,
yaml::MachineJumpTable &YamlJTI,
const MachineJumpTableInfo &JTI) {
diff --git a/llvm/lib/CodeGen/MachineDominators.cpp b/llvm/lib/CodeGen/MachineDominators.cpp
index a2cc8fdfa7c9f9..384f90c6da66c0 100644
--- a/llvm/lib/CodeGen/MachineDominators.cpp
+++ b/llvm/lib/CodeGen/MachineDominators.cpp
@@ -189,3 +189,19 @@ void MachineDominatorTree::applySplitCriticalEdges() const {
NewBBs.clear();
CriticalEdgesToSplit.clear();
}
+
+MachineBasicBlock *MachineDominatorTree::findNearestCommonDominator(
+ ArrayRef<MachineBasicBlock *> Blocks) const {
+ assert(!Blocks.empty());
+
+ MachineBasicBlock *NCD = Blocks.front();
+ for (MachineBasicBlock *BB : Blocks.drop_front()) {
+ NCD = Base::findNearestCommonDominator(NCD, BB);
+
+ // Stop when the root is reached.
+ if (Base::isVirtualRoot(Base::getNode(NCD)))
+ return nullptr;
+ }
+
+ return NCD;
+}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index deb0b627225c64..0de1f1d821a6e2 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -1607,6 +1607,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
int FrameIdx = MFI.CreateFixedSpillStackObject(Size, Offset);
assert(FrameIdx < 0);
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
continue;
}
}
@@ -1623,6 +1625,8 @@ bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
if ((unsigned)FrameIdx > MaxCSFrameIndex)
MaxCSFrameIndex = FrameIdx;
CS.setFrameIdx(FrameIdx);
+ if (RISCVRegisterInfo::isRVVRegClass(RC))
+ MFI.setStackID(FrameIdx, TargetStackID::ScalableVector);
}
// Allocate a fixed object that covers the full push or libcall size.
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
index d52ef0f3da74c7..2e8f3c460b2fe7 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir
@@ -86,8 +86,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
index ba621cf77f9aed..07e80538e793f5 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir
@@ -59,8 +59,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 16
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, type: default, offset: -16, size: 16,
diff --git a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
index 16e2de751381ad..31589a86599ff3 100644
--- a/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir
@@ -157,8 +157,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/aarch64st1.mir b/llvm/test/CodeGen/AArch64/aarch64st1.mir
index 22a024d37bc64f..439db1e97aa794 100644
--- a/llvm/test/CodeGen/AArch64/aarch64st1.mir
+++ b/llvm/test/CodeGen/AArch64/aarch64st1.mir
@@ -58,8 +58,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
index 31fa3832367bec..6851fdba1239a4 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir
@@ -80,8 +80,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 30000
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: p, type: default, offset: -30016, size: 30000, alignment: 1,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
index a24972d1388320..fe5c90a5e6dc54 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir
@@ -47,8 +47,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/cfi-fixup.mir b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
index f522df6bb3fa06..dd75cec7f6e0be 100644
--- a/llvm/test/CodeGen/AArch64/cfi-fixup.mir
+++ b/llvm/test/CodeGen/AArch64/cfi-fixup.mir
@@ -65,8 +65,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -248,8 +248,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -403,8 +403,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
diff --git a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
index 1c4447bffd8729..85f8abcbf7fe60 100644
--- a/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
+++ b/llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir
@@ -6,17 +6,23 @@
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
; CHECK: name: compiler_pop_stack
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: compiler_pop_stack_no_memoperands
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.1'
- ; CHECK: restorePoint: '%bb.7'
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.1'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.7'
; CHECK: name: f
; CHECK: frameInfo:
- ; CHECK: savePoint: '%bb.2'
- ; CHECK-NEXT: restorePoint: '%bb.4'
- ; CHECK-NEXT: stack:
+ ; CHECK: savePoints:
+ ; CHECK-NEXT: - point: '%bb.2'
+ ; CHECK: restorePoints:
+ ; CHECK-NEXT: - point: '%bb.4'
+ ; CHECK: stack:
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64"
diff --git a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
index a7f67f8b682c3c..6324db0cb2c0ff 100644
--- a/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
+++ b/llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir
@@ -105,8 +105,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
index f9878adfe5e448..3c98a1a128413e 100644
--- a/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
+++ b/llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir
@@ -75,8 +75,8 @@ frameInfo:
hasMustTailInVarArgFunc: false
hasTailCall: true
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
entry_values: []
diff --git a/llvm/test/CodeGen/AArch64/irg-nomem.mir b/llvm/test/CodeGen/AArch64/irg-nomem.mir
index 3b000fafbed46f..78438151405e66 100644
--- a/llvm/test/CodeGen/AArch64/irg-nomem.mir
+++ b/llvm/test/CodeGen/AArch64/irg-nomem.mir
@@ -47,8 +47,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack: []
callSites: []
diff --git a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
index a2532a854923f5..81cf5953895cab 100644
--- a/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
+++ b/llvm/test/CodeGen/AArch64/jump-table-duplicate.mir
@@ -92,8 +92,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 0
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,
diff --git a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
index f1f9e5fbc9b087..b431de2d9b35b3 100644
--- a/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
+++ b/llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir
@@ -103,8 +103,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -216,8 +216,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -327,8 +327,8 @@ frameInfo:
hasVAStart: false
hasMustTailInVarArgFunc: false
localFrameSize: 480
- savePoint: ''
- restorePoint: ''
+ savePoints: []
+ restorePoints: []
fixedStack: []
stack:
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
diff --git a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
index 612453ab53f438..4be16228814a3b 100644
--- a/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
+++ b/llvm/test/CodeGen/AArch64/live-debugvalues-sve.mir
@@ -120,8 +120,10 @@ frameInfo:
adjustsStack: true
hasC...
[truncated]
|
@arsenm, could you take a look, please. |
@@ -86,8 +86,8 @@ frameInfo: | |||
hasMustTailInVarArgFunc: false | |||
hasTailCall: false | |||
localFrameSize: 0 | |||
savePoint: '' | |||
restorePoint: '' | |||
savePoints: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will cut out a huge amount of spurious diff if you teach the parser to support both the singular and plural forms here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аddressed. Now MIR can be consumed both in singular:
savePoint: '%bb.1'
and plural:
savePoint:
- point: '%bb.1'
formats.
But printed in only plural format.
llvm/lib/CodeGen/MIRPrinter.cpp
Outdated
MachineBasicBlock *SRP) { | ||
std::string Str; | ||
yaml::SRPEntry Entry; | ||
raw_string_ostream StrOS(Str); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raw_svector_ostream + SmallVector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
llvm/lib/CodeGen/MIRPrinter.cpp
Outdated
raw_string_ostream StrOS(Str); | ||
StrOS << printMBBReference(*SRP); | ||
Entry.Point = StrOS.str(); | ||
Str.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry) | |||
namespace llvm { | |||
namespace yaml { | |||
|
|||
struct SRPEntry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename to SaveRestorePointEntry
? I don't think SRP is a common acronym. Also please add a docstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
llvm/lib/CodeGen/MIRPrinter.cpp
Outdated
raw_string_ostream StrOS(YamlMFI.RestorePoint.Value); | ||
StrOS << printMBBReference(*MFI.getRestorePoint()); | ||
} | ||
if (MFI.getSavePoint()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have singular getSavePoint, plural YamlMFI.SavePoints, and singular getSavePoint again. It is a little weird that we're mixing singular and plural.
This makes me think that we should get rid of SavePoint and RestorePoint and replace it entirely with the plural SavePoints and RestorePoints. By this I mean SavePoint
and RestorePoint
should be replaced entirely in MIR with SavePoints
and RestorePoints
. There plural version can do everything the singular version can and more.
This could be done in a follow up patch if others agree this would be a good direction to move in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it it the follow up patch.
Shrink-Wrap points split Part 2. RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581 Part 1: #117862 Part 3: #119357 Part 4: #119358 Part 5: #119359
…355) Shrink-Wrap points split Part 2. RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581 Part 1: llvm/llvm-project#117862 Part 3: llvm/llvm-project#119357 Part 4: llvm/llvm-project#119358 Part 5: llvm/llvm-project#119359
I think this patch is due for a rebase :) |
Reverse ping! |
@michaelmaitland, I was on long vacations. This week I plan to return to work on this MR:) |
Lovely, I hope you had a wonderful vacation! Excited to give review and drive this forward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments inline. With these addressed, I plan to approve as this has been on review for a long time, and we really need to get this moving.
/// Not null, if shrink-wrapping found a better place for the epilogue. | ||
MachineBasicBlock *Restore = nullptr; | ||
/// Not empty, if shrink-wrapping found a better place for the prologue. | ||
std::vector<MachineBasicBlock *> SavePoints; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not SmallVector? This seems like a classic use case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
const std::vector<MachineBasicBlock *> &getSavePoints() const { | ||
return SavePoints; | ||
} | ||
void setSavePoints(std::vector<MachineBasicBlock *> NewSavePoints) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use an ArrayRef instead, construct the SmallVector from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addresed
RestorePoints = std::move(NewRestorePoints); | ||
} | ||
|
||
void clearSavePoints() { SavePoints.clear(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need these, you can use setSavePoints({});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
// Return true if basic block was incorrectly specified in MIR | ||
bool MIRParserImpl::initializeSaveRestorePoints( | ||
PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRPoints, | ||
bool IsSavePoints) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust the interface to return a SmallVector by reference-param, and move the calls on MFI to the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
assert(MFI.getRestorePoint() && "Both restore and save must be set"); | ||
MachineBasicBlock *RestoreBlock = MFI.getRestorePoint(); | ||
if (!MFI.getSavePoints().empty()) { | ||
assert(MFI.getSavePoints().size() < 2 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
MachineBasicBlock *Save = MFI.getSavePoint(); | ||
|
||
assert(MFI.getSavePoints().size() < 2 && | ||
"MFI can't contain multiple save points!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace: "Multiple save points not yet supported"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
@@ -569,7 +579,10 @@ static void updateLiveness(MachineFunction &MF) { | |||
} | |||
Visited.insert(Save); | |||
|
|||
MachineBasicBlock *Restore = MFI.getRestorePoint(); | |||
assert(MFI.getRestorePoints().size() < 2 && | |||
"MFI can't contain multiple restore points!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
MachineBasicBlock *RestoreBlock = MFI.getRestorePoint(); | ||
if (!MFI.getSavePoints().empty()) { | ||
assert(MFI.getSavePoints().size() < 2 && | ||
"MFI can't contain multiple save points!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same basic pattern to comments as above...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
DstMFI.setRestorePoint(Src2DstMBB.find(RestorePt)->second); | ||
assert(SrcMFI.getSavePoints().size() < 2 && | ||
"MFI can't contain multiple save points!"); | ||
if (!SrcMFI.getSavePoints().empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code isn't correct or stylistically a good idea. Handle the general case of an array of save/restore points, and the incorrect bit (incorrect handling of empty source) falls out for free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed
using SaveRestorePoints = | ||
std::variant<std::vector<SaveRestorePointEntry>, StringValue>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know I suggested the variant, but looking at the code, the complexity added seems like a bad tradeoff.
I'd be tempted to do a small change which "manually" parses and prints a single entry array, and updates all the tests to the new format. If you did that, you could rebase this one on top and add the non-single entry general case.
I'll note that I'm explicitly okay with leaving this as is. We can land this patch, then remove the complexity and do the test change in a follow up. (Note to other reviews, I'm committing to write that patch if needed.)
@preames, in this patch I suggest to support two formats of save points in MFI and reduce complexity (change tests) in the follow up patch. |
@enoskova-sc small review process request. Each time you add "addressed" to a conversation, that triggers a separate email. It's really hard to find the meaningful updates between all the spam. You can either "mark resolved" if you're really really sure the thread is resolved (i.e. stylistic issues), or just put a summary comment on the review (i.e. one email, not many) Real review to follow in a bit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
For context of other reviewers....
This patch is not perfect (see below), but it's a reasonable step and has been stuck in review for an extremely long time. I am personally committing to following up on a few of the nits so that this can make forward progress.
A couple points for the record:
- This currently only models the case where all CSRs are spill/filled at the same set of points. This was a deliberate simplification for this patch, and will likely be revisited in future patches.
- This currently parses both the old MIR syntax and the new array syntax. This was triggered by an old review comment by me, and I think everyone agrees this was a bad idea in terms of net complexity. Once this lands, I'll post a patch which removes the variant bits, and updates the existing MIR tests in one go.
Once this goes in, we can move forward with reviewing the actual changes to shrink wrapping.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/163/builds/24513 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/11245 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/23387 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/23239 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/185/builds/23243 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/25057 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/32589 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/117/builds/12437 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/8/builds/19462 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/33/builds/21968 Here is the relevant piece of the build log for the reference
|
Hi, is someone working on a fix? |
@jplehr, yes |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/19529 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/18318 Here is the relevant piece of the build log for the reference
|
I've pushed a build fix in d8ce19a. With this check-llvm passes. |
Fix for failures: #153198 |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/56/builds/33073 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/24236 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/35301 Here is the relevant piece of the build log for the reference
|
std::variant cleanup posted: #153226 @enoskova-sc By some chance, are you not a member of the llvm-project github organization? I was unable to add you as a reviewer for the change. If not, can you fix that please? |
Currently mir supports only one save and one restore point specification:
This patch provide possibility to have multiple save and multiple restore points in mir:
Shrink-Wrap points split Part 3.
RFC: https://discourse.llvm.org/t/shrink-wrap-save-restore-points-splitting/83581
Part 1: #117862
Part 2: #119355
Part 4: #119358
Part 5: #119359