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"
13#include "llvm/ADT/Enum.h"
15#include "llvm/IR/Constants.h"
16#include "llvm/IR/InstrTypes.h"
17#include "llvm/IR/Module.h"
18#include "llvm/IR/PassManager.h"
20#include "llvm/Pass.h"
23#include <bitset>
24#include <optional>
25
26namespace llvm {
27
28template <typename T> class ArrayRef;
29
32 bool Masked = false;
33 /// Encoded calling convention: 0 means absent (std::nullopt), otherwise
34 /// stores CallingConv::ID + 1 so an explicit C (0) remains representable.
35 /// TODO: Since C++20 standard becomes default in LLVM we can return back to
36 /// use std::optional<CallingConv::ID> instead of unsigned and value_or()
37 /// in default constructor.
38 unsigned CC = 0;
39
40 constexpr VecDescData() {};
42 std::optional<CallingConv::ID> Conv)
44 CC(Conv ? static_cast<unsigned>(*Conv) + 1u : 0u) {}
45};
46
47/// Provides info so a possible vectorization of a function can be
48/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
49/// vectorized by a factor 'VectorizationFactor'.
50/// The VABIPrefix string holds information about isa, mask, vlen,
51/// and vparams so a scalar-to-vector mapping of the form:
52/// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
53/// can be constructed where:
54///
55/// <isa> = "_LLVM_"
56/// <mask> = "M" if masked, "N" if no mask.
57/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor`
58/// field of the `VecDesc` struct. If the number of lanes is scalable
59/// then 'x' is printed instead.
60/// <vparams> = "v", as many as are the numArgs.
61/// <scalarname> = the name of the scalar function.
62/// <vectorname> = the name of the vector function.
63class VecDesc {
64 // String 0 is ScalarFnName, 1 is VectorFnName, 2 is VABIPrefix.
66
67public:
68 VecDesc(const EnumString<VecDescData, 3> &Data) : Data(&Data) {}
69
70 StringRef getScalarFnName() const { return Data->name(0); }
71 StringRef getVectorFnName() const { return Data->name(1); }
73 return Data->value().VectorizationFactor;
74 }
75 bool isMasked() const { return Data->value().Masked; }
76 StringRef getVABIPrefix() const { return Data->name(2); }
77 std::optional<CallingConv::ID> getCallingConv() const {
78 unsigned CC = Data->value().CC;
79 if (CC == 0)
80 return std::nullopt;
81 return static_cast<CallingConv::ID>(CC - 1);
82 }
83
84 /// Returns a vector function ABI variant string on the form:
85 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
87};
88
89#define GET_TARGET_LIBRARY_INFO_ENUM
90#include "llvm/Analysis/TargetLibraryInfo.inc"
91
92/// Implementation of the target library information.
93///
94/// This class constructs tables that hold the target library information and
95/// make it available. However, it is somewhat expensive to compute and only
96/// depends on the triple. So users typically interact with the \c
97/// TargetLibraryInfo wrapper below.
99 friend class TargetLibraryInfo;
100
101 unsigned char AvailableArray[(NumLibFuncs+3)/4];
103#define GET_TARGET_LIBRARY_INFO_IMPL_DECL
104#include "llvm/Analysis/TargetLibraryInfo.inc"
105 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
106 unsigned SizeOfInt;
107 bool IsErrnoFunctionCall;
108
109 enum AvailabilityState {
110 StandardName = 3, // (memset to all ones)
111 CustomName = 1,
112 Unavailable = 0 // (memset to all zeros)
113 };
114 void setState(LibFunc F, AvailabilityState State) {
115 AvailableArray[F/4] &= ~(3 << 2*(F&3));
116 AvailableArray[F/4] |= State << 2*(F&3);
117 }
118 AvailabilityState getState(LibFunc F) const {
119 if (F == NotLibFunc)
120 return Unavailable;
121 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
122 }
123
124 /// Vectorization descriptors - sorted by ScalarFnName.
125 std::vector<VecDesc> VectorDescs;
126 /// Scalarization descriptors - same content as VectorDescs but sorted based
127 /// on VectorFnName rather than ScalarFnName.
128 std::vector<VecDesc> ScalarDescs;
129
130 /// Return true if the function type FTy is valid for the library function
131 /// F, regardless of whether the function is available.
132 LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
133 const Module &M) const;
134
135public:
139
140 // Provide value semantics.
145
146 /// Searches for a particular function name.
147 ///
148 /// Returns the corresponding LibFunc if it is one of the known library
149 /// functions, and NotLibFunc otherwise.
150 LLVM_ABI LibFunc getLibFunc(StringRef funcName) const;
151
152 /// Searches for a particular function name, also checking that its type is
153 /// valid for the library function matching that name.
154 ///
155 /// Returns the corresponding LibFunc if it is one of the known library
156 /// functions, and NotLibFunc otherwise.
157 ///
158 /// FDecl is assumed to have a parent Module when using this function.
159 LLVM_ABI LibFunc getLibFunc(const Function &FDecl) const;
160
161 /// Searches for a function name using an Instruction \p Opcode.
162 /// Currently, only the frem instruction is supported.
163 ///
164 /// Returns NotLibFunc if there is no matching library function.
165 LLVM_ABI LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const;
166
167 /// Forces a function to be marked as unavailable.
168 void setUnavailable(LibFunc F) {
169 setState(F, Unavailable);
170 }
171
172 /// Forces a function to be marked as available.
173 void setAvailable(LibFunc F) {
174 setState(F, StandardName);
175 }
176
177 /// Forces a function to be marked as available and provide an alternate name
178 /// that must be used.
179 void setAvailableWithName(LibFunc F, StringRef Name) {
180 if (StringRef(StandardNamesStrTable.getCString(StandardNamesOffsets[F]),
181 StandardNamesSizeTable[F]) != Name) {
182 setState(F, CustomName);
183 CustomNames[F] = std::string(Name);
184 assert(CustomNames.contains(F));
185 } else {
186 setState(F, StandardName);
187 }
188 }
189
190 /// Disables all builtins.
191 ///
192 /// This can be used for options like -fno-builtin.
194
195 /// Add a set of scalar -> vector mappings, queryable via
196 /// getVectorizedFunction and getScalarizedFunction.
198
199 /// Calls addVectorizableFunctions with a known preset of functions for the
200 /// given vector library.
201 LLVM_ABI void
203 const llvm::Triple &TargetTriple);
204
205 /// Return true if the function F has a vector equivalent with vectorization
206 /// factor VF.
208 return !(getVectorizedFunction(F, VF, false).empty() &&
209 getVectorizedFunction(F, VF, true).empty());
210 }
211
212 /// Return true if the function F has a vector equivalent with any
213 /// vectorization factor.
215
216 /// Return the name of the equivalent of F, vectorized with factor VF. If no
217 /// such mapping exists, return the empty string.
219 bool Masked) const;
220
221 /// Return a pointer to a VecDesc object holding all info for scalar to vector
222 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
223 /// If no such mapping exists, return nullpointer.
224 LLVM_ABI const VecDesc *
225 getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const;
226
227 /// Set to true iff i32 parameters to library functions should have signext
228 /// or zeroext attributes if they correspond to C-level int or unsigned int,
229 /// respectively.
230 void setShouldExtI32Param(bool Val) {
231 ShouldExtI32Param = Val;
232 }
233
234 /// Set to true iff i32 results from library functions should have signext
235 /// or zeroext attributes if they correspond to C-level int or unsigned int,
236 /// respectively.
237 void setShouldExtI32Return(bool Val) {
238 ShouldExtI32Return = Val;
239 }
240
241 /// Set to true iff i32 parameters to library functions should have signext
242 /// attribute if they correspond to C-level int or unsigned int.
244 ShouldSignExtI32Param = Val;
245 }
246
247 /// Set to true iff i32 results from library functions should have signext
248 /// attribute if they correspond to C-level int or unsigned int.
250 ShouldSignExtI32Return = Val;
251 }
252
253 /// Returns the size of the size_t type in bits.
254 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
255
256 /// Get size of a C-level int or unsigned int, in bits.
257 unsigned getIntSize() const {
258 return SizeOfInt;
259 }
260
261 /// Initialize the C-level size of an integer.
262 void setIntSize(unsigned Bits) {
263 SizeOfInt = Bits;
264 }
265
266 /// Returns the largest vectorization factor used in the list of
267 /// vector functions.
268 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
269 ElementCount &Scalable) const;
270
271 /// Returns true if call site / callee has cdecl-compatible calling
272 /// conventions.
274 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
275
276 bool isErrnoFunctionCall() const { return IsErrnoFunctionCall; }
277};
278
279/// Provides information about what library functions are available for
280/// the current target.
281///
282/// This both allows optimizations to handle them specially and frontends to
283/// disable such optimizations through -fno-builtin etc.
287
288 /// The global (module level) TLI info.
289 const TargetLibraryInfoImpl *Impl;
290
291 /// Support for -fno-builtin* options as function attributes, overrides
292 /// information in global TargetLibraryInfoImpl.
293 std::bitset<NumLibFuncs> OverrideAsUnavailable;
294
295public:
297
299 std::optional<const Function *> F = std::nullopt)
300 : Impl(&Impl) {
301 if (!F)
302 return;
303 if ((*F)->hasFnAttribute("no-builtins"))
305 else {
306 // Disable individual libc/libm calls in TargetLibraryInfo.
307 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
308 for (const Attribute &Attr : FnAttrs) {
309 if (!Attr.isStringAttribute())
310 continue;
311 auto AttrStr = Attr.getKindAsString();
312 if (!AttrStr.consume_front("no-builtin-"))
313 continue;
314 if (LibFunc LF = getLibFunc(AttrStr))
315 setUnavailable(LF);
316 }
317 }
318 }
319
320 // Provide value semantics.
325
326 /// Determine whether a callee with the given TLI can be inlined into
327 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
328 /// allow inlining into a caller with a superset of the callee's nobuiltin
329 /// attributes, which is conservatively correct.
331 bool AllowCallerSuperset) const {
332 if (!AllowCallerSuperset)
333 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
334 // We can inline if the callee's nobuiltin attributes are no stricter than
335 // the caller's.
336 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
337 }
338
339 /// Return true if the function type FTy is valid for the library function
340 /// F, regardless of whether the function is available.
341 bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
342 const Module &M) const {
343 return Impl->isValidProtoForLibFunc(FTy, F, M);
344 }
345
346 /// Searches for a particular function name.
347 ///
348 /// Returns the corresponding LibFunc if it is one of the known library
349 /// functions, and NotLibFunc otherwise.
350 LibFunc getLibFunc(StringRef funcName) const {
351 return Impl->getLibFunc(funcName);
352 }
353
354 LibFunc getLibFunc(const Function &FDecl) const {
355 return Impl->getLibFunc(FDecl);
356 }
357
358 /// If a callbase does not have the 'nobuiltin' attribute, return the library
359 /// function the callee is, and NotLibFunc otherwise.
360 LibFunc getLibFunc(const CallBase &CB) const {
361 if (CB.isNoBuiltin() || !CB.getCalledFunction())
362 return NotLibFunc;
363 return getLibFunc(*CB.getCalledFunction());
364 }
365
366 /// Searches for a function name using an Instruction \p Opcode.
367 /// Currently, only the frem instruction is supported.
368 ///
369 /// Returns NotLibFunc if there is no matching library function.
370 LibFunc getLibFunc(unsigned int Opcode, Type *Ty) const {
371 return Impl->getLibFunc(Opcode, Ty);
372 }
373
374 /// Disables all builtins.
375 ///
376 /// This can be used for options like -fno-builtin.
377 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
378
379 /// Forces a function to be marked as unavailable.
380 [[maybe_unused]] void setUnavailable(LibFunc F) {
381 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
382 OverrideAsUnavailable.set(F);
383 }
384
385 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
386 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
387 if (OverrideAsUnavailable[F])
388 return TargetLibraryInfoImpl::Unavailable;
389 return Impl->getState(F);
390 }
391
392 /// Tests whether a library function is available.
393 bool has(LibFunc F) const {
394 return getState(F) != TargetLibraryInfoImpl::Unavailable;
395 }
397 return Impl->isFunctionVectorizable(F, VF);
398 }
400 return Impl->isFunctionVectorizable(F);
401 }
403 bool Masked = false) const {
404 return Impl->getVectorizedFunction(F, VF, Masked);
405 }
407 bool Masked) const {
408 return Impl->getVectorMappingInfo(F, VF, Masked);
409 }
410
411 /// Tests if the function is both available and a candidate for optimized code
412 /// generation.
413 bool hasOptimizedCodeGen(LibFunc F) const {
414 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
415 return false;
416 switch (F) {
417 default: break;
418 // clang-format off
419 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
420 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
421 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
422 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
423 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
424 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
425 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
426 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
427 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
428 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
429 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
430 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
431 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
432 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
433 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
434 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
435 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
436 case LibFunc_sqrtl_finite:
437 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
438 case LibFunc_strnlen: case LibFunc_strstr: case LibFunc_memchr:
439 case LibFunc_memccpy: case LibFunc_mempcpy: case LibFunc_tan:
440 case LibFunc_tanf: case LibFunc_tanl: case LibFunc_tanh:
441 case LibFunc_tanhf: case LibFunc_tanhl:
442 // clang-format on
443 return true;
444 }
445 return false;
446 }
447
448 /// Return the canonical name for a LibFunc. This should not be used for
449 /// semantic purposes, use getName instead.
450 static StringRef getStandardName(LibFunc F) {
451 return StringRef(TargetLibraryInfoImpl::StandardNamesStrTable.getCString(
452 TargetLibraryInfoImpl::StandardNamesOffsets[F]),
453 TargetLibraryInfoImpl::StandardNamesSizeTable[F]);
454 }
455
456 StringRef getName(LibFunc F) const {
457 auto State = getState(F);
458 if (State == TargetLibraryInfoImpl::Unavailable)
459 return StringRef();
460 if (State == TargetLibraryInfoImpl::StandardName)
461 return StringRef(
462 Impl->StandardNamesStrTable.getCString(Impl->StandardNamesOffsets[F]),
463 Impl->StandardNamesSizeTable[F]);
464 assert(State == TargetLibraryInfoImpl::CustomName);
465 return Impl->CustomNames.find(F)->second;
466 }
467
468 LLVM_ABI static void initBoolExtensionsForTriple(bool &ShouldZExtBoolParam,
469 bool &ShouldZExtBoolReturn,
470 const Triple &T);
471
472 LLVM_ABI static void initExtensionsForTriple(bool &ShouldExtI32Param,
473 bool &ShouldExtI32Return,
474 bool &ShouldSignExtI32Param,
475 bool &ShouldSignExtI32Return,
476 const Triple &T);
477
478 /// Returns extension attribute kind to be used for i32 parameters
479 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
480 /// or none.
481private:
482 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
483 bool ShouldSignExtI32Param_,
484 bool Signed = true) {
485 if (ShouldExtI32Param_)
486 return Signed ? Attribute::SExt : Attribute::ZExt;
487 if (ShouldSignExtI32Param_)
488 return Attribute::SExt;
489 return Attribute::None;
490 }
491
492public:
494 bool ShouldZExtBoolParam, ShouldZExtBoolReturn;
495 initBoolExtensionsForTriple(ShouldZExtBoolParam, ShouldZExtBoolReturn, T);
496 return ShouldZExtBoolParam ? Attribute::ZExt : Attribute::None;
497 }
498
500 // Return the extension attributes here even though nothing special is
501 // done in case any target needs something different in the future.
502 return Signed ? Attribute::SExt : Attribute::ZExt;
503 }
504
506 bool Signed = true) {
507 bool ShouldExtI32Param, ShouldExtI32Return;
508 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
509 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
510 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
511 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
512 Signed);
513 }
514
516 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
517 Impl->ShouldSignExtI32Param, Signed);
518 }
519
520 /// Returns extension attribute kind to be used for i32 return values
521 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
522 /// or none.
523private:
524 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
525 bool ShouldSignExtI32Return_,
526 bool Signed) {
527 if (ShouldExtI32Return_)
528 return Signed ? Attribute::SExt : Attribute::ZExt;
529 if (ShouldSignExtI32Return_)
530 return Attribute::SExt;
531 return Attribute::None;
532 }
533
534public:
536 bool Signed = true) {
537 bool ShouldExtI32Param, ShouldExtI32Return;
538 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
539 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
540 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
541 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
542 Signed);
543 }
544
546 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
547 Impl->ShouldSignExtI32Return, Signed);
548 }
549
550 // Helper to create an AttributeList for args (and ret val) which all have
551 // the same signedness. Attributes in AL may be passed in to include them
552 // as well in the returned AttributeList.
554 bool Signed, bool Ret = false,
555 AttributeList AL = AttributeList()) const {
556 if (auto AK = getExtAttrForI32Param(Signed))
557 for (auto ArgNo : ArgNos)
558 AL = AL.addParamAttribute(*C, ArgNo, AK);
559 if (Ret)
560 if (auto AK = getExtAttrForI32Return(Signed))
561 AL = AL.addRetAttribute(*C, AK);
562 return AL;
563 }
564
565 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
566 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
567
568 /// Returns an IntegerType corresponding to size_t.
569 IntegerType *getSizeTType(const Module &M) const {
570 return IntegerType::get(M.getContext(), getSizeTSize(M));
571 }
572
573 /// Returns a constant materialized as a size_t type.
575 return ConstantInt::get(getSizeTType(M), V);
576 }
577
578 /// \copydoc TargetLibraryInfoImpl::getIntSize()
579 unsigned getIntSize() const {
580 return Impl->getIntSize();
581 }
582
583 /// Handle invalidation from the pass manager.
584 ///
585 /// If we try to invalidate this info, just return false. It cannot become
586 /// invalid even if the module or function changes.
588 ModuleAnalysisManager::Invalidator &) {
589 return false;
590 }
592 FunctionAnalysisManager::Invalidator &) {
593 return false;
594 }
595 /// Returns the largest vectorization factor used in the list of
596 /// vector functions.
597 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
598 ElementCount &ScalableVF) const {
599 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
600 }
601
602 /// Check if the function "F" is listed in a library known to LLVM.
604 return this->isFunctionVectorizable(F);
605 }
606
607 /// Returns whether `errno` is defined as a function call on known
608 /// environments.
609 bool isErrnoFunctionCall() const { return Impl->isErrnoFunctionCall(); }
610};
611
612/// Analysis pass providing the \c TargetLibraryInfo.
613///
614/// Note that this pass's result cannot be invalidated, it is immutable for the
615/// life of the module.
616class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
617public:
619
620 /// Default construct the library analysis.
621 ///
622 /// This will use the module's triple to construct the library info for that
623 /// module.
625
626 /// Construct a library analysis with baseline Module-level info.
627 ///
628 /// This will be supplemented with Function-specific info in the Result.
630 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
631
633
634private:
636 LLVM_ABI static AnalysisKey Key;
637
638 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
639};
640
643 std::optional<TargetLibraryInfo> TLI;
644
645 virtual void anchor();
646
647public:
648 static char ID;
649
650 /// The default constructor should not be used and is only for pass manager
651 /// initialization purposes.
653
654 explicit TargetLibraryInfoWrapperPass(const Triple &T);
656
657 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
658 // PassManager inside a pass.
660
663 TLI = TLA.run(F, DummyFAM);
664 return *TLI;
665 }
666};
667
668} // end namespace llvm
669
670#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:1238
@ Unavailable
We know the block is not fully available. This is a fixpoint.
Definition GVN.cpp:1240
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
RISCVCC::CondCode CC
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:445
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:106
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:125
@ None
No attributes have been set.
Definition Attributes.h:127
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
This is the shared class of boolean and integer constants.
Definition Constants.h:87
Class to represent function types.
ImmutablePass(char &pid)
Definition Pass.h:285
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:333
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 void addVectorizableFunctions(EnumStrings< VecDescData, 3 > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
LLVM_ABI unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
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
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
VecDesc(const EnumString< VecDescData, 3 > &Data)
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
unsigned CC
Encoded calling convention: 0 means absent (std::nullopt), otherwise stores CallingConv::ID + 1 so an...
ElementCount VectorizationFactor
constexpr VecDescData(ElementCount VectorizationFactor, bool Masked, std::optional< CallingConv::ID > Conv)