[LLVMdev] isa and friends as an alternative to dynamic cast?
Chris Lattner
sabre at nondot.org
Thu Apr 21 22:07:42 PDT 2005
On Thu, 21 Apr 2005, Reid Spencer wrote:
> one or more of the libraries. Since we don't have that situation in
> LLVM, using the various Casting.h facilities allows all that "dynamic"
> casting to actually be done statically, hence no runtime performance
> penalty.
Reid is right. isa on an instruction literally loads a field out of the
instruction and compares it against a constant. As another example, a
good compiler (ahem, like LLVM :) ), turns this:
if (... = dyn_cast<LoadInst>(Y)) {
...
} else if (... = dyn_cast<StoreInst>(Y)) {
...
} else if (... = dyn_cast<AllocaInst>(Y)) {
...
Into:
switch (Y->getOpcode()) {
case Instruction::Load:
...
case Instruction::Store:
...
case Instruction::AllocaInst:
...
Which is something that is just not possible with RTTI.
-Chris
--
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/
More information about the llvm-dev
mailing list