Programs that actually free memory were broken
[oota-llvm.git] / lib / Transforms / IPO / SimpleStructMutation.cpp
index 8583e3e850d7a2ac827abb9bd2e75641759293b9..5c64aa3537db1b00eccbd84040b6e367053c7e87 100644 (file)
@@ -17,7 +17,36 @@ using std::vector;
 using std::set;
 using std::pair;
 
-#include "llvm/Assembly/Writer.h"
+namespace {
+  class SimpleStructMutation : public MutateStructTypes {
+  public:
+    enum Transform { SwapElements, SortElements } CurrentXForm;
+    
+    SimpleStructMutation(enum Transform XForm) : CurrentXForm(XForm) {}
+    
+    virtual bool run(Module *M) {
+      setTransforms(getTransforms(M, CurrentXForm));
+      bool Changed = MutateStructTypes::run(M);
+      clearTransforms();
+      return Changed;
+    }
+    
+    // getAnalysisUsageInfo - This function needs the results of the
+    // FindUsedTypes and FindUnsafePointerTypes analysis passes...
+    //
+    virtual void 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);
+    }
+    
+  private:
+    TransformsType getTransforms(Module *M, enum Transform);
+  };
+}  // end anonymous namespace
+
 
 
 // PruneTypes - Given a type Ty, make sure that neither it, or one of its
@@ -87,6 +116,7 @@ static inline void GetTransformation(const StructType *ST,
   }
 }
 
+
 SimpleStructMutation::TransformsType
   SimpleStructMutation::getTransforms(Module *M, enum Transform XForm) {
   // We need to know which types to modify, and which types we CAN'T modify
@@ -137,13 +167,10 @@ SimpleStructMutation::TransformsType
 }
 
 
-// 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);
+Pass *createSwapElementsPass() {
+  return new SimpleStructMutation(SimpleStructMutation::SwapElements);
 }
+Pass *createSortElementsPass() {
+  return new SimpleStructMutation(SimpleStructMutation::SortElements);
+}
+