[llvm] [Analysis][NFC] Don't use BitVector for nobuiltin overrides (PR #103411)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 13:09:35 PDT 2024


https://github.com/aengelke created https://github.com/llvm/llvm-project/pull/103411

Avoid one heap allocation per function per constructed TLI. The
BitVector is never resized, so a bitset is sufficient.


>From 8989909a834b1a07aff2d1bab3fca956b94d6abd Mon Sep 17 00:00:00 2001
From: Alexis Engelke <engelke at in.tum.de>
Date: Tue, 13 Aug 2024 20:09:22 +0000
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/include/llvm/Analysis/TargetLibraryInfo.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.h b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
index db5e80ccdbaaba..d0506a89b88ef4 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -9,12 +9,12 @@
 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 
-#include "llvm/ADT/BitVector.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/TargetParser/Triple.h"
+#include <bitset>
 #include <optional>
 
 namespace llvm {
@@ -287,12 +287,12 @@ class TargetLibraryInfo {
 
   /// Support for -fno-builtin* options as function attributes, overrides
   /// information in global TargetLibraryInfoImpl.
-  BitVector OverrideAsUnavailable;
+  std::bitset<NumLibFuncs> OverrideAsUnavailable;
 
 public:
   explicit TargetLibraryInfo(const TargetLibraryInfoImpl &Impl,
                              std::optional<const Function *> F = std::nullopt)
-      : Impl(&Impl), OverrideAsUnavailable(NumLibFuncs) {
+      : Impl(&Impl) {
     if (!F)
       return;
     if ((*F)->hasFnAttribute("no-builtins"))
@@ -329,7 +329,7 @@ class TargetLibraryInfo {
       return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
     // We can inline if the callee's nobuiltin attributes are no stricter than
     // the caller's.
-    return !CalleeTLI.OverrideAsUnavailable.test(OverrideAsUnavailable);
+    return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
   }
 
   /// Return true if the function type FTy is valid for the library function
@@ -373,10 +373,12 @@ class TargetLibraryInfo {
 
   /// Forces a function to be marked as unavailable.
   void setUnavailable(LibFunc F) LLVM_ATTRIBUTE_UNUSED {
+    assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
     OverrideAsUnavailable.set(F);
   }
 
   TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
+    assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
     if (OverrideAsUnavailable[F])
       return TargetLibraryInfoImpl::Unavailable;
     return Impl->getState(F);



More information about the llvm-commits mailing list