LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 888 - [passmgr] Eliminate use of typeid/dynamic_cast
Summary: [passmgr] Eliminate use of typeid/dynamic_cast
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Core LLVM classes (show other bugs)
Version: 1.0
Hardware: All All
: P enhancement
Assignee: Reid Spencer
URL:
Keywords: quality-of-implementation
Depends on:
Blocks:
 
Reported: 2006-08-26 23:11 PDT by Chris Lattner
Modified: 2010-01-22 00:36 PST (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2006-08-26 23:11:07 PDT
The passmgr is the only significant user of RTTI data.  If we could eliminate its use, we could build all of 
LLVM with -fno-rtti, which is good for a 5-6% size reduction.  This would also provide (slightly) faster 
builds for everyone! :)

-Chris
Comment 1 Reid Spencer 2007-04-25 16:36:54 PDT
The new PassManager continues to use typeid:

Pass.h:    return lookupPassInfo(typeid(AnalysisClass));
PassSupport.h:  : RegisterPassBase(Name, PassArg, typeid(PassName),
PassSupport.h:    : RegisterAGBase(typeid(Interface),
&RPB.getPassInfo()->getTypeInfo(),
PassSupport.h:  : RegisterAGBase(typeid(Interface)) {

and dynamic_cast:
PassAnalysisSupport.h:  return dynamic_cast<AnalysisType*>
PassAnalysisSupport.h:  // AnalysisGroups), we must use dynamic_cast here to
potentially adjust the
PassAnalysisSupport.h:  AnalysisType *Result =
dynamic_cast<AnalysisType*>(ResultPass);
PassAnalysisSupport.h:   // AnalysisGroups), we must use dynamic_cast here to
potentially adjust the
PassAnalysisSupport.h:   AnalysisType *Result =
dynamic_cast<AnalysisType*>(ResultPass);

It would be nice if we could get rid of these and start turning on -no-rtti. 
Comment 2 Reid Spencer 2007-04-25 16:43:06 PDT
Devang,

Any chance this PR (888) could get implemented for 2.0?

Reid
Comment 3 Devang Patel 2007-04-25 20:02:13 PDT
I have not yet thought much about this. IMO, it is impractical to use isa,classof approach used by Value 
and Type classes because it will require each pass to identify itself. 

thoughts ? ideas ? suggestions ?
Comment 4 Reid Spencer 2007-04-25 20:13:43 PDT
Every Pass already identifies itself when it registers. I don't see it as being
a big deal.
Comment 5 Chris Lattner 2007-04-25 21:17:45 PDT
One suggested implementation approach:  Whenever a pass registration object's static ctor triggers, it 
could assign a unique ID to the pass.  The passmgr could use this.

Another approach: we could use the address of the pass registration object as a unique ID.
Comment 6 Devang Patel 2007-05-01 16:40:57 PDT
I eliminated typeid uses.

Comment 7 Reid Spencer 2007-05-01 16:45:24 PDT
Cool! Thanks.

When I get a chance to test it, I'll turn typeid support off in the Makefiles
and see if we're "clean" without it. If so, I'll resolve this PR.

Thanks, Devang!

Reid
Comment 8 Devang Patel 2007-05-01 16:47:57 PDT
Thanks Reid. I still need to deal with two remaining dynamic_cast in PassAnalysisSupport.h though.
Comment 9 Reid Spencer 2007-05-01 17:08:21 PDT
Okay, I'll watch for the commits. :)
Comment 10 Reid Spencer 2007-05-24 20:20:46 PDT
FYI, I turned off typeid support when building llvm-gcc and all hell broke
loose. It seems there are many other subtle uses. I'm just going on memory right
now but will provide details (or a fix) next week.
Comment 11 Chris Lattner 2010-01-22 00:36:04 PST
Passmanager no longer uses RTTI.