[LLVMdev] TableGen: Requesting feedback for "TGContext"

Chris Lattner sabre at nondot.org
Thu Oct 4 20:05:49 PDT 2012

On Oct 4, 2012, at 5:15 PM, Sean Silva <silvas at purdue.edu> wrote:

>> It won't cause a negative effect, go for it!  Dynamic_cast is realllly slow compared to dyn_cast, it is worth the memory.
> Ok, here's the first batch. It converts the RecTy hierarchy over to
> use LLVM-style RTTI. Along the way, I also wrote up a new doc "How to
> set up LLVM-style RTTI for your class hierarchy", which covers the
> previously undocumented (albeit not that complicated) process for
> hooking into Support/Casting.h.

Cool.  Please pull this content into the ProgrammersManual as a new section.

> Attached are 4 patches. I've also attached a convenient rendered PDF
> of the new documentation (credit to Nick Kledzik for the idea of doing
> this). Generated TableGen files are identical at all steps.
> 0001-tblgen-Put-dyn_cast-infrastructure-in-place-for-RecT.patch:
> Sets up Casting.h infrastructure.
> 0002-tblgen-Replace-uses-of-dynamic_cast-XXXRecTy-with-dy.patch:
> A mechanical transformation of dynamic_cast<> to dyn_cast<>. This
> leaves a number of "semantically inappropriate" dyn_cast<>'s (e.g. `if
> (dyn_cast<>) { /* ... */ }`).
> 0003-tblgen-Use-appropriate-LLVM-style-RTTI-functions.patch:
> Fix up "semantically inappropriate" dyn_cast<>'s to isa<> or cast<> as
> appropriate. If you want I can squash this with 0002.
> 0004-docs-Add-HowToSetUpLLVMStyleRTTI.rst.patch:
> Add docs for setting up LLVM-style RTTI for a class hierarchy. The
> attached PDF is the rendered version of this document. Please give
> feedback on inaccuracies or suggested improvements for this document.

These all look great, please apply.

> One question regarding `classof()`s of the form:
>    static bool classof(const Foo *) { return true; }
> Is the only purpose of this to optimize away "trivial" upcasts/isa<>
> checks which are known statically?


> If so, could we factor out this
> case into Casting.h (using a trait like std::is_base_of<>)?

That's a great idea, please do! :)


More information about the llvm-dev mailing list