This is an archive of the discontinued LLVM Phabricator instance.

Skip some unnecessary type checks.
ClosedPublic

Authored by sbenza on Dec 1 2014, 1:51 PM.

Details

Summary

Skip some unnecessary type checks wrt DynTypedNodes.
Add DynTypedNode::getUnchecked() to skip the runtime check when the type
is known.
Speed up DynTypedNode::operator== by using isSame() instead of
isBaseOf().
Skip the type check in MatcherInterface<T>::matches(). All calls come
from DynTypedMatcher::matches(), which already did the type check.
This change speeds up our clang-tidy benchmark by ~4%.

Diff Detail

Repository
rL LLVM

Event Timeline

sbenza updated this revision to Diff 16786.Dec 1 2014, 1:51 PM
sbenza retitled this revision from to Skip some unnecessary type checks..
sbenza updated this object.
sbenza edited the test plan for this revision. (Show Details)
sbenza added a reviewer: klimek.
sbenza added a subscriber: Unknown Object (MLST).
klimek added inline comments.Dec 2 2014, 12:43 AM
include/clang/AST/ASTTypeTraits.h
264 ↗(On Diff #16786)

Why doesn't this change behavior? -> can we not get the same node with a different more or less specific type?

sbenza added inline comments.Dec 2 2014, 6:13 AM
include/clang/AST/ASTTypeTraits.h
264 ↗(On Diff #16786)

It used to be that DynTypedNode::create() stored the static type of the node in NodeKind.
Recently we added ASTNodeKind::getFromNode() to get the dynamic type of the node and we store that on the DTN.
This was necessary for the RestrictKind optimizations.
Now that we store the exact node kind, we can compare them directly. This is also why we can drop the dyn_cast<> in favor of just cast<> in DynCastPtrConverter::get() below. The node kind check is enough.
Do you want a comment here?

klimek accepted this revision.Dec 2 2014, 6:32 AM
klimek edited edge metadata.

lg with comment added :)

include/clang/AST/ASTTypeTraits.h
264 ↗(On Diff #16786)

Yse please :)

This revision is now accepted and ready to land.Dec 2 2014, 6:32 AM
sbenza closed this revision.Dec 2 2014, 10:29 AM
sbenza updated this revision to Diff 16818.

Closed by commit rL223134 (authored by @sbenza).