Non-functionality change just to make it more clear what is going on
[oota-llvm.git] / lib / Transforms / IPO / MutateStructTypes.cpp
index 4058a3d03aa6f6ede21f43a370a9241cf2f2fd3b..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>
-#include <iostream>
+
 using std::map;
 using std::vector;
 
@@ -108,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
@@ -365,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:
@@ -405,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;
 
@@ -419,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;
       }