[Orc] Use raw TargetAddresses for callback trampoline addresses, rather than IR.
authorLang Hames <lhames@gmail.com>
Sun, 29 Mar 2015 21:55:27 +0000 (21:55 +0000)
committerLang Hames <lhames@gmail.com>
Sun, 29 Mar 2015 21:55:27 +0000 (21:55 +0000)
Add convenience function for building a typed IR Constant from trampoline
addresses.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233504 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
include/llvm/ExecutionEngine/Orc/IndirectionUtils.h

index 77b0c48d0a7a3344f7995172795a60ffac4fb531..15b74f53255fe88affcf3071e39ee8ad405d247a 100644 (file)
@@ -258,7 +258,8 @@ private:
           CompileCallbackMgr.getCompileCallback(*Proto->getFunctionType());
         GlobalVariable *FunctionBodyPointer =
           createImplPointer(*Proto, Name + AddrSuffix,
-                            CallbackInfo.getAddress());
+                            createIRTypedAddress(*Proto->getFunctionType(),
+                                                 CallbackInfo.getAddress()));
         makeStub(*Proto, *FunctionBodyPointer);
 
         F.setName(Name + BodySuffix);
index 8ce1d4d545286dd3a5ec60990f54f5154ad43ced..3a2158d63389ebd66421cb8f7c5e0b43f655d2e0 100644 (file)
@@ -37,11 +37,11 @@ public:
   ///        the compile and update actions for the callback.
   class CompileCallbackInfo {
   public:
-    CompileCallbackInfo(Constant *Addr, CompileFtor &Compile,
+    CompileCallbackInfo(TargetAddress Addr, CompileFtor &Compile,
                         UpdateFtor &Update)
       : Addr(Addr), Compile(Compile), Update(Update) {}
 
-    Constant* getAddress() const { return Addr; }
+    TargetAddress getAddress() const { return Addr; }
     void setCompileAction(CompileFtor Compile) {
       this->Compile = std::move(Compile);
     }
@@ -49,7 +49,7 @@ public:
       this->Update = std::move(Update);
     }
   private:
-    Constant *Addr;
+    TargetAddress Addr;
     CompileFtor &Compile;
     UpdateFtor &Update;
   };
@@ -139,13 +139,8 @@ public:
     TargetAddress TrampolineAddr = getAvailableTrampolineAddr(FT.getContext());
     auto &CallbackHandler =
       this->ActiveTrampolines[TrampolineAddr];
-    Constant *AddrIntVal =
-      ConstantInt::get(Type::getInt64Ty(FT.getContext()), TrampolineAddr);
-    Constant *AddrPtrVal =
-      ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
-                            PointerType::get(&FT, 0));
 
-    return CompileCallbackInfo(AddrPtrVal, CallbackHandler.Compile,
+    return CompileCallbackInfo(TrampolineAddr, CallbackHandler.Compile,
                                CallbackHandler.Update);
   }
 
@@ -201,6 +196,15 @@ private:
   TargetAddress ResolverBlockAddr;
 };
 
+Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) {
+  Constant *AddrIntVal =
+    ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr);
+  Constant *AddrPtrVal =
+    ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
+                          PointerType::get(&FT, 0));
+  return AddrPtrVal;
+}
+
 /// @brief Get an update functor for updating the value of a named function
 ///        pointer.
 template <typename JITLayerT>