[llvm] r234669 - [Orc] Tidy up IndirectionUtils API a little, add some comments. NFC.

Lang Hames lhames at gmail.com
Fri Apr 10 17:23:49 PDT 2015


Author: lhames
Date: Fri Apr 10 19:23:49 2015
New Revision: 234669

URL: http://llvm.org/viewvc/llvm-project?rev=234669&view=rev
Log:
[Orc] Tidy up IndirectionUtils API a little, add some comments. NFC.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
    llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
    llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=234669&r1=234668&r2=234669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Fri Apr 10 19:23:49 2015
@@ -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);

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h?rev=234669&r1=234668&r2=234669&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h Fri Apr 10 19:23:49 2015
@@ -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, typena
     };
   }
 
-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.

Modified: llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp?rev=234669&r1=234668&r2=234669&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp Fri Apr 10 19:23:49 2015
@@ -18,13 +18,20 @@
 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 ModulePa
     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 ModulePa
 
     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()) {





More information about the llvm-commits mailing list