Local variables get assigned global addresses based upon call tree When working with certain low-powered / embedded CPUs that are bad at using the stack, I need to avoid putting local variables there, instead opting to make them static variables. But this can waste a lot of address spaces since not every local in every function needs their own unique address. Rather, by looking at the call tree, functions that do call each other can share memory space.

For example, given code such as this:

void A() {
    int x;
    // ...
    B();
    C();
    // ...
}

void B() {
    int y;
    // ...
}

void C() {
    int z;
    // ...
}


The variables y and z can be assigned the same address, while x should be unique so that calls to B() and C() don't clobber it.

Obviously this breaks recursion and multi-threading, but neither of those are a problem for the use cases I'm working in.

Is there a name for this algorithm? I'm assuming that it's well known, but it's very hard to search for information about this specific problem.
This sounds similar to register allocation.  Normally, register allocation is done at the scope of a single function, but it can also be done globally (interprocedurally).  If you ignore all recursive and mutually recursive calls, you might be able to apply standard algorithms for register allocation to your situation.