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"
18#include "llvm/Pass.h"
21#include <bitset>
22#include <optional>
23
24namespace llvm {
25
26template <typename T> class ArrayRef;
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:
124
125 // Provide value semantics.
130
131 /// Searches for a particular function name.
132 ///
133 /// If it is one of the known library functions, return true and set F to the
134 /// corresponding value.
135 LLVM_ABI bool getLibFunc(StringRef funcName, LibFunc &F) const;
136
137 /// Searches for a particular function name, also checking that its type is
138 /// valid for the library function matching that name.
139 ///
140 /// If it is one of the known library functions, return true and set F to the
141 /// corresponding value.
142 ///
143 /// FDecl is assumed to have a parent Module when using this function.
144 LLVM_ABI bool getLibFunc(const Function &FDecl, LibFunc &F) const;
145
146 /// Searches for a function name using an Instruction \p Opcode.
147 /// Currently, only the frem instruction is supported.
148 LLVM_ABI bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const;
149
150 /// Forces a function to be marked as unavailable.
152 setState(F, Unavailable);
153 }
154
155 /// Forces a function to be marked as available.
157 setState(F, StandardName);
158 }
159
160 /// Forces a function to be marked as available and provide an alternate name
161 /// that must be used.
163 if (StandardNames[F] != Name) {
164 setState(F, CustomName);
165 CustomNames[F] = std::string(Name);
166 assert(CustomNames.contains(F));
167 } else {
168 setState(F, StandardName);
169 }
170 }
171
172 /// Disables all builtins.
173 ///
174 /// This can be used for options like -fno-builtin.
176
177 /// Add a set of scalar -> vector mappings, queryable via
178 /// getVectorizedFunction and getScalarizedFunction.
180
181 /// Calls addVectorizableFunctions with a known preset of functions for the
182 /// given vector library.
183 LLVM_ABI void
185 const llvm::Triple &TargetTriple);
186
187 /// Return true if the function F has a vector equivalent with vectorization
188 /// factor VF.
190 return !(getVectorizedFunction(F, VF, false).empty() &&
191 getVectorizedFunction(F, VF, true).empty());
192 }
193
194 /// Return true if the function F has a vector equivalent with any
195 /// vectorization factor.
197
198 /// Return the name of the equivalent of F, vectorized with factor VF. If no
199 /// such mapping exists, return the empty string.
201 bool Masked) const;
202
203 /// Return a pointer to a VecDesc object holding all info for scalar to vector
204 /// mappings in TLI for the equivalent of F, vectorized with factor VF.
205 /// If no such mapping exists, return nullpointer.
206 LLVM_ABI const VecDesc *
207 getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const;
208
209 /// Set to true iff i32 parameters to library functions should have signext
210 /// or zeroext attributes if they correspond to C-level int or unsigned int,
211 /// respectively.
212 void setShouldExtI32Param(bool Val) {
213 ShouldExtI32Param = Val;
214 }
215
216 /// Set to true iff i32 results from library functions should have signext
217 /// or zeroext attributes if they correspond to C-level int or unsigned int,
218 /// respectively.
219 void setShouldExtI32Return(bool Val) {
220 ShouldExtI32Return = Val;
221 }
222
223 /// Set to true iff i32 parameters to library functions should have signext
224 /// attribute if they correspond to C-level int or unsigned int.
226 ShouldSignExtI32Param = Val;
227 }
228
229 /// Set to true iff i32 results from library functions should have signext
230 /// attribute if they correspond to C-level int or unsigned int.
232 ShouldSignExtI32Return = Val;
233 }
234
235 /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
236 /// This queries the 'wchar_size' metadata.
237 LLVM_ABI unsigned getWCharSize(const Module &M) const;
238
239 /// Returns the size of the size_t type in bits.
240 LLVM_ABI unsigned getSizeTSize(const Module &M) const;
241
242 /// Get size of a C-level int or unsigned int, in bits.
243 unsigned getIntSize() const {
244 return SizeOfInt;
245 }
246
247 /// Initialize the C-level size of an integer.
248 void setIntSize(unsigned Bits) {
249 SizeOfInt = Bits;
250 }
251
252 /// Returns the largest vectorization factor used in the list of
253 /// vector functions.
254 LLVM_ABI void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
255 ElementCount &Scalable) const;
256
257 /// Returns true if call site / callee has cdecl-compatible calling
258 /// conventions.
260 LLVM_ABI static bool isCallingConvCCompatible(Function *Callee);
261};
262
263/// Provides information about what library functions are available for
264/// the current target.
265///
266/// This both allows optimizations to handle them specially and frontends to
267/// disable such optimizations through -fno-builtin etc.
271
272 /// The global (module level) TLI info.
273 const TargetLibraryInfoImpl *Impl;
274
275 /// Support for -fno-builtin* options as function attributes, overrides
276 /// information in global TargetLibraryInfoImpl.
277 std::bitset<NumLibFuncs> OverrideAsUnavailable;
278
279public:
281
283 std::optional<const Function *> F = std::nullopt)
284 : Impl(&Impl) {
285 if (!F)
286 return;
287 if ((*F)->hasFnAttribute("no-builtins"))
289 else {
290 // Disable individual libc/libm calls in TargetLibraryInfo.
291 LibFunc LF;
292 AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
293 for (const Attribute &Attr : FnAttrs) {
294 if (!Attr.isStringAttribute())
295 continue;
296 auto AttrStr = Attr.getKindAsString();
297 if (!AttrStr.consume_front("no-builtin-"))
298 continue;
299 if (getLibFunc(AttrStr, LF))
300 setUnavailable(LF);
301 }
302 }
303 }
304
305 // Provide value semantics.
310
311 /// Determine whether a callee with the given TLI can be inlined into
312 /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
313 /// allow inlining into a caller with a superset of the callee's nobuiltin
314 /// attributes, which is conservatively correct.
316 bool AllowCallerSuperset) const {
317 if (!AllowCallerSuperset)
318 return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
319 // We can inline if the callee's nobuiltin attributes are no stricter than
320 // the caller's.
321 return (CalleeTLI.OverrideAsUnavailable & ~OverrideAsUnavailable).none();
322 }
323
324 /// Return true if the function type FTy is valid for the library function
325 /// F, regardless of whether the function is available.
327 const Module &M) const {
328 return Impl->isValidProtoForLibFunc(FTy, F, M);
329 }
330
331 /// Searches for a particular function name.
332 ///
333 /// If it is one of the known library functions, return true and set F to the
334 /// corresponding value.
335 bool getLibFunc(StringRef funcName, LibFunc &F) const {
336 return Impl->getLibFunc(funcName, F);
337 }
338
339 bool getLibFunc(const Function &FDecl, LibFunc &F) const {
340 return Impl->getLibFunc(FDecl, F);
341 }
342
343 /// If a callbase does not have the 'nobuiltin' attribute, return if the
344 /// called function is a known library function and set F to that function.
345 bool getLibFunc(const CallBase &CB, LibFunc &F) const {
346 return !CB.isNoBuiltin() && CB.getCalledFunction() &&
348 }
349
350 /// Searches for a function name using an Instruction \p Opcode.
351 /// Currently, only the frem instruction is supported.
352 bool getLibFunc(unsigned int Opcode, Type *Ty, LibFunc &F) const {
353 return Impl->getLibFunc(Opcode, Ty, F);
354 }
355
356 /// Disables all builtins.
357 ///
358 /// This can be used for options like -fno-builtin.
359 [[maybe_unused]] void disableAllFunctions() { OverrideAsUnavailable.set(); }
360
361 /// Forces a function to be marked as unavailable.
362 [[maybe_unused]] void setUnavailable(LibFunc F) {
363 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
364 OverrideAsUnavailable.set(F);
365 }
366
367 TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
368 assert(F < OverrideAsUnavailable.size() && "out-of-bounds LibFunc");
369 if (OverrideAsUnavailable[F])
370 return TargetLibraryInfoImpl::Unavailable;
371 return Impl->getState(F);
372 }
373
374 /// Tests whether a library function is available.
375 bool has(LibFunc F) const {
376 return getState(F) != TargetLibraryInfoImpl::Unavailable;
377 }
379 return Impl->isFunctionVectorizable(F, VF);
380 }
382 return Impl->isFunctionVectorizable(F);
383 }
385 bool Masked = false) const {
386 return Impl->getVectorizedFunction(F, VF, Masked);
387 }
389 bool Masked) const {
390 return Impl->getVectorMappingInfo(F, VF, Masked);
391 }
392
393 /// Tests if the function is both available and a candidate for optimized code
394 /// generation.
396 if (getState(F) == TargetLibraryInfoImpl::Unavailable)
397 return false;
398 switch (F) {
399 default: break;
400 // clang-format off
401 case LibFunc_acos: case LibFunc_acosf: case LibFunc_acosl:
402 case LibFunc_asin: case LibFunc_asinf: case LibFunc_asinl:
403 case LibFunc_atan2: case LibFunc_atan2f: case LibFunc_atan2l:
404 case LibFunc_atan: case LibFunc_atanf: case LibFunc_atanl:
405 case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
406 case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
407 case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
408 case LibFunc_cosh: case LibFunc_coshf: case LibFunc_coshl:
409 case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
410 case LibFunc_exp10: case LibFunc_exp10f: case LibFunc_exp10l:
411 case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
412 case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
413 case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
414 case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
415 case LibFunc_ldexp: case LibFunc_ldexpf: case LibFunc_ldexpl:
416 case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
417 case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
418 case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
419 case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
420 case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
421 case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
422 case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
423 case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
424 case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
425 case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
426 case LibFunc_sqrtl_finite:
427 case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
428 case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
429 case LibFunc_tan: case LibFunc_tanf: case LibFunc_tanl:
430 case LibFunc_tanh: case LibFunc_tanhf: case LibFunc_tanhl:
431 case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
432 // clang-format on
433 return true;
434 }
435 return false;
436 }
437
438 /// Return the canonical name for a LibFunc. This should not be used for
439 /// semantic purposes, use getName instead.
441 return TargetLibraryInfoImpl::StandardNames[F];
442 }
443
445 auto State = getState(F);
446 if (State == TargetLibraryInfoImpl::Unavailable)
447 return StringRef();
448 if (State == TargetLibraryInfoImpl::StandardName)
449 return Impl->StandardNames[F];
450 assert(State == TargetLibraryInfoImpl::CustomName);
451 return Impl->CustomNames.find(F)->second;
452 }
453
454 static void initExtensionsForTriple(bool &ShouldExtI32Param,
455 bool &ShouldExtI32Return,
456 bool &ShouldSignExtI32Param,
457 bool &ShouldSignExtI32Return,
458 const Triple &T) {
459 ShouldExtI32Param = ShouldExtI32Return = false;
460 ShouldSignExtI32Param = ShouldSignExtI32Return = false;
461
462 // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
463 // returns corresponding to C-level ints and unsigned ints.
464 if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
465 T.getArch() == Triple::systemz) {
466 ShouldExtI32Param = true;
467 ShouldExtI32Return = true;
468 }
469 // LoongArch, Mips, and riscv64, on the other hand, need signext on i32
470 // parameters corresponding to both signed and unsigned ints.
471 if (T.isLoongArch() || T.isMIPS() || T.isRISCV64()) {
472 ShouldSignExtI32Param = true;
473 }
474 // LoongArch and riscv64 need signext on i32 returns corresponding to both
475 // signed and unsigned ints.
476 if (T.isLoongArch() || T.isRISCV64()) {
477 ShouldSignExtI32Return = true;
478 }
479 }
480
481 /// Returns extension attribute kind to be used for i32 parameters
482 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
483 /// or none.
484private:
485 static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
486 bool ShouldSignExtI32Param_,
487 bool Signed = true) {
488 if (ShouldExtI32Param_)
489 return Signed ? Attribute::SExt : Attribute::ZExt;
490 if (ShouldSignExtI32Param_)
491 return Attribute::SExt;
492 return Attribute::None;
493 }
494
495public:
497 bool Signed = true) {
498 bool ShouldExtI32Param, ShouldExtI32Return;
499 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
500 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
501 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
502 return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
503 Signed);
504 }
505
507 return getExtAttrForI32Param(Impl->ShouldExtI32Param,
508 Impl->ShouldSignExtI32Param, Signed);
509 }
510
511 /// Returns extension attribute kind to be used for i32 return values
512 /// corresponding to C-level int or unsigned int. May be zeroext, signext,
513 /// or none.
514private:
515 static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
516 bool ShouldSignExtI32Return_,
517 bool Signed) {
518 if (ShouldExtI32Return_)
519 return Signed ? Attribute::SExt : Attribute::ZExt;
520 if (ShouldSignExtI32Return_)
521 return Attribute::SExt;
522 return Attribute::None;
523 }
524
525public:
527 bool Signed = true) {
528 bool ShouldExtI32Param, ShouldExtI32Return;
529 bool ShouldSignExtI32Param, ShouldSignExtI32Return;
530 initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
531 ShouldSignExtI32Param, ShouldSignExtI32Return, T);
532 return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
533 Signed);
534 }
535
537 return getExtAttrForI32Return(Impl->ShouldExtI32Return,
538 Impl->ShouldSignExtI32Return, Signed);
539 }
540
541 // Helper to create an AttributeList for args (and ret val) which all have
542 // the same signedness. Attributes in AL may be passed in to include them
543 // as well in the returned AttributeList.
545 bool Signed, bool Ret = false,
546 AttributeList AL = AttributeList()) const {
547 if (auto AK = getExtAttrForI32Param(Signed))
548 for (auto ArgNo : ArgNos)
549 AL = AL.addParamAttribute(*C, ArgNo, AK);
550 if (Ret)
551 if (auto AK = getExtAttrForI32Return(Signed))
552 AL = AL.addRetAttribute(*C, AK);
553 return AL;
554 }
555
556 /// \copydoc TargetLibraryInfoImpl::getWCharSize()
557 unsigned getWCharSize(const Module &M) const {
558 return Impl->getWCharSize(M);
559 }
560
561 /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
562 unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
563
564 /// Returns an IntegerType corresponding to size_t.
565 IntegerType *getSizeTType(const Module &M) const {
566 return IntegerType::get(M.getContext(), getSizeTSize(M));
567 }
568
569 /// Returns a constant materialized as a size_t type.
570 ConstantInt *getAsSizeT(uint64_t V, const Module &M) const {
571 return ConstantInt::get(getSizeTType(M), V);
572 }
573
574 /// \copydoc TargetLibraryInfoImpl::getIntSize()
575 unsigned getIntSize() const {
576 return Impl->getIntSize();
577 }
578
579 /// Handle invalidation from the pass manager.
580 ///
581 /// If we try to invalidate this info, just return false. It cannot become
582 /// invalid even if the module or function changes.
584 ModuleAnalysisManager::Invalidator &) {
585 return false;
586 }
588 FunctionAnalysisManager::Invalidator &) {
589 return false;
590 }
591 /// Returns the largest vectorization factor used in the list of
592 /// vector functions.
593 void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
594 ElementCount &ScalableVF) const {
595 Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
596 }
597
598 /// Check if the function "F" is listed in a library known to LLVM.
600 return this->isFunctionVectorizable(F);
601 }
602};
603
604/// Analysis pass providing the \c TargetLibraryInfo.
605///
606/// Note that this pass's result cannot be invalidated, it is immutable for the
607/// life of the module.
608class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
609public:
611
612 /// Default construct the library analysis.
613 ///
614 /// This will use the module's triple to construct the library info for that
615 /// module.
617
618 /// Construct a library analysis with baseline Module-level info.
619 ///
620 /// This will be supplemented with Function-specific info in the Result.
622 : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
623
625
626private:
628 LLVM_ABI static AnalysisKey Key;
629
630 std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
631};
632
635 std::optional<TargetLibraryInfo> TLI;
636
637 virtual void anchor();
638
639public:
640 static char ID;
641
642 /// The default constructor should not be used and is only for pass manager
643 /// initialization purposes.
645
646 explicit TargetLibraryInfoWrapperPass(const Triple &T);
648
649 // FIXME: This should be removed when PlaceSafepoints is fixed to not create a
650 // PassManager inside a pass.
652
655 TLI = TLA.run(F, DummyFAM);
656 return *TLI;
657 }
658};
659
660} // end namespace llvm
661
662#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:40
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:361
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:88
@ None
No attributes have been set.
Definition Attributes.h:90
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
This is the shared class of boolean and integer constants.
Definition Constants.h:87
Class to represent function types.
ImmutablePass(char &pid)
Definition Pass.h:287
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:318
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
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