[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 Oct 4 06:53:21 PDT 2021
bjope updated this revision to Diff 376883.
bjope added a comment.
Rebased.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110585/new/
https://reviews.llvm.org/D110585
Files:
llvm/include/llvm/Analysis/TargetLibraryInfo.h
llvm/lib/Analysis/TargetLibraryInfo.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3292,11 +3292,8 @@
else
return nullptr;
- // FIXME: There is really no guarantee that sizeof(size_t) is equal to
- // sizeof(int*) for every target. So the assumption used here to derive the
- // SizeTBits based on the size of an integer pointer in address space zero
- // isn't always valid.
- Type *SizeTTy = DL.getIntPtrType(CI->getContext(), /*AddressSpace=*/0);
+ unsigned SizeTBits = TLI->getSizeTSize(*CI->getModule(), /*AddressSpace=*/0);
+ Type *SizeTTy = IntegerType::get(CI->getContext(), SizeTBits);
Value *LenV = ConstantInt::get(SizeTTy, Len);
Value *Ret = emitMemCpyChk(Dst, Src, LenV, ObjSize, B, DL, TLI);
// If the function was an __stpcpy_chk, and we were able to fold it into
Index: llvm/lib/Analysis/TargetLibraryInfo.cpp
===================================================================
--- llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -785,11 +785,7 @@
bool TargetLibraryInfoImpl::isValidProtoForLibFunc(const FunctionType &FTy,
LibFunc F,
const Module &M) const {
- // FIXME: There is really no guarantee that sizeof(size_t) is equal to
- // sizeof(int*) for every target. So the assumption used here to derive the
- // SizeTBits based on the size of an integer pointer in address space zero
- // isn't always valid.
- unsigned SizeTBits = M.getDataLayout().getPointerSizeInBits(/*AddrSpace=*/0);
+ unsigned SizeTBits = getSizeTSize(M, /*AddressSpace=*/0);
unsigned NumParams = FTy.getNumParams();
switch (F) {
@@ -1796,6 +1792,19 @@
return 0;
}
+unsigned TargetLibraryInfoImpl::getSizeTSize(const Module &M,
+ unsigned AddressSpace) const {
+ // There is really no guarantee that sizeof(size_t) is equal to sizeof(int*)
+ // for every target. If that isn't true then it should be possible to derive
+ // the SizeTTy from the target tripe here instead and do an early return.
+
+ // Here we assume that sizeof(size_t) is equal to sizeof(int*) in address
+ // space zero. This should work for most targets.
+ // TODO: Should this use getIndexSizeInBits instead?
+ const DataLayout &DL = M.getDataLayout();
+ return DL.getPointerSizeInBits(AddressSpace);
+}
+
TargetLibraryInfoWrapperPass::TargetLibraryInfoWrapperPass()
: ImmutablePass(ID), TLA(TargetLibraryInfoImpl()) {
initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
Index: llvm/include/llvm/Analysis/TargetLibraryInfo.h
===================================================================
--- llvm/include/llvm/Analysis/TargetLibraryInfo.h
+++ llvm/include/llvm/Analysis/TargetLibraryInfo.h
@@ -192,6 +192,9 @@
/// This queries the 'wchar_size' metadata.
unsigned getWCharSize(const Module &M) const;
+ /// Returns the size of the size_t type in bits or 0 if the size is unknown.
+ unsigned getSizeTSize(const Module &M, unsigned AddressSpace) const;
+
/// Get size of a C-level int or unsigned int, in bits.
unsigned getIntSize() const {
return SizeOfInt;
@@ -403,6 +406,11 @@
return Impl->getWCharSize(M);
}
+ /// \copydoc TargetLibraryInfoImpl::getSizeTSize()
+ unsigned getSizeTSize(const Module &M, unsigned AddressSpace) const {
+ return Impl->getSizeTSize(M, AddressSpace);
+ }
+
/// \copydoc TargetLibraryInfoImpl::getIntSize()
unsigned getIntSize() const {
return Impl->getIntSize();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110585.376883.patch
Type: text/x-patch
Size: 3731 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211004/3bf1b0b5/attachment.bin>
More information about the llvm-commits
mailing list