[PATCH] D110585: [Analysis][SimplifyLibCalls] Refactor code related to size_t in lib func signatures. NFCI

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 27 13:42:19 PDT 2021


bjope created this revision.
bjope added a reviewer: spatel.
Herald added a subscriber: hiraditya.
bjope requested review of this revision.
Herald added a project: LLVM.

A couple of refactorings happening here:

- Added a helper in TargetLibraryInfo to get size of "size_t" in bits, given a Module reference. The new getSizeTSize helper is using the same strategy as for example isValidProtoForLibFunc has been using in the past, assuming that the size can be derived by asking DataLayout about the size/type of a pointer to int.
- In TargetLibraryInfoImpl::isValidProtoForLibFunc we no longer need the IsSizeTTy lambda function and the SizeTTy object. Instead we just follow the regular structure of checking for integer types given an exepected number of bits (which we get for size_t using the new helper). Here we assume that there won't be a match if SizeOfSizeT is zero, e.g. if the Module isn't provided when doing the look up. This is the same defensive approach as the old code when not finding the DataLayout (which was taken from the Module).
- FortifiedLibCallSimplifier::optimizeStrpCpyChk was changed to use the new getSizeTSize helper instead of assuming that sizeof(size_t) is equal to sizeof(int*) by itself (that is the assumption used in TargetLibraryInfoImpl::getSizeTSize so the result will be the same).

One bonus with this refactoring is that it makes it easier to override
the assumption that sizeof(size_t) is equal to sizeof(int*) that still
exist in TargetLibraryInfoImpl::getSizeTSize. It should be pretty easy
to just override that based on the target triple for any target where
the assumption doesn't hold.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110585

Files:
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110585.375392.patch
Type: text/x-patch
Size: 13450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210927/ca68aa51/attachment.bin>


More information about the llvm-commits mailing list