-
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
Merged
asi-sc
merged 3 commits into
llvm:main
from
enoskova-sc:users/enoskova-sc/multiple-save-restore-points-mir
Aug 12, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -634,6 +634,55 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CalledGlobal) | |
| namespace llvm { | ||
| namespace yaml { | ||
|
|
||
| // Struct representing one save/restore point in the 'savePoint'/'restorePoint' | ||
| // list | ||
| struct SaveRestorePointEntry { | ||
| StringValue Point; | ||
|
|
||
| bool operator==(const SaveRestorePointEntry &Other) const { | ||
| return Point == Other.Point; | ||
| } | ||
| }; | ||
|
|
||
| using SaveRestorePoints = | ||
| std::variant<std::vector<SaveRestorePointEntry>, StringValue>; | ||
|
|
||
| template <> struct PolymorphicTraits<SaveRestorePoints> { | ||
|
|
||
| static NodeKind getKind(const SaveRestorePoints &SRPoints) { | ||
| if (std::holds_alternative<std::vector<SaveRestorePointEntry>>(SRPoints)) | ||
| return NodeKind::Sequence; | ||
| if (std::holds_alternative<StringValue>(SRPoints)) | ||
| return NodeKind::Scalar; | ||
| llvm_unreachable("Unsupported NodeKind of SaveRestorePoints"); | ||
| } | ||
|
|
||
| static SaveRestorePointEntry &getAsMap(SaveRestorePoints &SRPoints) { | ||
| llvm_unreachable("SaveRestorePoints can't be represented as Map"); | ||
| } | ||
|
|
||
| static std::vector<SaveRestorePointEntry> & | ||
| getAsSequence(SaveRestorePoints &SRPoints) { | ||
| if (!std::holds_alternative<std::vector<SaveRestorePointEntry>>(SRPoints)) | ||
| SRPoints = std::vector<SaveRestorePointEntry>(); | ||
|
|
||
| return std::get<std::vector<SaveRestorePointEntry>>(SRPoints); | ||
| } | ||
|
|
||
| static StringValue &getAsScalar(SaveRestorePoints &SRPoints) { | ||
| if (!std::holds_alternative<StringValue>(SRPoints)) | ||
| SRPoints = StringValue(); | ||
|
|
||
| return std::get<StringValue>(SRPoints); | ||
| } | ||
| }; | ||
|
|
||
| template <> struct MappingTraits<SaveRestorePointEntry> { | ||
| static void mapping(IO &YamlIO, SaveRestorePointEntry &Entry) { | ||
| YamlIO.mapRequired("point", Entry.Point); | ||
| } | ||
| }; | ||
|
|
||
| template <> struct MappingTraits<MachineJumpTable> { | ||
| static void mapping(IO &YamlIO, MachineJumpTable &JT) { | ||
| YamlIO.mapRequired("kind", JT.Kind); | ||
|
|
@@ -642,6 +691,14 @@ template <> struct MappingTraits<MachineJumpTable> { | |
| } | ||
| }; | ||
|
|
||
| } // namespace yaml | ||
| } // namespace llvm | ||
|
|
||
| LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SaveRestorePointEntry) | ||
|
|
||
| namespace llvm { | ||
| namespace yaml { | ||
|
|
||
| /// Serializable representation of MachineFrameInfo. | ||
| /// | ||
| /// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and | ||
|
|
@@ -669,8 +726,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 && | ||
|
|
@@ -691,7 +748,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; | ||
| } | ||
| }; | ||
|
|
@@ -723,10 +781,14 @@ 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( | ||
| "savePoint", MFI.SavePoints, | ||
| SaveRestorePoints( | ||
| StringValue())); // Don't print it out when it's empty. | ||
|
||
| YamlIO.mapOptional( | ||
| "restorePoint", MFI.RestorePoints, | ||
| SaveRestorePoints( | ||
| StringValue())); // Don't print it out when it's empty. | ||
| } | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't understand why this is a variant, and not just the vector of 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.
Several comments above (#119357 (comment)) @preames suggested to make support for multiple save/restore points backward compatible with single save/restore point approach.
It helped to "cut out a huge amount of spurious diff". So, StringValue in this variant needed for backward compatibility.
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.
We should make no effort to maintain MIR backwards compatibility. As a diff reduction strategy, this can be part 1. But we should absolutely rip out the old form
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.)