[LLVMdev] Several basic questions about Builder

Eli Friedman eli.friedman at gmail.com
Sun Jun 28 02:39:45 PDT 2009


On Sun, Jun 28, 2009 at 1:05 AM, Carter Cheng<carter_cheng at yahoo.com> wrote:
> 1) Using the Builder interface how does one create the equivalent of stack frames and access variables in the current stack frame or perhaps in the static enclosing scope (assuming functions can be nested)?

To create stack variables, you can use the alloca instruction; see
http://llvm.org/docs/tutorial/LangImpl7.html#memory .

LLVM doesn't directly support nested functions; you'll have to lower
them yourself.  For example, try something like the following in the
LLVM demo page (http://llvm.org/demo/index.cgi) with optimization off:
int main(int argc, char **argv) {
  void a(int x) { if (x == 10) return; a(x+1); argc += x; }
  a(0);
  return argc;
}

> 2) Is it possible to deallocate functions from a module and recycle the memory used without restarting the JIT? I am trying to build a server type application where objects/classes maybe be deallocated and thus the associated functions will no longer be used.

That should be possible; I'm not sure of the details, though.

> 3) How does one sequence instructions using Builder similar to a semi-colon in a language like C?

Instructions are ordered within a basic block, and they are guaranteed
to be executed in that order.  If you just build the instructions in
the same order that the statements occur in the code, it should work
without any special tweaking.

-Eli




More information about the llvm-dev mailing list