Converted SimpleStructMutation to take TargetData as a required pass.
llvm-svn: 3932
This commit is contained in:
parent
7b5746bfcf
commit
870a4a5bb4
|
@ -12,7 +12,6 @@
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::set;
|
using std::set;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
@ -20,8 +19,6 @@ using std::pair;
|
||||||
namespace {
|
namespace {
|
||||||
struct SimpleStructMutation : public MutateStructTypes {
|
struct SimpleStructMutation : public MutateStructTypes {
|
||||||
enum Transform { SwapElements, SortElements };
|
enum Transform { SwapElements, SortElements };
|
||||||
const TargetData &TD;
|
|
||||||
SimpleStructMutation(const TargetData &td) : TD(td) {}
|
|
||||||
|
|
||||||
virtual bool run(Module &M) = 0;
|
virtual bool run(Module &M) = 0;
|
||||||
|
|
||||||
|
@ -29,6 +26,7 @@ namespace {
|
||||||
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
|
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
|
||||||
//
|
//
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
AU.addRequired<TargetData>();
|
||||||
AU.addRequired<FindUsedTypes>();
|
AU.addRequired<FindUsedTypes>();
|
||||||
AU.addRequired<FindUnsafePointerTypes>();
|
AU.addRequired<FindUnsafePointerTypes>();
|
||||||
MutateStructTypes::getAnalysisUsage(AU);
|
MutateStructTypes::getAnalysisUsage(AU);
|
||||||
|
@ -39,8 +37,6 @@ namespace {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwapStructElements : public SimpleStructMutation {
|
struct SwapStructElements : public SimpleStructMutation {
|
||||||
SwapStructElements(const TargetData &TD) : SimpleStructMutation(TD) {}
|
|
||||||
|
|
||||||
virtual bool run(Module &M) {
|
virtual bool run(Module &M) {
|
||||||
setTransforms(getTransforms(M, SwapElements));
|
setTransforms(getTransforms(M, SwapElements));
|
||||||
bool Changed = MutateStructTypes::run(M);
|
bool Changed = MutateStructTypes::run(M);
|
||||||
|
@ -50,8 +46,6 @@ namespace {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SortStructElements : public SimpleStructMutation {
|
struct SortStructElements : public SimpleStructMutation {
|
||||||
SortStructElements(const TargetData &TD) : SimpleStructMutation(TD) {}
|
|
||||||
|
|
||||||
virtual bool run(Module &M) {
|
virtual bool run(Module &M) {
|
||||||
setTransforms(getTransforms(M, SortElements));
|
setTransforms(getTransforms(M, SortElements));
|
||||||
bool Changed = MutateStructTypes::run(M);
|
bool Changed = MutateStructTypes::run(M);
|
||||||
|
@ -59,8 +53,15 @@ namespace {
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RegisterOpt<SwapStructElements> X("swapstructs",
|
||||||
|
"Swap structure types around");
|
||||||
|
RegisterOpt<SortStructElements> Y("sortstructs",
|
||||||
|
"Sort structure elements by size");
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
Pass *createSwapElementsPass() { return new SwapStructElements(); }
|
||||||
|
Pass *createSortElementsPass() { return new SortStructElements(); }
|
||||||
|
|
||||||
|
|
||||||
// PruneTypes - Given a type Ty, make sure that neither it, or one of its
|
// PruneTypes - Given a type Ty, make sure that neither it, or one of its
|
||||||
|
@ -168,6 +169,7 @@ SimpleStructMutation::TransformsType
|
||||||
// Build up a set of structure types that we are going to modify, and
|
// Build up a set of structure types that we are going to modify, and
|
||||||
// information describing how to modify them.
|
// information describing how to modify them.
|
||||||
std::map<const StructType*, vector<int> > Transforms;
|
std::map<const StructType*, vector<int> > Transforms;
|
||||||
|
TargetData &TD = getAnalysis<TargetData>();
|
||||||
|
|
||||||
for (set<const StructType*>::iterator I = TypesToModify.begin(),
|
for (set<const StructType*>::iterator I = TypesToModify.begin(),
|
||||||
E = TypesToModify.end(); I != E; ++I) {
|
E = TypesToModify.end(); I != E; ++I) {
|
||||||
|
@ -179,20 +181,3 @@ SimpleStructMutation::TransformsType
|
||||||
|
|
||||||
return Transforms;
|
return Transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Pass *createSwapElementsPass(const TargetData &TD) {
|
|
||||||
return new SwapStructElements(TD);
|
|
||||||
}
|
|
||||||
Pass *createSortElementsPass(const TargetData &TD) {
|
|
||||||
return new SortStructElements(TD);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
RegisterOpt<SwapStructElements> X("swapstructs",
|
|
||||||
"Swap structure types around",
|
|
||||||
createSwapElementsPass);
|
|
||||||
RegisterOpt<SortStructElements> Y("sortstructs",
|
|
||||||
"Sort structure elements by size",
|
|
||||||
createSortElementsPass);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue