+static bool FirstLess(const pair<unsigned, unsigned> &LHS,
+ const pair<unsigned, unsigned> &RHS) {
+ return LHS.second < RHS.second;
+}
+
+static unsigned getIndex(const vector<pair<unsigned, unsigned> > &Vec,
+ unsigned Field) {
+ for (unsigned i = 0; ; ++i)
+ if (Vec[i].first == Field) return i;
+}
+
+static inline void GetTransformation(const StructType *ST,
+ vector<int> &Transform,
+ enum PrebuiltStructMutation::Transform XForm) {
+ unsigned NumElements = ST->getElementTypes().size();
+ Transform.reserve(NumElements);
+
+ switch (XForm) {
+ case PrebuiltStructMutation::SwapElements:
+ // The transformation to do is: just simply swap the elements
+ for (unsigned i = 0; i < NumElements; ++i)
+ Transform.push_back(NumElements-i-1);
+ break;
+
+ case PrebuiltStructMutation::SortElements: {
+ vector<pair<unsigned, unsigned> > ElList;
+
+ // Build mapping from index to size
+ for (unsigned i = 0; i < NumElements; ++i)
+ ElList.push_back(make_pair(i, TD.getTypeSize(ST->getElementTypes()[i])));