LLVM: include/llvm/Analysis/TargetLibraryInfo.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
10#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
11
19#include
20#include
21
22namespace llvm {
23
24template class ArrayRef;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
46 bool Masked;
48
49public:
53 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
55 VABIPrefix(VABIPrefix) {}
56
62
63
64
66};
67
69#define TLI_DEFINE_ENUM
70#include "llvm/Analysis/TargetLibraryInfo.def"
71
75
76
77
78
79
80
81
84
85 unsigned char AvailableArray[(NumLibFuncs+3)/4];
88 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
89 unsigned SizeOfInt;
90
91 enum AvailabilityState {
92 StandardName = 3,
93 CustomName = 1,
95 };
97 AvailableArray[F/4] &= ~(3 << 2*(F&3));
98 AvailableArray[F/4] |= State << 2*(F&3);
99 }
101 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
102 }
103
104
105 std::vector VectorDescs;
106
107
108 std::vector ScalarDescs;
109
110
111
113 const Module &M) const;
114
115public:
116
117
118
119
120
121
122
132 AMDLIBM
134
137
138
143
144
145
146
147
149
150
151
152
153
154
155
156
158
159
160
162
163
166 }
167
168
170 setState(F, StandardName);
171 }
172
173
174
176 if (StandardNames[F] != Name) {
177 setState(F, CustomName);
178 CustomNames[F] = std::string(Name);
179 assert(CustomNames.contains(F));
180 } else {
181 setState(F, StandardName);
182 }
183 }
184
185
186
187
189
190
191
193
194
195
198
199
200
204 }
205
206
207
209
210
211
214
215
216
217
220
221
222
223
225 ShouldExtI32Param = Val;
226 }
227
228
229
230
232 ShouldExtI32Return = Val;
233 }
234
235
236
238 ShouldSignExtI32Param = Val;
239 }
240
241
242
244 ShouldSignExtI32Return = Val;
245 }
246
247
248
250
251
253
254
256 return SizeOfInt;
257 }
258
259
261 SizeOfInt = Bits;
262 }
263
264
265
268
269
270
273};
274
275
276
277
278
279
283
284
286
287
288
289 std::bitset OverrideAsUnavailable;
290
291public:
293 std::optional<const Function *> F = std::nullopt)
294 : Impl(&Impl) {
295 if ()
296 return;
297 if ((*F)->hasFnAttribute("no-builtins"))
299 else {
300
302 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
303 for (const Attribute &Attr : FnAttrs) {
304 if (!Attr.isStringAttribute())
305 continue;
306 auto AttrStr = Attr.getKindAsString();
307 if (!AttrStr.consume_front("no-builtin-"))
308 continue;
311 }
312 }
313 }
314
315
320
321
322
323
324
326 bool AllowCallerSuperset) const {
327 if (!AllowCallerSuperset)
328 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
329
330
331 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
332 }
333
334
335
337 const Module &M) const {
338 return Impl->isValidProtoForLibFunc(FTy, F, M);
339 }
340
341
342
343
344
347 }
348
351 }
352
353
354
358 }
359
360
361
364 }
365
366
367
368
370 OverrideAsUnavailable.set();
371 }
372
373
375 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
376 OverrideAsUnavailable.set(F);
377 }
378
380 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
381 if (OverrideAsUnavailable[F])
382 return TargetLibraryInfoImpl::Unavailable;
383 return Impl->getState(F);
384 }
385
386
388 return getState(F) != TargetLibraryInfoImpl::Unavailable;
389 }
392 }
395 }
397 bool Masked = false) const {
399 }
403 }
404
405
406
408 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
409 return false;
410 switch (F) {
411 default: break;
412
413 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
414 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
415 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
416 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
417 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
418 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
419 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
420 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
421 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
422 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
423 case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
424 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
425 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
426 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
427 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
428 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
429 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
430 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
431 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
432 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
433 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
434 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
435 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
436 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
437 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
438 case LibFunc_sqrtl_finite:
439 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
440 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
441 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
442 case LibFunc_tanh: case LibFunc_tanhf: case LibFunc_tanhl:
443 case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
444
445 return true;
446 }
447 return false;
448 }
449
452 if (State == TargetLibraryInfoImpl::Unavailable)
454 if (State == TargetLibraryInfoImpl::StandardName)
455 return Impl->StandardNames[F];
456 assert(State == TargetLibraryInfoImpl::CustomName);
457 return Impl->CustomNames.find(F)->second;
458 }
459
461 bool &ShouldExtI32Return,
462 bool &ShouldSignExtI32Param,
463 bool &ShouldSignExtI32Return,
465 ShouldExtI32Param = ShouldExtI32Return = false;
466 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
467
468
469
472 ShouldExtI32Param = true;
473 ShouldExtI32Return = true;
474 }
475
476
477 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
478 ShouldSignExtI32Param = true;
479 }
480
481
482 if (T.isLoongArch() || T.isRISCV64()) {
483 ShouldSignExtI32Return = true;
484 }
485 }
486
487
488
489
490private:
491 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
492 bool ShouldSignExtI32Param_,
493 bool Signed = true) {
494 if (ShouldExtI32Param_)
495 return Signed ? Attribute::SExt : Attribute::ZExt;
496 if (ShouldSignExtI32Param_)
497 return Attribute::SExt;
499 }
500
501public:
503 bool Signed = true) {
504 bool ShouldExtI32Param, ShouldExtI32Return;
505 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
507 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
508 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
510 }
511
513 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
514 Impl->ShouldSignExtI32Param, Signed);
515 }
516
517
518
519
520private:
521 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
522 bool ShouldSignExtI32Return_,
524 if (ShouldExtI32Return_)
525 return Signed ? Attribute::SExt : Attribute::ZExt;
526 if (ShouldSignExtI32Return_)
527 return Attribute::SExt;
529 }
530
531public:
533 bool Signed = true) {
534 bool ShouldExtI32Param, ShouldExtI32Return;
535 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
537 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
538 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
540 }
541
543 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
544 Impl->ShouldSignExtI32Return, Signed);
545 }
546
547
548
549
551 bool Signed, bool Ret = false,
553 if (auto AK = getExtAttrForI32Param(Signed))
554 for (auto ArgNo : ArgNos)
555 AL = AL.addParamAttribute(*C, ArgNo, AK);
556 if (Ret)
557 if (auto AK = getExtAttrForI32Return(Signed))
558 AL = AL.addRetAttribute(*C, AK);
559 return AL;
560 }
561
562
565 }
566
567
569
570
573 }
574
575
578 }
579
580
583 }
584
585
586
587
588
591 return false;
592 }
595 return false;
596 }
597
598
601 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
602 }
603
604
607 }
608};
609
610
611
612
613
615public:
617
618
619
620
621
623
624
625
626
628 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
629
631
632private:
635
636 std::optional BaselineInfoImpl;
637};
638
641 std::optional TLI;
642
643 virtual void anchor();
644
645public:
650
651
652
654
657 TLI = TLA.run(F, DummyFAM);
658 return *TLI;
659 }
660};
661
662}
663
664#endif
#define LLVM_ATTRIBUTE_UNUSED
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.
Machine Check Debug Module
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...
This is the shared class of boolean and integer constants.
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.
Class to represent integer types.
static 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.
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...
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 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
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.
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.
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.
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.
IntegerType * getSizeTType(const Module &M) const
Returns an IntegerType corresponding to size_t.
static void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const
Searches for a function name using an Instruction Opcode.
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.
TargetLibraryInfo(TargetLibraryInfo &&TLI)=default
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
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::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV(<...
StringRef getScalarFnName() const
VecDesc(StringRef ScalarFnName, StringRef VectorFnName, ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix)
StringRef getVectorFnName() const
ElementCount getVectorizationFactor() const
@ 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.
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...
TODO: The following VectorizationFactor was pulled out of LoopVectorizationCostModel class.