LLVM 20.0.0git
TargetLibraryInfo.h
Go to the documentation of this file.
1//===-- TargetLibraryInfo.h - Library information ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
10#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/IR/InstrTypes.h"
14#include "llvm/IR/PassManager.h"
15#include "llvm/Pass.h"
17#include <bitset>
18#include <optional>
19
20namespace llvm {
21
22template <typename T> class ArrayRef;
23
24/// Provides info so a possible vectorization of a function can be
25/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
26/// vectorized by a factor 'VectorizationFactor'.
27/// The VABIPrefix string holds information about isa, mask, vlen,
28/// and vparams so a scalar-to-vector mapping of the form:
29/// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
30/// can be constructed where:
31///
32/// <isa> = "_LLVM_"
33/// <mask> = "M" if masked, "N" if no mask.
34/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor`
35/// field of the `VecDesc` struct. If the number of lanes is scalable
36/// then 'x' is printed instead.
37/// <vparams> = "v", as many as are the numArgs.
38/// <scalarname> = the name of the scalar function.
39/// <vectorname> = the name of the vector function.
40class VecDesc {
41 StringRef ScalarFnName;
42 StringRef VectorFnName;
44 bool Masked;
45 StringRef VABIPrefix;
46
47public:
48 VecDesc() = delete;
49 VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
50 ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix)
51 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
53 VABIPrefix(VABIPrefix) {}
54
55 StringRef getScalarFnName() const { return ScalarFnName; }
56 StringRef getVectorFnName() const { return VectorFnName; }
58 bool isMasked() const { return Masked; }
59 StringRef getVABIPrefix() const { return VABIPrefix; }
60
61 /// Returns a vector function ABI variant string on the form:
62 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
63 std::string getVectorFunctionABIVariantString() const;
64};
65
66 enum LibFunc : unsigned {
67#define TLI_DEFINE_ENUM
68#include "llvm/Analysis/TargetLibraryInfo.def"
69
72 };
73
74/// Implementation of the target library information.
75///
76/// This class constructs tables that hold the target library information and
77/// make it available. However, it is somewhat expensive to compute and only
78/// depends on the triple. So users typically interact with the \c
79/// TargetLibraryInfo wrapper below.
81 friend class TargetLibraryInfo;
82
83 unsigned char AvailableArray[(NumLibFuncs+3)/4];
85 static StringLiteral const StandardNames[NumLibFuncs];
86 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
87 unsigned SizeOfInt;
88
89 enum AvailabilityState {
90 StandardName = 3, // (memset to all ones)
91 CustomName = 1,
92 Unavailable = 0 // (memset to all zeros)
93 };
94 void setState(LibFunc F, AvailabilityState State) {
95 AvailableArray[F/4] &= ~(3 << 2*(F&3));
96 AvailableArray[F/4] |= State << 2*(F&3);
97 }
98 AvailabilityState getState(LibFunc F) const {
99 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
100 }
101
102 /// Vectorization descriptors - sorted by ScalarFnName.
103 std::vector<VecDesc> VectorDescs;
104 /// Scalarization descriptors - same content as VectorDescs but sorted based
105 /// on VectorFnName rather than ScalarFnName.
106 std::vector<VecDesc> ScalarDescs;
107
108 /// Return true if the function type FTy is valid for the library function
109 /// F, regardless of whether the function is available.
110 bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
111 const Module &M) const;
112
113public:
114 /// List of known vector-functions libraries.
115 ///
116 /// The vector-functions library defines, which functions are vectorizable
117 /// and with which factor. The library can be specified by either frontend,
118 /// or a commandline option, and then used by
119 /// addVectorizableFunctionsFromVecLib for filling up the tables of
120 /// vectorizable functions.
122 NoLibrary, // Don't use any vector library.
123 Accelerate, // Use Accelerate framework.
124 DarwinLibSystemM, // Use Darwin's libsystem_m.
125 LIBMVEC_X86, // GLIBC Vector Math library.
126 MASSV, // IBM MASS vector library.
127 SVML, // Intel short vector math library.
128 SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.
129 ArmPL, // Arm Performance Libraries.
130 AMDLIBM // AMD Math Vector library.
131 };
132
134 explicit TargetLibraryInfoImpl(const Triple &T);
135
136 // Provide value semantics.
141
142 /// Searches for a particular function name.
143 ///
144 /// If it is one of the known library functions, return true and set F to the
145 /// corresponding value.
146 bool getLibFunc(StringRef funcName, LibFunc &F) const;
147
148 /// Searches for a particular function name, also checking that its type is
149 /// valid for the library function matching that name.
150 ///
151 /// If it is one of the known library functions, return true and set F to the
152 /// corresponding value.
153 ///
154 /// FDecl is assumed to have a parent Module when using this function.
155 bool getLibFunc(const Function &FDecl, LibFunc &F) const;
156
157 /// Searches for a function name using an Instruction \p Opcode.
158 /// Currently, only the frem instruction is supported.
159 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
160
161 /// Forces a function to be marked as unavailable.
163 setState(F, Unavailable);
164 }
165
166 /// Forces a function to be marked as available.
168 setState(F, StandardName);
169 }
170
171 /// Forces a function to be marked as available and provide an alternate name
172 /// that must be used.
174 if (StandardNames[F] != Name) {
175 setState(F, CustomName);
176 CustomNames[F] = std::string(Name);
177 assert(CustomNames.contains(F));
178 } else {
179 setState(F, StandardName);
180 }
181 }
182
183 /// Disables all builtins.
184 ///
185 /// This can be used for options like -fno-builtin.
186 void disableAllFunctions();
187
188 /// Add a set of scalar -> vector mappings, queryable via
189 /// getVectorizedFunction and getScalarizedFunction.
191
192 /// Calls addVectorizableFunctions with a known preset of functions for the
193 /// given vector library.
195 const llvm::Triple &TargetTriple);
196
197 /// Return true if the function F has a vector equivalent with vectorization
198 /// factor VF.
200 return !(getVectorizedFunction(F, VF, false).empty() &&
201 getVectorizedFunction(F, VF, true).empty());
202 }
203
204 /// Return true if the function F has a vector equivalent with any
205 /// vectorization factor.
207
208 /// Return the name of the equivalent of F, vectorized with factor VF. If no
209 /// such mapping exists, return the empty string.
211 bool Masked) const;
212
213 /// Return a pointer to a VecDesc object holding all info for scalar to vector
214 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
215 /// If no such mapping exists, return nullpointer.
217 bool Masked) const;
218
219 /// Set to true iff i32 parameters to library functions should have signext
220 /// or zeroext attributes if they correspond to C-level int or unsigned int,
221 /// respectively.
222 void setShouldExtI32Param(bool Val) {
223 ShouldExtI32Param = Val;
224 }
225
226 /// Set to true iff i32 results from library functions should have signext
227 /// or zeroext attributes if they correspond to C-level int or unsigned int,
228 /// respectively.
229 void setShouldExtI32Return(bool Val) {
230 ShouldExtI32Return = Val;
231 }
232
233 /// Set to true iff i32 parameters to library functions should have signext
234 /// attribute if they correspond to C-level int or unsigned int.
236 ShouldSignExtI32Param = Val;
237 }
238
239 /// Set to true iff i32 results from library functions should have signext
240 /// attribute if they correspond to C-level int or unsigned int.
242 ShouldSignExtI32Return = Val;
243 }
244
245 /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
246 /// This queries the 'wchar_size' metadata.
247 unsigned getWCharSize(const Module &M) const;
248
249 /// Returns the size of the size_t type in bits.
250 unsigned getSizeTSize(const Module &M) const;
251
252 /// Get size of a C-level int or unsigned int, in bits.
253 unsigned getIntSize() const {
254 return SizeOfInt;
255 }
256
257 /// Initialize the C-level size of an integer.
258 void setIntSize(unsigned Bits) {
259 SizeOfInt = Bits;
260 }
261
262 /// Returns the largest vectorization factor used in the list of
263 /// vector functions.
264 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
265 ElementCount &Scalable) const;
266
267 /// Returns true if call site / callee has cdecl-compatible calling
268 /// conventions.
269 static bool isCallingConvCCompatible(CallBase *CI);
270 static bool isCallingConvCCompatible(Function *Callee);
271};
272
273/// Provides information about what library functions are available for
274/// the current target.
275///
276/// This both allows optimizations to handle them specially and frontends to
277/// disable such optimizations through -fno-builtin etc.
281
282 /// The global (module level) TLI info.
283 const TargetLibraryInfoImpl *Impl;
284
285 /// Support for -fno-builtin* options as function attributes, overrides
286 /// information in global TargetLibraryInfoImpl.
287 std::bitset<NumLibFuncs> OverrideAsUnavailable;
288
289public:
291 std::optional<const Function *> F = std::nullopt)
292 : Impl(&Impl) {
293 if (!F)
294 return;
295 if ((*F)->hasFnAttribute("no-builtins"))
297 else {
298 // Disable individual libc/libm calls in TargetLibraryInfo.
299 LibFunc LF;
300 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
301 for (const Attribute &Attr : FnAttrs) {
302 if (!Attr.isStringAttribute())
303 continue;
304 auto AttrStr = Attr.getKindAsString();
305 if (!AttrStr.consume_front("no-builtin-"))
306 continue;
307 if (getLibFunc(AttrStr, LF))
308 setUnavailable(LF);
309 }
310 }
311 }
312
313 // Provide value semantics.
318
319 /// Determine whether a callee with the given TLI can be inlined into
320 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
321 /// allow inlining into a caller with a superset of the callee's nobuiltin
322 /// attributes, which is conservatively correct.
324 bool AllowCallerSuperset) const {
325 if (!AllowCallerSuperset)
326 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
327 // We can inline if the callee's nobuiltin attributes are no stricter than
328 // the caller's.
329 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
330 }
331
332 /// Return true if the function type FTy is valid for the library function
333 /// F, regardless of whether the function is available.
335 const Module &M) const {
336 return Impl->isValidProtoForLibFunc(FTy, F, M);
337 }
338
339 /// Searches for a particular function name.
340 ///
341 /// If it is one of the known library functions, return true and set F to the
342 /// corresponding value.
343 bool getLibFunc(StringRef funcName, LibFunc &F) const {
344 return Impl->getLibFunc(funcName, F);
345 }
346
347 bool getLibFunc(const Function &FDecl, LibFunc &F) const {
348 return Impl->getLibFunc(FDecl, F);
349 }
350
351 /// If a callbase does not have the 'nobuiltin' attribute, return if the
352 /// called function is a known library function and set F to that function.
353 bool getLibFunc(const CallBase &CB, LibFunc &F) const {
354 return !CB.isNoBuiltin() && CB.getCalledFunction() &&
356 }
357
358 /// Searches for a function name using an Instruction \p Opcode.
359 /// Currently, only the frem instruction is supported.
360 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
361 return Impl->getLibFunc(Opcode, Ty, F);
362 }
363
364 /// Disables all builtins.
365 ///
366 /// This can be used for options like -fno-builtin.
368 OverrideAsUnavailable.set();
369 }
370
371 /// Forces a function to be marked as unavailable.
373 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
374 OverrideAsUnavailable.set(F);
375 }
376
377 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
378 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
379 if (OverrideAsUnavailable[F])
380 return TargetLibraryInfoImpl::Unavailable;
381 return Impl->getState(F);
382 }
383
384 /// Tests whether a library function is available.
385 bool has(LibFunc F) const {
386 return getState(F) != TargetLibraryInfoImpl::Unavailable;
387 }
389 return Impl->isFunctionVectorizable(F, VF);
390 }
392 return Impl->isFunctionVectorizable(F);
393 }
395 bool Masked = false) const {
396 return Impl->getVectorizedFunction(F, VF, Masked);
397 }
399 bool Masked) const {
400 return Impl->getVectorMappingInfo(F, VF, Masked);
401 }
402
403 /// Tests if the function is both available and a candidate for optimized code
404 /// generation.
406 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
407 return false;
408 switch (F) {
409 default: break;
410 // clang-format off
411 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
412 case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
413 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
414 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
415 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
416 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
417 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
418 case LibFunc_sqrtl_finite:
419 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
420 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
421 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
422 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
423 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
424 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
425 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
426 case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
427 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
428 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
429 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
430 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
431 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
432 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
433 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
434 // clang-format on
435 return true;
436 }
437 return false;
438 }
439
441 auto State = getState(F);
442 if (State == TargetLibraryInfoImpl::Unavailable)
443 return StringRef();
444 if (State == TargetLibraryInfoImpl::StandardName)
445 return Impl->StandardNames[F];
446 assert(State == TargetLibraryInfoImpl::CustomName);
447 return Impl->CustomNames.find(F)->second;
448 }
449
450 static void initExtensionsForTriple(bool &ShouldExtI32Param,
451 bool &ShouldExtI32Return,
452 bool &ShouldSignExtI32Param,
453 bool &ShouldSignExtI32Return,
454 const Triple &T) {
455 ShouldExtI32Param = ShouldExtI32Return = false;
456 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
457
458 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
459 // returns corresponding to C-level ints and unsigned ints.
460 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
461 T.getArch() == Triple::systemz) {
462 ShouldExtI32Param = true;
463 ShouldExtI32Return = true;
464 }
465 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
466 // parameters corresponding to both signed and unsigned ints.
467 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
468 ShouldSignExtI32Param = true;
469 }
470 // LoongArch and riscv64 need signext on i32 returns corresponding to both
471 // signed and unsigned ints.
472 if (T.isLoongArch() || T.isRISCV64()) {
473 ShouldSignExtI32Return = true;
474 }
475 }
476
477 /// Returns extension attribute kind to be used for i32 parameters
478 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
479 /// or none.
480private:
481 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
482 bool ShouldSignExtI32Param_,
483 bool Signed = true) {
484 if (ShouldExtI32Param_)
485 return Signed ? Attribute::SExt : Attribute::ZExt;
486 if (ShouldSignExtI32Param_)
487 return Attribute::SExt;
488 return Attribute::None;
489 }
490
491public:
493 bool Signed = true) {
494 bool ShouldExtI32Param, ShouldExtI32Return;
495 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
496 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
497 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
498 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
499 Signed);
500 }
501
503 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
504 Impl->ShouldSignExtI32Param, Signed);
505 }
506
507 /// Returns extension attribute kind to be used for i32 return values
508 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
509 /// or none.
510private:
511 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
512 bool ShouldSignExtI32Return_,
513 bool Signed) {
514 if (ShouldExtI32Return_)
515 return Signed ? Attribute::SExt : Attribute::ZExt;
516 if (ShouldSignExtI32Return_)
517 return Attribute::SExt;
518 return Attribute::None;
519 }
520
521public:
523 bool Signed = true) {
524 bool ShouldExtI32Param, ShouldExtI32Return;
525 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
526 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
527 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
528 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
529 Signed);
530 }
531
533 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
534 Impl->ShouldSignExtI32Return, Signed);
535 }
536
537 // Helper to create an AttributeList for args (and ret val) which all have
538 // the same signedness. Attributes in AL may be passed in to include them
539 // as well in the returned AttributeList.
541 bool Signed, bool Ret = false,
542 AttributeList AL = AttributeList()) const {
543 if (auto AK = getExtAttrForI32Param(Signed))
544 for (auto ArgNo : ArgNos)
545 AL = AL.addParamAttribute(*C, ArgNo, AK);
546 if (Ret)
547 if (auto AK = getExtAttrForI32Return(Signed))
548 AL = AL.addRetAttribute(*C, AK);
549 return AL;
550 }
551
552 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
553 unsigned getWCharSize(const Module &M) const {
554 return Impl->getWCharSize(M);
555 }
556
557 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
558 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
559
560 /// \copydoc TargetLibraryInfoImpl::getIntSize()
561 unsigned getIntSize() const {
562 return Impl->getIntSize();
563 }
564
565 /// Handle invalidation from the pass manager.
566 ///
567 /// If we try to invalidate this info, just return false. It cannot become
568 /// invalid even if the module or function changes.
571 return false;
572 }
575 return false;
576 }
577 /// Returns the largest vectorization factor used in the list of
578 /// vector functions.
579 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
580 ElementCount &ScalableVF) const {
581 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
582 }
583
584 /// Check if the function "F" is listed in a library known to LLVM.
586 return this->isFunctionVectorizable(F);
587 }
588};
589
590/// Analysis pass providing the \c TargetLibraryInfo.
591///
592/// Note that this pass's result cannot be invalidated, it is immutable for the
593/// life of the module.
594class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
595public:
597
598 /// Default construct the library analysis.
599 ///
600 /// This will use the module's triple to construct the library info for that
601 /// module.
603
604 /// Construct a library analysis with baseline Module-level info.
605 ///
606 /// This will be supplemented with Function-specific info in the Result.
608 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
609
611
612private:
614 static AnalysisKey Key;
615
616 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
617};
618
621 std::optional<TargetLibraryInfo> TLI;
622
623 virtual void anchor();
624
625public:
626 static char ID;
628 explicit TargetLibraryInfoWrapperPass(const Triple &T);
630
631 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
632 // PassManager inside a pass.
634
637 TLI = TLA.run(F, DummyFAM);
638 return *TLI;
639 }
640};
641
642} // end namespace llvm
643
644#endif
#define LLVM_ATTRIBUTE_UNUSED
Definition: Compiler.h:203
This file defines the DenseMap class.
std::string Name
AvailabilityState
Definition: GVN.cpp:872
@ Unavailable
We know the block is not fully available. This is a fixpoint.
#define F(x, y, z)
Definition: MD5.cpp:55
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.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition: Attributes.h:86
@ None
No attributes have been set.
Definition: Attributes.h:88
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1236
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Definition: InstrTypes.h:1965
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1465
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:155
Class to represent function types.
Definition: DerivedTypes.h:103
ImmutablePass class - This class is used to provide information that does not need to be run.
Definition: Pass.h:281
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:838
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
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.
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.
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)
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.
Definition: Triple.h:44
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
Provides info so a possible vectorization of a function can be computed.
StringRef getVABIPrefix() const
VecDesc()=delete
bool isMasked() const
std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
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.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
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.
Definition: STLExtras.h:1856
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition: PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition: Analysis.h:28
TODO: The following VectorizationFactor was pulled out of LoopVectorizationCostModel class.