Check the location of the definition of a Value object

Hello,

How to check whether a value object is within a particular basic block or not.

I have the following LLVM bytecode:

Zheng Wang wrote:

Hello,

How to check whether a value object is within a particular basic block or not.
  
There is a much simpler way to do this. Assuming that Value * pb holds the pointer to the value of %2, you do the following:

1) Check to see if %2 is an instruction (use dyn_cast<Instruction>(pb) and see if the result is NULL). If it's not an instruction, then it's definitely not defined in the entry block.

2) Use the result of dyn_cast<Instruction>(pb) to get the basic block in which the instruction is defined.

So, you do

// Entry is a Basic Block pointer pointing to the function's entry block
if (Instruction * PBI = dyn_cast<Instruction>(pb)) {
    if (PBI->getParent() == Entry)
       // pb is an instruction defined in the entry basic block.

-- John T.

Cheers John!