Eliminated the MemAccessInst class, folding contents into GEP class.
[oota-llvm.git] / lib / Transforms / Utils / Linker.cpp
index d8f67ff1aadd5857ba7555bdd88ab83b4653194e..beab3d5a847eab8a0ae010552fc2982fcf1529f7 100644 (file)
 
 #include "llvm/Transforms/Utils/Linker.h"
 #include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/GlobalVariable.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/iOther.h"
 #include "llvm/Constants.h"
-#include "llvm/Argument.h"
-#include <iostream>
 using std::cerr;
 using std::string;
 using std::map;
@@ -123,30 +118,29 @@ static Value *RemapOperand(const Value *In, map<const Value*, Value*> &LocalMap,
       Value *V = RemapOperand(CPR->getValue(), LocalMap, GlobalMap);
       Result = ConstantPointerRef::get(cast<GlobalValue>(V));
     } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
-      if (CE->getNumOperands() == 1) {
-        // Cast instruction, unary operator
+      if (CE->getOpcode() == Instruction::GetElementPtr) {
+        Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
+        std::vector<Constant*> Indices;
+        Indices.reserve(CE->getNumOperands()-1);
+        for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
+          Indices.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),
+                                                        LocalMap, GlobalMap)));
+
+        Result = ConstantExpr::getGetElementPtr(cast<Constant>(Ptr), Indices);
+      } else if (CE->getNumOperands() == 1) {
+        // Cast instruction
+        assert(CE->getOpcode() == Instruction::Cast);
         Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
-        Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(V),
-                                   CE->getType());
+        Result = ConstantExpr::getCast(cast<Constant>(V), CE->getType());
       } else if (CE->getNumOperands() == 2) {
         // Binary operator...
         Value *V1 = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
         Value *V2 = RemapOperand(CE->getOperand(1), LocalMap, GlobalMap);
 
         Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(V1),
-                                   cast<Constant>(V2), CE->getType());        
+                                   cast<Constant>(V2));        
       } else {
-        // GetElementPtr Expression
-        assert(CE->getOpcode() == Instruction::GetElementPtr);
-        Value *Ptr = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
-        std::vector<Constant*> Indices;
-        Indices.reserve(CE->getNumOperands()-1);
-        for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
-          Indices.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),
-                                                        LocalMap, GlobalMap)));
-
-        Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(Ptr),
-                                   Indices, CE->getType());
+        assert(0 && "Unknown constant expr type!");
       }
 
     } else {