Skip to content
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

Function to estimate stack size #1116

Closed
wants to merge 7 commits into from

Conversation

newling
Copy link
Contributor

@newling newling commented Feb 19, 2025

This is a simpler version of #1104

In this PR, the stack size is not set based on the assembly analysis, this PR just adds a check that the assigned stack is sufficient.

I have checked this locally by changing the stack size here and it works fine.

This should help avoid the bad situations like Xilinx/llvm-aie#342

Next steps (I'd like to do these in a separate PR):

  • a flag to manually set the stack size at compile time
  • ability to set the stack's base address after assembly is generated

@newling newling marked this pull request as draft February 19, 2025 18:01
@newling newling marked this pull request as ready for review February 19, 2025 20:13
Copy link
Collaborator

@jtuyls jtuyls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice! I just have some nits, so approving as well.


// Derived from lines containing substrings like 'paddb [sp], #224;'
// There is one vector of ints per function.
SmallVector<SmallVector<int>> bumps;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but you could use uint32_t as bumps would always be positive right? Same for a couple of other int variables in this function.

llvm::errs() << "Failed to get stack size from assembly file\n";
return failure();
}
auto upperBounds = std::move(maybeUpperBounds.value());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto upperBounds = std::move(maybeUpperBounds.value());
llvm::DenseMap<std::pair<int, int>, int> upperBounds = std::move(maybeUpperBounds.value());

<< ") is not found in the assembly file. ";
return failure();
}
auto stackSize = coreOp.getStackSize();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto stackSize = coreOp.getStackSize();
int32_t stackSize = coreOp.getStackSize();

mlir::FailureOr<llvm::DenseMap<std::pair<int, int>, int>> ubs =
detail::getUpperBoundStackSizes(asmStr);
EXPECT_TRUE(succeeded(ubs));
// auto upperBounds = maybeUpperBounds.value();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// auto upperBounds = maybeUpperBounds.value();

mlir::FailureOr<llvm::DenseMap<std::pair<int, int>, int>> ubs =
detail::getUpperBoundStackSizes(asmStr);
EXPECT_TRUE(succeeded(ubs));
// auto upperBounds = maybeUpperBounds.value();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// auto upperBounds = maybeUpperBounds.value();

mlir::FailureOr<llvm::DenseMap<std::pair<int, int>, int>> maybeUpperBounds =
detail::getUpperBoundStackSizes(asmStr);
EXPECT_TRUE(succeeded(maybeUpperBounds));
auto upperBounds = maybeUpperBounds.value();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto upperBounds = maybeUpperBounds.value();
llvm::DenseMap<std::pair<int, int>, int> upperBounds = maybeUpperBounds.value();

@newling
Copy link
Contributor Author

newling commented Feb 21, 2025

Closing in favor of #1121

@newling newling closed this Feb 21, 2025
newling added a commit that referenced this pull request Feb 21, 2025
This will replace #1116 --
instead of string matching the assembly file, it uses llvm's
`llvm-readelf` after adding `--stack-size-section` to the llc call.

Please read the paper trail of PRs I've left here for more information.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants