getting identifier for alloca instruction and basic blocks

Hi Duncan,

Hi Marcelo,

How can I retrieve the identifier in a alloca instruction?

except for globals, identifier names in LLVM IR are only there to make the IR
easier to read: they are optional and can't be relied upon to exist, or to mean
anything or be "correct" if they exist. Use debug info to map things back to
variable names in the original code.

I understand that these identifiers are only there to make the IR
easier to read, but anyhow I want to retrieve them. Is there any way I
can do this through the api? Does the llvm-dis generate the names for
the identifiers or obtains this information from somewhere else?

The reason is that I want to create an Haskell model out of the llvm
ir code so for instance given:

data Identifier = Local String | Global String
data Label = Label String
data Value = IConstant Int | Ident Identifier
data Instruction = ICmp Identifier IPred Value Value
                        > Br Value Label Label

And the LLVM IR instructions
  %2 = icmp eq i32 %argc, 3
  br i1 %2, label %3, label %40

I'm extending the llvm c bindings and haskell bindings to generate:

[ICmp (Local "%2") IEq (Ident (Local "%argc")) (IConstant 3),
Br (Ident (Local "%2")) (Label "%3") (Label "%40")]

If getting those identifiers is not possible through the api, I
believe I have to add extra effort to generate nameless identifiers
and use equality of LLVM Values to see that first value of the branch
instruction is the equal to the result of the icmp instruction. I
would get the icmp instruction from the use_iterator.

Would that be the proper way of doing this?

Regards,
Marcelo

Hi Marcel,

How can I retrieve the identifier in a alloca instruction?

except for globals, identifier names in LLVM IR are only there to make the IR
easier to read: they are optional and can't be relied upon to exist, or to mean
anything or be "correct" if they exist. Use debug info to map things back to
variable names in the original code.

I understand that these identifiers are only there to make the IR
easier to read, but anyhow I want to retrieve them. Is there any way I
can do this through the api?

V->getName()

  Does the llvm-dis generate the names for

the identifiers or obtains this information from somewhere else?

See below.

The reason is that I want to create an Haskell model out of the llvm
ir code so for instance given:

data Identifier = Local String | Global String
data Label = Label String
data Value = IConstant Int | Ident Identifier
data Instruction = ICmp Identifier IPred Value Value
                         > Br Value Label Label

And the LLVM IR instructions
   %2 = icmp eq i32 %argc, 3
   br i1 %2, label %3, label %40

Here %2 is not a name, this is a nameless value. However it has to be labelled
somehow in the human readable IR, so that llvm-as can understand that the branch
is referring to the icmp instruction, so it numbers them like this.

I'm extending the llvm c bindings and haskell bindings to generate:

[ICmp (Local "%2") IEq (Ident (Local "%argc")) (IConstant 3),
  Br (Ident (Local "%2")) (Label "%3") (Label "%40")]

If getting those identifiers is not possible through the api,

They aren't identifiers in the API sense of a name, %1, %2 etc are created by
llvm-dis for the benefit of llvm-as. They aren't accessible through the API.
Notice that you can't modify them freely, eg if you swap %2 and %3 everywhere
llvm-as will reject the file. This is not the case when using names.

  I

believe I have to add extra effort to generate nameless identifiers
and use equality of LLVM Values to see that first value of the branch
instruction is the equal to the result of the icmp instruction. I
would get the icmp instruction from the use_iterator.

Would that be the proper way of doing this?

I didn't really understand what you are trying to do, but you can always name
everything using the instnamer pass.

Ciao, Duncan.