I have a LLVM instruction like the following
%0 = load i32** %pp, align 8
I have a LoadInst &inst handle to this instruction. In addition, i could access the pointer being loaded from using the inst.getPointerOperand…
However, is there a way to access the handle to the value being loaded? Essentially, i wanted to access the %0 in the statement listed.
The end goal is to do some amount of points-to analysis. I have this pointer %pp being loaded into %0 and later i have a store instruction storing %0 into some other pointer. If i cannot establish the %0 link here, i would not be able to establish points-to.
Any help in this regards would be appreciated. Thanks
The instruction is the result!
Thanks Sean. It clarified my query.
Do you have an answer to my other question (in a different mail-chain) listed below
Is there a simple way to check if a given instruction operand (represented by Value *) is a virtual register or otherwise? Context: I am creating a ModulePass for pointer Analysis.
Is there a simple way to check if a given instruction operand (represented
by Value *) is a virtual register or otherwise? Context: I am creating a
ModulePass for pointer Analysis.
Values exist before any distinction is made between virtual and
physical registers (they only get introduced after or, in rare cases
at lowering to MachineInstrs). Or did you mean some distinction other
than virtual/physical? What would you expect the Value to be if it's
not a virtual register?
Assume a store instruction. Store has 2 Operands. I can use the store->getOperand(0) and store->getOperand(1) methods to access these operands in form of Value *.
Very likely that the operands are stack variables or formal variables or global variables. It is also possible that these operands are LLVM virtual-registers. Is there a way to determine if a given operand is a virtual-register or memory-related-on.
I hope this clarifies my question.
You can use the LLVM custom RTTI implementation to distinguish between
different kinds of Value using dyn_cast<>, isa<>. See
As Tim said, Values exist before regalloc. When you see a reference
like %foo in the IR, it's a reference to the Value, not the actual
Thanks for the response.
Yes. I could use the LLVM custom RTTI implementation. However, i think there isnt a type called VirtualRegister. If it exists, i could do a dyn_cast<> to check if an operand (represented by Value *) is indeed virtual-register or not. I hope i explained the problem i am facing.
Yes. I could use the LLVM custom RTTI implementation. However, i think there
isnt a type called VirtualRegister. If it exists, i could do a dyn_cast<> to
check if an operand (represented by Value *) is indeed virtual-register or
not. I hope i explained the problem i am facing.
I think the question itself is problematic in LLVM terms. (Almost) all
Values are inevitably going to become virtual registers in the
backend, and after that may or may not be spilled to stack slots at
some points. Much of the time, even the other cases you explicitly
mentioned will be allocated to a virtual register too.
You're probably going to have to implement custom logic to spot just
what you consider not to be a virtual-register. Some possible
edge-cases you might want to think about are:
1. Is getelementptr(i8* @var, i32 %a) a virtual register or a global?
2. What about "%a = ptrtoint i8* @var to i64; %b = add i64 %a, 42; %c
= inttoptr i64 %b to i8*"?
3. And "%a = sub i64 ptrtoint(i8* @var1 to i64), ptrtoint(i8* @var2 to
i64); %b = inttoptr i64 %a to i8*"?
It might be time to rethink why you want to classify every Value into
virtual-register or not. As an outsider it sounds like you're trying
to pick the wrong way to divide instructions. Could you explain a bit
about what you intend to do with this partition once you have it? What
operations do you want to do that only work on virtual registers, or