[llvm-commits] [llvm] r67332 - in /llvm/branches/Apple/Dib: include/llvm/Transforms/IPO/InlinerPass.h lib/Analysis/IPA/CallGraph.cpp lib/Transforms/IPO/Inliner.cpp lib/Transforms/IPO/PruneEH.cpp lib/Transforms/Scalar/Reassociate.cpp

Bill Wendling isanbard at gmail.com
Thu Mar 19 13:05:15 PDT 2009


Author: void
Date: Thu Mar 19 15:05:15 2009
New Revision: 67332

URL: http://llvm.org/viewvc/llvm-project?rev=67332&view=rev
Log:
--- Merging (from foreign repository) r67306 into '.':
U    lib/Transforms/Scalar/Reassociate.cpp

This pass keeps a map of Instructions to Rank numbers,
and was deleting Instructions without clearing the
corresponding map entry.  This led to nondeterministic
behavior if the same address got allocated to another
Instruction within a short time.

--- Merging (from foreign repository) r67311 into '.':
U    include/llvm/Transforms/IPO/InlinerPass.h
U    lib/Analysis/IPA/CallGraph.cpp
U    lib/Transforms/IPO/Inliner.cpp
U    lib/Transforms/IPO/PruneEH.cpp

Clear the cached cost when removing a function in
the inliner; prevents nondeterministic behavior
when the same address is reallocated.
Don't build call graph nodes for debug intrinsic calls;
they're useless, and there were typically a lot of them.

Modified:
    llvm/branches/Apple/Dib/include/llvm/Transforms/IPO/InlinerPass.h
    llvm/branches/Apple/Dib/lib/Analysis/IPA/CallGraph.cpp
    llvm/branches/Apple/Dib/lib/Transforms/IPO/Inliner.cpp
    llvm/branches/Apple/Dib/lib/Transforms/IPO/PruneEH.cpp
    llvm/branches/Apple/Dib/lib/Transforms/Scalar/Reassociate.cpp

Modified: llvm/branches/Apple/Dib/include/llvm/Transforms/IPO/InlinerPass.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/include/llvm/Transforms/IPO/InlinerPass.h?rev=67332&r1=67331&r2=67332&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/include/llvm/Transforms/IPO/InlinerPass.h (original)
+++ llvm/branches/Apple/Dib/include/llvm/Transforms/IPO/InlinerPass.h Thu Mar 19 15:05:15 2009
@@ -19,6 +19,9 @@
 
 #include "llvm/CallGraphSCCPass.h"
 #include "llvm/Transforms/Utils/InlineCost.h"
+#include "llvm/Target/TargetData.h"
+#include <set>
+
 
 namespace llvm {
   class CallSite;
@@ -43,6 +46,10 @@
   // processing to avoid breaking the SCC traversal.
   virtual bool doFinalization(CallGraph &CG);
 
+  // InlineCallIfPossible
+  bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
+                            const std::set<Function*> &SCCFunctions,
+                            const TargetData &TD);
 
   /// This method returns the value specified by the -inline-threshold value,
   /// specified on the command line.  This is typically not directly needed.

