-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[NFC] Don't recompute type name #119631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] Don't recompute type name #119631
Conversation
@llvm/pr-subscribers-llvm-support Author: Ian Wood (IanWood1) ChangesThis change uses a local static variable to cache the I found that llvm-project/mlir/include/mlir/IR/Types.h Lines 294 to 300 in 4b825c7
Full diff: https://github.com/llvm/llvm-project/pull/119631.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Support/TypeName.h b/llvm/include/llvm/Support/TypeName.h
index 9547e76a7fa79b..61ba09c2163047 100644
--- a/llvm/include/llvm/Support/TypeName.h
+++ b/llvm/include/llvm/Support/TypeName.h
@@ -13,18 +13,8 @@
namespace llvm {
-/// We provide a function which tries to compute the (demangled) name of a type
-/// statically.
-///
-/// This routine may fail on some platforms or for particularly unusual types.
-/// Do not use it for anything other than logging and debugging aids. It isn't
-/// portable or dependendable in any real sense.
-///
-/// The returned StringRef will point into a static storage duration string.
-/// However, it may not be null terminated and may be some strangely aligned
-/// inner substring of a larger string.
-template <typename DesiredTypeName>
-inline StringRef getTypeName() {
+namespace detail {
+template <typename DesiredTypeName> inline StringRef getTypeNameImpl() {
#if defined(__clang__) || defined(__GNUC__)
StringRef Name = __PRETTY_FUNCTION__;
@@ -58,6 +48,22 @@ inline StringRef getTypeName() {
return "UNKNOWN_TYPE";
#endif
}
+} // namespace detail
+
+/// We provide a function which tries to compute the (demangled) name of a type
+/// statically.
+///
+/// This routine may fail on some platforms or for particularly unusual types.
+/// Do not use it for anything other than logging and debugging aids. It isn't
+/// portable or dependendable in any real sense.
+///
+/// The returned StringRef will point into a static storage duration string.
+/// However, it may not be null terminated and may be some strangely aligned
+/// inner substring of a larger string.
+template <typename DesiredTypeName> inline StringRef getTypeName() {
+ static StringRef Name = detail::getTypeNameImpl<DesiredTypeName>();
+ return Name;
+}
} // namespace llvm
|
Thanks. I noticed this in debug builds too |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/2/builds/13172 Here is the relevant piece of the build log for the reference
|
This change uses a local static variable to cache the computed
StringRef
containing the type's name.I found that
RelWithDebInfo
builds of MLIR were spending a relatively large amount of time inStringRef::find
and I tracked it down togetTypeName
which utilizesStringRef
methods that are defined in a separate translation unit. This is especially impactful on perf becausegetTypeName
is supposed to be used for debug logging. See an example here:llvm-project/mlir/include/mlir/IR/Types.h
Lines 294 to 300 in 4b825c7