aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms/Utils/SimplifyLibCalls.cpp
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2012-11-29 19:15:17 +0000
committerMeador Inge <meadori@codesourcery.com>2012-11-29 19:15:17 +0000
commitaa8cccf1292503f4a5d3fc55610f9a24f6dbee74 (patch)
tree9d890f8ecc1992f865fcb0cf9242878e72618bf4 /lib/Transforms/Utils/SimplifyLibCalls.cpp
parentf2c87b1c054fd4ea6f0215affb4ccfc36b77bcd8 (diff)
downloadexternal_llvm-aa8cccf1292503f4a5d3fc55610f9a24f6dbee74.zip
external_llvm-aa8cccf1292503f4a5d3fc55610f9a24f6dbee74.tar.gz
external_llvm-aa8cccf1292503f4a5d3fc55610f9a24f6dbee74.tar.bz2
instcombine: Migrate puts optimizations
This patch migrates the puts optimizations from the simplify-libcalls pass into the instcombine library call simplifier. All the simplifiers from simplify-libcalls have now been migrated to instcombine. Yay! Just a few other bits to migrate (prototype attribute inference and a few statistics) and simplify-libcalls can finally be put to rest. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r--lib/Transforms/Utils/SimplifyLibCalls.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 8d81ba4..6e01829 100644
--- a/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -1632,6 +1632,31 @@ struct FPutsOpt : public LibCallOptimization {
}
};
+struct PutsOpt : public LibCallOptimization {
+ virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) {
+ // Require one fixed pointer argument and an integer/void result.
+ FunctionType *FT = Callee->getFunctionType();
+ if (FT->getNumParams() < 1 || !FT->getParamType(0)->isPointerTy() ||
+ !(FT->getReturnType()->isIntegerTy() ||
+ FT->getReturnType()->isVoidTy()))
+ return 0;
+
+ // Check for a constant string.
+ StringRef Str;
+ if (!getConstantStringInfo(CI->getArgOperand(0), Str))
+ return 0;
+
+ if (Str.empty() && CI->use_empty()) {
+ // puts("") -> putchar('\n')
+ Value *Res = EmitPutChar(B.getInt32('\n'), B, TD, TLI);
+ if (CI->use_empty() || !Res) return Res;
+ return B.CreateIntCast(Res, CI->getType(), true);
+ }
+
+ return 0;
+ }
+};
+
} // End anonymous namespace.
namespace llvm {
@@ -1691,6 +1716,7 @@ class LibCallSimplifierImpl {
FPrintFOpt FPrintF;
FWriteOpt FWrite;
FPutsOpt FPuts;
+ PutsOpt Puts;
void initOptimizations();
void addOpt(LibFunc::Func F, LibCallOptimization* Opt);
@@ -1819,6 +1845,7 @@ void LibCallSimplifierImpl::initOptimizations() {
addOpt(LibFunc::fprintf, &FPrintF);
addOpt(LibFunc::fwrite, &FWrite);
addOpt(LibFunc::fputs, &FPuts);
+ addOpt(LibFunc::puts, &Puts);
}
Value *LibCallSimplifierImpl::optimizeCall(CallInst *CI) {