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 initBoolExtensionsForTriple(bool &ShouldZExtBoolParam,
468 bool &ShouldZExtBoolReturn,
469 const Triple &T) {
470 ShouldZExtBoolParam = ShouldZExtBoolReturn = false;
471
472 if (!T.isAArch64() && !T.isOSDarwin()) {
473 ShouldZExtBoolParam = true;
474 ShouldZExtBoolReturn = true;
475 }
476 }
477
478 LLVM_ABI static void initExtensionsForTriple(bool &ShouldExtI32Param,
479 bool &ShouldExtI32Return,
480 bool &ShouldSignExtI32Param,
481 bool &ShouldSignExtI32Return,
482 const Triple &T);
483
484 /// Returns extension attribute kind to be used for i32 parameters
485 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
486 /// or none.
487private:
488 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
489 bool ShouldSignExtI32Param_,
490 bool Signed = true) {
491 if (ShouldExtI32Param_)
492 return Signed ? Attribute::SExt : Attribute::ZExt;
493 if (ShouldSignExtI32Param_)
494 return Attribute::SExt;
495 return Attribute::None;
496 }
497
498public:
500 bool ShouldZExtBoolParam, ShouldZExtBoolReturn;
501 initBoolExtensionsForTriple(ShouldZExtBoolParam, ShouldZExtBoolReturn, T);
502 return ShouldZExtBoolParam ? Attribute::ZExt : Attribute::None;
503 }
504
506 // Return the extension attributes here even though nothing special is
507 // done in case any target needs something different in the future.
508 return Signed ? Attribute::SExt : Attribute::ZExt;
509 }
510
512 bool Signed = true) {
513 bool ShouldExtI32Param, ShouldExtI32Return;
514 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
515 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
516 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
517 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
518 Signed);
519 }
520
522 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
523 Impl->ShouldSignExtI32Param, Signed);
524 }
525
526 /// Returns extension attribute kind to be used for i32 return values
527 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
528 /// or none.
529private:
530 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
531 bool ShouldSignExtI32Return_,
532 bool Signed) {
533 if (ShouldExtI32Return_)
534 return Signed ? Attribute::SExt : Attribute::ZExt;
535 if (ShouldSignExtI32Return_)
536 return Attribute::SExt;
537 return Attribute::None;
538 }
539
540public:
542 bool Signed = true) {
543 bool ShouldExtI32Param, ShouldExtI32Return;
544 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
545 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
546 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
547 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
548 Signed);
549 }
550
552 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
553 Impl->ShouldSignExtI32Return, Signed);
554 }
555
556 // Helper to create an AttributeList for args (and ret val) which all have
557 // the same signedness. Attributes in AL may be passed in to include them
558 // as well in the returned AttributeList.
560 bool Signed, bool Ret = false,
561 AttributeList AL = AttributeList()) const {
562 if (auto AK = getExtAttrForI32Param(Signed))
563 for (auto ArgNo : ArgNos)
564 AL = AL.addParamAttribute(*C, ArgNo, AK);
565 if (Ret)
566 if (auto AK = getExtAttrForI32Return(Signed))
567 AL = AL.addRetAttribute(*C, AK);
568 return AL;
569 }
570
571 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
572 unsigned getWCharSize(const Module &M) const {
573 return Impl->getWCharSize(M);
574 }
575
576 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
577 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
578
579 /// Returns an IntegerType corresponding to size_t.
580 IntegerType *getSizeTType(const Module &M) const {
581 return IntegerType::get(M.getContext(), getSizeTSize(M));
582 }
583
584 /// Returns a constant materialized as a size_t type.
585 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
586 return ConstantInt::get(getSizeTType(M), V);
587 }
588
589 /// \copydoc TargetLibraryInfoImpl::getIntSize()
590 unsigned getIntSize() const {
591 return Impl->getIntSize();
592 }
593
594 /// Handle invalidation from the pass manager.
595 ///
596 /// If we try to invalidate this info, just return false. It cannot become
597 /// invalid even if the module or function changes.
599 ModuleAnalysisManager::Invalidator &) {
600 return false;
601 }
603 FunctionAnalysisManager::Invalidator &) {
604 return false;
605 }
606 /// Returns the largest vectorization factor used in the list of
607 /// vector functions.
608 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
609 ElementCount &ScalableVF) const {
610 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
611 }
612
613 /// Check if the function "F" is listed in a library known to LLVM.
615 return this->isFunctionVectorizable(F);
616 }
617
618 /// Returns whether `errno` is defined as a function call on known
619 /// environments.
620 bool isErrnoFunctionCall() const { return Impl->isErrnoFunctionCall(); }
621};
622
623/// Analysis pass providing the \c TargetLibraryInfo.
624///
625/// Note that this pass's result cannot be invalidated, it is immutable for the
626/// life of the module.
627class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
628public:
630
631 /// Default construct the library analysis.
632 ///
633 /// This will use the module's triple to construct the library info for that
634 /// module.
636
637 /// Construct a library analysis with baseline Module-level info.
638 ///
639 /// This will be supplemented with Function-specific info in the Result.
641 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
642
644
645private:
647 LLVM_ABI static AnalysisKey Key;
648
649 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
650};
651
654 std::optional<TargetLibraryInfo> TLI;
655
656 virtual void anchor();
657
658public:
659 static char ID;
660
661 /// The default constructor should not be used and is only for pass manager
662 /// initialization purposes.
664
665 explicit TargetLibraryInfoWrapperPass(const Triple &T);
667
668 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
669 // PassManager inside a pass.
671
674 TLI = TLA.run(F, DummyFAM);
675 return *TLI;
676 }
677};
678
679} // end namespace llvm
680
681#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:211
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:1229
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Definition GVN.cpp:1231
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:406
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
@ None
No attributes have been set.
Definition Attributes.h:127
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:285
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:338
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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)
static Attribute::AttrKind getExtAttrForI8Param(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
static Attribute::AttrKind getExtAttrForBoolParam(const Triple &T)
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.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
static void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam, bool &ShouldZExtBoolReturn, const Triple &T)
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
static LLVM_ABI void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
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:1933
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