[PATCH] D32837: TargetLibraryInfo: Introduce wcslen

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 3 16:38:17 PDT 2017


MatzeB created this revision.
Herald added subscribers: wdng, mcrosier.

wcslen is part of the C99 and C++98 standards.

- This introduces the function to TargetLibraryInfo.
- Also set attributes for wcslen in llvm::inferLibFuncAttributes().

This especially helps eliminating unnecessary exception landing pads in the std::wstring constructor which is often inlined.


Repository:
  rL LLVM

https://reviews.llvm.org/D32837

Files:
  include/llvm/Analysis/TargetLibraryInfo.def
  lib/Analysis/TargetLibraryInfo.cpp
  lib/Transforms/Utils/BuildLibCalls.cpp


Index: lib/Transforms/Utils/BuildLibCalls.cpp
===================================================================
--- lib/Transforms/Utils/BuildLibCalls.cpp
+++ lib/Transforms/Utils/BuildLibCalls.cpp
@@ -113,6 +113,7 @@
   bool Changed = false;
   switch (TheLibFunc) {
   case LibFunc_strlen:
+  case LibFunc_wcslen:
     Changed |= setOnlyReadsMemory(F);
     Changed |= setDoesNotThrow(F);
     Changed |= setDoesNotCapture(F, 0);
Index: lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- lib/Analysis/TargetLibraryInfo.cpp
+++ lib/Analysis/TargetLibraryInfo.cpp
@@ -1176,6 +1176,10 @@
             FTy.getParamType(0)->isPointerTy() &&
             FTy.getParamType(1) == SizeTTy && FTy.getParamType(2) == SizeTTy);
 
+  case LibFunc_wcslen:
+    return (NumParams == 1 && FTy.getParamType(0)->isPointerTy() &&
+            FTy.getReturnType()->isIntegerTy());
+
   case LibFunc::NumLibFuncs:
     break;
   }
Index: include/llvm/Analysis/TargetLibraryInfo.def
===================================================================
--- include/llvm/Analysis/TargetLibraryInfo.def
+++ include/llvm/Analysis/TargetLibraryInfo.def
@@ -1115,6 +1115,9 @@
 /// int vsscanf(const char *s, const char *format, va_list arg);
 TLI_DEFINE_ENUM_INTERNAL(vsscanf)
 TLI_DEFINE_STRING_INTERNAL("vsscanf")
+/// size_t wcslen (const wchar_t* wcs);
+TLI_DEFINE_ENUM_INTERNAL(wcslen)
+TLI_DEFINE_STRING_INTERNAL("wcslen")
 /// ssize_t write(int fildes, const void *buf, size_t nbyte);
 TLI_DEFINE_ENUM_INTERNAL(write)
 TLI_DEFINE_STRING_INTERNAL("write")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32837.97745.patch
Type: text/x-patch
Size: 1593 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170503/46184ba2/attachment.bin>


More information about the llvm-commits mailing list