Modified: llvm/branches/Apple/Dib/lib/Analysis/IPA/CallGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Analysis/IPA/CallGraph.cpp?rev=67332&r1=67331&r2=67332&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Analysis/IPA/CallGraph.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Analysis/IPA/CallGraph.cpp Thu Mar 19 15:05:15 2009
@@ -15,6 +15,7 @@
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Streams.h"
@@ -143,7 +144,7 @@
       for (BasicBlock::iterator II = BB->begin(), IE = BB->end();
            II != IE; ++II) {
         CallSite CS = CallSite::get(II);
-        if (CS.getInstruction()) {
+        if (CS.getInstruction() && !isa<DbgInfoIntrinsic>(II)) {
           const Function *Callee = CS.getCalledFunction();
           if (Callee)
             Node->addCalledFunction(CS, getOrInsertFunction(Callee));

Modified: llvm/branches/Apple/Dib/lib/Transforms/IPO/Inliner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/IPO/Inliner.cpp?rev=67332&r1=67331&r2=67332&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/IPO/Inliner.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/IPO/Inliner.cpp Thu Mar 19 15:05:15 2009
@@ -16,6 +16,7 @@
 #define DEBUG_TYPE "inline"
 #include "llvm/Module.h"
 #include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Target/TargetData.h"
@@ -50,7 +51,7 @@
 
 // InlineCallIfPossible - If it is possible to inline the specified call site,
 // do so and update the CallGraph for this operation.
-static bool InlineCallIfPossible(CallSite CS, CallGraph &CG,
+bool Inliner::InlineCallIfPossible(CallSite CS, CallGraph &CG,
                                  const std::set<Function*> &SCCFunctions,
                                  const TargetData &TD) {
   Function *Callee = CS.getCalledFunction();
@@ -76,6 +77,8 @@
     // Remove any call graph edges from the callee to its callees.
     CalleeNode->removeAllCalledFunctions();
 
+    resetCachedCostInfo(CalleeNode->getFunction());
+
     // Removing the node for callee from the call graph and delete it.
     delete CG.removeFunctionFromModule(CalleeNode);
     ++NumDeleted;
@@ -123,6 +126,7 @@
 
 bool Inliner::runOnSCC(const std::vector<CallGraphNode*> &SCC) {
   CallGraph &CG = getAnalysis<CallGraph>();
+  TargetData &TD = getAnalysis<TargetData>();
 
   std::set<Function*> SCCFunctions;
   DOUT << "Inliner visiting SCC:";
@@ -142,7 +146,8 @@
       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
         for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) {
           CallSite CS = CallSite::get(I);
-          if (CS.getInstruction() && (!CS.getCalledFunction() ||
+          if (CS.getInstruction() && !isa<DbgInfoIntrinsic>(I) &&
+                                     (!CS.getCalledFunction() ||
                                       !CS.getCalledFunction()->isDeclaration()))
             CallSites.push_back(CS);
         }
@@ -186,11 +191,10 @@
         if (shouldInline(CS)) {
           Function *Caller = CS.getCaller();
           // Attempt to inline the function...
-          if (InlineCallIfPossible(CS, CG, SCCFunctions, 
-                                   getAnalysis<TargetData>())) {
-            // Remove any cached cost info for this caller, as inlining the callee
-            // has increased the size of the caller (which may be the same as the
-            // callee).
+          if (InlineCallIfPossible(CS, CG, SCCFunctions, TD)) {
+            // Remove any cached cost info for this caller, as inlining the
+            // callee has increased the size of the caller (which may be the
+            // same as the callee).
             resetCachedCostInfo(Caller);
 
             // Remove this call site from the list.  If possible, use 
@@ -263,6 +267,7 @@
   bool Changed = false;
   for (std::set<CallGraphNode*>::iterator I = FunctionsToRemove.begin(),
          E = FunctionsToRemove.end(); I != E; ++I) {
+    resetCachedCostInfo((*I)->getFunction());
     delete CG.removeFunctionFromModule(*I);
     ++NumDeleted;
     Changed = true;

Modified: llvm/branches/Apple/Dib/lib/Transforms/IPO/PruneEH.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/IPO/PruneEH.cpp?rev=67332&r1=67331&r2=67332&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/IPO/PruneEH.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/IPO/PruneEH.cpp Thu Mar 19 15:05:15 2009
@@ -20,6 +20,7 @@
 #include "llvm/Constants.h"
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
@@ -235,9 +236,10 @@
   CallGraphNode *CGN = CG[BB->getParent()];
   for (BasicBlock::iterator I = BB->end(), E = BB->begin(); I != E; ) {
     --I;
-    if (CallInst *CI = dyn_cast<CallInst>(I))
-      CGN->removeCallEdgeFor(CI);
-    else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
+    if (CallInst *CI = dyn_cast<CallInst>(I)) {
+      if (!isa<DbgInfoIntrinsic>(I))
+        CGN->removeCallEdgeFor(CI);
+    } else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
       CGN->removeCallEdgeFor(II);
     if (!I->use_empty())
       I->replaceAllUsesWith(UndefValue::get(I->getType()));

Modified: llvm/branches/Apple/Dib/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/Transforms/Scalar/Reassociate.cpp?rev=67332&r1=67331&r2=67332&view=diff

==============================================================================
--- llvm/branches/Apple/Dib/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/branches/Apple/Dib/lib/Transforms/Scalar/Reassociate.cpp Thu Mar 19 15:05:15 2009
@@ -196,10 +196,12 @@
 
 /// LowerNegateToMultiply - Replace 0-X with X*-1.
 ///
-static Instruction *LowerNegateToMultiply(Instruction *Neg) {
+static Instruction *LowerNegateToMultiply(Instruction *Neg,
+                                     std::map<Value*, unsigned> &ValueRankMap) {
   Constant *Cst = ConstantInt::getAllOnesValue(Neg->getType());
 
   Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg);
+  ValueRankMap.erase(Neg);
   Res->takeName(Neg);
   Neg->replaceAllUsesWith(Res);
   Neg->eraseFromParent();
@@ -260,11 +262,11 @@
   // transform them into multiplies by -1 so they can be reassociated.
   if (I->getOpcode() == Instruction::Mul) {
     if (!LHSBO && LHS->hasOneUse() && BinaryOperator::isNeg(LHS)) {
-      LHS = LowerNegateToMultiply(cast<Instruction>(LHS));
+      LHS = LowerNegateToMultiply(cast<Instruction>(LHS), ValueRankMap);
       LHSBO = isReassociableOp(LHS, Opcode);
     }
     if (!RHSBO && RHS->hasOneUse() && BinaryOperator::isNeg(RHS)) {
-      RHS = LowerNegateToMultiply(cast<Instruction>(RHS));
+      RHS = LowerNegateToMultiply(cast<Instruction>(RHS), ValueRankMap);
       RHSBO = isReassociableOp(RHS, Opcode);
     }
   }
@@ -424,7 +426,8 @@
 /// BreakUpSubtract - If we have (X-Y), and if either X is an add, or if this is
 /// only used by an add, transform this into (X+(0-Y)) to promote better
 /// reassociation.
-static Instruction *BreakUpSubtract(Instruction *Sub) {
+static Instruction *BreakUpSubtract(Instruction *Sub,
+                                    std::map<Value*, unsigned> &ValueRankMap) {
   // Convert a subtract into an add and a neg instruction... so that sub
   // instructions can be commuted with other add instructions...
   //
@@ -437,6 +440,7 @@
   New->takeName(Sub);
 
   // Everyone now refers to the add instruction.
+  ValueRankMap.erase(Sub);
   Sub->replaceAllUsesWith(New);
   Sub->eraseFromParent();
 
@@ -447,7 +451,8 @@
 /// ConvertShiftToMul - If this is a shift of a reassociable multiply or is used
 /// by one, change this into a multiply by a constant to assist with further
 /// reassociation.
-static Instruction *ConvertShiftToMul(Instruction *Shl) {
+static Instruction *ConvertShiftToMul(Instruction *Shl, 
+                                      std::map<Value*, unsigned> &ValueRankMap){
   // If an operand of this shift is a reassociable multiply, or if the shift
   // is used by a reassociable multiply or add, turn into a multiply.
   if (isReassociableOp(Shl->getOperand(0), Instruction::Mul) ||
@@ -459,6 +464,7 @@
     
     Instruction *Mul = BinaryOperator::CreateMul(Shl->getOperand(0), MulCst,
                                                  "", Shl);
+    ValueRankMap.erase(Shl);
     Mul->takeName(Shl);
     Shl->replaceAllUsesWith(Mul);
     Shl->eraseFromParent();
@@ -772,7 +778,7 @@
     Instruction *BI = BBI++;
     if (BI->getOpcode() == Instruction::Shl &&
         isa<ConstantInt>(BI->getOperand(1)))
-      if (Instruction *NI = ConvertShiftToMul(BI)) {
+      if (Instruction *NI = ConvertShiftToMul(BI, ValueRankMap)) {
         MadeChange = true;
         BI = NI;
       }
@@ -786,7 +792,7 @@
     // see if we can convert it to X+-Y.
     if (BI->getOpcode() == Instruction::Sub) {
       if (ShouldBreakUpSubtract(BI)) {
-        BI = BreakUpSubtract(BI);
+        BI = BreakUpSubtract(BI, ValueRankMap);
         MadeChange = true;
       } else if (BinaryOperator::isNeg(BI)) {
         // Otherwise, this is a negation.  See if the operand is a multiply tree
@@ -794,7 +800,7 @@
         if (isReassociableOp(BI->getOperand(1), Instruction::Mul) &&
             (!BI->hasOneUse() ||
              !isReassociableOp(BI->use_back(), Instruction::Mul))) {
-          BI = LowerNegateToMultiply(BI);
+          BI = LowerNegateToMultiply(BI, ValueRankMap);
           MadeChange = true;
         }
       }





More information about the llvm-commits mailing list