LLVM 24.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"
14#include "llvm/IR/Constants.h"
15#include "llvm/IR/InstrTypes.h"
16#include "llvm/IR/Module.h"
17#include "llvm/IR/PassManager.h"
19#include "llvm/Pass.h"
22#include <bitset>
23#include <optional>
24
25namespace llvm {
26
27template <typename T> class ArrayRef;
28
29/// Provides info so a possible vectorization of a function can be
30/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
31/// vectorized by a factor 'VectorizationFactor'.
32/// The VABIPrefix string holds information about isa, mask, vlen,
33/// and vparams so a scalar-to-vector mapping of the form:
34/// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
35/// can be constructed where:
36///
37/// <isa> = "_LLVM_"
38/// <mask> = "M" if masked, "N" if no mask.
39/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor`
40/// field of the `VecDesc` struct. If the number of lanes is scalable
41/// then 'x' is printed instead.
42/// <vparams> = "v", as many as are the numArgs.
43/// <scalarname> = the name of the scalar function.
44/// <vectorname> = the name of the vector function.
45class VecDesc {
46 StringRef ScalarFnName;
47 StringRef VectorFnName;
48 ElementCount VectorizationFactor;
49 bool Masked;
50 StringRef VABIPrefix;
51 /// Encoded calling convention: 0 means absent (std::nullopt), otherwise
52 /// stores CallingConv::ID + 1 so an explicit C (0) remains representable.
53 /// TODO: Since C++20 standard becomes default in LLVM we can return back to
54 /// use std::optional<CallingConv::ID> instead of unsigned and value_or()
55 /// in default constructor.
56 unsigned CC;
57
58public:
59 VecDesc() = delete;
60 constexpr VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
61 ElementCount VectorizationFactor, bool Masked,
62 StringRef VABIPrefix, std::optional<CallingConv::ID> Conv)
63 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
64 VectorizationFactor(VectorizationFactor), Masked(Masked),
65 VABIPrefix(VABIPrefix),
66 CC(Conv ? static_cast<unsigned>(*Conv) + 1u : 0u) {}
67
68 StringRef getScalarFnName() const { return ScalarFnName; }
69 StringRef getVectorFnName() const { return VectorFnName; }
70 ElementCount getVectorizationFactor() const { return VectorizationFactor; }
71 bool isMasked() const { return Masked; }
72 StringRef getVABIPrefix() const { return VABIPrefix; }
73 std::optional<CallingConv::ID> getCallingConv() const {
74 if (CC == 0)
75 return std::nullopt;
76 return static_cast<CallingConv::ID>(CC - 1);
77 }
78
79 /// Returns a vector function ABI variant string on the form:
80 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
82};
83
84#define GET_TARGET_LIBRARY_INFO_ENUM
85#include "llvm/Analysis/TargetLibraryInfo.inc"
86
87/// Implementation of the target library information.
88///
89/// This class constructs tables that hold the target library information and
90/// make it available. However, it is somewhat expensive to compute and only
91/// depends on the triple. So users typically interact with the \c
92/// TargetLibraryInfo wrapper below.
94 friend class TargetLibraryInfo;
95
96 unsigned char AvailableArray[(NumLibFuncs+3)/4];
98#define GET_TARGET_LIBRARY_INFO_IMPL_DECL
99#include "llvm/Analysis/TargetLibraryInfo.inc"
100 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
101 unsigned SizeOfInt;
102 bool IsErrnoFunctionCall;
103
104 enum AvailabilityState {
105 StandardName = 3, // (memset to all ones)
106 CustomName = 1,
107 Unavailable = 0 // (memset to all zeros)
108 };
109 void setState(LibFunc F, AvailabilityState State) {
110 AvailableArray[F/4] &= ~(3 << 2*(F&3));
111 AvailableArray[F/4] |= State << 2*(F&3);
112 }
113 AvailabilityState getState(LibFunc F) const {
114 if (F == NotLibFunc)
115 return Unavailable;
116 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
117 }
118
119 /// Vectorization descriptors - sorted by ScalarFnName.
120 std::vector<VecDesc> VectorDescs;
121 /// Scalarization descriptors - same content as VectorDescs but sorted based
122 /// on VectorFnName rather than ScalarFnName.
123 std::vector<VecDesc> ScalarDescs;
124
125 /// Return true if the function type FTy is valid for the library function
126 /// F, regardless of whether the function is available.
127 LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
128 const Module &M) const;
129
130public:
134
135 // Provide value semantics.
140
141 /// Searches for a particular function name.
142 ///
143 /// Returns the corresponding LibFunc if it is one of the known library
144 /// functions, and NotLibFunc otherwise.
145 LLVM_ABI LibFunc getLibFunc(StringRef funcName) const;
146
147 /// Searches for a particular function name, also checking that its type is
148 /// valid for the library function matching that name.
149 ///
150 /// Returns the corresponding LibFunc if it is one of the known library
151 /// functions, and NotLibFunc otherwise.
152 ///
153 /// FDecl is assumed to have a parent Module when using this function.
154 LLVM_ABI LibFunc getLibFunc(const Function &FDecl) const;
155
156 /// Searches for a function name using an Instruction \p Opcode.
157 /// Currently, only the frem instruction is supported.
158 ///
159 /// Returns NotLibFunc if there is no matching library function.
160 LLVM_ABI LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const;
161
162 /// Forces a function to be marked as unavailable.
163 void setUnavailable(LibFunc F) {
164 setState(F, Unavailable);
165 }
166
167 /// Forces a function to be marked as available.
168 void setAvailable(LibFunc F) {
169 setState(F, StandardName);
170 }
171
172 /// Forces a function to be marked as available and provide an alternate name
173 /// that must be used.
174 void setAvailableWithName(LibFunc F, StringRef Name) {
175 if (StringRef(StandardNamesStrTable.getCString(StandardNamesOffsets[F]),
176 StandardNamesSizeTable[F]) != Name) {
177 setState(F, CustomName);
178 CustomNames[F] = std::string(Name);
179 assert(CustomNames.contains(F));
180 } else {
181 setState(F, StandardName);
182 }
183 }
184
185 /// Disables all builtins.
186 ///
187 /// This can be used for options like -fno-builtin.
189
190 /// Add a set of scalar -> vector mappings, queryable via
191 /// getVectorizedFunction and getScalarizedFunction.
193
194 /// Calls addVectorizableFunctions with a known preset of functions for the
195 /// given vector library.
196 LLVM_ABI void
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.
219 LLVM_ABI const VecDesc *
220 getVectorMappingInfo(StringRef F, const ElementCount &VF, 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.
249 /// This queries the 'wchar_size' metadata.
250 LLVM_ABI unsigned getWCharSize(const Module &M) const;
251
252 /// Returns the size of the size_t type in bits.
253 LLVM_ABI 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 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
268 ElementCount &Scalable) const;
269
270 /// Returns true if call site / callee has cdecl-compatible calling
271 /// conventions.
273 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
274
275 bool isErrnoFunctionCall() const { return IsErrnoFunctionCall; }
276};
277
278/// Provides information about what library functions are available for
279/// the current target.
280///
281/// This both allows optimizations to handle them specially and frontends to
282/// disable such optimizations through -fno-builtin etc.
286
287 /// The global (module level) TLI info.
288 const TargetLibraryInfoImpl *Impl;
289
290 /// Support for -fno-builtin* options as function attributes, overrides
291 /// information in global TargetLibraryInfoImpl.
292 std::bitset<NumLibFuncs> OverrideAsUnavailable;
293
294public:
296
298 std::optional<const Function *> F = std::nullopt)
299 : Impl(&Impl) {
300 if (!F)
301 return;
302 if ((*F)->hasFnAttribute("no-builtins"))
304 else {
305 // Disable individual libc/libm calls in TargetLibraryInfo.
306 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
307 for (const Attribute &Attr : FnAttrs) {
308 if (!Attr.isStringAttribute())
309 continue;
310 auto AttrStr = Attr.getKindAsString();
311 if (!AttrStr.consume_front("no-builtin-"))
312 continue;
313 if (LibFunc LF = getLibFunc(AttrStr))
314 setUnavailable(LF);
315 }
316 }
317 }
318
319 // Provide value semantics.
324
325 /// Determine whether a callee with the given TLI can be inlined into
326 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
327 /// allow inlining into a caller with a superset of the callee's nobuiltin
328 /// attributes, which is conservatively correct.
330 bool AllowCallerSuperset) const {
331 if (!AllowCallerSuperset)
332 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
333 // We can inline if the callee's nobuiltin attributes are no stricter than
334 // the caller's.
335 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
336 }
337
338 /// Return true if the function type FTy is valid for the library function
339 /// F, regardless of whether the function is available.
340 bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
341 const Module &M) const {
342 return Impl->isValidProtoForLibFunc(FTy, F, M);
343 }
344
345 /// Searches for a particular function name.
346 ///
347 /// Returns the corresponding LibFunc if it is one of the known library
348 /// functions, and NotLibFunc otherwise.
349 LibFunc getLibFunc(StringRef funcName) const {
350 return Impl->getLibFunc(funcName);
351 }
352
353 LibFunc getLibFunc(const Function &FDecl) const {
354 return Impl->getLibFunc(FDecl);
355 }
356
357 /// If a callbase does not have the 'nobuiltin' attribute, return the library
358 /// function the callee is, and NotLibFunc otherwise.
359 LibFunc getLibFunc(const CallBase &CB) const {
360 if (CB.isNoBuiltin() || !CB.getCalledFunction())
361 return NotLibFunc;
362 return getLibFunc(*CB.getCalledFunction());
363 }
364
365 /// Searches for a function name using an Instruction \p Opcode.
366 /// Currently, only the frem instruction is supported.
367 ///
368 /// Returns NotLibFunc if there is no matching library function.
369 LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const {
370 return Impl->getLibFunc(Opcode, Ty);
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.
412 bool hasOptimizedCodeGen(LibFunc F) const {
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_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
423 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
424 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
425 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
426 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
427 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
428 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
429 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
430 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
431 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
432 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
433 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
434 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
435 case LibFunc_sqrtl_finite:
436 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
437 case LibFunc_strnlen: case LibFunc_strstr: case LibFunc_memchr:
438 case LibFunc_memccpy: case LibFunc_mempcpy: case LibFunc_tan:
439 case LibFunc_tanf: case LibFunc_tanl: case LibFunc_tanh:
440 case LibFunc_tanhf: case LibFunc_tanhl:
441 // clang-format on
442 return true;
443 }
444 return false;
445 }
446
447 /// Return the canonical name for a LibFunc. This should not be used for
448 /// semantic purposes, use getName instead.
449 static StringRef getStandardName(LibFunc F) {
450 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
451 TargetLibraryInfoImpl::StandardNamesOffsets[F]),
452 TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
453 }
454
455 StringRef getName(LibFunc F) const {
456 auto State = getState(F);
457 if (State == TargetLibraryInfoImpl::Unavailable)
458 return StringRef();
459 if (State == TargetLibraryInfoImpl::StandardName)
460 return StringRef(
461 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
462 Impl->StandardNamesSizeTable[F]);
463 assert(State == TargetLibraryInfoImpl::CustomName);
464 return Impl->CustomNames.find(F)->second;
465 }
466
467 static void initExtensionsForTriple(bool &ShouldExtI32Param,
468 bool &ShouldExtI32Return,
469 bool &ShouldSignExtI32Param,
470 bool &ShouldSignExtI32Return,
471 const Triple &T) {
472 ShouldExtI32Param = ShouldExtI32Return = false;
473 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
474
475 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
476 // returns corresponding to C-level ints and unsigned ints.
477 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
478 T.getArch() == Triple::systemz) {
479 ShouldExtI32Param = true;
480 ShouldExtI32Return = true;
481 }
482 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
483 // parameters corresponding to both signed and unsigned ints.
484 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
485 ShouldSignExtI32Param = true;
486 }
487 // LoongArch and riscv64 need signext on i32 returns corresponding to both
488 // signed and unsigned ints.
489 if (T.isLoongArch() || T.isRISCV64()) {
490 ShouldSignExtI32Return = true;
491 }
492 }
493
494 /// Returns extension attribute kind to be used for i32 parameters
495 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
496 /// or none.
497private:
498 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
499 bool ShouldSignExtI32Param_,
500 bool Signed = true) {
501 if (ShouldExtI32Param_)
502 return Signed ? Attribute::SExt : Attribute::ZExt;
503 if (ShouldSignExtI32Param_)
504 return Attribute::SExt;
505 return Attribute::None;
506 }
507
508public:
510 bool Signed = true) {
511 bool ShouldExtI32Param, ShouldExtI32Return;
512 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
513 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
514 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
515 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
516 Signed);
517 }
518
520 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
521 Impl->ShouldSignExtI32Param, Signed);
522 }
523
524 /// Returns extension attribute kind to be used for i32 return values
525 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
526 /// or none.
527private:
528 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
529 bool ShouldSignExtI32Return_,
530 bool Signed) {
531 if (ShouldExtI32Return_)
532 return Signed ? Attribute::SExt : Attribute::ZExt;
533 if (ShouldSignExtI32Return_)
534 return Attribute::SExt;
535 return Attribute::None;
536 }
537
538public:
540 bool Signed = true) {
541 bool ShouldExtI32Param, ShouldExtI32Return;
542 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
543 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
544 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
545 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
546 Signed);
547 }
548
550 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
551 Impl->ShouldSignExtI32Return, Signed);
552 }
553
554 // Helper to create an AttributeList for args (and ret val) which all have
555 // the same signedness. Attributes in AL may be passed in to include them
556 // as well in the returned AttributeList.
558 bool Signed, bool Ret = false,
559 AttributeList AL = AttributeList()) const {
560 if (auto AK = getExtAttrForI32Param(Signed))
561 for (auto ArgNo : ArgNos)
562 AL = AL.addParamAttribute(*C, ArgNo, AK);
563 if (Ret)
564 if (auto AK = getExtAttrForI32Return(Signed))
565 AL = AL.addRetAttribute(*C, AK);
566 return AL;
567 }
568
569 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
570 unsigned getWCharSize(const Module &M) const {
571 return Impl->getWCharSize(M);
572 }
573
574 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
575 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
576
577 /// Returns an IntegerType corresponding to size_t.
578 IntegerType *getSizeTType(const Module &M) const {
579 return IntegerType::get(M.getContext(), getSizeTSize(M));
580 }
581
582 /// Returns a constant materialized as a size_t type.
583 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
584 return ConstantInt::get(getSizeTType(M), V);
585 }
586
587 /// \copydoc TargetLibraryInfoImpl::getIntSize()
588 unsigned getIntSize() const {
589 return Impl->getIntSize();
590 }
591
592 /// Handle invalidation from the pass manager.
593 ///
594 /// If we try to invalidate this info, just return false. It cannot become
595 /// invalid even if the module or function changes.
597 ModuleAnalysisManager::Invalidator &) {
598 return false;
599 }
601 FunctionAnalysisManager::Invalidator &) {
602 return false;
603 }
604 /// Returns the largest vectorization factor used in the list of
605 /// vector functions.
606 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
607 ElementCount &ScalableVF) const {
608 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
609 }
610
611 /// Check if the function "F" is listed in a library known to LLVM.
613 return this->isFunctionVectorizable(F);
614 }
615
616 /// Returns whether `errno` is defined as a function call on known
617 /// environments.
618 bool isErrnoFunctionCall() const { return Impl->isErrnoFunctionCall(); }
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!")
unsigned uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:215
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:942
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Definition GVN.cpp:944
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:54
#define T
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:407
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
@ None
No attributes have been set.
Definition Attributes.h:126
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:348
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
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.
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.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
LLVM_ABI LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
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 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.
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.
bool isErrnoFunctionCall() const
Returns whether errno is defined as a function call on known environments.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const
LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const
Searches for a function name using an Instruction Opcode.
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.
LibFunc getLibFunc(const Function &FDecl) const
TargetLibraryInfo(const TargetLibraryInfoImpl &Impl, std::optional< const Function * > F=std::nullopt)
static Attribute::AttrKind getExtAttrForI32Return(const Triple &T, bool Signed=true)
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)
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
LibFunc getLibFunc(const CallBase &CB) const
If a callbase does not have the 'nobuiltin' attribute, return the library function the callee is,...
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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
constexpr VecDesc(StringRef ScalarFnName, StringRef VectorFnName, ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix, std::optional< CallingConv::ID > Conv)
StringRef getVectorFnName() const
ElementCount getVectorizationFactor() const
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
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:1917
VectorLibrary
List of known vector-functions libraries.
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:878
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29