9#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
10#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
38#define TLI_DEFINE_ENUM
39#include "llvm/Analysis/TargetLibraryInfo.def"
57 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
60 enum AvailabilityState {
66 AvailableArray[
F/4] &= ~(3 << 2*(
F&3));
67 AvailableArray[
F/4] |= State << 2*(
F&3);
74 std::vector<VecDesc> VectorDescs;
77 std::vector<VecDesc> ScalarDescs;
133 setState(
F, StandardName);
139 if (StandardNames[
F] !=
Name) {
140 setState(
F, CustomName);
141 CustomNames[
F] = std::string(
Name);
142 assert(CustomNames.contains(
F));
144 setState(
F, StandardName);
182 ShouldExtI32Param = Val;
189 ShouldExtI32Return = Val;
195 ShouldSignExtI32Param = Val;
201 ShouldSignExtI32Return = Val;
250 std::optional<const Function *>
F = std::nullopt)
251 : Impl(&Impl), OverrideAsUnavailable(
NumLibFuncs) {
254 if ((*F)->hasFnAttribute(
"no-builtins"))
259 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
261 if (!Attr.isStringAttribute())
263 auto AttrStr = Attr.getKindAsString();
264 if (!AttrStr.consume_front(
"no-builtin-"))
275 : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
279 OverrideAsUnavailable = TLI.OverrideAsUnavailable;
288 bool AllowCallerSuperset)
const {
289 if (!AllowCallerSuperset)
290 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
292 B |= CalleeTLI.OverrideAsUnavailable;
295 return B == OverrideAsUnavailable;
302 return Impl->isValidProtoForLibFunc(FTy,
F, M);
328 OverrideAsUnavailable.
set();
333 OverrideAsUnavailable.
set(
F);
337 if (OverrideAsUnavailable[
F])
338 return TargetLibraryInfoImpl::Unavailable;
339 return Impl->getState(
F);
344 return getState(
F) != TargetLibraryInfoImpl::Unavailable;
353 bool Masked =
false)
const {
360 if (
getState(
F) == TargetLibraryInfoImpl::Unavailable)
364 case LibFunc_copysign:
case LibFunc_copysignf:
case LibFunc_copysignl:
365 case LibFunc_fabs:
case LibFunc_fabsf:
case LibFunc_fabsl:
366 case LibFunc_sin:
case LibFunc_sinf:
case LibFunc_sinl:
367 case LibFunc_cos:
case LibFunc_cosf:
case LibFunc_cosl:
368 case LibFunc_sqrt:
case LibFunc_sqrtf:
case LibFunc_sqrtl:
369 case LibFunc_sqrt_finite:
case LibFunc_sqrtf_finite:
370 case LibFunc_sqrtl_finite:
371 case LibFunc_fmax:
case LibFunc_fmaxf:
case LibFunc_fmaxl:
372 case LibFunc_fmin:
case LibFunc_fminf:
case LibFunc_fminl:
373 case LibFunc_floor:
case LibFunc_floorf:
case LibFunc_floorl:
374 case LibFunc_nearbyint:
case LibFunc_nearbyintf:
case LibFunc_nearbyintl:
375 case LibFunc_ceil:
case LibFunc_ceilf:
case LibFunc_ceill:
376 case LibFunc_rint:
case LibFunc_rintf:
case LibFunc_rintl:
377 case LibFunc_round:
case LibFunc_roundf:
case LibFunc_roundl:
378 case LibFunc_trunc:
case LibFunc_truncf:
case LibFunc_truncl:
379 case LibFunc_log2:
case LibFunc_log2f:
case LibFunc_log2l:
380 case LibFunc_exp2:
case LibFunc_exp2f:
case LibFunc_exp2l:
381 case LibFunc_ldexp:
case LibFunc_ldexpf:
case LibFunc_ldexpl:
382 case LibFunc_memcpy:
case LibFunc_memset:
case LibFunc_memmove:
383 case LibFunc_memcmp:
case LibFunc_bcmp:
case LibFunc_strcmp:
384 case LibFunc_strcpy:
case LibFunc_stpcpy:
case LibFunc_strlen:
385 case LibFunc_strnlen:
case LibFunc_memchr:
case LibFunc_mempcpy:
393 if (State == TargetLibraryInfoImpl::Unavailable)
395 if (State == TargetLibraryInfoImpl::StandardName)
396 return Impl->StandardNames[
F];
397 assert(State == TargetLibraryInfoImpl::CustomName);
398 return Impl->CustomNames.
find(
F)->second;
402 bool &ShouldExtI32Return,
403 bool &ShouldSignExtI32Param,
404 bool &ShouldSignExtI32Return,
406 ShouldExtI32Param = ShouldExtI32Return =
false;
407 ShouldSignExtI32Param = ShouldSignExtI32Return =
false;
413 ShouldExtI32Param =
true;
414 ShouldExtI32Return =
true;
418 if (
T.isLoongArch() ||
T.isMIPS() ||
T.isRISCV64()) {
419 ShouldSignExtI32Param =
true;
423 if (
T.isLoongArch() ||
T.isRISCV64()) {
424 ShouldSignExtI32Return =
true;
433 bool ShouldSignExtI32Param_,
435 if (ShouldExtI32Param_)
436 return Signed ? Attribute::SExt : Attribute::ZExt;
437 if (ShouldSignExtI32Param_)
438 return Attribute::SExt;
445 bool ShouldExtI32Param, ShouldExtI32Return;
446 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
448 ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
449 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
454 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
455 Impl->ShouldSignExtI32Param,
Signed);
463 bool ShouldSignExtI32Return_,
465 if (ShouldExtI32Return_)
466 return Signed ? Attribute::SExt : Attribute::ZExt;
467 if (ShouldSignExtI32Return_)
468 return Attribute::SExt;
475 bool ShouldExtI32Param, ShouldExtI32Return;
476 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
478 ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
479 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
484 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
485 Impl->ShouldSignExtI32Return,
Signed);
492 bool Signed,
bool Ret =
false,
494 if (
auto AK = getExtAttrForI32Param(
Signed))
495 for (
auto ArgNo : ArgNos)
496 AL = AL.addParamAttribute(*
C, ArgNo, AK);
498 if (
auto AK = getExtAttrForI32Return(
Signed))
499 AL = AL.addRetAttribute(*
C, AK);
559 : BaselineInfoImpl(
std::
move(BaselineInfoImpl)) {}
567 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
572 std::optional<TargetLibraryInfo> TLI;
574 virtual void anchor();
584 TLI = TLA.
run(
F, DummyFAM);
amdgpu Simplify well known AMD library false FunctionCallee Callee
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ATTRIBUTE_UNUSED
This file defines the DenseMap class.
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Machine Check Debug Module
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
API to communicate dependencies between analyses during invalidation.
A container for analyses that lazily runs them and caches their results.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
@ None
No attributes have been set.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
iterator find(const_arg_type_t< KeyT > Val)
Class to represent function types.
ImmutablePass class - This class is used to provide information that does not need to be run.
This is an important class for using LLVM in a threaded context.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Analysis pass providing the TargetLibraryInfo.
TargetLibraryAnalysis()=default
Default construct the library analysis.
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
TargetLibraryAnalysis(TargetLibraryInfoImpl BaselineInfoImpl)
Construct a library analysis with baseline Module-level info.
Implementation of the target library information.
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &Scalable) const
Returns the largest vectorization factor used in the list of vector functions.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used.
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib, const llvm::Triple &TargetTriple)
Calls addVectorizableFunctions with a known preset of functions for the given vector library.
void setIntSize(unsigned Bits)
Initialize the C-level size of an integer.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
static bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
void setShouldSignExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext attribute if they correspond t...
TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
void disableAllFunctions()
Disables all builtins.
VectorLibrary
List of known vector-functions libraries.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const
Return the name of the equivalent of F, vectorized with factor VF.
void setAvailable(LibFunc F)
Forces a function to be marked as available.
TargetLibraryInfoWrapperPass()
TargetLibraryInfo & getTLI(const Function &F)
Provides information about what library functions are available for the current target.
AttributeList getAttrList(LLVMContext *C, ArrayRef< unsigned > ArgNos, bool Signed, bool Ret=false, AttributeList AL=AttributeList()) const
TargetLibraryInfo & operator=(TargetLibraryInfo &&TLI)
static Attribute::AttrKind getExtAttrForI32Param(const Triple &T, bool Signed=true)
bool areInlineCompatible(const TargetLibraryInfo &CalleeTLI, bool AllowCallerSuperset) const
Determine whether a callee with the given TLI can be inlined into caller with this TLI,...
bool getLibFunc(const CallBase &CB, LibFunc &F) const
If a callbase does not have the 'nobuiltin' attribute, return if the called function is a known libra...
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Handle invalidation from the pass manager.
TargetLibraryInfo(TargetLibraryInfo &&TLI)
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
Attribute::AttrKind getExtAttrForI32Return(bool Signed=true) const
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
bool isKnownVectorFunctionInLibrary(StringRef F) const
Check if the function "F" is listed in a library known to LLVM.
bool isFunctionVectorizable(StringRef F) const
bool has(LibFunc F) const
Tests whether a library function is available.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const
TargetLibraryInfo & operator=(const TargetLibraryInfo &TLI)=default
void disableAllFunctions() LLVM_ATTRIBUTE_UNUSED
Disables all builtins.
TargetLibraryInfo(const TargetLibraryInfo &TLI)=default
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &ScalableVF) const
Returns the largest vectorization factor used in the list of vector functions.
void setUnavailable(LibFunc F) LLVM_ATTRIBUTE_UNUSED
Forces a function to be marked as unavailable.
TargetLibraryInfo(const TargetLibraryInfoImpl &Impl, std::optional< const Function * > F=std::nullopt)
static Attribute::AttrKind getExtAttrForI32Return(const Triple &T, bool Signed=true)
bool getLibFunc(const Function &FDecl, LibFunc &F) const
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
static void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
StringRef getName(LibFunc F) const
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Triple - Helper class for working with autoconf configuration names.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Describes a possible vectorization of a function.
ElementCount VectorizationFactor