[LLVMdev] How to add an include file

John McCall rjmccall at apple.com
Wed Jul 8 00:16:43 PDT 2009


On Jul 7, 2009, at 11:14 PM, David Minor wrote:
> Adding includes is trivial even w/o llvm, but the real problem here  
> is manipulation of classes, if I understand you correctly adding an  
> inheritee wouldn't be possible.

The problem is that LLVM bitcode is not the right level of abstraction  
to approach this from.  LLVM bitcode doesn't know anything about  
classes;  classes are a higher-level language construct, and it's a  
front-end's responsibility to turn them into the lower-level types  
(with lower-level operations on them) that LLVM understands.  Once  
you've built an LLVM type, it's immutable, so your "leaf class A" type  
would be different from your "class A with base B" type; you can't  
just modify the type in place, and as Eli said, LLVM instructions  
aren't designed for that anyway.  And even if you cloned huge swathes  
of code, painstakingly replacing one type with the other and carefully  
updating member accesses, there's really no reason to think in general  
that the semantics of the result would match what you'd have gotten  
from declaring the proper class inheritance to begin with.

It sounds like what you really want is to hack a C++ front-end (like  
llvm-g++ or clang) to adjust its internal representation of class A  
before it's all lowered into bitcode.  Is there a reason this needs to  
be done as part of some later optimization pass?

John.



More information about the llvm-dev mailing list