From 793c6b80d3e322c3fefb3c7314b054c7880d1691 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 31 Jan 2002 00:45:11 +0000 Subject: [PATCH] Convert xforms over to new pass structure. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1605 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/ConstantMerge.cpp | 2 ++ lib/Transforms/IPO/DeadTypeElimination.cpp | 24 ++++++++++----- lib/Transforms/IPO/GlobalDCE.cpp | 17 ++++++++--- lib/Transforms/IPO/MutateStructTypes.cpp | 18 +++++++++++ lib/Transforms/IPO/SimpleStructMutation.cpp | 33 +++++++++++--------- lib/Transforms/Scalar/ADCE.cpp | 24 +++++++++------ lib/Transforms/Scalar/IndVarSimplify.cpp | 16 +++++++--- lib/Transforms/Scalar/InductionVars.cpp | 34 +++++++++++++-------- lib/Transforms/Utils/LowerAllocations.cpp | 1 + 9 files changed, 115 insertions(+), 54 deletions(-) diff --git a/lib/Transforms/IPO/ConstantMerge.cpp b/lib/Transforms/IPO/ConstantMerge.cpp index acb3b6b9379..0951c731e1c 100644 --- a/lib/Transforms/IPO/ConstantMerge.cpp +++ b/lib/Transforms/IPO/ConstantMerge.cpp @@ -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 diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index c170e151643..297eaddfba5 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -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 &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 &UsedTypes = FUT.getTypes(); + const std::set &UsedTypes = + getAnalysis().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); +} diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp index 664381cec68..1b64a0b369b 100644 --- a/lib/Transforms/IPO/GlobalDCE.cpp +++ b/lib/Transforms/IPO/GlobalDCE.cpp @@ -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()); +} + +// 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); } diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index 8beac2f2d04..77109330c4e 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -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" @@ -25,6 +26,12 @@ 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); +} diff --git a/lib/Transforms/IPO/SimpleStructMutation.cpp b/lib/Transforms/IPO/SimpleStructMutation.cpp index 7e28af3df3a..8583e3e850d 100644 --- a/lib/Transforms/IPO/SimpleStructMutation.cpp +++ b/lib/Transforms/IPO/SimpleStructMutation.cpp @@ -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 &UnsafePTys = FUPT->getUnsafeTypes(); - const set &UsedTypes = FUT->getTypes(); + FindUsedTypes &FUT = getAnalysis(); + const set &UsedTypes = FUT.getTypes(); + + FindUnsafePointerTypes &FUPT = getAnalysis(); + const set &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); +} diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index 3c3ba78f5a5..5449f223462 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -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 &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::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); } diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 35844cadb6c..48faffebf4b 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -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()); +} + +void InductionVariableSimplify::getAnalysisUsageInfo(Pass::AnalysisSet &Req, + Pass::AnalysisSet &Dest, + Pass::AnalysisSet &Prov) { + Req.push_back(cfg::LoopInfo::ID); +} diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index 6d7df4169b6..48982f4773d 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -25,13 +25,12 @@ #include "llvm/Assembly/Writer.h" #include "llvm/SymbolTable.h" #include "llvm/iPHINode.h" +#include "llvm/Method.h" #include "Support/STLExtras.h" #include #include 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()); +} + +// 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); +} diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 0d26e2a2336..ff7a3674ec1 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -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"