Getting a named value in llvm-c

Hi all,

I am wondering if there is a way to get a value by name in the C
interface for the LLVM Jit?

There seems to be a way to name values consistently, but no way to
retrieve those LLVMValueRef's by name.

I see it is possible to get a struct by name and a type by name and a
function by name, and a few other esoteric things, but not a general
value.

The reason I am wanting this is that I am writing a language where
there is a separation between the back end and the code which
processes the AST. In particular, I do not have any LLVM values or
types in the AST nodes themselves, only strings naming those values
and types. When the back end processes the AST it looks up the
relevant types and values by string name.

The specific circumstance where this causes an issue is with
allocating local variables. The back end code needs to access such
variables at points different from where they were defined. At present
I have to store the relevant LLVMValueRef's in the AST or in some
other type information elsewhere in my implementation, rather than
store a string name and look them up as needed.

Bill.

Hi Bill,

I am wondering if there is a way to get a value by name in the C
interface for the LLVM Jit?

since a Value includes simple constants like 42 that have no name, this is
not possible in general. Moreover names are usually optional and have no
real meaning: they are just there to make the IR easier to read (an exception
being struct type names).

Perhaps you could maintain a map from name to Value* in your front-end?

Ciao, Duncan.

That's what I am doing of course, It;s just odd that I can get a
global by name but not a local.

Bill.

Hi Bill,

That's what I am doing of course, It;s just odd that I can get a
global by name but not a local.

actually it's not that odd, since globals variables can be accessed by name
from other compilation units, while local variables cannot.

Ciao, Duncan.

I understand the logic of that. Thanks.

I guess what I was imagining was a function:

LLVMValueRef LLVMGetValueByName(LLVMBuilderRef B, const char * Name);

That would be sufficient to completely separate the code I use to
handle the "back end", from the rest of my interpreter. A minor
elegance I can live without I guess.

Bill.