[Orc] Teach the CompileOnDemand layer to clone aliases.
[oota-llvm.git] / lib / ExecutionEngine / Orc / IndirectionUtils.cpp
index b439810ed330ee43f9e12609d422145398fcb3b4..ddd1921657b3324fe5f5d7a03b9b764150b3dfe0 100644 (file)
@@ -177,5 +177,19 @@ void moveGlobalVariableInitializer(GlobalVariable &OrigGV,
                                  nullptr, Materializer));
 }
 
+GlobalAlias* cloneGlobalAlias(Module &Dst, const GlobalAlias &OrigA,
+                              ValueToValueMapTy &VMap,
+                              ValueMaterializer *Materializer) {
+  assert(OrigA.getAliasee() && "Original alias doesn't have an aliasee?");
+  auto *NewA = GlobalAlias::create(OrigA.getValueType(),
+                                   OrigA.getType()->getPointerAddressSpace(),
+                                   OrigA.getLinkage(), OrigA.getName(), &Dst);
+  NewA->copyAttributesFrom(&OrigA);
+  VMap[&OrigA] = NewA;
+  NewA->setAliasee(cast<Constant>(MapValue(OrigA.getAliasee(), VMap, RF_None,
+                                           nullptr, Materializer)));
+  return NewA;
+}
+
 } // End namespace orc.
 } // End namespace llvm.