9 #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H 10 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H 23 template <
typename T>
class ArrayRef;
35 #define TLI_DEFINE_ENUM 36 #include "llvm/Analysis/TargetLibraryInfo.def" 54 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param;
56 enum AvailabilityState {
61 void setState(
LibFunc F, AvailabilityState State) {
62 AvailableArray[F/4] &= ~(3 << 2*(F&3));
63 AvailableArray[F/4] |= State << 2*(F&3);
65 AvailabilityState getState(
LibFunc F)
const {
66 return static_cast<AvailabilityState
>((AvailableArray[F/4] >> 2*(F&3)) & 3);
70 std::vector<VecDesc> VectorDescs;
73 std::vector<VecDesc> ScalarDescs;
119 setState(F, Unavailable);
124 setState(F, StandardName);
130 if (StandardNames[F] != Name) {
131 setState(F, CustomName);
132 CustomNames[
F] =
Name;
133 assert(CustomNames.find(F) != CustomNames.end());
135 setState(F, StandardName);
142 void disableAllFunctions();
150 void addVectorizableFunctionsFromVecLib(
enum VectorLibrary VecLib);
155 return !getVectorizedFunction(F, VF).empty();
160 bool isFunctionVectorizable(
StringRef F)
const;
169 return !getScalarizedFunction(F, VF).empty();
182 ShouldExtI32Param = Val;
189 ShouldExtI32Return = Val;
195 ShouldSignExtI32Param = Val;
200 unsigned getWCharSize(
const Module &M)
const;
204 unsigned getWidestVF(
StringRef ScalarF)
const;
226 : Impl(&Impl), OverrideAsUnavailable(
NumLibFuncs) {
229 if ((*F)->hasFnAttribute(
"no-builtins"))
230 disableAllFunctions();
234 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttributes();
236 if (!Attr.isStringAttribute())
238 auto AttrStr = Attr.getKindAsString();
239 if (!AttrStr.consume_front(
"no-builtin-"))
241 if (getLibFunc(AttrStr, LF))
249 : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
251 : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
254 OverrideAsUnavailable = TLI.OverrideAsUnavailable;
259 OverrideAsUnavailable = TLI.OverrideAsUnavailable;
286 OverrideAsUnavailable.
set();
291 OverrideAsUnavailable.
set(
F);
295 if (OverrideAsUnavailable[F])
296 return TargetLibraryInfoImpl::Unavailable;
297 return Impl->getState(F);
302 return getState(F) != TargetLibraryInfoImpl::Unavailable;
317 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
321 case LibFunc_copysign:
case LibFunc_copysignf:
case LibFunc_copysignl:
322 case LibFunc_fabs:
case LibFunc_fabsf:
case LibFunc_fabsl:
323 case LibFunc_sin:
case LibFunc_sinf:
case LibFunc_sinl:
324 case LibFunc_cos:
case LibFunc_cosf:
case LibFunc_cosl:
325 case LibFunc_sqrt:
case LibFunc_sqrtf:
case LibFunc_sqrtl:
326 case LibFunc_sqrt_finite:
case LibFunc_sqrtf_finite:
327 case LibFunc_sqrtl_finite:
328 case LibFunc_fmax:
case LibFunc_fmaxf:
case LibFunc_fmaxl:
329 case LibFunc_fmin:
case LibFunc_fminf:
case LibFunc_fminl:
330 case LibFunc_floor:
case LibFunc_floorf:
case LibFunc_floorl:
331 case LibFunc_nearbyint:
case LibFunc_nearbyintf:
case LibFunc_nearbyintl:
332 case LibFunc_ceil:
case LibFunc_ceilf:
case LibFunc_ceill:
333 case LibFunc_rint:
case LibFunc_rintf:
case LibFunc_rintl:
334 case LibFunc_round:
case LibFunc_roundf:
case LibFunc_roundl:
335 case LibFunc_trunc:
case LibFunc_truncf:
case LibFunc_truncl:
336 case LibFunc_log2:
case LibFunc_log2f:
case LibFunc_log2l:
337 case LibFunc_exp2:
case LibFunc_exp2f:
case LibFunc_exp2l:
338 case LibFunc_memcmp:
case LibFunc_bcmp:
case LibFunc_strcmp:
339 case LibFunc_strcpy:
case LibFunc_stpcpy:
case LibFunc_strlen:
340 case LibFunc_strnlen:
case LibFunc_memchr:
case LibFunc_mempcpy:
347 auto State = getState(F);
348 if (State == TargetLibraryInfoImpl::Unavailable)
350 if (State == TargetLibraryInfoImpl::StandardName)
351 return Impl->StandardNames[
F];
352 assert(State == TargetLibraryInfoImpl::CustomName);
353 return Impl->CustomNames.
find(F)->second;
360 if (Impl->ShouldExtI32Param)
361 return Signed ? Attribute::SExt : Attribute::ZExt;
362 if (Impl->ShouldSignExtI32Param)
363 return Attribute::SExt;
371 if (Impl->ShouldExtI32Return)
372 return Signed ? Attribute::SExt : Attribute::ZExt;
419 : BaselineInfoImpl(
std::move(BaselineInfoImpl)) {}
434 virtual void anchor();
444 TLI = TLA.
run(F, DummyFAM);
unsigned getWidestVF(StringRef ScalarF) const
Returns the largest vectorization factor used in the list of vector functions.
A parsed version of the target data layout string in and methods for querying it. ...
This class represents lattice values for constants.
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
VectorLibrary
List of known vector-functions libraries.
TargetLibraryInfo(const TargetLibraryInfoImpl &Impl, Optional< const Function *> F=None)
TargetLibraryInfo(const TargetLibraryInfo &TLI)
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
StringRef getName(LibFunc F) const
void disableAllFunctions() LLVM_ATTRIBUTE_UNUSED
Disables all builtins.
Implementation of the target library information.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
TargetLibraryInfo & operator=(const TargetLibraryInfo &TLI)
bool isFunctionScalarizable(StringRef F, unsigned &VF) const
Return true if the function F has a scalar equivalent, and set VF to be the vectorization factor...
bool getLibFunc(const Function &FDecl, LibFunc &F) const
TargetLibraryInfo & operator=(TargetLibraryInfo &&TLI)
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
Returns extension attribute kind to be used for i32 parameters corresponding to C-level int or unsign...
TargetLibraryAnalysis()
Default construct the library analysis.
Attribute::AttrKind getExtAttrForI32Return(bool Signed=true) const
Returns extension attribute kind to be used for i32 return values corresponding to C-level int or uns...
No attributes have been set.
void setUnavailable(LibFunc F) LLVM_ATTRIBUTE_UNUSED
Forces a function to be marked as unavailable.
Class to represent function types.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool has(LibFunc F) const
Tests whether a library function is available.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
iterator find(const_arg_type_t< KeyT > Val)
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
A set of analyses that are preserved following a run of a transformation pass.
bool isFunctionVectorizable(StringRef F, unsigned VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
A CRTP mix-in that provides informational APIs needed for analysis passes.
#define LLVM_ATTRIBUTE_UNUSED
TargetLibraryInfo & getTLI(const Function &F)
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const
Triple - Helper class for working with autoconf configuration names.
unsigned VectorizationFactor
ImmutablePass class - This class is used to provide information that does not need to be run...
Describes a possible vectorization of a function.
bool isFunctionVectorizable(StringRef F, unsigned VF) const
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
StringRef getVectorizedFunction(StringRef F, unsigned VF) const
Return the name of the equivalent of F, vectorized with factor VF.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
StringRef getVectorizedFunction(StringRef F, unsigned VF) const
TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
bool getLibFunc(ImmutableCallSite CS, LibFunc &F) const
If a callsite does not have the 'nobuiltin' attribute, return if the called function is a known libra...
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
TargetLibraryAnalysis(TargetLibraryInfoImpl BaselineInfoImpl)
Construct a library analysis with baseline Module-level info.
bool isFunctionVectorizable(StringRef F) const
Establish a view to a call site for examination.
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
API to communicate dependencies between analyses during invalidation.
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Handle invalidation from the pass manager.
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used...
StringRef - Represent a constant reference to a string, i.e.
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
TargetLibraryInfo(TargetLibraryInfo &&TLI)
void setAvailable(LibFunc F)
Forces a function to be marked as available.
unsigned getWidestVF(StringRef ScalarF) const
Returns the largest vectorization factor used in the list of vector functions.
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
A special type used by analysis passes to provide an address that identifies that particular analysis...
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...