Programs that actually free memory were broken
[oota-llvm.git] / lib / Transforms / IPO / MutateStructTypes.cpp
index dc3ef7f770b5d23502bde5f46884becbbe9b9640..fcad5fa050bfed7d85eae298d0d3f78083a39c25 100644 (file)
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Function.h"
+#include "llvm/BasicBlock.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/iPHINode.h"
 #include "llvm/iMemory.h"
 #include "llvm/iTerminators.h"
 #include "llvm/iOther.h"
+#include "llvm/Argument.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 using std::map;
@@ -35,9 +37,7 @@ using std::vector;
 // To enable debugging, uncomment this...
 //#define DEBUG_MST(x) x
 
-#ifdef DEBUG_MST
-#include "llvm/Assembly/Writer.h"
-#else
+#ifndef DEBUG_MST
 #define DEBUG_MST(x)   // Disable debug code
 #endif
 
@@ -57,12 +57,12 @@ const Type *MutateStructTypes::ConvertType(const Type *Ty) {
   if (Ty->isPrimitiveType() ||
       isa<OpaqueType>(Ty)) return Ty;  // Don't convert primitives
 
-  map<const Type *, PATypeHolder<Type> >::iterator I = TypeMap.find(Ty);
+  map<const Type *, PATypeHolder>::iterator I = TypeMap.find(Ty);
   if (I != TypeMap.end()) return I->second;
 
   const Type *DestTy = 0;
 
-  PATypeHolder<Type> PlaceHolder = OpaqueType::get();
+  PATypeHolder PlaceHolder = OpaqueType::get();
   TypeMap.insert(std::make_pair(Ty, PlaceHolder.get()));
 
   switch (Ty->getPrimitiveID()) {
@@ -226,7 +226,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) {
     }
 
     // Create a new type that corresponds to the destination type
-    PATypeHolder<StructType> NSTy = StructType::get(NewType);
+    PATypeHolder NSTy = StructType::get(NewType);
 
     // Refine the old opaque type to the new type to properly handle recursive
     // types...
@@ -235,7 +235,8 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) {
     cast<DerivedType>(OldTypeStub)->refineAbstractTypeTo(NSTy);
 
     // Add the transformation to the Transforms map.
-    Transforms.insert(std::make_pair(OldTy, std::make_pair(NSTy, InVec)));
+    Transforms.insert(std::make_pair(OldTy,
+                       std::make_pair(cast<StructType>(NSTy.get()), InVec)));
 
     DEBUG_MST(cerr << "Mutate " << OldTy << "\nTo " << NSTy << endl);
   }
@@ -336,12 +337,11 @@ void MutateStructTypes::transformMethod(Function *m) {
   Function *NewMeth = cast<Function>(GMI->second);
 
   // Okay, first order of business, create the arguments...
-  for (unsigned i = 0; i < M->getArgumentList().size(); ++i) {
-    const FunctionArgument *OMA = M->getArgumentList()[i];
-    FunctionArgument *NMA = new FunctionArgument(ConvertType(OMA->getType()),
-                                                 OMA->getName());
-    NewMeth->getArgumentList().push_back(NMA);
-    LocalValueMap[OMA] = NMA; // Keep track of value mapping
+  for (unsigned i = 0, e = M->getArgumentList().size(); i != e; ++i) {
+    const Argument *OFA = M->getArgumentList()[i];
+    Argument *NFA = new Argument(ConvertType(OFA->getType()), OFA->getName());
+    NewMeth->getArgumentList().push_back(NFA);
+    LocalValueMap[OFA] = NFA; // Keep track of value mapping
   }