9#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
10#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
42 std::optional<CallingConv::ID> Conv)
44 CC(Conv ? static_cast<
unsigned>(*Conv) + 1u : 0u) {}
73 return Data->value().VectorizationFactor;
75 bool isMasked()
const {
return Data->value().Masked; }
78 unsigned CC = Data->value().CC;
89#define GET_TARGET_LIBRARY_INFO_ENUM
90#include "llvm/Analysis/TargetLibraryInfo.inc"
101 unsigned char AvailableArray[(NumLibFuncs+3)/4];
103#define GET_TARGET_LIBRARY_INFO_IMPL_DECL
104#include "llvm/Analysis/TargetLibraryInfo.inc"
105 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
107 bool IsErrnoFunctionCall;
114 void setState(LibFunc
F, AvailabilityState State) {
115 AvailableArray[
F/4] &= ~(3 << 2*(
F&3));
116 AvailableArray[
F/4] |= State << 2*(
F&3);
118 AvailabilityState getState(LibFunc
F)
const {
121 return static_cast<AvailabilityState
>((AvailableArray[
F/4] >> 2*(
F&3)) & 3);
125 std::vector<VecDesc> VectorDescs;
128 std::vector<VecDesc> ScalarDescs;
132 LLVM_ABI bool isValidProtoForLibFunc(
const FunctionType &FTy, LibFunc
F,
169 setState(
F, Unavailable);
174 setState(
F, StandardName);
180 if (
StringRef(StandardNamesStrTable.getCString(StandardNamesOffsets[
F]),
181 StandardNamesSizeTable[
F]) != Name) {
182 setState(
F, CustomName);
183 CustomNames[
F] = std::string(Name);
184 assert(CustomNames.contains(
F));
186 setState(
F, StandardName);
231 ShouldExtI32Param = Val;
238 ShouldExtI32Return = Val;
244 ShouldSignExtI32Param = Val;
250 ShouldSignExtI32Return = Val;
293 std::bitset<NumLibFuncs> OverrideAsUnavailable;
299 std::optional<const Function *>
F = std::nullopt)
303 if ((*F)->hasFnAttribute(
"no-builtins"))
307 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
309 if (!Attr.isStringAttribute())
311 auto AttrStr = Attr.getKindAsString();
312 if (!AttrStr.consume_front(
"no-builtin-"))
331 bool AllowCallerSuperset)
const {
332 if (!AllowCallerSuperset)
333 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
336 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
343 return Impl->isValidProtoForLibFunc(FTy,
F, M);
351 return Impl->getLibFunc(funcName);
355 return Impl->getLibFunc(FDecl);
371 return Impl->getLibFunc(Opcode, Ty);
381 assert(
F < OverrideAsUnavailable.size() &&
"out-of-bounds LibFunc");
382 OverrideAsUnavailable.set(
F);
385 TargetLibraryInfoImpl::AvailabilityState
getState(LibFunc
F)
const {
386 assert(
F < OverrideAsUnavailable.size() &&
"out-of-bounds LibFunc");
387 if (OverrideAsUnavailable[
F])
388 return TargetLibraryInfoImpl::Unavailable;
389 return Impl->getState(
F);
394 return getState(
F) != TargetLibraryInfoImpl::Unavailable;
397 return Impl->isFunctionVectorizable(
F, VF);
400 return Impl->isFunctionVectorizable(
F);
403 bool Masked =
false)
const {
404 return Impl->getVectorizedFunction(
F, VF,
Masked);
408 return Impl->getVectorMappingInfo(
F, VF,
Masked);
414 if (
getState(
F) == TargetLibraryInfoImpl::Unavailable)
419 case LibFunc_acos:
case LibFunc_acosf:
case LibFunc_acosl:
420 case LibFunc_asin:
case LibFunc_asinf:
case LibFunc_asinl:
421 case LibFunc_atan2:
case LibFunc_atan2f:
case LibFunc_atan2l:
422 case LibFunc_atan:
case LibFunc_atanf:
case LibFunc_atanl:
423 case LibFunc_copysign:
case LibFunc_copysignf:
case LibFunc_copysignl:
424 case LibFunc_cos:
case LibFunc_cosf:
case LibFunc_cosl:
425 case LibFunc_cosh:
case LibFunc_coshf:
case LibFunc_coshl:
426 case LibFunc_exp2:
case LibFunc_exp2f:
case LibFunc_exp2l:
427 case LibFunc_exp10:
case LibFunc_exp10f:
case LibFunc_exp10l:
428 case LibFunc_ldexp:
case LibFunc_ldexpf:
case LibFunc_ldexpl:
429 case LibFunc_log2:
case LibFunc_log2f:
case LibFunc_log2l:
430 case LibFunc_memcmp:
case LibFunc_bcmp:
case LibFunc_strcmp:
431 case LibFunc_memcpy:
case LibFunc_memset:
case LibFunc_memmove:
432 case LibFunc_sin:
case LibFunc_sinf:
case LibFunc_sinl:
433 case LibFunc_sinh:
case LibFunc_sinhf:
case LibFunc_sinhl:
434 case LibFunc_sqrt:
case LibFunc_sqrtf:
case LibFunc_sqrtl:
435 case LibFunc_sqrt_finite:
case LibFunc_sqrtf_finite:
436 case LibFunc_sqrtl_finite:
437 case LibFunc_strcpy:
case LibFunc_stpcpy:
case LibFunc_strlen:
438 case LibFunc_strnlen:
case LibFunc_strstr:
case LibFunc_memchr:
439 case LibFunc_memccpy:
case LibFunc_mempcpy:
case LibFunc_tan:
440 case LibFunc_tanf:
case LibFunc_tanl:
case LibFunc_tanh:
441 case LibFunc_tanhf:
case LibFunc_tanhl:
451 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
452 TargetLibraryInfoImpl::StandardNamesOffsets[
F]),
453 TargetLibraryInfoImpl::StandardNamesSizeTable[
F]);
458 if (State == TargetLibraryInfoImpl::Unavailable)
460 if (State == TargetLibraryInfoImpl::StandardName)
462 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[
F]),
463 Impl->StandardNamesSizeTable[
F]);
464 assert(State == TargetLibraryInfoImpl::CustomName);
465 return Impl->CustomNames.find(
F)->second;
469 bool &ShouldZExtBoolReturn,
473 bool &ShouldExtI32Return,
474 bool &ShouldSignExtI32Param,
475 bool &ShouldSignExtI32Return,
483 bool ShouldSignExtI32Param_,
485 if (ShouldExtI32Param_)
486 return Signed ? Attribute::SExt : Attribute::ZExt;
487 if (ShouldSignExtI32Param_)
488 return Attribute::SExt;
494 bool ShouldZExtBoolParam, ShouldZExtBoolReturn;
502 return Signed ? Attribute::SExt : Attribute::ZExt;
507 bool ShouldExtI32Param, ShouldExtI32Return;
508 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
510 ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
511 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
516 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
517 Impl->ShouldSignExtI32Param,
Signed);
525 bool ShouldSignExtI32Return_,
527 if (ShouldExtI32Return_)
528 return Signed ? Attribute::SExt : Attribute::ZExt;
529 if (ShouldSignExtI32Return_)
530 return Attribute::SExt;
537 bool ShouldExtI32Param, ShouldExtI32Return;
538 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
540 ShouldSignExtI32Param, ShouldSignExtI32Return,
T);
541 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
546 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
547 Impl->ShouldSignExtI32Return,
Signed);
554 bool Signed,
bool Ret =
false,
556 if (
auto AK = getExtAttrForI32Param(
Signed))
557 for (
auto ArgNo : ArgNos)
558 AL = AL.addParamAttribute(*
C, ArgNo, AK);
560 if (
auto AK = getExtAttrForI32Return(
Signed))
561 AL = AL.addRetAttribute(*
C, AK);
580 return Impl->getIntSize();
588 ModuleAnalysisManager::Invalidator &) {
592 FunctionAnalysisManager::Invalidator &) {
599 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
630 : BaselineInfoImpl(
std::
move(BaselineInfoImpl)) {}
638 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
643 std::optional<TargetLibraryInfo> TLI;
645 virtual void anchor();
663 TLI = TLA.run(
F, DummyFAM);
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
This class holds the attributes for a particular argument, parameter, function, or return value.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
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...
This is the shared class of boolean and integer constants.
Class to represent function types.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
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.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
Check if the string is empty.
Analysis pass providing the TargetLibraryInfo.
TargetLibraryAnalysis()=default
Default construct the library analysis.
LLVM_ABI 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 ...
friend class TargetLibraryInfo
LLVM_ABI 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.
TargetLibraryInfoImpl()=delete
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
LLVM_ABI 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.
LLVM_ABI void addVectorizableFunctions(EnumStrings< VecDescData, 3 > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
LLVM_ABI unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
LLVM_ABI const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
Return a pointer to a VecDesc object holding all info for scalar to vector mappings in TLI for the eq...
static LLVM_ABI bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
bool isErrnoFunctionCall() const
void setShouldSignExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext attribute if they correspond t...
LLVM_ABI TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
LLVM_ABI void disableAllFunctions()
Disables all builtins.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
LLVM_ABI LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
LLVM_ABI 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()
The default constructor should not be used and is only for pass manager initialization purposes.
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
static Attribute::AttrKind getExtAttrForI32Param(const Triple &T, bool Signed=true)
static Attribute::AttrKind getExtAttrForI8Param(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 invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Handle invalidation from the pass manager.
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...
TargetLibraryInfo()=delete
ConstantInt * getAsSizeT(uint64_t V, const Module &M) const
Returns a constant materialized as a size_t type.
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.
static StringRef getStandardName(LibFunc F)
Return the canonical name for a LibFunc.
bool isFunctionVectorizable(StringRef F) const
bool has(LibFunc F) const
Tests whether a library function is available.
void disableAllFunctions()
Disables all builtins.
bool isErrnoFunctionCall() const
Returns whether errno is defined as a function call on known environments.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const
LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const
Searches for a function name using an Instruction Opcode.
TargetLibraryInfo & operator=(const TargetLibraryInfo &TLI)=default
TargetLibraryInfo(const TargetLibraryInfo &TLI)=default
static Attribute::AttrKind getExtAttrForBoolParam(const Triple &T)
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &ScalableVF) const
Returns the largest vectorization factor used in the list of vector functions.
LibFunc getLibFunc(const Function &FDecl) const
TargetLibraryInfo(const TargetLibraryInfoImpl &Impl, std::optional< const Function * > F=std::nullopt)
static Attribute::AttrKind getExtAttrForI32Return(const Triple &T, bool Signed=true)
IntegerType * getSizeTType(const Module &M) const
Returns an IntegerType corresponding to size_t.
static LLVM_ABI void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam, bool &ShouldZExtBoolReturn, const Triple &T)
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
StringRef getName(LibFunc F) const
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
TargetLibraryInfo & operator=(TargetLibraryInfo &&TLI)=default
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
friend class TargetLibraryInfoWrapperPass
TargetLibraryInfo(TargetLibraryInfo &&TLI)=default
static LLVM_ABI void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
friend class TargetLibraryAnalysis
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
LibFunc getLibFunc(const CallBase &CB) const
If a callbase does not have the 'nobuiltin' attribute, return the library function the callee is,...
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
Provides info so a possible vectorization of a function can be computed.
StringRef getVABIPrefix() const
std::optional< CallingConv::ID > getCallingConv() const
LLVM_ABI std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getScalarFnName() const
StringRef getVectorFnName() const
VecDesc(const EnumString< VecDescData, 3 > &Data)
ElementCount getVectorizationFactor() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
VectorLibrary
List of known vector-functions libraries.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
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...
unsigned CC
Encoded calling convention: 0 means absent (std::nullopt), otherwise stores CallingConv::ID + 1 so an...
ElementCount VectorizationFactor
constexpr VecDescData(ElementCount VectorizationFactor, bool Masked, std::optional< CallingConv::ID > Conv)