mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 06:30:16 +00:00
* Break the two different behaviors of SimpleStructMutation into two subclasses
* Register the passes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3013 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
33494521d3
commit
e9754ef595
@ -17,27 +17,13 @@ using std::vector;
|
|||||||
using std::set;
|
using std::set;
|
||||||
using std::pair;
|
using std::pair;
|
||||||
|
|
||||||
// FIXME: TargetData Hack: Eventually we will have annotations given to us by
|
|
||||||
// the backend so that we know stuff about type size and alignments. For now
|
|
||||||
// though, just use this, because it happens to match the model that GCC and the
|
|
||||||
// Sparc backend use.
|
|
||||||
//
|
|
||||||
const TargetData TD("SimpleStructMutation Should be GCC though!");
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct SimpleStructMutation : public MutateStructTypes {
|
struct SimpleStructMutation : public MutateStructTypes {
|
||||||
enum Transform { SwapElements, SortElements } CurrentXForm;
|
enum Transform { SwapElements, SortElements };
|
||||||
|
const TargetData &TD;
|
||||||
|
SimpleStructMutation(const TargetData &td) : TD(td) {}
|
||||||
|
|
||||||
SimpleStructMutation(enum Transform XForm) : CurrentXForm(XForm) {}
|
virtual bool run(Module &M) = 0;
|
||||||
|
|
||||||
const char *getPassName() const { return "Simple Struct Mutation"; }
|
|
||||||
|
|
||||||
virtual bool run(Module &M) {
|
|
||||||
setTransforms(getTransforms(M, CurrentXForm));
|
|
||||||
bool Changed = MutateStructTypes::run(M);
|
|
||||||
clearTransforms();
|
|
||||||
return Changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
// getAnalysisUsage - This function needs the results of the
|
// getAnalysisUsage - This function needs the results of the
|
||||||
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
|
// FindUsedTypes and FindUnsafePointerTypes analysis passes...
|
||||||
@ -48,9 +34,31 @@ namespace {
|
|||||||
MutateStructTypes::getAnalysisUsage(AU);
|
MutateStructTypes::getAnalysisUsage(AU);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
TransformsType getTransforms(Module &M, enum Transform);
|
TransformsType getTransforms(Module &M, enum Transform);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SwapStructElements : public SimpleStructMutation {
|
||||||
|
SwapStructElements(const TargetData &TD) : SimpleStructMutation(TD) {}
|
||||||
|
|
||||||
|
virtual bool run(Module &M) {
|
||||||
|
setTransforms(getTransforms(M, SwapElements));
|
||||||
|
bool Changed = MutateStructTypes::run(M);
|
||||||
|
clearTransforms();
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SortStructElements : public SimpleStructMutation {
|
||||||
|
SortStructElements(const TargetData &TD) : SimpleStructMutation(TD) {}
|
||||||
|
|
||||||
|
virtual bool run(Module &M) {
|
||||||
|
setTransforms(getTransforms(M, SortElements));
|
||||||
|
bool Changed = MutateStructTypes::run(M);
|
||||||
|
clearTransforms();
|
||||||
|
return Changed;
|
||||||
|
}
|
||||||
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
@ -91,7 +99,7 @@ static unsigned getIndex(const vector<pair<unsigned, unsigned> > &Vec,
|
|||||||
if (Vec[i].first == Field) return i;
|
if (Vec[i].first == Field) return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void GetTransformation(const StructType *ST,
|
static inline void GetTransformation(const TargetData &TD, const StructType *ST,
|
||||||
vector<int> &Transform,
|
vector<int> &Transform,
|
||||||
enum SimpleStructMutation::Transform XForm) {
|
enum SimpleStructMutation::Transform XForm) {
|
||||||
unsigned NumElements = ST->getElementTypes().size();
|
unsigned NumElements = ST->getElementTypes().size();
|
||||||
@ -166,17 +174,25 @@ SimpleStructMutation::TransformsType
|
|||||||
const StructType *ST = *I;
|
const StructType *ST = *I;
|
||||||
|
|
||||||
vector<int> &Transform = Transforms[ST]; // Fill in the map directly
|
vector<int> &Transform = Transforms[ST]; // Fill in the map directly
|
||||||
GetTransformation(ST, Transform, XForm);
|
GetTransformation(TD, ST, Transform, XForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Transforms;
|
return Transforms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Pass *createSwapElementsPass() {
|
Pass *createSwapElementsPass(const TargetData &TD) {
|
||||||
return new SimpleStructMutation(SimpleStructMutation::SwapElements);
|
return new SwapStructElements(TD);
|
||||||
}
|
}
|
||||||
Pass *createSortElementsPass() {
|
Pass *createSortElementsPass(const TargetData &TD) {
|
||||||
return new SimpleStructMutation(SimpleStructMutation::SortElements);
|
return new SortStructElements(TD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
RegisterPass<SwapStructElements> X("swapstructs",
|
||||||
|
"Swap structure types around",
|
||||||
|
createSwapElementsPass);
|
||||||
|
RegisterPass<SortStructElements> Y("sortstructs",
|
||||||
|
"Sort structure elements by size",
|
||||||
|
createSortElementsPass);
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user