[PM] Simplify (ha! ha!) the way that instcombine calls the
authorChandler Carruth <chandlerc@gmail.com>
Wed, 21 Jan 2015 11:23:40 +0000 (11:23 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Wed, 21 Jan 2015 11:23:40 +0000 (11:23 +0000)
SimplifyLibCalls utility by sinking it into the specific call part of
the combiner.

This will avoid us needing to do any contortions to build this object in
a subsequent refactoring I'm doing and seems generally better factored.
We don't need this utility everywhere and it carries no interesting
state so we might as well build it on demand.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226654 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombine.h
lib/Transforms/InstCombine/InstCombineCalls.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp

index e404581bd9159123ef5ec0a376294ea68c8f2423..5aaba2c17e2ed0b1f24c2e9cfdcd93d2d3080799 100644 (file)
@@ -22,7 +22,6 @@
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/Pass.h"
-#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
 
 #define DEBUG_TYPE "instcombine"
 
@@ -111,7 +110,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner
   DominatorTree *DT;
   LoopInfo *LI;
   bool MadeIRChange;
-  LibCallSimplifier *Simplifier;
   bool MinimizeSize;
 
 public:
index dab2c4b47ad66da89f27d72b0d31fe821a4c822b..40f288c175caff354d67f6c08932f6fbecb7c43f 100644 (file)
@@ -21,6 +21,7 @@
 #include "llvm/IR/Statepoint.h"
 #include "llvm/Transforms/Utils/BuildLibCalls.h"
 #include "llvm/Transforms/Utils/Local.h"
+#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
 using namespace llvm;
 using namespace PatternMatch;
 
@@ -1184,7 +1185,11 @@ static bool isSafeToEliminateVarargsCast(const CallSite CS,
 Instruction *InstCombiner::tryOptimizeCall(CallInst *CI, const DataLayout *DL) {
   if (!CI->getCalledFunction()) return nullptr;
 
-  if (Value *With = Simplifier->optimizeCall(CI)) {
+  auto InstCombineRAUW = [this](Instruction *From, Value *With) {
+    ReplaceInstUsesWith(*From, With);
+  };
+  LibCallSimplifier Simplifier(DL, TLI, InstCombineRAUW);
+  if (Value *With = Simplifier.optimizeCall(CI)) {
     ++NumSimplified;
     return CI->use_empty() ? CI : ReplaceInstUsesWith(*CI, With);
   }
index 33f024b2729fb25882aba3be73de26b610acb1b3..9436f23345b6e7328d1849edc4a4df5590ea9964 100644 (file)
@@ -2943,12 +2943,6 @@ bool InstCombiner::run(Function &F, AssumptionCache *AC, const DataLayout *DL,
       F.getContext(), TargetFolder(DL), InstCombineIRInserter(Worklist, AC));
   Builder = &TheBuilder;
 
-  auto InstCombineRAUW = [this](Instruction *From, Value *With) {
-    ReplaceInstUsesWith(*From, With);
-  };
-  LibCallSimplifier TheSimplifier(DL, TLI, InstCombineRAUW);
-  Simplifier = &TheSimplifier;
-
   bool EverMadeChange = false;
 
   // Lower dbg.declare intrinsics otherwise their value may be clobbered