Skip to content

codegen: keep a symbolically-sized register array on the stack - #2504

Draft
ThrudPrimrose wants to merge 6 commits into
mainfrom
vla-stack-arrays
Draft

codegen: keep a symbolically-sized register array on the stack#2504
ThrudPrimrose wants to merge 6 commits into
mainfrom
vla-stack-arrays

Conversation

@ThrudPrimrose

@ThrudPrimrose ThrudPrimrose commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

A StorageType.Register array whose size is symbolic was allocated on the heap with a warning, though GCC, Clang and NVHPC all accept variable-length arrays. It is now declared in place, with allocation and deallocation sharing one predicate so they cannot disagree.

I think this is important because this means CloudSC and Velocity Tendencies code gets 2x faster!

double tmp[N];   // was: double *tmp; tmp = new double[N];

ThrudPrimrose and others added 6 commits August 17, 2026 19:47
A StorageType.Register array whose size is symbolic was allocated on the heap
with a warning. GCC, Clang and NVHPC all accept variable-length arrays, so it is
now declared in place; allocation and deallocation share one predicate so they
cannot disagree, and a VLA takes a memset rather than a brace initializer.
A VLA dies with its block, but Global, Persistent and External arrays are declared
outside it -- codegen emits a program-level pointer for those, which the local
declaration shadowed while leaving the pointer null.
… emitter

MarkVLAArrays sets Data.vla on the symbolically-sized register arrays whose lifetime ends with
the block they are declared in and whose size is already defined there; code generation reads
the flag and nothing else. A size that only an interstate edge assigns splits the declaration
from the allocation, and a VLA declared under that split shadows the SDFG-scope pointer, which
stays null - the segfaulting case the earlier in-emitter predicate missed.
…declaration

A size that only an interstate edge assigns makes framecode declare the pointer at SDFG scope and
allocate in a later block; a VLA there shadows that pointer, which stays null - four tests
segfaulted on it. declared_arrays already records that, so allocation and deallocation both ask
the same predicate rather than a descriptor flag no pass can set correctly.
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.

1 participant