How to recognize global & local variable?

Can you guys tell how to recognize local & global variables ? Is there any macro on Value* defined in LLVM?

Hi Soumya_Prasad_Ukil,

Can you guys tell how to recognize local & global variables ? Is there
any macro on Value* defined in LLVM?

Global variable: isa<GlobalVariable>(V)
Local variable: isa<AllocaInst>(V)

Ciao,

Duncan.

Yeah that’s true. But I want somewhat different. Through Instruction how do u know that? If an instruction like %a = alloca i32 is there, how to get the variable ‘a’ ? Then on that variable we can check as you have said Right? How to capture that variable ?

Yeah that's true. But I want somewhat different. Through Instruction how
do u know that? If an instruction like %a = alloca i32 is there, how to
get the variable 'a' ? Then on that variable we can check as you have
said Right? How to capture that variable ?

I didn't understand the question. There is no difference between "%a"
and the alloca instruction, "%a" is just a name given to the instruction
and exists only to make the IR more readable for humans. If you want to
use "%a" somewhere, just pass the alloca instruction.

Ciao,

Duncan.