[PATCH] D135488: [codegen] Add a remarks based Stack Layout Analysis pass

Paul Kirth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 15:06:27 PST 2023


paulkirth added a comment.

In D135488#4048380 <https://reviews.llvm.org/D135488#4048380>, @nickdesaulniers wrote:

> It would be really nice if we could limit this to a specific function somehow.

I think you can do that, right ?
see: 
https://llvm.org/docs/Remarks.html#cmdoption-pass-remarks-filter
https://llvm.org/docs/Remarks.html#cmdoption-pass-remarks-filter

> Quick feedback from giving Diff 488727 a spin on the Linux kernel:
>
> via `ARCH=arm make LLVM=1 -j128 -s allyesconfig all` I found:
>
>     CC      drivers/net/ethernet/mellanox/mlx5/core/en_main.o
>   drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3597:12: error: stack frame size (1256) exceeds limit (1024) in 'mlx5e_setup_tc' [-Werror,-Wframe-larger-than]
>   static int mlx5e_setup_tc(struct net_device *dev, enum tc_setup_type type,
>              ^
>
> When I rebuild with:
>
>   ARCH=arm make LLVM=1 -j128 drivers/net/ethernet/mellanox/mlx5/core/en_main.o KCFLAGS=-Rpass-analysis=stack-frame-layout
>
> I get a printout of the stack usage of every function in this TU. That's 1929 lines of text output...I only care about `mlx5e_setup_tc`.  Is there a way to limit that?

see: https://llvm.org/docs/Remarks.html#cmdoption-pass-remarks-filter

If that doesn't sort you out, we can probably do //something// about this. In the worst case we'd need to make this a bigger pass, and also emit diagnostics for stack size, etc instead of in prologue/epilogue inserter. That was mentioned earlier, but I think that should be a separate change.

> Filtering through the logs though, I do see:
>
>   drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3599:1: remark: 
>   Function: mlx5e_setup_tc
>   ...
>   Offset: [SP-400], Type: Variable, Align: 8, Size: 352
>   Offset: [SP-752], Type: Variable, Align: 8, Size: 352
>   Offset: [SP-1088], Type: Variable, Align: 8, Size: 336
>
> which is good!  If I flip on debug info and rebuild, this looks like:
>
>   drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3599:1: remark: 
>   Function: mlx5e_setup_tc
>   ...
>   Offset: [SP-400], Type: Variable, Align: 8, Size: 352
>       old_params @ drivers/net/ethernet/mellanox/mlx5/core/en_main.c:2934
>       old_chs @ drivers/net/ethernet/mellanox/mlx5/core/en_main.c:2958
>       new_params @ drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3539
>   Offset: [SP-752], Type: Variable, Align: 8, Size: 352
>       new_chs @ drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3000
>   Offset: [SP-1088], Type: Variable, Align: 8, Size: 336
>       new_params @ drivers/net/ethernet/mellanox/mlx5/core/en_main.c:3424
>
> Which is pretty awesome!
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mellanox/mlx5/core/en_main.c#n3424 for the last one, which shows we should probably be heap allocating instances of `struct mlx5e_params` rather than stack allocating them!
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/net/ethernet/mellanox/mlx5/core/en_main.c#n3000 shows the same for `struct mlx5e_channels`. Cool stuff! Now we can finally debug `-Wframe-larger-than=`!!!

Glad this helps! If you think of more issues, let me know.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135488/new/

https://reviews.llvm.org/D135488



More information about the llvm-commits mailing list