[LLVMdev] another question

Bill? Wendling wendling at isanbard.org
Mon Sep 16 16:48:01 PDT 2002


Also sprach xli3 at uiuc.edu:
} In the section expaining "dyn_cast"
} There are following lines of code:
}  if (AllocationInst *AI = dyn_cast<AllocationInst>(Val)) {
}             ...
}           }
} I cannot understand how you take a operand, a value, and cast
} it into a Instruction. Can you explain it for me?
} 
} Another common example is:
} 
} // Loop over all of the phi nodes in a basic block
} BasicBlock::iterator BBI = BB->begin();
} for (; PHINode *PN = dyn_cast<PHINode>(&*BBI); ++BBI)
}       cerr << *PN;
} 
} In this case you cast &*BBI. It's not an operand. Can you
} explain to me a little about what you can cast and what
} cannot?
} 
} Besides, maybe this is a stupid question, but what do you mean
} by "&*BBI"?
} 
I may be incorrect, but here it goes anyway.

Operands in LLVM can point to the actual instruction that produces the
result that will be used for the instruction. So the first case is valid
since 'Val' would point to that instruction.

The second is iterating through a basic block which is a list of
instructions. The first few instructions in a basic block are the Phi
nodes used in SSA. The BasicBlock::iterator returns an instruction type
(right?).

The "&*BBI" is taking the iterator "BBI", dereferencing it "*BBI" to get
the Instruction reference, and then taking the address of that "&*BBI" to
get a pointer to that instruction.

-- 
|| Bill? Wendling			wendling at isanbard.org



More information about the llvm-dev mailing list