Getting load/store byte size

I’m instrumenting memory loads and stores in a LLVM module pass. In this work, I need to do
(1) Getting memory address of the operand, (Looks I’ve done correctly)
(2) Getting memory read/write size, (Question)
(3) Location id of the load/store instruction. (Easy, I’ve done)

For example, say that I’m reading a local variable ‘a’:

%1 = load i32* %a, align 4

I need to know the address of the variable ‘a’ and the size. Of course, memory loads/stores could be from general GEP or global variables.

Getting the address was easily doable by using “PtrToIntInst(load_inst->getPointerOperand(), …)”. However, getting load/store size wasn’t that straight forward. In this example, it should be four bytes. I tried to get the Type* from the getPointerOperand() and tried to retrieve the size of the type, but failed.

Question:
[1] How can I retrieve the read/write size of load/store instruction?

I have another question. If I can get the size, then what would be the maximum size? Obviously, 1 ~ 8 bytes for built-in types, but wondering even the larger size could be obtained. I suspect a vector load instruction could load up to 32 bytes (= 256 bits, in case of x86 AVX).

Question:
[2] What would be the maximum size of load/store operand?

Thank you!

Hi nullnull,

I'm instrumenting memory loads and stores in a LLVM module pass. In this work, I
need to do
(1) Getting memory address of the operand, (Looks I've done correctly)
(2) Getting memory read/write size, (Question)

use getTypeStoreSize defined in TargetData.

Ciao, Duncan.

You can take a look at
http://code.google.com/p/data-race-test/source/browse/trunk/llvm/opt/ThreadSanitizer/ThreadSanitizer.cpp,
where I do practically the same. The routine that obtains the size is
getMopPtrSize(), getting the addresses is done in instrumentMop().

Alex