[ORC] Improve debugging output for ORC.
(1) Print debugging output under a session lock to avoid garbled messages when
compiling on multiple threads.
(2) Name MaterializationUnits, add an ostream operator for them, and so they can
be easily referenced in debugging output, and have that ostream operator
optionally print code/data/hidden symbols provided by that materialization unit
based on command line options.
llvm-svn: 343323
diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp
index f47634f..38afead 100644
--- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp
@@ -9,6 +9,9 @@
#include "llvm/ExecutionEngine/Orc/Layer.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "orc"
namespace llvm {
namespace orc {
@@ -44,7 +47,18 @@
: MaterializationUnit(std::move(SymbolFlags)), TSM(std::move(TSM)),
SymbolToDefinition(std::move(SymbolToDefinition)) {}
+StringRef IRMaterializationUnit::getName() const {
+ if (TSM.getModule())
+ return TSM.getModule()->getModuleIdentifier();
+ return "<null module>";
+}
+
void IRMaterializationUnit::discard(const JITDylib &JD, SymbolStringPtr Name) {
+ LLVM_DEBUG(JD.getExecutionSession().runSessionLocked([&]() {
+ dbgs() << "In " << JD.getName() << " discarding " << *Name << " from MU@"
+ << this << " (" << getName() << ")\n";
+ }););
+
auto I = SymbolToDefinition.find(Name);
assert(I != SymbolToDefinition.end() &&
"Symbol not provided by this MU, or previously discarded");
@@ -65,8 +79,20 @@
if (L.getCloneToNewContextOnEmit())
TSM = cloneToNewContext(TSM);
+#ifndef NDEBUG
+ auto &ES = R.getTargetJITDylib().getExecutionSession();
+#endif // NDEBUG
+
auto Lock = TSM.getContextLock();
+ LLVM_DEBUG(ES.runSessionLocked([&]() {
+ dbgs() << "Emitting, for " << R.getTargetJITDylib().getName() << ", "
+ << *this << "\n";
+ }););
L.emit(std::move(R), std::move(K), std::move(TSM));
+ LLVM_DEBUG(ES.runSessionLocked([&]() {
+ dbgs() << "Finished emitting, for " << R.getTargetJITDylib().getName()
+ << ", " << *this << "\n";
+ }););
}
ObjectLayer::ObjectLayer(ExecutionSession &ES) : ES(ES) {}
@@ -102,6 +128,12 @@
: MaterializationUnit(std::move(SymbolFlags)), L(L), K(std::move(K)),
O(std::move(O)) {}
+StringRef BasicObjectLayerMaterializationUnit::getName() const {
+ if (O)
+ return O->getBufferIdentifier();
+ return "<null object>";
+}
+
void BasicObjectLayerMaterializationUnit::materialize(
MaterializationResponsibility R) {
L.emit(std::move(R), std::move(K), std::move(O));