[PATCH] D39111: Extensible LLVM RTTI

Lang Hames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 19 22:29:31 PDT 2017


lhames created this revision.

This patch extracts the RTTI part of llvm::ErrorInfo into its own class (RTTIExtends) so that it can be used in other non-error hierarchies, and makes it compatible with the existing LLVM RTTI function templates (isa, cast, dyn_cast, dyn_cast_or_null) by adding the classof method.

This system makes different trade-offs to the existing LLVM RTTI approach (described in https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html) and would be complementary to the existing system rather than replacing it. Specifically: the extensible scheme is slower than the existing scheme (requiring a virtual call per isa check), but it leaves hierarchies open for extension and is slightly easier to use (since it eliminates the enumeration and switch boilerplate).

I believe that extensible RTTI makes sense for the Error hierarchy (which is why it was originally developed there) and I speculate that it may be useful in other hierarchies (e.g. Object) where casting is expected to be rare and not performance sensitive. I don't have a use-case in tree yet and am in no rush for this to go in, but thought I would throw it up for discussion, and in case it is useful to anyone else.


Repository:
  rL LLVM

https://reviews.llvm.org/D39111

Files:
  Support/ExtensibleRTTI.cpp
  Support/ExtensibleRTTITest.cpp
  llvm/Support/ExtensibleRTTI.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39111.119629.patch
Type: text/x-patch
Size: 5661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171020/ff662572/attachment.bin>


More information about the llvm-commits mailing list