[PATCH] D78665: [TLI] Optimize no-builtins attribute check (NFC)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 22 13:03:26 PDT 2020


nikic created this revision.
nikic added reviewers: tejohnson, wenlei.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Looking up a string function attribute is expensive, because attributes are stored as a plain list (not a map), and functions tend to have a large number of attributes. As the TargetLibraryInfo constructor needs to scan over all attributes to check for `no-builtin-*` anyway, we can also integrate the `no-builtins` check in the same loop. D77632 <https://reviews.llvm.org/D77632> will then be able to also check for `veclib` in the same loop, which should mitigate most of the negative impact of that change.

Here are the improvements to instructions retired with this change: http://llvm-compile-time-tracker.com/compare.php?from=b3f5472c2b9c8cf99239a9ac655555e9f0ba9e5d&to=b1eb5ae2f8bcdb888b8a0d7c0356fa10e6e51d6a&stat=instructions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78665

Files:
  include/llvm/Analysis/TargetLibraryInfo.h


Index: include/llvm/Analysis/TargetLibraryInfo.h
===================================================================
--- include/llvm/Analysis/TargetLibraryInfo.h
+++ include/llvm/Analysis/TargetLibraryInfo.h
@@ -226,18 +226,17 @@
       : Impl(&Impl), OverrideAsUnavailable(NumLibFuncs) {
     if (!F)
       return;
-    if ((*F)->hasFnAttribute("no-builtins"))
-      disableAllFunctions();
-    else {
-      // Disable individual libc/libm calls in TargetLibraryInfo.
-      LibFunc LF;
-      AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
-      for (const Attribute &Attr : FnAttrs) {
-        if (!Attr.isStringAttribute())
-          continue;
-        auto AttrStr = Attr.getKindAsString();
-        if (!AttrStr.consume_front("no-builtin-"))
-          continue;
+
+    AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
+    for (const Attribute &Attr : FnAttrs) {
+      if (!Attr.isStringAttribute())
+        continue;
+      auto AttrStr = Attr.getKindAsString();
+      if (AttrStr == "no-builtins") {
+        disableAllFunctions();
+      } else if (AttrStr.consume_front("no-builtin-")) {
+        // Disable individual libc/libm calls in TargetLibraryInfo.
+        LibFunc LF;
         if (getLibFunc(AttrStr, LF))
           setUnavailable(LF);
       }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78665.259369.patch
Type: text/x-patch
Size: 1308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200422/f8e44bfd/attachment.bin>


More information about the llvm-commits mailing list