Convert xforms over to new pass structure.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1605 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-01-31 00:45:11 +00:00
parent 9c9be48b83
commit 793c6b80d3
9 changed files with 115 additions and 54 deletions

View 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

View 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);
}

View 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);
}

View 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"
@ -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);
}

View 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);
}

View 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);
}

View 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);
}

View File

@ -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 <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);
}

View 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"