Hi,
I was wondering how Mill with most of the function local data not on real stack, would approach implementing C alloca, or C99 VLA (Variable Length Arrays).
For example:
#include <stdlib.h>
struct S {
int a;
float b;
};
void enumerate(int* count, struct S* data1, struct S* data2);
int example(int k) {
int count = 0;
enumerate(&count, NULL, NULL);
struct S* data1 = alloca(count * sizeof(struct S));
struct S* data2 = alloca(count * sizeof(struct S));
enumerate(&count, data1, data2);
int ret = 0;
for (int i = 0; i < count; i++) {
ret += (data1[i].a + k) * (data2[i].a - k);
}
return ret;
}
I guess, it might depend on calling conventions, but I don't expect for every function to have real stack, as this could be slightly deterimental to performance. Or would having functions that use zero stack, be fine, and just not advance the in-memory stack?
Or some other tricks to do it? Maybe for small dynamic stack allocations a scratchpad can be used somehow dynamically?