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