LLVM 23.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_strstr: case LibFunc_memchr:
427 case LibFunc_mempcpy: case LibFunc_tan: case LibFunc_tanf:
428 case LibFunc_tanl: case LibFunc_tanh: case LibFunc_tanhf:
429 case LibFunc_tanhl: case LibFunc_trunc: case LibFunc_truncf:
430 case LibFunc_truncl:
431 // clang-format on
432 return true;
433 }
434 return false;
435 }
436
437 /// Return the canonical name for a LibFunc. This should not be used for
438 /// semantic purposes, use getName instead.
439 static StringRef getStandardName(LibFunc F) {
440 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
441 TargetLibraryInfoImpl::StandardNamesOffsets[F]),
442 TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
443 }
444
445 StringRef getName(LibFunc F) const {
446 auto State = getState(F);
447 if (State == TargetLibraryInfoImpl::Unavailable)
448 return StringRef();
449 if (State == TargetLibraryInfoImpl::StandardName)
450 return StringRef(
451 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
452 Impl->StandardNamesSizeTable[F]);
453 assert(State == TargetLibraryInfoImpl::CustomName);
454 return Impl->CustomNames.find(F)->second;
455 }
456
457 static void initExtensionsForTriple(bool &ShouldExtI32Param,
458 bool &ShouldExtI32Return,
459 bool &ShouldSignExtI32Param,
460 bool &ShouldSignExtI32Return,
461 const Triple &T) {
462 ShouldExtI32Param = ShouldExtI32Return = false;
463 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
464
465 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
466 // returns corresponding to C-level ints and unsigned ints.
467 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
468 T.getArch() == Triple::systemz) {
469 ShouldExtI32Param = true;
470 ShouldExtI32Return = true;
471 }
472 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
473 // parameters corresponding to both signed and unsigned ints.
474 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
475 ShouldSignExtI32Param = true;
476 }
477 // LoongArch and riscv64 need signext on i32 returns corresponding to both
478 // signed and unsigned ints.
479 if (T.isLoongArch() || T.isRISCV64()) {
480 ShouldSignExtI32Return = true;
481 }
482 }
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 Signed = true) {
501 bool ShouldExtI32Param, ShouldExtI32Return;
502 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
503 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
504 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
505 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
506 Signed);
507 }
508
510 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
511 Impl->ShouldSignExtI32Param, Signed);
512 }
513
514 /// Returns extension attribute kind to be used for i32 return values
515 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
516 /// or none.
517private:
518 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
519 bool ShouldSignExtI32Return_,
520 bool Signed) {
521 if (ShouldExtI32Return_)
522 return Signed ? Attribute::SExt : Attribute::ZExt;
523 if (ShouldSignExtI32Return_)
524 return Attribute::SExt;
525 return Attribute::None;
526 }
527
528public:
530 bool Signed = true) {
531 bool ShouldExtI32Param, ShouldExtI32Return;
532 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
533 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
534 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
535 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
536 Signed);
537 }
538
540 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
541 Impl->ShouldSignExtI32Return, Signed);
542 }
543
544 // Helper to create an AttributeList for args (and ret val) which all have
545 // the same signedness. Attributes in AL may be passed in to include them
546 // as well in the returned AttributeList.
548 bool Signed, bool Ret = false,
549 AttributeList AL = AttributeList()) const {
550 if (auto AK = getExtAttrForI32Param(Signed))
551 for (auto ArgNo : ArgNos)
552 AL = AL.addParamAttribute(*C, ArgNo, AK);
553 if (Ret)
554 if (auto AK = getExtAttrForI32Return(Signed))
555 AL = AL.addRetAttribute(*C, AK);
556 return AL;
557 }
558
559 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
560 unsigned getWCharSize(const Module &M) const {
561 return Impl->getWCharSize(M);
562 }
563
564 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
565 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
566
567 /// Returns an IntegerType corresponding to size_t.
568 IntegerType *getSizeTType(const Module &M) const {
569 return IntegerType::get(M.getContext(), getSizeTSize(M));
570 }
571
572 /// Returns a constant materialized as a size_t type.
573 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
574 return ConstantInt::get(getSizeTType(M), V);
575 }
576
577 /// \copydoc TargetLibraryInfoImpl::getIntSize()
578 unsigned getIntSize() const {
579 return Impl->getIntSize();
580 }
581
582 /// Handle invalidation from the pass manager.
583 ///
584 /// If we try to invalidate this info, just return false. It cannot become
585 /// invalid even if the module or function changes.
587 ModuleAnalysisManager::Invalidator &) {
588 return false;
589 }
591 FunctionAnalysisManager::Invalidator &) {
592 return false;
593 }
594 /// Returns the largest vectorization factor used in the list of
595 /// vector functions.
596 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
597 ElementCount &ScalableVF) const {
598 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
599 }
600
601 /// Check if the function "F" is listed in a library known to LLVM.
603 return this->isFunctionVectorizable(F);
604 }
605};
606
607/// Analysis pass providing the \c TargetLibraryInfo.
608///
609/// Note that this pass's result cannot be invalidated, it is immutable for the
610/// life of the module.
611class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
612public:
614
615 /// Default construct the library analysis.
616 ///
617 /// This will use the module's triple to construct the library info for that
618 /// module.
620
621 /// Construct a library analysis with baseline Module-level info.
622 ///
623 /// This will be supplemented with Function-specific info in the Result.
625 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
626
628
629private:
631 LLVM_ABI static AnalysisKey Key;
632
633 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
634};
635
638 std::optional<TargetLibraryInfo> TLI;
639
640 virtual void anchor();
641
642public:
643 static char ID;
644
645 /// The default constructor should not be used and is only for pass manager
646 /// initialization purposes.
648
649 explicit TargetLibraryInfoWrapperPass(const Triple &T);
651
652 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
653 // PassManager inside a pass.
655
658 TLI = TLA.run(F, DummyFAM);
659 return *TLI;
660 }
661};
662
663} // end namespace llvm
664
665#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.
Definition Types.h:26
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:1915
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:870
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:93
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29