TargetLibraryInfo.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- TargetLibraryInfo.h - Library information ---------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ANALYSIS_TARGETLIBRARYINFO_H
  14. #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
  15. #include "llvm/ADT/BitVector.h"
  16. #include "llvm/ADT/DenseMap.h"
  17. #include "llvm/ADT/Triple.h"
  18. #include "llvm/IR/InstrTypes.h"
  19. #include "llvm/IR/PassManager.h"
  20. #include "llvm/Pass.h"
  21. #include <optional>
  22. namespace llvm {
  23. template <typename T> class ArrayRef;
  24. class Function;
  25. class Module;
  26. class Triple;
  27. /// Describes a possible vectorization of a function.
  28. /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized
  29. /// by a factor 'VectorizationFactor'.
  30. struct VecDesc {
  31. StringRef ScalarFnName;
  32. StringRef VectorFnName;
  33. ElementCount VectorizationFactor;
  34. };
  35. enum LibFunc : unsigned {
  36. #define TLI_DEFINE_ENUM
  37. #include "llvm/Analysis/TargetLibraryInfo.def"
  38. NumLibFuncs,
  39. NotLibFunc
  40. };
  41. /// Implementation of the target library information.
  42. ///
  43. /// This class constructs tables that hold the target library information and
  44. /// make it available. However, it is somewhat expensive to compute and only
  45. /// depends on the triple. So users typically interact with the \c
  46. /// TargetLibraryInfo wrapper below.
  47. class TargetLibraryInfoImpl {
  48. friend class TargetLibraryInfo;
  49. unsigned char AvailableArray[(NumLibFuncs+3)/4];
  50. DenseMap<unsigned, std::string> CustomNames;
  51. static StringLiteral const StandardNames[NumLibFuncs];
  52. bool ShouldExtI32Param, ShouldExtI32Return, ShouldSignExtI32Param, ShouldSignExtI32Return;
  53. unsigned SizeOfInt;
  54. enum AvailabilityState {
  55. StandardName = 3, // (memset to all ones)
  56. CustomName = 1,
  57. Unavailable = 0 // (memset to all zeros)
  58. };
  59. void setState(LibFunc F, AvailabilityState State) {
  60. AvailableArray[F/4] &= ~(3 << 2*(F&3));
  61. AvailableArray[F/4] |= State << 2*(F&3);
  62. }
  63. AvailabilityState getState(LibFunc F) const {
  64. return static_cast<AvailabilityState>((AvailableArray[F/4] >> 2*(F&3)) & 3);
  65. }
  66. /// Vectorization descriptors - sorted by ScalarFnName.
  67. std::vector<VecDesc> VectorDescs;
  68. /// Scalarization descriptors - same content as VectorDescs but sorted based
  69. /// on VectorFnName rather than ScalarFnName.
  70. std::vector<VecDesc> ScalarDescs;
  71. /// Return true if the function type FTy is valid for the library function
  72. /// F, regardless of whether the function is available.
  73. bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
  74. const Module &M) const;
  75. public:
  76. /// List of known vector-functions libraries.
  77. ///
  78. /// The vector-functions library defines, which functions are vectorizable
  79. /// and with which factor. The library can be specified by either frontend,
  80. /// or a commandline option, and then used by
  81. /// addVectorizableFunctionsFromVecLib for filling up the tables of
  82. /// vectorizable functions.
  83. enum VectorLibrary {
  84. NoLibrary, // Don't use any vector library.
  85. Accelerate, // Use Accelerate framework.
  86. DarwinLibSystemM, // Use Darwin's libsystem_m.
  87. LIBMVEC_X86, // GLIBC Vector Math library.
  88. MASSV, // IBM MASS vector library.
  89. SVML, // Intel short vector math library.
  90. SLEEFGNUABI // SLEEF - SIMD Library for Evaluating Elementary Functions.
  91. };
  92. TargetLibraryInfoImpl();
  93. explicit TargetLibraryInfoImpl(const Triple &T);
  94. // Provide value semantics.
  95. TargetLibraryInfoImpl(const TargetLibraryInfoImpl &TLI);
  96. TargetLibraryInfoImpl(TargetLibraryInfoImpl &&TLI);
  97. TargetLibraryInfoImpl &operator=(const TargetLibraryInfoImpl &TLI);
  98. TargetLibraryInfoImpl &operator=(TargetLibraryInfoImpl &&TLI);
  99. /// Searches for a particular function name.
  100. ///
  101. /// If it is one of the known library functions, return true and set F to the
  102. /// corresponding value.
  103. bool getLibFunc(StringRef funcName, LibFunc &F) const;
  104. /// Searches for a particular function name, also checking that its type is
  105. /// valid for the library function matching that name.
  106. ///
  107. /// If it is one of the known library functions, return true and set F to the
  108. /// corresponding value.
  109. ///
  110. /// FDecl is assumed to have a parent Module when using this function.
  111. bool getLibFunc(const Function &FDecl, LibFunc &F) const;
  112. /// Forces a function to be marked as unavailable.
  113. void setUnavailable(LibFunc F) {
  114. setState(F, Unavailable);
  115. }
  116. /// Forces a function to be marked as available.
  117. void setAvailable(LibFunc F) {
  118. setState(F, StandardName);
  119. }
  120. /// Forces a function to be marked as available and provide an alternate name
  121. /// that must be used.
  122. void setAvailableWithName(LibFunc F, StringRef Name) {
  123. if (StandardNames[F] != Name) {
  124. setState(F, CustomName);
  125. CustomNames[F] = std::string(Name);
  126. assert(CustomNames.find(F) != CustomNames.end());
  127. } else {
  128. setState(F, StandardName);
  129. }
  130. }
  131. /// Disables all builtins.
  132. ///
  133. /// This can be used for options like -fno-builtin.
  134. void disableAllFunctions();
  135. /// Add a set of scalar -> vector mappings, queryable via
  136. /// getVectorizedFunction and getScalarizedFunction.
  137. void addVectorizableFunctions(ArrayRef<VecDesc> Fns);
  138. /// Calls addVectorizableFunctions with a known preset of functions for the
  139. /// given vector library.
  140. void addVectorizableFunctionsFromVecLib(enum VectorLibrary VecLib,
  141. const llvm::Triple &TargetTriple);
  142. /// Return true if the function F has a vector equivalent with vectorization
  143. /// factor VF.
  144. bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const {
  145. return !getVectorizedFunction(F, VF).empty();
  146. }
  147. /// Return true if the function F has a vector equivalent with any
  148. /// vectorization factor.
  149. bool isFunctionVectorizable(StringRef F) const;
  150. /// Return the name of the equivalent of F, vectorized with factor VF. If no
  151. /// such mapping exists, return the empty string.
  152. StringRef getVectorizedFunction(StringRef F, const ElementCount &VF) const;
  153. /// Set to true iff i32 parameters to library functions should have signext
  154. /// or zeroext attributes if they correspond to C-level int or unsigned int,
  155. /// respectively.
  156. void setShouldExtI32Param(bool Val) {
  157. ShouldExtI32Param = Val;
  158. }
  159. /// Set to true iff i32 results from library functions should have signext
  160. /// or zeroext attributes if they correspond to C-level int or unsigned int,
  161. /// respectively.
  162. void setShouldExtI32Return(bool Val) {
  163. ShouldExtI32Return = Val;
  164. }
  165. /// Set to true iff i32 parameters to library functions should have signext
  166. /// attribute if they correspond to C-level int or unsigned int.
  167. void setShouldSignExtI32Param(bool Val) {
  168. ShouldSignExtI32Param = Val;
  169. }
  170. /// Set to true iff i32 results from library functions should have signext
  171. /// attribute if they correspond to C-level int or unsigned int.
  172. void setShouldSignExtI32Return(bool Val) {
  173. ShouldSignExtI32Return = Val;
  174. }
  175. /// Returns the size of the wchar_t type in bytes or 0 if the size is unknown.
  176. /// This queries the 'wchar_size' metadata.
  177. unsigned getWCharSize(const Module &M) const;
  178. /// Returns the size of the size_t type in bits.
  179. unsigned getSizeTSize(const Module &M) const;
  180. /// Get size of a C-level int or unsigned int, in bits.
  181. unsigned getIntSize() const {
  182. return SizeOfInt;
  183. }
  184. /// Initialize the C-level size of an integer.
  185. void setIntSize(unsigned Bits) {
  186. SizeOfInt = Bits;
  187. }
  188. /// Returns the largest vectorization factor used in the list of
  189. /// vector functions.
  190. void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
  191. ElementCount &Scalable) const;
  192. /// Returns true if call site / callee has cdecl-compatible calling
  193. /// conventions.
  194. static bool isCallingConvCCompatible(CallBase *CI);
  195. static bool isCallingConvCCompatible(Function *Callee);
  196. };
  197. /// Provides information about what library functions are available for
  198. /// the current target.
  199. ///
  200. /// This both allows optimizations to handle them specially and frontends to
  201. /// disable such optimizations through -fno-builtin etc.
  202. class TargetLibraryInfo {
  203. friend class TargetLibraryAnalysis;
  204. friend class TargetLibraryInfoWrapperPass;
  205. /// The global (module level) TLI info.
  206. const TargetLibraryInfoImpl *Impl;
  207. /// Support for -fno-builtin* options as function attributes, overrides
  208. /// information in global TargetLibraryInfoImpl.
  209. BitVector OverrideAsUnavailable;
  210. public:
  211. explicit TargetLibraryInfo(const TargetLibraryInfoImpl &Impl,
  212. std::optional<const Function *> F = std::nullopt)
  213. : Impl(&Impl), OverrideAsUnavailable(NumLibFuncs) {
  214. if (!F)
  215. return;
  216. if ((*F)->hasFnAttribute("no-builtins"))
  217. disableAllFunctions();
  218. else {
  219. // Disable individual libc/libm calls in TargetLibraryInfo.
  220. LibFunc LF;
  221. AttributeSet FnAttrs = (*F)->getAttributes().getFnAttrs();
  222. for (const Attribute &Attr : FnAttrs) {
  223. if (!Attr.isStringAttribute())
  224. continue;
  225. auto AttrStr = Attr.getKindAsString();
  226. if (!AttrStr.consume_front("no-builtin-"))
  227. continue;
  228. if (getLibFunc(AttrStr, LF))
  229. setUnavailable(LF);
  230. }
  231. }
  232. }
  233. // Provide value semantics.
  234. TargetLibraryInfo(const TargetLibraryInfo &TLI) = default;
  235. TargetLibraryInfo(TargetLibraryInfo &&TLI)
  236. : Impl(TLI.Impl), OverrideAsUnavailable(TLI.OverrideAsUnavailable) {}
  237. TargetLibraryInfo &operator=(const TargetLibraryInfo &TLI) = default;
  238. TargetLibraryInfo &operator=(TargetLibraryInfo &&TLI) {
  239. Impl = TLI.Impl;
  240. OverrideAsUnavailable = TLI.OverrideAsUnavailable;
  241. return *this;
  242. }
  243. /// Determine whether a callee with the given TLI can be inlined into
  244. /// caller with this TLI, based on 'nobuiltin' attributes. When requested,
  245. /// allow inlining into a caller with a superset of the callee's nobuiltin
  246. /// attributes, which is conservatively correct.
  247. bool areInlineCompatible(const TargetLibraryInfo &CalleeTLI,
  248. bool AllowCallerSuperset) const {
  249. if (!AllowCallerSuperset)
  250. return OverrideAsUnavailable == CalleeTLI.OverrideAsUnavailable;
  251. BitVector B = OverrideAsUnavailable;
  252. B |= CalleeTLI.OverrideAsUnavailable;
  253. // We can inline if the union of the caller and callee's nobuiltin
  254. // attributes is no stricter than the caller's nobuiltin attributes.
  255. return B == OverrideAsUnavailable;
  256. }
  257. /// Return true if the function type FTy is valid for the library function
  258. /// F, regardless of whether the function is available.
  259. bool isValidProtoForLibFunc(const FunctionType &FTy, LibFunc F,
  260. const Module &M) const {
  261. return Impl->isValidProtoForLibFunc(FTy, F, M);
  262. }
  263. /// Searches for a particular function name.
  264. ///
  265. /// If it is one of the known library functions, return true and set F to the
  266. /// corresponding value.
  267. bool getLibFunc(StringRef funcName, LibFunc &F) const {
  268. return Impl->getLibFunc(funcName, F);
  269. }
  270. bool getLibFunc(const Function &FDecl, LibFunc &F) const {
  271. return Impl->getLibFunc(FDecl, F);
  272. }
  273. /// If a callbase does not have the 'nobuiltin' attribute, return if the
  274. /// called function is a known library function and set F to that function.
  275. bool getLibFunc(const CallBase &CB, LibFunc &F) const {
  276. return !CB.isNoBuiltin() && CB.getCalledFunction() &&
  277. getLibFunc(*(CB.getCalledFunction()), F);
  278. }
  279. /// Disables all builtins.
  280. ///
  281. /// This can be used for options like -fno-builtin.
  282. void disableAllFunctions() LLVM_ATTRIBUTE_UNUSED {
  283. OverrideAsUnavailable.set();
  284. }
  285. /// Forces a function to be marked as unavailable.
  286. void setUnavailable(LibFunc F) LLVM_ATTRIBUTE_UNUSED {
  287. OverrideAsUnavailable.set(F);
  288. }
  289. TargetLibraryInfoImpl::AvailabilityState getState(LibFunc F) const {
  290. if (OverrideAsUnavailable[F])
  291. return TargetLibraryInfoImpl::Unavailable;
  292. return Impl->getState(F);
  293. }
  294. /// Tests whether a library function is available.
  295. bool has(LibFunc F) const {
  296. return getState(F) != TargetLibraryInfoImpl::Unavailable;
  297. }
  298. bool isFunctionVectorizable(StringRef F, const ElementCount &VF) const {
  299. return Impl->isFunctionVectorizable(F, VF);
  300. }
  301. bool isFunctionVectorizable(StringRef F) const {
  302. return Impl->isFunctionVectorizable(F);
  303. }
  304. StringRef getVectorizedFunction(StringRef F, const ElementCount &VF) const {
  305. return Impl->getVectorizedFunction(F, VF);
  306. }
  307. /// Tests if the function is both available and a candidate for optimized code
  308. /// generation.
  309. bool hasOptimizedCodeGen(LibFunc F) const {
  310. if (getState(F) == TargetLibraryInfoImpl::Unavailable)
  311. return false;
  312. switch (F) {
  313. default: break;
  314. case LibFunc_copysign: case LibFunc_copysignf: case LibFunc_copysignl:
  315. case LibFunc_fabs: case LibFunc_fabsf: case LibFunc_fabsl:
  316. case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
  317. case LibFunc_cos: case LibFunc_cosf: case LibFunc_cosl:
  318. case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:
  319. case LibFunc_sqrt_finite: case LibFunc_sqrtf_finite:
  320. case LibFunc_sqrtl_finite:
  321. case LibFunc_fmax: case LibFunc_fmaxf: case LibFunc_fmaxl:
  322. case LibFunc_fmin: case LibFunc_fminf: case LibFunc_fminl:
  323. case LibFunc_floor: case LibFunc_floorf: case LibFunc_floorl:
  324. case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
  325. case LibFunc_ceil: case LibFunc_ceilf: case LibFunc_ceill:
  326. case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
  327. case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
  328. case LibFunc_trunc: case LibFunc_truncf: case LibFunc_truncl:
  329. case LibFunc_log2: case LibFunc_log2f: case LibFunc_log2l:
  330. case LibFunc_exp2: case LibFunc_exp2f: case LibFunc_exp2l:
  331. case LibFunc_memcpy: case LibFunc_memset: case LibFunc_memmove:
  332. case LibFunc_memcmp: case LibFunc_bcmp: case LibFunc_strcmp:
  333. case LibFunc_strcpy: case LibFunc_stpcpy: case LibFunc_strlen:
  334. case LibFunc_strnlen: case LibFunc_memchr: case LibFunc_mempcpy:
  335. return true;
  336. }
  337. return false;
  338. }
  339. StringRef getName(LibFunc F) const {
  340. auto State = getState(F);
  341. if (State == TargetLibraryInfoImpl::Unavailable)
  342. return StringRef();
  343. if (State == TargetLibraryInfoImpl::StandardName)
  344. return Impl->StandardNames[F];
  345. assert(State == TargetLibraryInfoImpl::CustomName);
  346. return Impl->CustomNames.find(F)->second;
  347. }
  348. static void initExtensionsForTriple(bool &ShouldExtI32Param,
  349. bool &ShouldExtI32Return,
  350. bool &ShouldSignExtI32Param,
  351. bool &ShouldSignExtI32Return,
  352. const Triple &T) {
  353. ShouldExtI32Param = ShouldExtI32Return = false;
  354. ShouldSignExtI32Param = ShouldSignExtI32Return = false;
  355. // PowerPC64, Sparc64, SystemZ need signext/zeroext on i32 parameters and
  356. // returns corresponding to C-level ints and unsigned ints.
  357. if (T.isPPC64() || T.getArch() == Triple::sparcv9 ||
  358. T.getArch() == Triple::systemz) {
  359. ShouldExtI32Param = true;
  360. ShouldExtI32Return = true;
  361. }
  362. // Mips and riscv64, on the other hand, needs signext on i32 parameters
  363. // corresponding to both signed and unsigned ints.
  364. if (T.isMIPS() || T.isRISCV64()) {
  365. ShouldSignExtI32Param = true;
  366. }
  367. // riscv64 needs signext on i32 returns corresponding to both signed and
  368. // unsigned ints.
  369. if (T.isRISCV64()) {
  370. ShouldSignExtI32Return = true;
  371. }
  372. }
  373. /// Returns extension attribute kind to be used for i32 parameters
  374. /// corresponding to C-level int or unsigned int. May be zeroext, signext,
  375. /// or none.
  376. private:
  377. static Attribute::AttrKind getExtAttrForI32Param(bool ShouldExtI32Param_,
  378. bool ShouldSignExtI32Param_,
  379. bool Signed = true) {
  380. if (ShouldExtI32Param_)
  381. return Signed ? Attribute::SExt : Attribute::ZExt;
  382. if (ShouldSignExtI32Param_)
  383. return Attribute::SExt;
  384. return Attribute::None;
  385. }
  386. public:
  387. static Attribute::AttrKind getExtAttrForI32Param(const Triple &T,
  388. bool Signed = true) {
  389. bool ShouldExtI32Param, ShouldExtI32Return;
  390. bool ShouldSignExtI32Param, ShouldSignExtI32Return;
  391. initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
  392. ShouldSignExtI32Param, ShouldSignExtI32Return, T);
  393. return getExtAttrForI32Param(ShouldExtI32Param, ShouldSignExtI32Param,
  394. Signed);
  395. }
  396. Attribute::AttrKind getExtAttrForI32Param(bool Signed = true) const {
  397. return getExtAttrForI32Param(Impl->ShouldExtI32Param,
  398. Impl->ShouldSignExtI32Param, Signed);
  399. }
  400. /// Returns extension attribute kind to be used for i32 return values
  401. /// corresponding to C-level int or unsigned int. May be zeroext, signext,
  402. /// or none.
  403. private:
  404. static Attribute::AttrKind getExtAttrForI32Return(bool ShouldExtI32Return_,
  405. bool ShouldSignExtI32Return_,
  406. bool Signed) {
  407. if (ShouldExtI32Return_)
  408. return Signed ? Attribute::SExt : Attribute::ZExt;
  409. if (ShouldSignExtI32Return_)
  410. return Attribute::SExt;
  411. return Attribute::None;
  412. }
  413. public:
  414. static Attribute::AttrKind getExtAttrForI32Return(const Triple &T,
  415. bool Signed = true) {
  416. bool ShouldExtI32Param, ShouldExtI32Return;
  417. bool ShouldSignExtI32Param, ShouldSignExtI32Return;
  418. initExtensionsForTriple(ShouldExtI32Param, ShouldExtI32Return,
  419. ShouldSignExtI32Param, ShouldSignExtI32Return, T);
  420. return getExtAttrForI32Return(ShouldExtI32Return, ShouldSignExtI32Return,
  421. Signed);
  422. }
  423. Attribute::AttrKind getExtAttrForI32Return(bool Signed = true) const {
  424. return getExtAttrForI32Return(Impl->ShouldExtI32Return,
  425. Impl->ShouldSignExtI32Return, Signed);
  426. }
  427. // Helper to create an AttributeList for args (and ret val) which all have
  428. // the same signedness. Attributes in AL may be passed in to include them
  429. // as well in the returned AttributeList.
  430. AttributeList getAttrList(LLVMContext *C, ArrayRef<unsigned> ArgNos,
  431. bool Signed, bool Ret = false,
  432. AttributeList AL = AttributeList()) const {
  433. if (auto AK = getExtAttrForI32Param(Signed))
  434. for (auto ArgNo : ArgNos)
  435. AL = AL.addParamAttribute(*C, ArgNo, AK);
  436. if (Ret)
  437. if (auto AK = getExtAttrForI32Return(Signed))
  438. AL = AL.addRetAttribute(*C, AK);
  439. return AL;
  440. }
  441. /// \copydoc TargetLibraryInfoImpl::getWCharSize()
  442. unsigned getWCharSize(const Module &M) const {
  443. return Impl->getWCharSize(M);
  444. }
  445. /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
  446. unsigned getSizeTSize(const Module &M) const { return Impl->getSizeTSize(M); }
  447. /// \copydoc TargetLibraryInfoImpl::getIntSize()
  448. unsigned getIntSize() const {
  449. return Impl->getIntSize();
  450. }
  451. /// Handle invalidation from the pass manager.
  452. ///
  453. /// If we try to invalidate this info, just return false. It cannot become
  454. /// invalid even if the module or function changes.
  455. bool invalidate(Module &, const PreservedAnalyses &,
  456. ModuleAnalysisManager::Invalidator &) {
  457. return false;
  458. }
  459. bool invalidate(Function &, const PreservedAnalyses &,
  460. FunctionAnalysisManager::Invalidator &) {
  461. return false;
  462. }
  463. /// Returns the largest vectorization factor used in the list of
  464. /// vector functions.
  465. void getWidestVF(StringRef ScalarF, ElementCount &FixedVF,
  466. ElementCount &ScalableVF) const {
  467. Impl->getWidestVF(ScalarF, FixedVF, ScalableVF);
  468. }
  469. /// Check if the function "F" is listed in a library known to LLVM.
  470. bool isKnownVectorFunctionInLibrary(StringRef F) const {
  471. return this->isFunctionVectorizable(F);
  472. }
  473. };
  474. /// Analysis pass providing the \c TargetLibraryInfo.
  475. ///
  476. /// Note that this pass's result cannot be invalidated, it is immutable for the
  477. /// life of the module.
  478. class TargetLibraryAnalysis : public AnalysisInfoMixin<TargetLibraryAnalysis> {
  479. public:
  480. typedef TargetLibraryInfo Result;
  481. /// Default construct the library analysis.
  482. ///
  483. /// This will use the module's triple to construct the library info for that
  484. /// module.
  485. TargetLibraryAnalysis() = default;
  486. /// Construct a library analysis with baseline Module-level info.
  487. ///
  488. /// This will be supplemented with Function-specific info in the Result.
  489. TargetLibraryAnalysis(TargetLibraryInfoImpl BaselineInfoImpl)
  490. : BaselineInfoImpl(std::move(BaselineInfoImpl)) {}
  491. TargetLibraryInfo run(const Function &F, FunctionAnalysisManager &);
  492. private:
  493. friend AnalysisInfoMixin<TargetLibraryAnalysis>;
  494. static AnalysisKey Key;
  495. std::optional<TargetLibraryInfoImpl> BaselineInfoImpl;
  496. };
  497. class TargetLibraryInfoWrapperPass : public ImmutablePass {
  498. TargetLibraryAnalysis TLA;
  499. std::optional<TargetLibraryInfo> TLI;
  500. virtual void anchor();
  501. public:
  502. static char ID;
  503. TargetLibraryInfoWrapperPass();
  504. explicit TargetLibraryInfoWrapperPass(const Triple &T);
  505. explicit TargetLibraryInfoWrapperPass(const TargetLibraryInfoImpl &TLI);
  506. TargetLibraryInfo &getTLI(const Function &F) {
  507. FunctionAnalysisManager DummyFAM;
  508. TLI = TLA.run(F, DummyFAM);
  509. return *TLI;
  510. }
  511. };
  512. } // end namespace llvm
  513. #endif
  514. #ifdef __GNUC__
  515. #pragma GCC diagnostic pop
  516. #endif