Non-functionality change just to make it more clear what is going on
[oota-llvm.git] / lib / Transforms / IPO / MutateStructTypes.cpp
index 31692f8a392cb077b8879ba3c886ca543d1b99e1..7f62f2b50e1947c086100d4d6649003bbafe7d3e 100644 (file)
 #include "llvm/Transforms/IPO/MutateStructTypes.h"
 #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 "llvm/Constants.h"
 #include "Support/STLExtras.h"
-#include "Support/StatisticReporter.h"
+#include "Support/Statistic.h"
 #include <algorithm>
+
 using std::map;
 using std::vector;
 
@@ -107,7 +104,7 @@ const Type *MutateStructTypes::ConvertType(const Type *Ty) {
 //
 void MutateStructTypes::AdjustIndices(const CompositeType *OldTy,
                                       vector<Value*> &Idx,
-                                      unsigned i = 0) {
+                                      unsigned i) {
   assert(i < Idx.size() && "i out of range!");
   const CompositeType *NewCT = cast<CompositeType>(ConvertType(OldTy));
   if (NewCT == OldTy) return;  // No adjustment unless type changes
@@ -168,7 +165,7 @@ Value *MutateStructTypes::ConvertValue(const Value *V) {
     return LocalValueMap[V] = new BasicBlock(BB->getName());
   }
 
-  DEBUG(cerr << "NPH: " << V << "\n");
+  DEBUG(std::cerr << "NPH: " << V << "\n");
 
   // Otherwise make a constant to represent it
   return LocalValueMap[V] = new ValuePlaceHolder(ConvertType(V->getType()));
@@ -227,7 +224,7 @@ void MutateStructTypes::setTransforms(const TransformsType &XForm) {
     Transforms.insert(std::make_pair(OldTy,
                        std::make_pair(cast<StructType>(NSTy.get()), InVec)));
 
-    DEBUG(cerr << "Mutate " << OldTy << "\nTo " << NSTy << "\n");
+    DEBUG(std::cerr << "Mutate " << OldTy << "\nTo " << NSTy << "\n");
   }
 }
 
@@ -364,12 +361,6 @@ void MutateStructTypes::transformFunction(Function *m) {
       case Instruction::Invoke:
         assert(0 && "Insn not implemented!");
 
-        // Unary Instructions
-      case Instruction::Not:
-        NewI = UnaryOperator::create((Instruction::UnaryOps)I.getOpcode(),
-                                     ConvertValue(I.getOperand(0)));
-        break;
-
         // Binary Instructions
       case Instruction::Add:
       case Instruction::Sub:
@@ -404,12 +395,14 @@ void MutateStructTypes::transformFunction(Function *m) {
         // Memory Instructions
       case Instruction::Alloca:
         NewI = 
-          new AllocaInst(ConvertType(I.getType()),
+          new MallocInst(
+                  ConvertType(cast<PointerType>(I.getType())->getElementType()),
                          I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
         break;
       case Instruction::Malloc:
         NewI = 
-          new MallocInst(ConvertType(I.getType()),
+          new MallocInst(
+                  ConvertType(cast<PointerType>(I.getType())->getElementType()),
                          I.getNumOperands() ? ConvertValue(I.getOperand(0)) :0);
         break;
 
@@ -418,26 +411,22 @@ void MutateStructTypes::transformFunction(Function *m) {
         break;
 
       case Instruction::Load:
+        NewI = new LoadInst(ConvertValue(I.getOperand(0)));
+        break;
       case Instruction::Store:
+        NewI = new StoreInst(ConvertValue(I.getOperand(0)),
+                             ConvertValue(I.getOperand(1)));
+        break;
       case Instruction::GetElementPtr: {
-        const MemAccessInst &MAI = cast<MemAccessInst>(I);
-        vector<Value*> Indices(MAI.idx_begin(), MAI.idx_end());
-        const Value *Ptr = MAI.getPointerOperand();
-        Value *NewPtr = ConvertValue(Ptr);
+        const GetElementPtrInst &GEP = cast<GetElementPtrInst>(I);
+        vector<Value*> Indices(GEP.idx_begin(), GEP.idx_end());
         if (!Indices.empty()) {
-          const Type *PTy = cast<PointerType>(Ptr->getType())->getElementType();
+          const Type *PTy =
+            cast<PointerType>(GEP.getOperand(0)->getType())->getElementType();
           AdjustIndices(cast<CompositeType>(PTy), Indices);
         }
 
-        if (isa<LoadInst>(I)) {
-          NewI = new LoadInst(NewPtr, Indices);
-        } else if (isa<StoreInst>(I)) {
-          NewI = new StoreInst(ConvertValue(I.getOperand(0)), NewPtr, Indices);
-        } else if (isa<GetElementPtrInst>(I)) {
-          NewI = new GetElementPtrInst(NewPtr, Indices);
-        } else {
-          assert(0 && "Unknown memory access inst!!!");
-        }
+        NewI = new GetElementPtrInst(ConvertValue(GEP.getOperand(0)), Indices);
         break;
       }