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"
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 std::optional<CallingConv::ID> CC;
52
53public:
54 VecDesc() = delete;
55 VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
56 ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix,
57 std::optional<CallingConv::ID> Conv)
58 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
59 VectorizationFactor(VectorizationFactor), Masked(Masked),
60 VABIPrefix(VABIPrefix), CC(Conv) {}
61
62 StringRef getScalarFnName() const { return ScalarFnName; }
63 StringRef getVectorFnName() const { return VectorFnName; }
64 ElementCount getVectorizationFactor() const { return VectorizationFactor; }
65 bool isMasked() const { return Masked; }
66 StringRef getVABIPrefix() const { return VABIPrefix; }
67 std::optional<CallingConv::ID> getCallingConv() const { return CC; }
68
69 /// Returns a vector function ABI variant string on the form:
70 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
72};
73
74#define GET_TARGET_LIBRARY_INFO_ENUM
75#include "llvm/Analysis/TargetLibraryInfo.inc"
76
77/// Implementation of the target library information.
78///
79/// This class constructs tables that hold the target library information and
80/// make it available. However, it is somewhat expensive to compute and only
81/// depends on the triple. So users typically interact with the \c
82/// TargetLibraryInfo wrapper below.
84 friend class TargetLibraryInfo;
85
86 unsigned char AvailableArray[(NumLibFuncs+3)/4];
88#define GET_TARGET_LIBRARY_INFO_IMPL_DECL
89#include "llvm/Analysis/TargetLibraryInfo.inc"
90 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
91 unsigned SizeOfInt;
92
94 StandardName = 3, // (memset to all ones)
95 CustomName = 1,
96 Unavailable = 0 // (memset to all zeros)
97 };
98 void setState(LibFunc F, AvailabilityState State) {
99 AvailableArray[F/4] &= ~(3 << 2*(F&3));
100 AvailableArray[F/4] |= State << 2*(F&3);
101 }
102 AvailabilityState getState(LibFunc F) const {
103 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
104 }
105
106 /// Vectorization descriptors - sorted by ScalarFnName.
107 std::vector<VecDesc> VectorDescs;
108 /// Scalarization descriptors - same content as VectorDescs but sorted based
109 /// on VectorFnName rather than ScalarFnName.
110 std::vector<VecDesc> ScalarDescs;
111
112 /// Return true if the function type FTy is valid for the library function
113 /// F, regardless of whether the function is available.
114 LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
115 const Module &M) const;
116
117public:
121
122 // Provide value semantics.
127
128 /// Searches for a particular function name.
129 ///
130 /// If it is one of the known library functions, return true and set F to the
131 /// corresponding value.
132 LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const;
133
134 /// Searches for a particular function name, also checking that its type is
135 /// valid for the library function matching that name.
136 ///
137 /// If it is one of the known library functions, return true and set F to the
138 /// corresponding value.
139 ///
140 /// FDecl is assumed to have a parent Module when using this function.
141 LLVM_ABI bool getLibFunc(const Function &FDecl, LibFunc &F) const;
142
143 /// Searches for a function name using an Instruction \p Opcode.
144 /// Currently, only the frem instruction is supported.
145 LLVM_ABI bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
146
147 /// Forces a function to be marked as unavailable.
148 void setUnavailable(LibFunc F) {
149 setState(F, Unavailable);
150 }
151
152 /// Forces a function to be marked as available.
153 void setAvailable(LibFunc F) {
154 setState(F, StandardName);
155 }
156
157 /// Forces a function to be marked as available and provide an alternate name
158 /// that must be used.
159 void setAvailableWithName(LibFunc F, StringRef Name) {
160 if (StringRef(StandardNamesStrTable.getCString(StandardNamesOffsets[F]),
161 StandardNamesSizeTable[F]) != Name) {
162 setState(F, CustomName);
163 CustomNames[F] = std::string(Name);
164 assert(CustomNames.contains(F));
165 } else {
166 setState(F, StandardName);
167 }
168 }
169
170 /// Disables all builtins.
171 ///
172 /// This can be used for options like -fno-builtin.
174
175 /// Add a set of scalar -> vector mappings, queryable via
176 /// getVectorizedFunction and getScalarizedFunction.
178
179 /// Calls addVectorizableFunctions with a known preset of functions for the
180 /// given vector library.
181 LLVM_ABI void
183 const llvm::Triple &TargetTriple);
184
185 /// Return true if the function F has a vector equivalent with vectorization
186 /// factor VF.
188 return !(getVectorizedFunction(F, VF, false).empty() &&
189 getVectorizedFunction(F, VF, true).empty());
190 }
191
192 /// Return true if the function F has a vector equivalent with any
193 /// vectorization factor.
195
196 /// Return the name of the equivalent of F, vectorized with factor VF. If no
197 /// such mapping exists, return the empty string.
199 bool Masked) const;
200
201 /// Return a pointer to a VecDesc object holding all info for scalar to vector
202 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
203 /// If no such mapping exists, return nullpointer.
204 LLVM_ABI const VecDesc *
205 getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const;
206
207 /// Set to true iff i32 parameters to library functions should have signext
208 /// or zeroext attributes if they correspond to C-level int or unsigned int,
209 /// respectively.
210 void setShouldExtI32Param(bool Val) {
211 ShouldExtI32Param = Val;
212 }
213
214 /// Set to true iff i32 results from library functions should have signext
215 /// or zeroext attributes if they correspond to C-level int or unsigned int,
216 /// respectively.
217 void setShouldExtI32Return(bool Val) {
218 ShouldExtI32Return = Val;
219 }
220
221 /// Set to true iff i32 parameters to library functions should have signext
222 /// attribute if they correspond to C-level int or unsigned int.
224 ShouldSignExtI32Param = Val;
225 }
226
227 /// Set to true iff i32 results from library functions should have signext
228 /// attribute if they correspond to C-level int or unsigned int.
230 ShouldSignExtI32Return = Val;
231 }
232
233 /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
234 /// This queries the 'wchar_size' metadata.
235 LLVM_ABI unsigned getWCharSize(const Module &M) const;
236
237 /// Returns the size of the size_t type in bits.
238 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
239
240 /// Get size of a C-level int or unsigned int, in bits.
241 unsigned getIntSize() const {
242 return SizeOfInt;
243 }
244
245 /// Initialize the C-level size of an integer.
246 void setIntSize(unsigned Bits) {
247 SizeOfInt = Bits;
248 }
249
250 /// Returns the largest vectorization factor used in the list of
251 /// vector functions.
252 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
253 ElementCount &Scalable) const;
254
255 /// Returns true if call site / callee has cdecl-compatible calling
256 /// conventions.
258 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
259};
260
261/// Provides information about what library functions are available for
262/// the current target.
263///
264/// This both allows optimizations to handle them specially and frontends to
265/// disable such optimizations through -fno-builtin etc.
269
270 /// The global (module level) TLI info.
271 const TargetLibraryInfoImpl *Impl;
272
273 /// Support for -fno-builtin* options as function attributes, overrides
274 /// information in global TargetLibraryInfoImpl.
275 std::bitset<NumLibFuncs> OverrideAsUnavailable;
276
277public:
279
281 std::optional<const Function *> F = std::nullopt)
282 : Impl(&Impl) {
283 if (!F)
284 return;
285 if ((*F)->hasFnAttribute("no-builtins"))
287 else {
288 // Disable individual libc/libm calls in TargetLibraryInfo.
289 LibFunc LF;
290 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
291 for (const Attribute &Attr : FnAttrs) {
292 if (!Attr.isStringAttribute())
293 continue;
294 auto AttrStr = Attr.getKindAsString();
295 if (!AttrStr.consume_front("no-builtin-"))
296 continue;
297 if (getLibFunc(AttrStr, LF))
298 setUnavailable(LF);
299 }
300 }
301 }
302
303 // Provide value semantics.
308
309 /// Determine whether a callee with the given TLI can be inlined into
310 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
311 /// allow inlining into a caller with a superset of the callee's nobuiltin
312 /// attributes, which is conservatively correct.
314 bool AllowCallerSuperset) const {
315 if (!AllowCallerSuperset)
316 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
317 // We can inline if the callee's nobuiltin attributes are no stricter than
318 // the caller's.
319 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
320 }
321
322 /// Return true if the function type FTy is valid for the library function
323 /// F, regardless of whether the function is available.
324 bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
325 const Module &M) const {
326 return Impl->isValidProtoForLibFunc(FTy, F, M);
327 }
328
329 /// Searches for a particular function name.
330 ///
331 /// If it is one of the known library functions, return true and set F to the
332 /// corresponding value.
333 bool getLibFunc(StringRef funcName, LibFunc &F) const {
334 return Impl->getLibFunc(funcName, F);
335 }
336
337 bool getLibFunc(const Function &FDecl, LibFunc &F) const {
338 return Impl->getLibFunc(FDecl, F);
339 }
340
341 /// If a callbase does not have the 'nobuiltin' attribute, return if the
342 /// called function is a known library function and set F to that function.
343 bool getLibFunc(const CallBase &CB, LibFunc &F) const {
344 return !CB.isNoBuiltin() && CB.getCalledFunction() &&
346 }
347
348 /// Searches for a function name using an Instruction \p Opcode.
349 /// Currently, only the frem instruction is supported.
350 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
351 return Impl->getLibFunc(Opcode, Ty, F);
352 }
353
354 /// Disables all builtins.
355 ///
356 /// This can be used for options like -fno-builtin.
357 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
358
359 /// Forces a function to be marked as unavailable.
360 [[maybe_unused]] void setUnavailable(LibFunc F) {
361 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
362 OverrideAsUnavailable.set(F);
363 }
364
365 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
366 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
367 if (OverrideAsUnavailable[F])
368 return TargetLibraryInfoImpl::Unavailable;
369 return Impl->getState(F);
370 }
371
372 /// Tests whether a library function is available.
373 bool has(LibFunc F) const {
374 return getState(F) != TargetLibraryInfoImpl::Unavailable;
375 }
377 return Impl->isFunctionVectorizable(F, VF);
378 }
380 return Impl->isFunctionVectorizable(F);
381 }
383 bool Masked = false) const {
384 return Impl->getVectorizedFunction(F, VF, Masked);
385 }
387 bool Masked) const {
388 return Impl->getVectorMappingInfo(F, VF, Masked);
389 }
390
391 /// Tests if the function is both available and a candidate for optimized code
392 /// generation.
393 bool hasOptimizedCodeGen(LibFunc F) const {
394 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
395 return false;
396 switch (F) {
397 default: break;
398 // clang-format off
399 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
400 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
401 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
402 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
403 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
404 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
405 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
406 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
407 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
408 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
409 case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
410 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
411 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
412 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
413 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
414 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
415 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
416 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
417 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
418 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
419 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
420 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
421 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
422 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
423 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
424 case LibFunc_sqrtl_finite:
425 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
426 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
427 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
428 case LibFunc_tanh: case LibFunc_tanhf: case LibFunc_tanhl:
429 case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
430 // clang-format on
431 return true;
432 }
433 return false;
434 }
435
436 /// Return the canonical name for a LibFunc. This should not be used for
437 /// semantic purposes, use getName instead.
438 static StringRef getStandardName(LibFunc F) {
439 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
440 TargetLibraryInfoImpl::StandardNamesOffsets[F]),
441 TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
442 }
443
444 StringRef getName(LibFunc F) const {
445 auto State = getState(F);
446 if (State == TargetLibraryInfoImpl::Unavailable)
447 return StringRef();
448 if (State == TargetLibraryInfoImpl::StandardName)
449 return StringRef(
450 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
451 Impl->StandardNamesSizeTable[F]);
452 assert(State == TargetLibraryInfoImpl::CustomName);
453 return Impl->CustomNames.find(F)->second;
454 }
455
456 static void initExtensionsForTriple(bool &ShouldExtI32Param,
457 bool &ShouldExtI32Return,
458 bool &ShouldSignExtI32Param,
459 bool &ShouldSignExtI32Return,
460 const Triple &T) {
461 ShouldExtI32Param = ShouldExtI32Return = false;
462 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
463
464 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
465 // returns corresponding to C-level ints and unsigned ints.
466 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
467 T.getArch() == Triple::systemz) {
468 ShouldExtI32Param = true;
469 ShouldExtI32Return = true;
470 }
471 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
472 // parameters corresponding to both signed and unsigned ints.
473 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
474 ShouldSignExtI32Param = true;
475 }
476 // LoongArch and riscv64 need signext on i32 returns corresponding to both
477 // signed and unsigned ints.
478 if (T.isLoongArch() || T.isRISCV64()) {
479 ShouldSignExtI32Return = true;
480 }
481 }
482
483 /// Returns extension attribute kind to be used for i32 parameters
484 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
485 /// or none.
486private:
487 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
488 bool ShouldSignExtI32Param_,
489 bool Signed = true) {
490 if (ShouldExtI32Param_)
491 return Signed ? Attribute::SExt : Attribute::ZExt;
492 if (ShouldSignExtI32Param_)
493 return Attribute::SExt;
494 return Attribute::None;
495 }
496
497public:
499 bool Signed = true) {
500 bool ShouldExtI32Param, ShouldExtI32Return;
501 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
502 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
503 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
504 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
505 Signed);
506 }
507
509 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
510 Impl->ShouldSignExtI32Param, Signed);
511 }
512
513 /// Returns extension attribute kind to be used for i32 return values
514 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
515 /// or none.
516private:
517 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
518 bool ShouldSignExtI32Return_,
519 bool Signed) {
520 if (ShouldExtI32Return_)
521 return Signed ? Attribute::SExt : Attribute::ZExt;
522 if (ShouldSignExtI32Return_)
523 return Attribute::SExt;
524 return Attribute::None;
525 }
526
527public:
529 bool Signed = true) {
530 bool ShouldExtI32Param, ShouldExtI32Return;
531 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
532 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
533 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
534 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
535 Signed);
536 }
537
539 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
540 Impl->ShouldSignExtI32Return, Signed);
541 }
542
543 // Helper to create an AttributeList for args (and ret val) which all have
544 // the same signedness. Attributes in AL may be passed in to include them
545 // as well in the returned AttributeList.
547 bool Signed, bool Ret = false,
548 AttributeList AL = AttributeList()) const {
549 if (auto AK = getExtAttrForI32Param(Signed))
550 for (auto ArgNo : ArgNos)
551 AL = AL.addParamAttribute(*C, ArgNo, AK);
552 if (Ret)
553 if (auto AK = getExtAttrForI32Return(Signed))
554 AL = AL.addRetAttribute(*C, AK);
555 return AL;
556 }
557
558 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
559 unsigned getWCharSize(const Module &M) const {
560 return Impl->getWCharSize(M);
561 }
562
563 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
564 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
565
566 /// Returns an IntegerType corresponding to size_t.
567 IntegerType *getSizeTType(const Module &M) const {
568 return IntegerType::get(M.getContext(), getSizeTSize(M));
569 }
570
571 /// Returns a constant materialized as a size_t type.
572 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
573 return ConstantInt::get(getSizeTType(M), V);
574 }
575
576 /// \copydoc TargetLibraryInfoImpl::getIntSize()
577 unsigned getIntSize() const {
578 return Impl->getIntSize();
579 }
580
581 /// Handle invalidation from the pass manager.
582 ///
583 /// If we try to invalidate this info, just return false. It cannot become
584 /// invalid even if the module or function changes.
586 ModuleAnalysisManager::Invalidator &) {
587 return false;
588 }
590 FunctionAnalysisManager::Invalidator &) {
591 return false;
592 }
593 /// Returns the largest vectorization factor used in the list of
594 /// vector functions.
595 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
596 ElementCount &ScalableVF) const {
597 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
598 }
599
600 /// Check if the function "F" is listed in a library known to LLVM.
602 return this->isFunctionVectorizable(F);
603 }
604};
605
606/// Analysis pass providing the \c TargetLibraryInfo.
607///
608/// Note that this pass's result cannot be invalidated, it is immutable for the
609/// life of the module.
610class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
611public:
613
614 /// Default construct the library analysis.
615 ///
616 /// This will use the module's triple to construct the library info for that
617 /// module.
619
620 /// Construct a library analysis with baseline Module-level info.
621 ///
622 /// This will be supplemented with Function-specific info in the Result.
624 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
625
627
628private:
630 LLVM_ABI static AnalysisKey Key;
631
632 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
633};
634
637 std::optional<TargetLibraryInfo> TLI;
638
639 virtual void anchor();
640
641public:
642 static char ID;
643
644 /// The default constructor should not be used and is only for pass manager
645 /// initialization purposes.
647
648 explicit TargetLibraryInfoWrapperPass(const Triple &T);
650
651 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
652 // PassManager inside a pass.
654
657 TLI = TLA.run(F, DummyFAM);
658 return *TLI;
659 }
660};
661
662} // end namespace llvm
663
664#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
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Definition GVN.cpp:949
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
Machine Check Debug Module
#define T
ArrayRef - 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: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:318
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
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.
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
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:867
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29