[Orc] Add support for emitting indirect stubs directly into the JIT target's
[oota-llvm.git] / lib / ExecutionEngine / Orc / IndirectionUtils.cpp
index 4d207cffd207fa039f6ca8e66658e24d4b1ccf09..5b1eccd82a42b2ab984bbb0f83f7e7721f69aa64 100644 (file)
@@ -19,6 +19,9 @@
 namespace llvm {
 namespace orc {
 
+void JITCompileCallbackManagerBase::anchor() {}
+void IndirectStubsManagerBase::anchor() {}
+
 Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) {
   Constant *AddrIntVal =
     ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr);
@@ -37,7 +40,7 @@ GlobalVariable* createImplPointer(PointerType &PT, Module &M,
   return IP;
 }
 
-void makeStub(Function &F, GlobalVariable &ImplPointer) {
+void makeStub(Function &F, Value &ImplPointer) {
   assert(F.isDeclaration() && "Can't turn a definition into a stub.");
   assert(F.getParent() && "Function isn't in a module.");
   Module &M = *F.getParent();
@@ -106,6 +109,9 @@ void makeAllSymbolsExternallyAccessible(Module &M) {
 
   for (auto &GV : M.globals())
     raiseVisibilityOnValue(GV, Renamer);
+
+  for (auto &A : M.aliases())
+    raiseVisibilityOnValue(A, Renamer);
 }
 
 Function* cloneFunctionDecl(Module &Dst, const Function &F,
@@ -177,17 +183,14 @@ void moveGlobalVariableInitializer(GlobalVariable &OrigGV,
                                  nullptr, Materializer));
 }
 
-GlobalAlias* cloneGlobalAlias(Module &Dst, const GlobalAlias &OrigA,
-                              ValueToValueMapTy &VMap,
-                              ValueMaterializer *Materializer) {
+GlobalAlias* cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA,
+                                  ValueToValueMapTy &VMap) {
   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;
 }