Convert xforms over to new pass structure.
authorChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2002 00:45:11 +0000 (00:45 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2002 00:45:11 +0000 (00:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1605 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/ConstantMerge.cpp
lib/Transforms/IPO/DeadTypeElimination.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/Transforms/IPO/MutateStructTypes.cpp
lib/Transforms/IPO/SimpleStructMutation.cpp
lib/Transforms/Scalar/ADCE.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InductionVars.cpp
lib/Transforms/Utils/LowerAllocations.cpp

index acb3b6b9379941780c93c1c9edc24fd0c4507b9a..0951c731e1ce007974a4cd61b7f6d99f4486ba31 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "llvm/Transforms/ConstantMerge.h"
 #include "llvm/GlobalVariable.h"
+#include "llvm/Module.h"
+#include "llvm/Method.h"
 
 // mergeDuplicateConstants - Workhorse for the pass.  This eliminates duplicate
 // constants, starting at global ConstantNo, and adds vars to the map if they
index c170e1516434cb960aef159ddc1cedf0e7466de7..297eaddfba5696f538f552a7c82a81b0da6e9575 100644 (file)
@@ -13,7 +13,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/CleanupGCCOutput.h"
+#include "llvm/Analysis/FindUsedTypes.h"
 #include "TransformInternals.h"
+#include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iPHINode.h"
@@ -225,8 +227,6 @@ static inline bool ShouldNukeSymtabEntry(const std::pair<string, Value*> &E) {
 bool CleanupGCCOutput::doInitialization(Module *M) {
   bool Changed = false;
 
-  FUT.doInitialization(M);
-
   if (PtrSByte == 0)
     PtrSByte = PointerType::get(Type::SByteTy);
 
@@ -491,19 +491,17 @@ static bool fixLocalProblems(Method *M) {
 // doPerMethodWork - This method simplifies the specified method hopefully.
 //
 bool CleanupGCCOutput::runOnMethod(Method *M) {
-  bool Changed = fixLocalProblems(M);
-
-  FUT.runOnMethod(M);
-  return Changed;
+  return fixLocalProblems(M);
 }
 
 bool CleanupGCCOutput::doFinalization(Module *M) {
   bool Changed = false;
-  FUT.doFinalization(M);
+  
 
   if (M->hasSymbolTable()) {
     SymbolTable *ST = M->getSymbolTable();
-    const std::set<const Type *> &UsedTypes = FUT.getTypes();
+    const std::set<const Type *> &UsedTypes =
+      getAnalysis<FindUsedTypes>().getTypes();
 
     // Check the symbol table for superfluous type entries that aren't used in
     // the program
@@ -529,3 +527,13 @@ bool CleanupGCCOutput::doFinalization(Module *M) {
   }
   return Changed;
 }
+
+// getAnalysisUsageInfo - This function needs the results of the
+// FindUsedTypes and FindUnsafePointerTypes analysis passes...
+//
+void CleanupGCCOutput::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
+                                            Pass::AnalysisSet &Destroyed,
+                                            Pass::AnalysisSet &Provided) {
+  // FIXME: Invalidates the CFG
+  Required.push_back(FindUsedTypes::ID);
+}
index 664381cec684ee50162368ae724d48a754b3ddfe..1b64a0b369bf8b8bc649816cd924c3ddb0cab3a8 100644 (file)
@@ -46,8 +46,17 @@ static bool RemoveUnreachableMethods(Module *M, cfg::CallGraph &CallGraph) {
 }
 
 bool GlobalDCE::run(Module *M) {
-  // TODO: FIXME: GET THE CALL GRAPH FROM THE PASS!
-  // Create a call graph if one is not already available...
-  cfg::CallGraph CallGraph(M);
-  return RemoveUnreachableMethods(M, CallGraph);
+  return RemoveUnreachableMethods(M, getAnalysis<cfg::CallGraph>());
+}
+
+// getAnalysisUsageInfo - This function works on the call graph of a module.
+// It is capable of updating the call graph to reflect the new state of the
+// module.
+//
+void GlobalDCE::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
+                                     Pass::AnalysisSet &Destroyed,
+                                     Pass::AnalysisSet &Provided) {
+  Required.push_back(cfg::CallGraph::ID);
+  // FIXME: This should update the callgraph, not destroy it!
+  Destroyed.push_back(cfg::CallGraph::ID);
 }
index 8beac2f2d043a665cc11e3d586b8d33012708282..77109330c4ecd9c9449d93a42bf376c2a9fcf2ce 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "llvm/Transforms/IPO/MutateStructTypes.h"
 #include "llvm/DerivedTypes.h"
+#include "llvm/Module.h"
 #include "llvm/Method.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 using std::map;
 using std::vector;
 
+//FIXME: These headers are only included because the analyses are killed!!!
+#include "llvm/Analysis/CallGraph.h"
+#include "llvm/Analysis/FindUsedTypes.h"
+#include "llvm/Analysis/FindUnsafePointerTypes.h"
+//FIXME end
+
 // To enable debugging, uncomment this...
 //#define DEBUG_MST(x) x
 
@@ -515,3 +522,14 @@ bool MutateStructTypes::run(Module *M) {
   removeDeadGlobals(M);
   return true;
 }
+
+// getAnalysisUsageInfo - This function needs the results of the
+// FindUsedTypes and FindUnsafePointerTypes analysis passes...
+//
+void MutateStructTypes::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
+                                             Pass::AnalysisSet &Destroyed,
+                                             Pass::AnalysisSet &Provided) {
+  Destroyed.push_back(FindUsedTypes::ID);
+  Destroyed.push_back(FindUnsafePointerTypes::ID);
+  Destroyed.push_back(cfg::CallGraph::ID);
+}
index 7e28af3df3afeb1a32b2cb6c3ef72856537922f9..8583e3e850d7a2ac827abb9bd2e75641759293b9 100644 (file)
@@ -89,24 +89,16 @@ static inline void GetTransformation(const StructType *ST,
 
 SimpleStructMutation::TransformsType
   SimpleStructMutation::getTransforms(Module *M, enum Transform XForm) {
-
-  // FIXME: These should be calculated by the Pass framework!
-
   // We need to know which types to modify, and which types we CAN'T modify
-  FindUsedTypes          *FUT = new FindUsedTypes(/*true*/); // TODO: Do symbol tables as well
-  FindUnsafePointerTypes *FUPT = new FindUnsafePointerTypes();
-
-  // Simutaneously find all of the types used, and all of the types that aren't
-  // safe.
-  //
-  PassManager Analyses;
-  Analyses.add(FUT);
-  Analyses.add(FUPT);
-  Analyses.run(M);  // Do analyses
+  // TODO: Do symbol tables as well
 
   // Get the results out of the analyzers...
-  const set<PointerType*> &UnsafePTys = FUPT->getUnsafeTypes();
-  const set<const Type *> &UsedTypes  = FUT->getTypes();
+  FindUsedTypes          &FUT = getAnalysis<FindUsedTypes>();
+  const set<const Type *> &UsedTypes  = FUT.getTypes();
+
+  FindUnsafePointerTypes &FUPT = getAnalysis<FindUnsafePointerTypes>();
+  const set<PointerType*> &UnsafePTys = FUPT.getUnsafeTypes();
+
 
 
   // Combine the two sets, weeding out non structure types.  Closures in C++
@@ -144,3 +136,14 @@ SimpleStructMutation::TransformsType
   return Transforms;
 }
 
+
+// getAnalysisUsageInfo - This function needs the results of the
+// FindUsedTypes and FindUnsafePointerTypes analysis passes...
+//
+void SimpleStructMutation::getAnalysisUsageInfo(Pass::AnalysisSet &Required,
+                                                Pass::AnalysisSet &Destroyed,
+                                                Pass::AnalysisSet &Provided){
+  Required.push_back(FindUsedTypes::ID);
+  Required.push_back(FindUnsafePointerTypes::ID);
+  MutateStructTypes::getAnalysisUsageInfo(Required, Destroyed, Provided);
+}
index 3c3ba78f5a5816eb3476739e41965374586a89a4..5449f223462dfafaacc97f09f357ff7e3cbb1d17 100644 (file)
@@ -42,7 +42,7 @@ public:
 
   // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
   // true if the method was modified.
-  bool doADCE();
+  bool doADCE(cfg::DominanceFrontier &CDG);
 
   //===--------------------------------------------------------------------===//
   // The implementation of this class
@@ -76,12 +76,7 @@ private:
 // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
 // true if the method was modified.
 //
-bool ADCE::doADCE() {
-  // Compute the control dependence graph...  Note that this has a side effect
-  // on the CFG: a new return bb is added and all returns are merged here.
-  //
-  cfg::DominanceFrontier CDG(cfg::DominatorSet(M, true));
-
+bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
 #ifdef DEBUG_ADCE
   cerr << "Method: " << M;
 #endif
@@ -296,8 +291,19 @@ BasicBlock *ADCE::fixupCFG(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks,
 
 // doADCE - Execute the Agressive Dead Code Elimination Algorithm
 //
-bool AgressiveDCE::doADCE(Method *M) {
+bool AgressiveDCE::runOnMethod(Method *M) {
   if (M->isExternal()) return false;
   ADCE DCE(M);
-  return DCE.doADCE();
+  return DCE.doADCE(
+       getAnalysis<cfg::DominanceFrontier>(cfg::DominanceFrontier::PostDomID));
+}
+
+
+// getAnalysisUsageInfo - We require post dominance frontiers (aka Control
+// Dependence Graph)
+//
+void AgressiveDCE::getAnalysisUsageInfo(Pass::AnalysisSet &Requires,
+                                        Pass::AnalysisSet &Destroyed,
+                                        Pass::AnalysisSet &Provided) {
+  Requires.push_back(cfg::DominanceFrontier::PostDomID);
 }
index 35844cadb6c567e9fec0c3ad8ecfad4b38039a04..48faffebf4bd177ef3081c76ae11f158b7fe1449 100644 (file)
@@ -8,7 +8,6 @@
 #include "llvm/Transforms/Scalar/IndVarSimplify.h"
 #include "llvm/Analysis/InductionVariable.h"
 #include "llvm/Analysis/LoopInfo.h"
-#include "llvm/Analysis/Dominators.h"
 #include "llvm/iPHINode.h"
 #include "llvm/iOther.h"
 #include "llvm/Type.h"
@@ -185,14 +184,21 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
   return Changed;
 }
 
-bool InductionVariableSimplify::doit(Method *M) {
+bool InductionVariableSimplify::doit(Method *M, cfg::LoopInfo &Loops) {
   if (M->isExternal()) return false;
 
-  // Figure out the loop structure of the method...
-  cfg::LoopInfo Loops(M);
-
   // Induction Variables live in the header nodes of the loops of the method...
   return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
                            Loops.getTopLevelLoops().end(),
                            std::bind1st(std::ptr_fun(TransformLoop), &Loops));
 }
+
+bool InductionVariableSimplify::runOnMethod(Method *M) {
+  return doit(M, getAnalysis<cfg::LoopInfo>());
+}
+
+void InductionVariableSimplify::getAnalysisUsageInfo(Pass::AnalysisSet &Req,
+                                                     Pass::AnalysisSet &Dest,
+                                                     Pass::AnalysisSet &Prov) {
+  Req.push_back(cfg::LoopInfo::ID);
+}
index 6d7df4169b69744e24ca32615201b9d590e1df25..48982f4773d99280cd961784c7113c88965c033f 100644 (file)
 #include "llvm/Assembly/Writer.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/iPHINode.h"
+#include "llvm/Method.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 #include <iostream>
 using std::cerr;
 
-#include "llvm/Analysis/LoopDepth.h"
-
 // isLoopInvariant - Return true if the specified value/basic block source is 
 // an interval invariant computation.
 //
@@ -371,19 +370,11 @@ static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) {
 // This function loops over an interval partition of a program, reducing it
 // until the graph is gone.
 //
-bool InductionVariableCannonicalize::doIt(Method *M) {
-  // TODO: REMOVE
-  if (0) {   // Print basic blocks with their depth
-    LoopDepthCalculator LDC(M);
-    for (Method::iterator I = M->begin(); I != M->end(); ++I) {
-      cerr << "Basic Block Depth: " << LDC.getLoopDepth(*I) << *I;
-    }
-  }
-
-
-  cfg::IntervalPartition *IP = new cfg::IntervalPartition(M);
+bool InductionVariableCannonicalize::doIt(Method *M, 
+                                          cfg::IntervalPartition &IP) {
   bool Changed = false;
 
+#if 0
   while (!IP->isDegeneratePartition()) {
     Changed |= ProcessIntervalPartition(*IP);
 
@@ -400,5 +391,22 @@ bool InductionVariableCannonicalize::doIt(Method *M) {
   }
 
   delete IP;
+#endif
   return Changed;
 }
+
+
+bool InductionVariableCannonicalize::runOnMethod(Method *M) {
+  return doIt(M, getAnalysis<cfg::IntervalPartition>());
+}
+
+// getAnalysisUsageInfo - This function works on the call graph of a module.
+// It is capable of updating the call graph to reflect the new state of the
+// module.
+//
+void InductionVariableCannonicalize::getAnalysisUsageInfo(
+                                           Pass::AnalysisSet &Required,
+                                           Pass::AnalysisSet &Destroyed,
+                                           Pass::AnalysisSet &Provided) {
+  Required.push_back(cfg::IntervalPartition::ID);
+}
index 0d26e2a2336a36e4f829048a196f227959b19697..ff7a3674ec1d2fa1cb237f4260b822e54aa08cb7 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "llvm/Transforms/ChangeAllocations.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iMemory.h"
 #include "llvm/iOther.h"