[opaque pointer type] Explicitly store the pointee type of the result of a GEP
[oota-llvm.git] / lib / Transforms / Utils / ValueMapper.cpp
index a70d6d769b7d90eeed51765af915e3831b6e5c1e..8c72641da9e7a7fbb3ce15ce7fe466009868e00a 100644 (file)
@@ -384,17 +384,27 @@ void llvm::RemapInstruction(Instruction *I, ValueToValueMapTy &VMap,
       I->setMetadata(MI->first, New);
   }
   
+  if (!TypeMapper)
+    return;
+
   // If the instruction's type is being remapped, do so now.
   if (auto CS = CallSite(I)) {
     SmallVector<Type *, 3> Tys;
-    FunctionType *Old = CS.getFunctionType();
-    unsigned NumOld = Old->getNumParams();
-    assert(NumOld <= CS.arg_size());
-    for (unsigned i = 0; i != NumOld; ++i)
-      Tys.push_back(CS.getArgument(i)->getType());
+    FunctionType *FTy = CS.getFunctionType();
+    Tys.reserve(FTy->getNumParams());
+    for (Type *Ty : FTy->params())
+      Tys.push_back(TypeMapper->remapType(Ty));
     CS.mutateFunctionType(FunctionType::get(
-        TypeMapper ? TypeMapper->remapType(I->getType()) : I->getType(), Tys,
-        Old->isVarArg()));
-  } else if (TypeMapper)
-    I->mutateType(TypeMapper->remapType(I->getType()));
+        TypeMapper->remapType(I->getType()), Tys, FTy->isVarArg()));
+    return;
+  }
+  if (auto *AI = dyn_cast<AllocaInst>(I))
+    AI->setAllocatedType(TypeMapper->remapType(AI->getAllocatedType()));
+  if (auto *GEP = dyn_cast<GetElementPtrInst>(I)) {
+    GEP->setSourceElementType(
+        TypeMapper->remapType(GEP->getSourceElementType()));
+    GEP->setResultElementType(
+        TypeMapper->remapType(GEP->getResultElementType()));
+  }
+  I->mutateType(TypeMapper->remapType(I->getType()));
 }