[llvm] r343365 - [ORC] Add more utilities to aid debugging output.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 28 14:49:53 PDT 2018


Author: lhames
Date: Fri Sep 28 14:49:53 2018
New Revision: 343365

URL: http://llvm.org/viewvc/llvm-project?rev=343365&view=rev
Log:
[ORC] Add more utilities to aid debugging output.

(1) A const accessor for the LLVMContext held by a ThreadSafeContext.

(2) A const accessor for the ThreadSafeModules held by an IRMaterializationUnit.

(3) A const MaterializationResponsibility reference to IRTransformLayer2's
    transform function. This makes IRTransformLayer2 useful for JIT debugging
    (since it can inspect JIT state through the responsibility argument) as well
    as program transformations.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
    llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h
    llvm/trunk/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
    llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp
    llvm/trunk/tools/lli/lli.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h?rev=343365&r1=343364&r2=343365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IRTransformLayer.h Fri Sep 28 14:49:53 2018
@@ -25,8 +25,8 @@ namespace orc {
 
 class IRTransformLayer2 : public IRLayer {
 public:
-  using TransformFunction =
-      std::function<Expected<ThreadSafeModule>(ThreadSafeModule)>;
+  using TransformFunction = std::function<Expected<ThreadSafeModule>(
+      ThreadSafeModule, const MaterializationResponsibility &R)>;
 
   IRTransformLayer2(ExecutionSession &ES, IRLayer &BaseLayer,
                     TransformFunction Transform = identityTransform);
@@ -38,7 +38,9 @@ public:
   void emit(MaterializationResponsibility R, VModuleKey K,
             ThreadSafeModule TSM) override;
 
-  static ThreadSafeModule identityTransform(ThreadSafeModule TSM) {
+  static ThreadSafeModule
+  identityTransform(ThreadSafeModule TSM,
+                    const MaterializationResponsibility &R) {
     return TSM;
   }
 

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h?rev=343365&r1=343364&r2=343365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/Layer.h Fri Sep 28 14:49:53 2018
@@ -89,6 +89,8 @@ public:
   /// Return the ModuleIdentifier as the name for this MaterializationUnit.
   StringRef getName() const override;
 
+  const ThreadSafeModule &getModule() const { return TSM; }
+
 protected:
   ThreadSafeModule TSM;
   SymbolNameToDefinitionMap SymbolToDefinition;

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h?rev=343365&r1=343364&r2=343365&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/ThreadSafeModule.h Fri Sep 28 14:49:53 2018
@@ -66,6 +66,10 @@ public:
   /// instance, or null if the instance was default constructed.
   LLVMContext *getContext() { return S ? S->Ctx.get() : nullptr; }
 
+  /// Returns a pointer to the LLVMContext that was used to construct this
+  /// instance, or null if the instance was default constructed.
+  const LLVMContext *getContext() const { return S ? S->Ctx.get() : nullptr; }
+
   Lock getLock() {
     assert(S && "Can not lock an empty ThreadSafeContext");
     return Lock(S);

Modified: llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp?rev=343365&r1=343364&r2=343365&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IRTransformLayer.cpp Fri Sep 28 14:49:53 2018
@@ -22,7 +22,7 @@ void IRTransformLayer2::emit(Materializa
                              ThreadSafeModule TSM) {
   assert(TSM.getModule() && "Module must not be null");
 
-  if (auto TransformedTSM = Transform(std::move(TSM)))
+  if (auto TransformedTSM = Transform(std::move(TSM), R))
     BaseLayer.emit(std::move(R), std::move(K), std::move(*TransformedTSM));
   else {
     R.failMaterialization();

Modified: llvm/trunk/tools/lli/lli.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=343365&r1=343364&r2=343365&view=diff
==============================================================================
--- llvm/trunk/tools/lli/lli.cpp (original)
+++ llvm/trunk/tools/lli/lli.cpp Fri Sep 28 14:49:53 2018
@@ -702,10 +702,12 @@ int main(int argc, char **argv, char * c
 static orc::IRTransformLayer2::TransformFunction createDebugDumper() {
   switch (OrcDumpKind) {
   case DumpKind::NoDump:
-    return [](orc::ThreadSafeModule TSM) { return TSM; };
+    return [](orc::ThreadSafeModule TSM,
+              const orc::MaterializationResponsibility &R) { return TSM; };
 
   case DumpKind::DumpFuncsToStdOut:
-    return [](orc::ThreadSafeModule TSM) {
+    return [](orc::ThreadSafeModule TSM,
+              const orc::MaterializationResponsibility &R) {
       printf("[ ");
 
       for (const auto &F : *TSM.getModule()) {
@@ -724,7 +726,8 @@ static orc::IRTransformLayer2::Transform
     };
 
   case DumpKind::DumpModsToStdOut:
-    return [](orc::ThreadSafeModule TSM) {
+    return [](orc::ThreadSafeModule TSM,
+              const orc::MaterializationResponsibility &R) {
       outs() << "----- Module Start -----\n"
              << *TSM.getModule() << "----- Module End -----\n";
 
@@ -732,7 +735,8 @@ static orc::IRTransformLayer2::Transform
     };
 
   case DumpKind::DumpModsToDisk:
-    return [](orc::ThreadSafeModule TSM) {
+    return [](orc::ThreadSafeModule TSM,
+              const orc::MaterializationResponsibility &R) {
       std::error_code EC;
       raw_fd_ostream Out(TSM.getModule()->getModuleIdentifier() + ".ll", EC,
                          sys::fs::F_Text);
@@ -792,12 +796,13 @@ int runOrcLazyJIT(const char *ProgName)
 
   auto Dump = createDebugDumper();
 
-  J->setLazyCompileTransform([&](orc::ThreadSafeModule TSM) {
+  J->setLazyCompileTransform([&](orc::ThreadSafeModule TSM,
+                                 const orc::MaterializationResponsibility &R) {
     if (verifyModule(*TSM.getModule(), &dbgs())) {
       dbgs() << "Bad module: " << *TSM.getModule() << "\n";
       exit(1);
     }
-    return Dump(std::move(TSM));
+    return Dump(std::move(TSM), R);
   });
   J->getMainJITDylib().setFallbackDefinitionGenerator(
       orc::DynamicLibraryFallbackGenerator(




More information about the llvm-commits mailing list