LLVM 22.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/Constants.h"
14#include "llvm/IR/InstrTypes.h"
15#include "llvm/IR/Module.h"
16#include "llvm/IR/PassManager.h"
17#include "llvm/Pass.h"
20#include <bitset>
21#include <optional>
22
23namespace llvm {
24
25template <typename T> class ArrayRef;
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;
46 ElementCount VectorizationFactor;
47 bool Masked;
48 StringRef VABIPrefix;
49 std::optional<CallingConv::ID> CC;
50
51public:
52 VecDesc() = delete;
53 VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
54 ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix,
55 std::optional<CallingConv::ID> Conv)
56 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
57 VectorizationFactor(VectorizationFactor), Masked(Masked),
58 VABIPrefix(VABIPrefix), CC(Conv) {}
59
60 StringRef getScalarFnName() const { return ScalarFnName; }
61 StringRef getVectorFnName() const { return VectorFnName; }
62 ElementCount getVectorizationFactor() const { return VectorizationFactor; }
63 bool isMasked() const { return Masked; }
64 StringRef getVABIPrefix() const { return VABIPrefix; }
65 std::optional<CallingConv::ID> getCallingConv() const { return CC; }
66
67 /// Returns a vector function ABI variant string on the form:
68 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
70};
71
72 enum LibFunc : unsigned {
73#define TLI_DEFINE_ENUM
74#include "llvm/Analysis/TargetLibraryInfo.def"
75
78 };
79
80/// Implementation of the target library information.
81///
82/// This class constructs tables that hold the target library information and
83/// make it available. However, it is somewhat expensive to compute and only
84/// depends on the triple. So users typically interact with the \c
85/// TargetLibraryInfo wrapper below.
87 friend class TargetLibraryInfo;
88
89 unsigned char AvailableArray[(NumLibFuncs+3)/4];
91 LLVM_ABI static StringLiteral const StandardNames[NumLibFuncs];
92 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
93 unsigned SizeOfInt;
94
95 enum AvailabilityState {
96 StandardName = 3, // (memset to all ones)
97 CustomName = 1,
98 Unavailable = 0 // (memset to all zeros)
99 };
100 void setState(LibFunc F, AvailabilityState State) {
101 AvailableArray[F/4] &= ~(3 << 2*(F&3));
102 AvailableArray[F/4] |= State << 2*(F&3);
103 }
104 AvailabilityState getState(LibFunc F) const {
105 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
106 }
107
108 /// Vectorization descriptors - sorted by ScalarFnName.
109 std::vector<VecDesc> VectorDescs;
110 /// Scalarization descriptors - same content as VectorDescs but sorted based
111 /// on VectorFnName rather than ScalarFnName.
112 std::vector<VecDesc> ScalarDescs;
113
114 /// Return true if the function type FTy is valid for the library function
115 /// F, regardless of whether the function is available.
116 LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
117 const Module &M) const;
118
119public:
120 /// List of known vector-functions libraries.
121 ///
122 /// The vector-functions library defines, which functions are vectorizable
123 /// and with which factor. The library can be specified by either frontend,
124 /// or a commandline option, and then used by
125 /// addVectorizableFunctionsFromVecLib for filling up the tables of
126 /// vectorizable functions.
128 NoLibrary, // Don't use any vector library.
129 Accelerate, // Use Accelerate framework.
130 DarwinLibSystemM, // Use Darwin's libsystem_m.
131 LIBMVEC, // GLIBC Vector Math library.
132 MASSV, // IBM MASS vector library.
133 SVML, // Intel short vector math library.
134 SLEEFGNUABI, // SLEEF - SIMD Library for Evaluating Elementary Functions.
135 ArmPL, // Arm Performance Libraries.
136 AMDLIBM // AMD Math Vector library.
137 };
138
140 LLVM_ABI explicit TargetLibraryInfoImpl(const Triple &T);
141
142 // Provide value semantics.
147
148 /// Searches for a particular function name.
149 ///
150 /// If it is one of the known library functions, return true and set F to the
151 /// corresponding value.
152 LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const;
153
154 /// Searches for a particular function name, also checking that its type is
155 /// valid for the library function matching that name.
156 ///
157 /// If it is one of the known library functions, return true and set F to the
158 /// corresponding value.
159 ///
160 /// FDecl is assumed to have a parent Module when using this function.
161 LLVM_ABI bool getLibFunc(const Function &FDecl, LibFunc &F) const;
162
163 /// Searches for a function name using an Instruction \p Opcode.
164 /// Currently, only the frem instruction is supported.
165 LLVM_ABI bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
166
167 /// Forces a function to be marked as unavailable.
169 setState(F, Unavailable);
170 }
171
172 /// Forces a function to be marked as available.
174 setState(F, StandardName);
175 }
176
177 /// Forces a function to be marked as available and provide an alternate name
178 /// that must be used.
180 if (StandardNames[F] != Name) {
181 setState(F, CustomName);
182 CustomNames[F] = std::string(Name);
183 assert(CustomNames.contains(F));
184 } else {
185 setState(F, StandardName);
186 }
187 }
188
189 /// Disables all builtins.
190 ///
191 /// This can be used for options like -fno-builtin.
193
194 /// Add a set of scalar -> vector mappings, queryable via
195 /// getVectorizedFunction and getScalarizedFunction.
197
198 /// Calls addVectorizableFunctions with a known preset of functions for the
199 /// given vector library.
200 LLVM_ABI void
202 const llvm::Triple &TargetTriple);
203
204 /// Return true if the function F has a vector equivalent with vectorization
205 /// factor VF.
207 return !(getVectorizedFunction(F, VF, false).empty() &&
208 getVectorizedFunction(F, VF, true).empty());
209 }
210
211 /// Return true if the function F has a vector equivalent with any
212 /// vectorization factor.
214
215 /// Return the name of the equivalent of F, vectorized with factor VF. If no
216 /// such mapping exists, return the empty string.
218 bool Masked) const;
219
220 /// Return a pointer to a VecDesc object holding all info for scalar to vector
221 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
222 /// If no such mapping exists, return nullpointer.
223 LLVM_ABI const VecDesc *
224 getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const;
225
226 /// Set to true iff i32 parameters to library functions should have signext
227 /// or zeroext attributes if they correspond to C-level int or unsigned int,
228 /// respectively.
229 void setShouldExtI32Param(bool Val) {
230 ShouldExtI32Param = Val;
231 }
232
233 /// Set to true iff i32 results from library functions should have signext
234 /// or zeroext attributes if they correspond to C-level int or unsigned int,
235 /// respectively.
236 void setShouldExtI32Return(bool Val) {
237 ShouldExtI32Return = Val;
238 }
239
240 /// Set to true iff i32 parameters to library functions should have signext
241 /// attribute if they correspond to C-level int or unsigned int.
243 ShouldSignExtI32Param = Val;
244 }
245
246 /// Set to true iff i32 results from library functions should have signext
247 /// attribute if they correspond to C-level int or unsigned int.
249 ShouldSignExtI32Return = Val;
250 }
251
252 /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
253 /// This queries the 'wchar_size' metadata.
254 LLVM_ABI unsigned getWCharSize(const Module &M) const;
255
256 /// Returns the size of the size_t type in bits.
257 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
258
259 /// Get size of a C-level int or unsigned int, in bits.
260 unsigned getIntSize() const {
261 return SizeOfInt;
262 }
263
264 /// Initialize the C-level size of an integer.
265 void setIntSize(unsigned Bits) {
266 SizeOfInt = Bits;
267 }
268
269 /// Returns the largest vectorization factor used in the list of
270 /// vector functions.
271 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
272 ElementCount &Scalable) const;
273
274 /// Returns true if call site / callee has cdecl-compatible calling
275 /// conventions.
277 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
278};
279
280/// Provides information about what library functions are available for
281/// the current target.
282///
283/// This both allows optimizations to handle them specially and frontends to
284/// disable such optimizations through -fno-builtin etc.
288
289 /// The global (module level) TLI info.
290 const TargetLibraryInfoImpl *Impl;
291
292 /// Support for -fno-builtin* options as function attributes, overrides
293 /// information in global TargetLibraryInfoImpl.
294 std::bitset<NumLibFuncs> OverrideAsUnavailable;
295
296public:
298
300 std::optional<const Function *> F = std::nullopt)
301 : Impl(&Impl) {
302 if (!F)
303 return;
304 if ((*F)->hasFnAttribute("no-builtins"))
306 else {
307 // Disable individual libc/libm calls in TargetLibraryInfo.
308 LibFunc LF;
309 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
310 for (const Attribute &Attr : FnAttrs) {
311 if (!Attr.isStringAttribute())
312 continue;
313 auto AttrStr = Attr.getKindAsString();
314 if (!AttrStr.consume_front("no-builtin-"))
315 continue;
316 if (getLibFunc(AttrStr, LF))
317 setUnavailable(LF);
318 }
319 }
320 }
321
322 // Provide value semantics.
327
328 /// Determine whether a callee with the given TLI can be inlined into
329 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
330 /// allow inlining into a caller with a superset of the callee's nobuiltin
331 /// attributes, which is conservatively correct.
333 bool AllowCallerSuperset) const {
334 if (!AllowCallerSuperset)
335 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
336 // We can inline if the callee's nobuiltin attributes are no stricter than
337 // the caller's.
338 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
339 }
340
341 /// Return true if the function type FTy is valid for the library function
342 /// F, regardless of whether the function is available.
344 const Module &M) const {
345 return Impl->isValidProtoForLibFunc(FTy, F, M);
346 }
347
348 /// Searches for a particular function name.
349 ///
350 /// If it is one of the known library functions, return true and set F to the
351 /// corresponding value.
352 bool getLibFunc(StringRef funcName, LibFunc &F) const {
353 return Impl->getLibFunc(funcName, F);
354 }
355
356 bool getLibFunc(const Function &FDecl, LibFunc &F) const {
357 return Impl->getLibFunc(FDecl, F);
358 }
359
360 /// If a callbase does not have the 'nobuiltin' attribute, return if the
361 /// called function is a known library function and set F to that function.
362 bool getLibFunc(const CallBase &CB, LibFunc &F) const {
363 return !CB.isNoBuiltin() && CB.getCalledFunction() &&
365 }
366
367 /// Searches for a function name using an Instruction \p Opcode.
368 /// Currently, only the frem instruction is supported.
369 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
370 return Impl->getLibFunc(Opcode, Ty, F);
371 }
372
373 /// Disables all builtins.
374 ///
375 /// This can be used for options like -fno-builtin.
376 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
377
378 /// Forces a function to be marked as unavailable.
379 [[maybe_unused]] void setUnavailable(LibFunc F) {
380 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
381 OverrideAsUnavailable.set(F);
382 }
383
384 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
385 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
386 if (OverrideAsUnavailable[F])
387 return TargetLibraryInfoImpl::Unavailable;
388 return Impl->getState(F);
389 }
390
391 /// Tests whether a library function is available.
392 bool has(LibFunc F) const {
393 return getState(F) != TargetLibraryInfoImpl::Unavailable;
394 }
396 return Impl->isFunctionVectorizable(F, VF);
397 }
399 return Impl->isFunctionVectorizable(F);
400 }
402 bool Masked = false) const {
403 return Impl->getVectorizedFunction(F, VF, Masked);
404 }
406 bool Masked) const {
407 return Impl->getVectorMappingInfo(F, VF, Masked);
408 }
409
410 /// Tests if the function is both available and a candidate for optimized code
411 /// generation.
413 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
414 return false;
415 switch (F) {
416 default: break;
417 // clang-format off
418 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
419 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
420 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
421 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
422 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
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_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
429 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
430 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
431 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
432 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
433 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
434 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
435 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
436 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
437 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
438 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
439 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
440 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
441 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
442 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
443 case LibFunc_sqrtl_finite:
444 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
445 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
446 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
447 case LibFunc_tanh: case LibFunc_tanhf: case LibFunc_tanhl:
448 case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
449 // clang-format on
450 return true;
451 }
452 return false;
453 }
454
455 /// Return the canonical name for a LibFunc. This should not be used for
456 /// semantic purposes, use getName instead.
458 return TargetLibraryInfoImpl::StandardNames[F];
459 }
460
462 auto State = getState(F);
463 if (State == TargetLibraryInfoImpl::Unavailable)
464 return StringRef();
465 if (State == TargetLibraryInfoImpl::StandardName)
466 return Impl->StandardNames[F];
467 assert(State == TargetLibraryInfoImpl::CustomName);
468 return Impl->CustomNames.find(F)->second;
469 }
470
471 static void initExtensionsForTriple(bool &ShouldExtI32Param,
472 bool &ShouldExtI32Return,
473 bool &ShouldSignExtI32Param,
474 bool &ShouldSignExtI32Return,
475 const Triple &T) {
476 ShouldExtI32Param = ShouldExtI32Return = false;
477 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
478
479 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
480 // returns corresponding to C-level ints and unsigned ints.
481 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
482 T.getArch() == Triple::systemz) {
483 ShouldExtI32Param = true;
484 ShouldExtI32Return = true;
485 }
486 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
487 // parameters corresponding to both signed and unsigned ints.
488 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
489 ShouldSignExtI32Param = true;
490 }
491 // LoongArch and riscv64 need signext on i32 returns corresponding to both
492 // signed and unsigned ints.
493 if (T.isLoongArch() || T.isRISCV64()) {
494 ShouldSignExtI32Return = true;
495 }
496 }
497
498 /// Returns extension attribute kind to be used for i32 parameters
499 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
500 /// or none.
501private:
502 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
503 bool ShouldSignExtI32Param_,
504 bool Signed = true) {
505 if (ShouldExtI32Param_)
506 return Signed ? Attribute::SExt : Attribute::ZExt;
507 if (ShouldSignExtI32Param_)
508 return Attribute::SExt;
509 return Attribute::None;
510 }
511
512public:
514 bool Signed = true) {
515 bool ShouldExtI32Param, ShouldExtI32Return;
516 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
517 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
518 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
519 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
520 Signed);
521 }
522
524 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
525 Impl->ShouldSignExtI32Param, Signed);
526 }
527
528 /// Returns extension attribute kind to be used for i32 return values
529 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
530 /// or none.
531private:
532 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
533 bool ShouldSignExtI32Return_,
534 bool Signed) {
535 if (ShouldExtI32Return_)
536 return Signed ? Attribute::SExt : Attribute::ZExt;
537 if (ShouldSignExtI32Return_)
538 return Attribute::SExt;
539 return Attribute::None;
540 }
541
542public:
544 bool Signed = true) {
545 bool ShouldExtI32Param, ShouldExtI32Return;
546 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
547 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
548 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
549 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
550 Signed);
551 }
552
554 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
555 Impl->ShouldSignExtI32Return, Signed);
556 }
557
558 // Helper to create an AttributeList for args (and ret val) which all have
559 // the same signedness. Attributes in AL may be passed in to include them
560 // as well in the returned AttributeList.
562 bool Signed, bool Ret = false,
563 AttributeList AL = AttributeList()) const {
564 if (auto AK = getExtAttrForI32Param(Signed))
565 for (auto ArgNo : ArgNos)
566 AL = AL.addParamAttribute(*C, ArgNo, AK);
567 if (Ret)
568 if (auto AK = getExtAttrForI32Return(Signed))
569 AL = AL.addRetAttribute(*C, AK);
570 return AL;
571 }
572
573 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
574 unsigned getWCharSize(const Module &M) const {
575 return Impl->getWCharSize(M);
576 }
577
578 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
579 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
580
581 /// Returns an IntegerType corresponding to size_t.
582 IntegerType *getSizeTType(const Module &M) const {
583 return IntegerType::get(M.getContext(), getSizeTSize(M));
584 }
585
586 /// Returns a constant materialized as a size_t type.
587 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
588 return ConstantInt::get(getSizeTType(M), V);
589 }
590
591 /// \copydoc TargetLibraryInfoImpl::getIntSize()
592 unsigned getIntSize() const {
593 return Impl->getIntSize();
594 }
595
596 /// Handle invalidation from the pass manager.
597 ///
598 /// If we try to invalidate this info, just return false. It cannot become
599 /// invalid even if the module or function changes.
601 ModuleAnalysisManager::Invalidator &) {
602 return false;
603 }
605 FunctionAnalysisManager::Invalidator &) {
606 return false;
607 }
608 /// Returns the largest vectorization factor used in the list of
609 /// vector functions.
610 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
611 ElementCount &ScalableVF) const {
612 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
613 }
614
615 /// Check if the function "F" is listed in a library known to LLVM.
617 return this->isFunctionVectorizable(F);
618 }
619};
620
621/// Analysis pass providing the \c TargetLibraryInfo.
622///
623/// Note that this pass's result cannot be invalidated, it is immutable for the
624/// life of the module.
625class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
626public:
628
629 /// Default construct the library analysis.
630 ///
631 /// This will use the module's triple to construct the library info for that
632 /// module.
634
635 /// Construct a library analysis with baseline Module-level info.
636 ///
637 /// This will be supplemented with Function-specific info in the Result.
639 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
640
642
643private:
645 LLVM_ABI static AnalysisKey Key;
646
647 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
648};
649
652 std::optional<TargetLibraryInfo> TLI;
653
654 virtual void anchor();
655
656public:
657 static char ID;
658
659 /// The default constructor should not be used and is only for pass manager
660 /// initialization purposes.
662
663 explicit TargetLibraryInfoWrapperPass(const Triple &T);
665
666 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
667 // PassManager inside a pass.
669
672 TLI = TLA.run(F, DummyFAM);
673 return *TLI;
674 }
675};
676
677} // end namespace llvm
678
679#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition Compiler.h:213
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
AvailabilityState
Definition GVN.cpp:947
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:55
Machine Check Debug Module
#define T
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:88
@ None
No attributes have been set.
Definition Attributes.h:90
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.
Definition Constants.h:87
Class to represent function types.
ImmutablePass(char &pid)
Definition Pass.h:287
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.
Definition Type.cpp:319
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
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 ...
LLVM_ABI unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
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.
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 unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
LLVM_ABI void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
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.
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.
VectorLibrary
List of known vector-functions libraries.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
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)
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.
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.
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
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.
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.
friend class TargetLibraryInfoWrapperPass
TargetLibraryInfo(TargetLibraryInfo &&TLI)=default
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
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:47
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::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
ElementCount getVectorizationFactor() const
VecDesc(StringRef ScalarFnName, StringRef VectorFnName, ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix, std::optional< CallingConv::ID > Conv)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
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.
Definition STLExtras.h:1867
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29