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 size_t type in bits.
249 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
250
251 /// Get size of a C-level int or unsigned int, in bits.
252 unsigned getIntSize() const {
253 return SizeOfInt;
254 }
255
256 /// Initialize the C-level size of an integer.
257 void setIntSize(unsigned Bits) {
258 SizeOfInt = Bits;
259 }
260
261 /// Returns the largest vectorization factor used in the list of
262 /// vector functions.
263 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
264 ElementCount &Scalable) const;
265
266 /// Returns true if call site / callee has cdecl-compatible calling
267 /// conventions.
269 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
270
271 bool isErrnoFunctionCall() const { return IsErrnoFunctionCall; }
272};
273
274/// Provides information about what library functions are available for
275/// the current target.
276///
277/// This both allows optimizations to handle them specially and frontends to
278/// disable such optimizations through -fno-builtin etc.
282
283 /// The global (module level) TLI info.
284 const TargetLibraryInfoImpl *Impl;
285
286 /// Support for -fno-builtin* options as function attributes, overrides
287 /// information in global TargetLibraryInfoImpl.
288 std::bitset<NumLibFuncs> OverrideAsUnavailable;
289
290public:
292
294 std::optional<const Function *> F = std::nullopt)
295 : Impl(&Impl) {
296 if (!F)
297 return;
298 if ((*F)->hasFnAttribute("no-builtins"))
300 else {
301 // Disable individual libc/libm calls in TargetLibraryInfo.
302 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
303 for (const Attribute &Attr : FnAttrs) {
304 if (!Attr.isStringAttribute())
305 continue;
306 auto AttrStr = Attr.getKindAsString();
307 if (!AttrStr.consume_front("no-builtin-"))
308 continue;
309 if (LibFunc LF = getLibFunc(AttrStr))
310 setUnavailable(LF);
311 }
312 }
313 }
314
315 // Provide value semantics.
320
321 /// Determine whether a callee with the given TLI can be inlined into
322 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
323 /// allow inlining into a caller with a superset of the callee's nobuiltin
324 /// attributes, which is conservatively correct.
326 bool AllowCallerSuperset) const {
327 if (!AllowCallerSuperset)
328 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
329 // We can inline if the callee's nobuiltin attributes are no stricter than
330 // the caller's.
331 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
332 }
333
334 /// Return true if the function type FTy is valid for the library function
335 /// F, regardless of whether the function is available.
336 bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
337 const Module &M) const {
338 return Impl->isValidProtoForLibFunc(FTy, F, M);
339 }
340
341 /// Searches for a particular function name.
342 ///
343 /// Returns the corresponding LibFunc if it is one of the known library
344 /// functions, and NotLibFunc otherwise.
345 LibFunc getLibFunc(StringRef funcName) const {
346 return Impl->getLibFunc(funcName);
347 }
348
349 LibFunc getLibFunc(const Function &FDecl) const {
350 return Impl->getLibFunc(FDecl);
351 }
352
353 /// If a callbase does not have the 'nobuiltin' attribute, return the library
354 /// function the callee is, and NotLibFunc otherwise.
355 LibFunc getLibFunc(const CallBase &CB) const {
356 if (CB.isNoBuiltin() || !CB.getCalledFunction())
357 return NotLibFunc;
358 return getLibFunc(*CB.getCalledFunction());
359 }
360
361 /// Searches for a function name using an Instruction \p Opcode.
362 /// Currently, only the frem instruction is supported.
363 ///
364 /// Returns NotLibFunc if there is no matching library function.
365 LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const {
366 return Impl->getLibFunc(Opcode, Ty);
367 }
368
369 /// Disables all builtins.
370 ///
371 /// This can be used for options like -fno-builtin.
372 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
373
374 /// Forces a function to be marked as unavailable.
375 [[maybe_unused]] void setUnavailable(LibFunc F) {
376 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
377 OverrideAsUnavailable.set(F);
378 }
379
380 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
381 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
382 if (OverrideAsUnavailable[F])
383 return TargetLibraryInfoImpl::Unavailable;
384 return Impl->getState(F);
385 }
386
387 /// Tests whether a library function is available.
388 bool has(LibFunc F) const {
389 return getState(F) != TargetLibraryInfoImpl::Unavailable;
390 }
392 return Impl->isFunctionVectorizable(F, VF);
393 }
395 return Impl->isFunctionVectorizable(F);
396 }
398 bool Masked = false) const {
399 return Impl->getVectorizedFunction(F, VF, Masked);
400 }
402 bool Masked) const {
403 return Impl->getVectorMappingInfo(F, VF, Masked);
404 }
405
406 /// Tests if the function is both available and a candidate for optimized code
407 /// generation.
408 bool hasOptimizedCodeGen(LibFunc F) const {
409 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
410 return false;
411 switch (F) {
412 default: break;
413 // clang-format off
414 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
415 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
416 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
417 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
418 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
419 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
420 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
421 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
422 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
423 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
424 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
425 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
426 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
427 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
428 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
429 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
430 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
431 case LibFunc_sqrtl_finite:
432 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
433 case LibFunc_strnlen: case LibFunc_strstr: case LibFunc_memchr:
434 case LibFunc_memccpy: case LibFunc_mempcpy: case LibFunc_tan:
435 case LibFunc_tanf: case LibFunc_tanl: case LibFunc_tanh:
436 case LibFunc_tanhf: case LibFunc_tanhl:
437 // clang-format on
438 return true;
439 }
440 return false;
441 }
442
443 /// Return the canonical name for a LibFunc. This should not be used for
444 /// semantic purposes, use getName instead.
445 static StringRef getStandardName(LibFunc F) {
446 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
447 TargetLibraryInfoImpl::StandardNamesOffsets[F]),
448 TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
449 }
450
451 StringRef getName(LibFunc F) const {
452 auto State = getState(F);
453 if (State == TargetLibraryInfoImpl::Unavailable)
454 return StringRef();
455 if (State == TargetLibraryInfoImpl::StandardName)
456 return StringRef(
457 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
458 Impl->StandardNamesSizeTable[F]);
459 assert(State == TargetLibraryInfoImpl::CustomName);
460 return Impl->CustomNames.find(F)->second;
461 }
462
463 LLVM_ABI static void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam,
464 bool &ShouldZExtBoolReturn,
465 const Triple &T);
466
467 LLVM_ABI static void initExtensionsForTriple(bool &ShouldExtI32Param,
468 bool &ShouldExtI32Return,
469 bool &ShouldSignExtI32Param,
470 bool &ShouldSignExtI32Return,
471 const Triple &T);
472
473 /// Returns extension attribute kind to be used for i32 parameters
474 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
475 /// or none.
476private:
477 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
478 bool ShouldSignExtI32Param_,
479 bool Signed = true) {
480 if (ShouldExtI32Param_)
481 return Signed ? Attribute::SExt : Attribute::ZExt;
482 if (ShouldSignExtI32Param_)
483 return Attribute::SExt;
484 return Attribute::None;
485 }
486
487public:
489 bool ShouldZExtBoolParam, ShouldZExtBoolReturn;
490 initBoolExtensionsForTriple(ShouldZExtBoolParam, ShouldZExtBoolReturn, T);
491 return ShouldZExtBoolParam ? Attribute::ZExt : Attribute::None;
492 }
493
495 // Return the extension attributes here even though nothing special is
496 // done in case any target needs something different in the future.
497 return Signed ? Attribute::SExt : Attribute::ZExt;
498 }
499
501 bool Signed = true) {
502 bool ShouldExtI32Param, ShouldExtI32Return;
503 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
504 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
505 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
506 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
507 Signed);
508 }
509
511 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
512 Impl->ShouldSignExtI32Param, Signed);
513 }
514
515 /// Returns extension attribute kind to be used for i32 return values
516 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
517 /// or none.
518private:
519 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
520 bool ShouldSignExtI32Return_,
521 bool Signed) {
522 if (ShouldExtI32Return_)
523 return Signed ? Attribute::SExt : Attribute::ZExt;
524 if (ShouldSignExtI32Return_)
525 return Attribute::SExt;
526 return Attribute::None;
527 }
528
529public:
531 bool Signed = true) {
532 bool ShouldExtI32Param, ShouldExtI32Return;
533 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
534 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
535 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
536 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
537 Signed);
538 }
539
541 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
542 Impl->ShouldSignExtI32Return, Signed);
543 }
544
545 // Helper to create an AttributeList for args (and ret val) which all have
546 // the same signedness. Attributes in AL may be passed in to include them
547 // as well in the returned AttributeList.
549 bool Signed, bool Ret = false,
550 AttributeList AL = AttributeList()) const {
551 if (auto AK = getExtAttrForI32Param(Signed))
552 for (auto ArgNo : ArgNos)
553 AL = AL.addParamAttribute(*C, ArgNo, AK);
554 if (Ret)
555 if (auto AK = getExtAttrForI32Return(Signed))
556 AL = AL.addRetAttribute(*C, AK);
557 return AL;
558 }
559
560 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
561 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
562
563 /// Returns an IntegerType corresponding to size_t.
564 IntegerType *getSizeTType(const Module &M) const {
565 return IntegerType::get(M.getContext(), getSizeTSize(M));
566 }
567
568 /// Returns a constant materialized as a size_t type.
570 return ConstantInt::get(getSizeTType(M), V);
571 }
572
573 /// \copydoc TargetLibraryInfoImpl::getIntSize()
574 unsigned getIntSize() const {
575 return Impl->getIntSize();
576 }
577
578 /// Handle invalidation from the pass manager.
579 ///
580 /// If we try to invalidate this info, just return false. It cannot become
581 /// invalid even if the module or function changes.
583 ModuleAnalysisManager::Invalidator &) {
584 return false;
585 }
587 FunctionAnalysisManager::Invalidator &) {
588 return false;
589 }
590 /// Returns the largest vectorization factor used in the list of
591 /// vector functions.
592 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
593 ElementCount &ScalableVF) const {
594 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
595 }
596
597 /// Check if the function "F" is listed in a library known to LLVM.
599 return this->isFunctionVectorizable(F);
600 }
601
602 /// Returns whether `errno` is defined as a function call on known
603 /// environments.
604 bool isErrnoFunctionCall() const { return Impl->isErrnoFunctionCall(); }
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
const TargetLowering & TLI
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:448
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:107
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:126
@ None
No attributes have been set.
Definition Attributes.h:128
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 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...
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.
static LLVM_ABI void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam, bool &ShouldZExtBoolReturn, const Triple &T)
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
StringRef getName(LibFunc F) const
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
TargetLibraryInfo & operator=(TargetLibraryInfo &&TLI)=default
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
friend class TargetLibraryInfoWrapperPass
TargetLibraryInfo(TargetLibraryInfo &&TLI)=default
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:879
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