LLVM 22.0.0git
TargetLibraryInfo.h
Go to the documentation of this file.
1//===-- TargetLibraryInfo.h - Library information ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
10#define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/IR/Constants.h"
14#include "llvm/IR/InstrTypes.h"
15#include "llvm/IR/Module.h"
16#include "llvm/IR/PassManager.h"
17#include "llvm/Pass.h"
20#include <bitset>
21#include <optional>
22
23namespace llvm {
24
25template <typename T> class ArrayRef;
26enum class VectorLibrary;
27
28/// Provides info so a possible vectorization of a function can be
29/// computed. Function 'VectorFnName' is equivalent to 'ScalarFnName'
30/// vectorized by a factor 'VectorizationFactor'.
31/// The VABIPrefix string holds information about isa, mask, vlen,
32/// and vparams so a scalar-to-vector mapping of the form:
33/// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
34/// can be constructed where:
35///
36/// <isa> = "_LLVM_"
37/// <mask> = "M" if masked, "N" if no mask.
38/// <vlen> = Number of concurrent lanes, stored in the `VectorizationFactor`
39/// field of the `VecDesc` struct. If the number of lanes is scalable
40/// then 'x' is printed instead.
41/// <vparams> = "v", as many as are the numArgs.
42/// <scalarname> = the name of the scalar function.
43/// <vectorname> = the name of the vector function.
44class VecDesc {
45 StringRef ScalarFnName;
46 StringRef VectorFnName;
47 ElementCount VectorizationFactor;
48 bool Masked;
49 StringRef VABIPrefix;
50 std::optional<CallingConv::ID> CC;
51
52public:
53 VecDesc() = delete;
54 VecDesc(StringRef ScalarFnName, StringRef VectorFnName,
55 ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix,
56 std::optional<CallingConv::ID> Conv)
57 : ScalarFnName(ScalarFnName), VectorFnName(VectorFnName),
58 VectorizationFactor(VectorizationFactor), Masked(Masked),
59 VABIPrefix(VABIPrefix), CC(Conv) {}
60
61 StringRef getScalarFnName() const { return ScalarFnName; }
62 StringRef getVectorFnName() const { return VectorFnName; }
63 ElementCount getVectorizationFactor() const { return VectorizationFactor; }
64 bool isMasked() const { return Masked; }
65 StringRef getVABIPrefix() const { return VABIPrefix; }
66 std::optional<CallingConv::ID> getCallingConv() const { return CC; }
67
68 /// Returns a vector function ABI variant string on the form:
69 /// _ZGV<isa><mask><vlen><vparams>_<scalarname>(<vectorname>)
71};
72
73 enum LibFunc : unsigned {
74#define TLI_DEFINE_ENUM
75#include "llvm/Analysis/TargetLibraryInfo.def"
76
79 };
80
81/// Implementation of the target library information.
82///
83/// This class constructs tables that hold the target library information and
84/// make it available. However, it is somewhat expensive to compute and only
85/// depends on the triple. So users typically interact with the \c
86/// TargetLibraryInfo wrapper below.
88 friend class TargetLibraryInfo;
89
90 unsigned char AvailableArray[(NumLibFuncs+3)/4];
92 LLVM_ABI static StringLiteral const StandardNames[NumLibFuncs];
93 bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
94 unsigned SizeOfInt;
95
96 enum AvailabilityState {
97 StandardName = 3, // (memset to all ones)
98 CustomName = 1,
99 Unavailable = 0 // (memset to all zeros)
100 };
101 void setState(LibFunc F, AvailabilityState State) {
102 AvailableArray[F/4] &= ~(3 << 2*(F&3));
103 AvailableArray[F/4] |= State << 2*(F&3);
104 }
105 AvailabilityState getState(LibFunc F) const {
106 return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
107 }
108
109 /// Vectorization descriptors - sorted by ScalarFnName.
110 std::vector<VecDesc> VectorDescs;
111 /// Scalarization descriptors - same content as VectorDescs but sorted based
112 /// on VectorFnName rather than ScalarFnName.
113 std::vector<VecDesc> ScalarDescs;
114
115 /// Return true if the function type FTy is valid for the library function
116 /// F, regardless of whether the function is available.
117 LLVM_ABI bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
118 const Module &M) const;
119
120public:
122 LLVM_ABI explicit TargetLibraryInfoImpl(const Triple &T);
123
124 // Provide value semantics.
129
130 /// Searches for a particular function name.
131 ///
132 /// If it is one of the known library functions, return true and set F to the
133 /// corresponding value.
134 LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const;
135
136 /// Searches for a particular function name, also checking that its type is
137 /// valid for the library function matching that name.
138 ///
139 /// If it is one of the known library functions, return true and set F to the
140 /// corresponding value.
141 ///
142 /// FDecl is assumed to have a parent Module when using this function.
143 LLVM_ABI bool getLibFunc(const Function &FDecl, LibFunc &F) const;
144
145 /// Searches for a function name using an Instruction \p Opcode.
146 /// Currently, only the frem instruction is supported.
147 LLVM_ABI bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
148
149 /// Forces a function to be marked as unavailable.
151 setState(F, Unavailable);
152 }
153
154 /// Forces a function to be marked as available.
156 setState(F, StandardName);
157 }
158
159 /// Forces a function to be marked as available and provide an alternate name
160 /// that must be used.
162 if (StandardNames[F] != Name) {
163 setState(F, CustomName);
164 CustomNames[F] = std::string(Name);
165 assert(CustomNames.contains(F));
166 } else {
167 setState(F, StandardName);
168 }
169 }
170
171 /// Disables all builtins.
172 ///
173 /// This can be used for options like -fno-builtin.
175
176 /// Add a set of scalar -> vector mappings, queryable via
177 /// getVectorizedFunction and getScalarizedFunction.
179
180 /// Calls addVectorizableFunctions with a known preset of functions for the
181 /// given vector library.
182 LLVM_ABI void
184 const llvm::Triple &TargetTriple);
185
186 /// Return true if the function F has a vector equivalent with vectorization
187 /// factor VF.
189 return !(getVectorizedFunction(F, VF, false).empty() &&
190 getVectorizedFunction(F, VF, true).empty());
191 }
192
193 /// Return true if the function F has a vector equivalent with any
194 /// vectorization factor.
196
197 /// Return the name of the equivalent of F, vectorized with factor VF. If no
198 /// such mapping exists, return the empty string.
200 bool Masked) const;
201
202 /// Return a pointer to a VecDesc object holding all info for scalar to vector
203 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
204 /// If no such mapping exists, return nullpointer.
205 LLVM_ABI const VecDesc *
206 getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const;
207
208 /// Set to true iff i32 parameters to library functions should have signext
209 /// or zeroext attributes if they correspond to C-level int or unsigned int,
210 /// respectively.
211 void setShouldExtI32Param(bool Val) {
212 ShouldExtI32Param = Val;
213 }
214
215 /// Set to true iff i32 results from library functions should have signext
216 /// or zeroext attributes if they correspond to C-level int or unsigned int,
217 /// respectively.
218 void setShouldExtI32Return(bool Val) {
219 ShouldExtI32Return = Val;
220 }
221
222 /// Set to true iff i32 parameters to library functions should have signext
223 /// attribute if they correspond to C-level int or unsigned int.
225 ShouldSignExtI32Param = Val;
226 }
227
228 /// Set to true iff i32 results from library functions should have signext
229 /// attribute if they correspond to C-level int or unsigned int.
231 ShouldSignExtI32Return = Val;
232 }
233
234 /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
235 /// This queries the 'wchar_size' metadata.
236 LLVM_ABI unsigned getWCharSize(const Module &M) const;
237
238 /// Returns the size of the size_t type in bits.
239 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
240
241 /// Get size of a C-level int or unsigned int, in bits.
242 unsigned getIntSize() const {
243 return SizeOfInt;
244 }
245
246 /// Initialize the C-level size of an integer.
247 void setIntSize(unsigned Bits) {
248 SizeOfInt = Bits;
249 }
250
251 /// Returns the largest vectorization factor used in the list of
252 /// vector functions.
253 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
254 ElementCount &Scalable) const;
255
256 /// Returns true if call site / callee has cdecl-compatible calling
257 /// conventions.
259 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
260};
261
262/// Provides information about what library functions are available for
263/// the current target.
264///
265/// This both allows optimizations to handle them specially and frontends to
266/// disable such optimizations through -fno-builtin etc.
270
271 /// The global (module level) TLI info.
272 const TargetLibraryInfoImpl *Impl;
273
274 /// Support for -fno-builtin* options as function attributes, overrides
275 /// information in global TargetLibraryInfoImpl.
276 std::bitset<NumLibFuncs> OverrideAsUnavailable;
277
278public:
280
282 std::optional<const Function *> F = std::nullopt)
283 : Impl(&Impl) {
284 if (!F)
285 return;
286 if ((*F)->hasFnAttribute("no-builtins"))
288 else {
289 // Disable individual libc/libm calls in TargetLibraryInfo.
290 LibFunc LF;
291 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
292 for (const Attribute &Attr : FnAttrs) {
293 if (!Attr.isStringAttribute())
294 continue;
295 auto AttrStr = Attr.getKindAsString();
296 if (!AttrStr.consume_front("no-builtin-"))
297 continue;
298 if (getLibFunc(AttrStr, LF))
299 setUnavailable(LF);
300 }
301 }
302 }
303
304 // Provide value semantics.
309
310 /// Determine whether a callee with the given TLI can be inlined into
311 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
312 /// allow inlining into a caller with a superset of the callee's nobuiltin
313 /// attributes, which is conservatively correct.
315 bool AllowCallerSuperset) const {
316 if (!AllowCallerSuperset)
317 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
318 // We can inline if the callee's nobuiltin attributes are no stricter than
319 // the caller's.
320 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
321 }
322
323 /// Return true if the function type FTy is valid for the library function
324 /// F, regardless of whether the function is available.
326 const Module &M) const {
327 return Impl->isValidProtoForLibFunc(FTy, F, M);
328 }
329
330 /// Searches for a particular function name.
331 ///
332 /// If it is one of the known library functions, return true and set F to the
333 /// corresponding value.
334 bool getLibFunc(StringRef funcName, LibFunc &F) const {
335 return Impl->getLibFunc(funcName, F);
336 }
337
338 bool getLibFunc(const Function &FDecl, LibFunc &F) const {
339 return Impl->getLibFunc(FDecl, F);
340 }
341
342 /// If a callbase does not have the 'nobuiltin' attribute, return if the
343 /// called function is a known library function and set F to that function.
344 bool getLibFunc(const CallBase &CB, LibFunc &F) const {
345 return !CB.isNoBuiltin() && CB.getCalledFunction() &&
347 }
348
349 /// Searches for a function name using an Instruction \p Opcode.
350 /// Currently, only the frem instruction is supported.
351 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
352 return Impl->getLibFunc(Opcode, Ty, F);
353 }
354
355 /// Disables all builtins.
356 ///
357 /// This can be used for options like -fno-builtin.
358 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
359
360 /// Forces a function to be marked as unavailable.
361 [[maybe_unused]] void setUnavailable(LibFunc F) {
362 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
363 OverrideAsUnavailable.set(F);
364 }
365
366 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
367 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
368 if (OverrideAsUnavailable[F])
369 return TargetLibraryInfoImpl::Unavailable;
370 return Impl->getState(F);
371 }
372
373 /// Tests whether a library function is available.
374 bool has(LibFunc F) const {
375 return getState(F) != TargetLibraryInfoImpl::Unavailable;
376 }
378 return Impl->isFunctionVectorizable(F, VF);
379 }
381 return Impl->isFunctionVectorizable(F);
382 }
384 bool Masked = false) const {
385 return Impl->getVectorizedFunction(F, VF, Masked);
386 }
388 bool Masked) const {
389 return Impl->getVectorMappingInfo(F, VF, Masked);
390 }
391
392 /// Tests if the function is both available and a candidate for optimized code
393 /// generation.
395 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
396 return false;
397 switch (F) {
398 default: break;
399 // clang-format off
400 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
401 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
402 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
403 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
404 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
405 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
406 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
407 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
408 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
409 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
410 case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
411 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
412 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
413 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
414 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
415 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
416 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
417 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
418 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
419 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
420 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
421 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
422 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
423 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
424 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
425 case LibFunc_sqrtl_finite:
426 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
427 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
428 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
429 case LibFunc_tanh: case LibFunc_tanhf: case LibFunc_tanhl:
430 case LibFunc_trunc: case LibFunc_truncf: 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.
440 return TargetLibraryInfoImpl::StandardNames[F];
441 }
442
444 auto State = getState(F);
445 if (State == TargetLibraryInfoImpl::Unavailable)
446 return StringRef();
447 if (State == TargetLibraryInfoImpl::StandardName)
448 return Impl->StandardNames[F];
449 assert(State == TargetLibraryInfoImpl::CustomName);
450 return Impl->CustomNames.find(F)->second;
451 }
452
453 static void initExtensionsForTriple(bool &ShouldExtI32Param,
454 bool &ShouldExtI32Return,
455 bool &ShouldSignExtI32Param,
456 bool &ShouldSignExtI32Return,
457 const Triple &T) {
458 ShouldExtI32Param = ShouldExtI32Return = false;
459 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
460
461 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
462 // returns corresponding to C-level ints and unsigned ints.
463 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
464 T.getArch() == Triple::systemz) {
465 ShouldExtI32Param = true;
466 ShouldExtI32Return = true;
467 }
468 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
469 // parameters corresponding to both signed and unsigned ints.
470 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
471 ShouldSignExtI32Param = true;
472 }
473 // LoongArch and riscv64 need signext on i32 returns corresponding to both
474 // signed and unsigned ints.
475 if (T.isLoongArch() || T.isRISCV64()) {
476 ShouldSignExtI32Return = true;
477 }
478 }
479
480 /// Returns extension attribute kind to be used for i32 parameters
481 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
482 /// or none.
483private:
484 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
485 bool ShouldSignExtI32Param_,
486 bool Signed = true) {
487 if (ShouldExtI32Param_)
488 return Signed ? Attribute::SExt : Attribute::ZExt;
489 if (ShouldSignExtI32Param_)
490 return Attribute::SExt;
491 return Attribute::None;
492 }
493
494public:
496 bool Signed = true) {
497 bool ShouldExtI32Param, ShouldExtI32Return;
498 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
499 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
500 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
501 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
502 Signed);
503 }
504
506 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
507 Impl->ShouldSignExtI32Param, Signed);
508 }
509
510 /// Returns extension attribute kind to be used for i32 return values
511 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
512 /// or none.
513private:
514 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
515 bool ShouldSignExtI32Return_,
516 bool Signed) {
517 if (ShouldExtI32Return_)
518 return Signed ? Attribute::SExt : Attribute::ZExt;
519 if (ShouldSignExtI32Return_)
520 return Attribute::SExt;
521 return Attribute::None;
522 }
523
524public:
526 bool Signed = true) {
527 bool ShouldExtI32Param, ShouldExtI32Return;
528 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
529 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
530 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
531 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
532 Signed);
533 }
534
536 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
537 Impl->ShouldSignExtI32Return, Signed);
538 }
539
540 // Helper to create an AttributeList for args (and ret val) which all have
541 // the same signedness. Attributes in AL may be passed in to include them
542 // as well in the returned AttributeList.
544 bool Signed, bool Ret = false,
545 AttributeList AL = AttributeList()) const {
546 if (auto AK = getExtAttrForI32Param(Signed))
547 for (auto ArgNo : ArgNos)
548 AL = AL.addParamAttribute(*C, ArgNo, AK);
549 if (Ret)
550 if (auto AK = getExtAttrForI32Return(Signed))
551 AL = AL.addRetAttribute(*C, AK);
552 return AL;
553 }
554
555 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
556 unsigned getWCharSize(const Module &M) const {
557 return Impl->getWCharSize(M);
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.
569 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
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
603/// Analysis pass providing the \c TargetLibraryInfo.
604///
605/// Note that this pass's result cannot be invalidated, it is immutable for the
606/// life of the module.
607class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
608public:
610
611 /// Default construct the library analysis.
612 ///
613 /// This will use the module's triple to construct the library info for that
614 /// module.
616
617 /// Construct a library analysis with baseline Module-level info.
618 ///
619 /// This will be supplemented with Function-specific info in the Result.
621 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
622
624
625private:
627 LLVM_ABI static AnalysisKey Key;
628
629 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
630};
631
634 std::optional<TargetLibraryInfo> TLI;
635
636 virtual void anchor();
637
638public:
639 static char ID;
640
641 /// The default constructor should not be used and is only for pass manager
642 /// initialization purposes.
644
645 explicit TargetLibraryInfoWrapperPass(const Triple &T);
647
648 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
649 // PassManager inside a pass.
651
654 TLI = TLA.run(F, DummyFAM);
655 return *TLI;
656 }
657};
658
659} // end namespace llvm
660
661#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
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:41
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
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition StringRef.h:854
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
Analysis pass providing the TargetLibraryInfo.
TargetLibraryAnalysis()=default
Default construct the library analysis.
LLVM_ABI TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &)
TargetLibraryAnalysis(TargetLibraryInfoImpl BaselineInfoImpl)
Construct a library analysis with baseline Module-level info.
Implementation of the target library information.
void setShouldExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext or zeroext attributes if they...
void setShouldExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext or zeroext attributes if they ...
LLVM_ABI unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &Scalable) const
Returns the largest vectorization factor used in the list of vector functions.
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Return true if the function F has a vector equivalent with vectorization factor VF.
void setShouldSignExtI32Param(bool Val)
Set to true iff i32 parameters to library functions should have signext attribute if they correspond ...
void setAvailableWithName(LibFunc F, StringRef Name)
Forces a function to be marked as available and provide an alternate name that must be used.
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
LLVM_ABI void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib, const llvm::Triple &TargetTriple)
Calls addVectorizableFunctions with a known preset of functions for the given vector library.
void setIntSize(unsigned Bits)
Initialize the C-level size of an integer.
LLVM_ABI unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
LLVM_ABI void addVectorizableFunctions(ArrayRef< VecDesc > Fns)
Add a set of scalar -> vector mappings, queryable via getVectorizedFunction and getScalarizedFunction...
LLVM_ABI const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
Return a pointer to a VecDesc object holding all info for scalar to vector mappings in TLI for the eq...
static LLVM_ABI bool isCallingConvCCompatible(CallBase *CI)
Returns true if call site / callee has cdecl-compatible calling conventions.
void setShouldSignExtI32Return(bool Val)
Set to true iff i32 results from library functions should have signext attribute if they correspond t...
LLVM_ABI TargetLibraryInfoImpl & operator=(const TargetLibraryInfoImpl &TLI)
LLVM_ABI void disableAllFunctions()
Disables all builtins.
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
LLVM_ABI StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked) const
Return the name of the equivalent of F, vectorized with factor VF.
void setAvailable(LibFunc F)
Forces a function to be marked as available.
TargetLibraryInfoWrapperPass()
The default constructor should not be used and is only for pass manager initialization purposes.
TargetLibraryInfo & getTLI(const Function &F)
Provides information about what library functions are available for the current target.
AttributeList getAttrList(LLVMContext *C, ArrayRef< unsigned > ArgNos, bool Signed, bool Ret=false, AttributeList AL=AttributeList()) const
static Attribute::AttrKind getExtAttrForI32Param(const Triple &T, bool Signed=true)
bool areInlineCompatible(const TargetLibraryInfo &CalleeTLI, bool AllowCallerSuperset) const
Determine whether a callee with the given TLI can be inlined into caller with this TLI,...
bool getLibFunc(const CallBase &CB, LibFunc &F) const
If a callbase does not have the 'nobuiltin' attribute, return if the called function is a known libra...
bool invalidate(Module &, const PreservedAnalyses &, ModuleAnalysisManager::Invalidator &)
Handle invalidation from the pass manager.
bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F, const Module &M) const
Return true if the function type FTy is valid for the library function F, regardless of whether the f...
unsigned getWCharSize(const Module &M) const
Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
ConstantInt * getAsSizeT(uint64_t V, const Module &M) const
Returns a constant materialized as a size_t type.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
Attribute::AttrKind getExtAttrForI32Return(bool Signed=true) const
bool invalidate(Function &, const PreservedAnalyses &, FunctionAnalysisManager::Invalidator &)
bool isKnownVectorFunctionInLibrary(StringRef F) const
Check if the function "F" is listed in a library known to LLVM.
static StringRef getStandardName(LibFunc F)
Return the canonical name for a LibFunc.
bool isFunctionVectorizable(StringRef F) const
bool has(LibFunc F) const
Tests whether a library function is available.
void disableAllFunctions()
Disables all builtins.
unsigned getSizeTSize(const Module &M) const
Returns the size of the size_t type in bits.
TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const
TargetLibraryInfo & operator=(const TargetLibraryInfo &TLI)=default
TargetLibraryInfo(const TargetLibraryInfo &TLI)=default
void getWidestVF(StringRef ScalarF, ElementCount &FixedVF, ElementCount &ScalableVF) const
Returns the largest vectorization factor used in the list of vector functions.
TargetLibraryInfo(const TargetLibraryInfoImpl &Impl, std::optional< const Function * > F=std::nullopt)
static Attribute::AttrKind getExtAttrForI32Return(const Triple &T, bool Signed=true)
bool getLibFunc(const Function &FDecl, LibFunc &F) const
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
IntegerType * getSizeTType(const Module &M) const
Returns an IntegerType corresponding to size_t.
static void initExtensionsForTriple(bool &ShouldExtI32Param, bool &ShouldExtI32Return, bool &ShouldSignExtI32Param, bool &ShouldSignExtI32Return, const Triple &T)
bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const
Searches for a function name using an Instruction Opcode.
StringRef getVectorizedFunction(StringRef F, const ElementCount &VF, bool Masked=false) const
StringRef getName(LibFunc F) const
const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const
TargetLibraryInfo & operator=(TargetLibraryInfo &&TLI)=default
unsigned getIntSize() const
Get size of a C-level int or unsigned int, in bits.
friend class TargetLibraryInfoWrapperPass
TargetLibraryInfo(TargetLibraryInfo &&TLI)=default
void setUnavailable(LibFunc F)
Forces a function to be marked as unavailable.
Attribute::AttrKind getExtAttrForI32Param(bool Signed=true) const
bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
Provides info so a possible vectorization of a function can be computed.
StringRef getVABIPrefix() const
VecDesc()=delete
bool isMasked() const
std::optional< CallingConv::ID > getCallingConv() const
LLVM_ABI std::string getVectorFunctionABIVariantString() const
Returns a vector function ABI variant string on the form: ZGV<isa><mask><vlen><vparams><scalarname>(<...
StringRef getScalarFnName() const
StringRef getVectorFnName() const
ElementCount getVectorizationFactor() const
VecDesc(StringRef ScalarFnName, StringRef VectorFnName, ElementCount VectorizationFactor, bool Masked, StringRef VABIPrefix, std::optional< CallingConv::ID > Conv)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1867
VectorLibrary
List of known vector-functions libraries.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29