[Orc] Tidy up IndirectionUtils API a little, add some comments. NFC.
authorLang Hames <lhames@gmail.com>
Sat, 11 Apr 2015 00:23:49 +0000 (00:23 +0000)
committerLang Hames <lhames@gmail.com>
Sat, 11 Apr 2015 00:23:49 +0000 (00:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234669 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7c1398a51c8ef4476072bd2ae1797a224652ad53..3dc3927a15c211cc9fc8ae2333bca4902d0c4ce7 100644 (file)
@@ -261,7 +261,8 @@ private:
         auto CallbackInfo =
           CompileCallbackMgr.getCompileCallback(Proto->getContext());
         GlobalVariable *FunctionBodyPointer =
-          createImplPointer(*Proto, Name + AddrSuffix,
+          createImplPointer(*Proto->getType(), *Proto->getParent(),
+                            Name + AddrSuffix,
                             createIRTypedAddress(*Proto->getFunctionType(),
                                                  CallbackInfo.getAddress()));
         makeStub(*Proto, *FunctionBodyPointer);
index 94032910a2b20bfe8b87762583998d9658a65938..7b4f611393f449ab69d443e4c4399fb7e92db78d 100644 (file)
@@ -203,16 +203,7 @@ private:
   TargetAddress ResolverBlockAddr;
 };
 
-inline 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
+/// @brief Get an update functor that updates the value of a named function
 ///        pointer.
 template <typename JITLayerT>
 JITCompileCallbackManagerBase::UpdateFtor
@@ -228,13 +219,26 @@ getLocalFPUpdater(JITLayerT &JIT, typename JITLayerT::ModuleSetHandleT H,
     };
   }
 
-GlobalVariable* createImplPointer(Function &F, const Twine &Name,
-                                  Constant *Initializer);
+/// @brief Build a function pointer of FunctionType with the given constant
+///        address.
+///
+///   Usage example: Turn a trampoline address into a function pointer constant
+/// for use in a stub.
+Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr);
 
+/// @brief Create a function pointer with the given type, name, and initializer
+///        in the given Module.
+GlobalVariable* createImplPointer(PointerType &PT, Module &M,
+                                  const Twine &Name, Constant *Initializer);
+
+/// @brief Turn a function declaration into a stub function that makes an
+///        indirect call using the given function pointer.
 void makeStub(Function &F, GlobalVariable &ImplPointer);
 
 typedef std::map<Module*, DenseSet<const GlobalValue*>> ModulePartitionMap;
 
+/// @brief Extract subsections of a Module into the given Module according to
+///        the given ModulePartitionMap.
 void partition(Module &M, const ModulePartitionMap &PMap);
 
 /// @brief Struct for trivial "complete" partitioning of a module.
@@ -250,6 +254,7 @@ public:
         Functions(std::move(S.Functions)) {}
 };
 
+/// @brief Extract every function in M into a separate module.
 FullyPartitionedModule fullyPartition(Module &M);
 
 } // End namespace orc.
index 74766450e8c416633b7b0ecac1501ee253dd8897..bcf22f582661f801a6674e74fa8328b89c01d958 100644 (file)
 namespace llvm {
 namespace orc {
 
-GlobalVariable* createImplPointer(Function &F, const Twine &Name,
-                                  Constant *Initializer) {
-  assert(F.getParent() && "Function isn't in a module.");
+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;
+}
+
+GlobalVariable* createImplPointer(PointerType &PT, Module &M,
+                                  const Twine &Name, Constant *Initializer) {
   if (!Initializer)
-    Initializer = Constant::getNullValue(F.getType());
-  Module &M = *F.getParent();
-  return new GlobalVariable(M, F.getType(), false, GlobalValue::ExternalLinkage,
+    Initializer = Constant::getNullValue(&PT);
+  return new GlobalVariable(M, &PT, false, GlobalValue::ExternalLinkage,
                             Initializer, Name, nullptr,
                             GlobalValue::NotThreadLocal, 0, true);
 }
@@ -51,6 +58,7 @@ void partition(Module &M, const ModulePartitionMap &PMap) {
     auto ExtractGlobalVars =
       [&](GlobalVariable &New, const GlobalVariable &Orig,
           ValueToValueMapTy &VMap) {
+        assert(Orig.hasName() && "Extracted globals must have names.");
         if (KVPair.second.count(&Orig)) {
           copyGVInitializer(New, Orig, VMap);
         }
@@ -62,6 +70,7 @@ void partition(Module &M, const ModulePartitionMap &PMap) {
 
     auto ExtractFunctions =
       [&](Function &New, const Function &Orig, ValueToValueMapTy &VMap) {
+        assert(Orig.hasName() && "Extracted functions must have names.");
         if (KVPair.second.count(&Orig))
           copyFunctionBody(New, Orig, VMap);
         if (New.hasLocalLinkage()) {