aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bolvansky <david.bolvansky@gmail.com>2018-05-31 16:39:27 +0000
committerDavid Bolvansky <david.bolvansky@gmail.com>2018-05-31 16:39:27 +0000
commit5430b7375565a27ccadcf4a413153a3ceac8715a (patch)
treedd45fa7db23bc06e85081637ad02b508c42b6fdb
parent90aba024c539cd214f2e124890355246db431104 (diff)
downloadllvm-5430b7375565a27ccadcf4a413153a3ceac8715a.zip
llvm-5430b7375565a27ccadcf4a413153a3ceac8715a.tar.gz
llvm-5430b7375565a27ccadcf4a413153a3ceac8715a.tar.bz2
[SimplifyLibcalls] [NFC] Cleanup, improvements
Summary: * Use "find('%')" instead of loop to find '%' char (we already uses find('%') in optimizePrintFString..) * Convert getParent() chains to getModule()/getFunction() Reviewers: lebedev.ri, spatel Reviewed By: spatel Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D47397 llvm-svn: 333668
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 32e47b6..685922c 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -538,7 +538,7 @@ Value *LibCallSimplifier::optimizeStrLen(CallInst *CI, IRBuilder<> &B) {
}
Value *LibCallSimplifier::optimizeWcslen(CallInst *CI, IRBuilder<> &B) {
- Module &M = *CI->getParent()->getParent()->getParent();
+ Module &M = *CI->getModule();
unsigned WCharSize = TLI->getWCharSize(M) * 8;
// We cannot perform this optimization without wchar_size metadata.
if (WCharSize == 0)
@@ -1865,9 +1865,8 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI, IRBuilder<> &B) {
if (CI->getNumArgOperands() == 2) {
// Make sure there's no % in the constant array. We could try to handle
// %% -> % in the future if we cared.
- for (unsigned i = 0, e = FormatStr.size(); i != e; ++i)
- if (FormatStr[i] == '%')
- return nullptr; // we found a format specifier, bail out.
+ if (FormatStr.find('%') != StringRef::npos)
+ return nullptr; // we found a format specifier, bail out.
// sprintf(str, fmt) -> llvm.memcpy(align 1 str, align 1 fmt, strlen(fmt)+1)
B.CreateMemCpy(CI->getArgOperand(0), 1, CI->getArgOperand(1), 1,
@@ -1952,9 +1951,8 @@ Value *LibCallSimplifier::optimizeSnPrintFString(CallInst *CI, IRBuilder<> &B) {
if (CI->getNumArgOperands() == 3) {
// Make sure there's no % in the constant array. We could try to handle
// %% -> % in the future if we cared.
- for (unsigned i = 0, e = FormatStr.size(); i != e; ++i)
- if (FormatStr[i] == '%')
- return nullptr; // we found a format specifier, bail out.
+ if (FormatStr.find('%') != StringRef::npos)
+ return nullptr; // we found a format specifier, bail out.
if (N == 0)
return ConstantInt::get(CI->getType(), FormatStr.size());
@@ -2039,9 +2037,9 @@ Value *LibCallSimplifier::optimizeFPrintFString(CallInst *CI, IRBuilder<> &B) {
// fprintf(F, "foo") --> fwrite("foo", 3, 1, F)
if (CI->getNumArgOperands() == 2) {
- for (unsigned i = 0, e = FormatStr.size(); i != e; ++i)
- if (FormatStr[i] == '%') // Could handle %% -> % if we cared.
- return nullptr; // We found a format specifier.
+ // Could handle %% -> % if we cared.
+ if (FormatStr.find('%') != StringRef::npos)
+ return nullptr; // We found a format specifier.
return emitFWrite(
CI->getArgOperand(1),
@@ -2128,7 +2126,7 @@ Value *LibCallSimplifier::optimizeFPuts(CallInst *CI, IRBuilder<> &B) {
// Don't rewrite fputs to fwrite when optimising for size because fwrite
// requires more arguments and thus extra MOVs are required.
- if (CI->getParent()->getParent()->optForSize())
+ if (CI->getFunction()->optForSize())
return nullptr;
// Check if has any use