[PATCH] D107882: BPF: Enable frontend constant folding for VLA size

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 1 18:06:31 PDT 2021


yonghong-song added a comment.

I checked EmitAutoVarAlloca(). It emits the llvm.stacksave() due to

  // If the type is variably-modified, emit all the VLA sizes for it.
  if (Ty->isVariablyModifiedType())
    EmitVariablyModifiedType(Ty);

Here, in order not to generate llvm.stacksave(), we need to evaluate the array size expression for `Ty`.
But it is probably not a good idea to re-evaluate `Ty` during code generation phase. If we really want to evaluate, we should evaluate earlier during semantic analysis phase like this patch.

Another solution is to implement pruning llvm.stacksave/stackrestore in backend. Currently InstCombine phase tries to remove some adjacent stacksave() and stackrestore() instrinsics. We could try to enhance InstCombine to handle more complicated cases, or considering this may be just a BPF use case (which doesn't support dynamic memory allocation), we can implement a bpf backend IR phase to remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107882



More information about the cfe-commits mailing list