Skip to content

Commit ce8cb7c

Browse files
authored
[Analysis][NFC] Don't use BitVector for nobuiltin overrides
Avoid one heap allocation per function per constructed TLI. The BitVector is never resized, so a bitset is sufficient. Pull Request: #103411
1 parent 6da3361 commit ce8cb7c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
1010
#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
1111

12-
#include "llvm/ADT/BitVector.h"
1312
#include "llvm/ADT/DenseMap.h"
1413
#include "llvm/IR/InstrTypes.h"
1514
#include "llvm/IR/PassManager.h"
1615
#include "llvm/Pass.h"
1716
#include "llvm/TargetParser/Triple.h"
17+
#include <bitset>
1818
#include <optional>
1919

2020
namespace llvm {
@@ -287,12 +287,12 @@ class TargetLibraryInfo {
287287

288288
/// Support for -fno-builtin* options as function attributes, overrides
289289
/// information in global TargetLibraryInfoImpl.
290-
BitVector OverrideAsUnavailable;
290+
std::bitset<NumLibFuncs> OverrideAsUnavailable;
291291

292292
public:
293293
explicit TargetLibraryInfo(const TargetLibraryInfoImpl &Impl,
294294
std::optional<const Function *> F = std::nullopt)
295-
: Impl(&Impl), OverrideAsUnavailable(NumLibFuncs) {
295+
: Impl(&Impl) {
296296
if (!F)
297297
return;
298298
if ((*F)->hasFnAttribute("no-builtins"))
@@ -329,7 +329,7 @@ class TargetLibraryInfo {
329329
return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
330330
// We can inline if the callee's nobuiltin attributes are no stricter than
331331
// the caller's.
332-
return !CalleeTLI.OverrideAsUnavailable.test(OverrideAsUnavailable);
332+
return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
333333
}
334334

335335
/// Return true if the function type FTy is valid for the library function
@@ -373,10 +373,12 @@ class TargetLibraryInfo {
373373

374374
/// Forces a function to be marked as unavailable.
375375
void setUnavailable(LibFunc F) LLVM_ATTRIBUTE_UNUSED {
376+
assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
376377
OverrideAsUnavailable.set(F);
377378
}
378379

379380
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
381+
assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
380382
if (OverrideAsUnavailable[F])
381383
return TargetLibraryInfoImpl::Unavailable;
382384
return Impl->getState(F);

0 commit comments

Comments
 (0)