How could I get memory address for each basic block?

On the pervious mail, I am trying to add label for each basic basic because I think I could get address by using nm if nm can show the address of each label, but it seems not . so do you guys have some idea how to get address for each basic block? Thanks.

LLVM does not have a notion of C-style 'labels' that you can address and
use as parameters. LLVM labels are simply NAMES of basic blocks, and
they are printed out as `labels'.

You can 'set' a name for a BasicBlock, but that's not what you are
looking for, please see my other email for more details.

Qiuyu,

The dynamic optimization project (an internal research project in our group) uses some way to map LLVM basic blocks to native code addresses. If this is what you want, perhaps you can ask Brian Gaeke (gaeke@uiuc.edu) to give you some information about how that is done.

--Vikram
http://www.cs.uiuc.edu/~vadve
http://llvm.cs.uiuc.edu/

I'd be interested to hear how that's being done - if Brian would reply to the list about it, I'd appreciate it.

-mike

The dynamic optimization project (an internal research project in our
group) uses some way to map LLVM basic blocks to native code addresses.
If this is what you want, perhaps you can ask Brian Gaeke
(gaeke@uiuc.edu) to give you some information about how that is done.

I'm still quite curious why you want to do this. If you want to get the
machine code address of particular places in the code, you could always
insert an intrinsic function that the code generator handles specially.

Why do you think you need the address of a basic block? What are you
trying to do?

-Chris

Note: The way we currently map LLVM basic blocks to native code addresses
only works with the SparcV9 target. It's turned on by passing the
"-march=sparcv9 -enable-maps" options to llc.

In the SparcV9 target, we rely on having a one-to-one correspondence
between MachineBasicBlocks and LLVM BasicBlocks. The MappingInfo.cpp pass
(in lib/Target/SparcV9) stores a table of tuples of the form

  <block number, starting machine instr, number of machine instrs>

in a global variable called FunctionBB, such that there is one tuple for
each basic block in each function.

Since each SparcV9 machine instruction is 4 bytes, the "starting machine
instr" and "number of machine instrs" can be trivially translated into
addresses, given that you know the address of the function, and assuming
that the "block number" uniquely identifies and orders both LLVM BasicBlocks
and SparcV9 MachineBasicBlocks within a function.

Now, Qiuyu can probably accomplish his stated task more simply: just
make the target-specific AsmPrinter pass output a global symbol for each
basic block. In SparcV9AsmPrinter.cpp, for example, you'd add it to
SparcV9AsmPrinter::emitBasicBlock(). Then you could get the addresses
using nm(1) or dlsym(3).

But the question remains: why get the address of each basic block?
Is there some problem we're not solving at a higher level?

-Brian