[ORC] Add debugging output for LLJIT construction.

This can be handy for checking whether the LLJIT instance you're constructing
matches your expectations.
This commit is contained in:
Lang Hames 2020-05-28 17:55:49 -07:00
parent a6deaeec37
commit ff92d3c672
3 changed files with 112 additions and 0 deletions

View File

@ -25,6 +25,9 @@
#include <vector>
namespace llvm {
class raw_ostream;
namespace orc {
/// A utility class for building TargetMachines for JITs.
@ -136,6 +139,12 @@ public:
/// Access Triple.
const Triple &getTargetTriple() const { return TT; }
#ifndef NDEBUG
/// Debug-dump a JITTargetMachineBuilder.
friend raw_ostream &operator<<(raw_ostream &OS,
const JITTargetMachineBuilder &JTMB);
#endif
private:
Triple TT;
std::string CPU;

View File

@ -10,6 +10,7 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
namespace orc {
@ -63,5 +64,78 @@ JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
return *this;
}
#ifndef NDEBUG
raw_ostream &operator<<(raw_ostream &OS, const JITTargetMachineBuilder &JTMB) {
OS << "{ Triple = \"" << JTMB.TT.str() << "\", CPU = \"" << JTMB.CPU
<< "\", Options = <not-printable>, Relocation Model = ";
if (JTMB.RM) {
switch (*JTMB.RM) {
case Reloc::Static:
OS << "Static";
break;
case Reloc::PIC_:
OS << "PIC_";
break;
case Reloc::DynamicNoPIC:
OS << "DynamicNoPIC";
break;
case Reloc::ROPI:
OS << "ROPI";
break;
case Reloc::RWPI:
OS << "RWPI";
break;
case Reloc::ROPI_RWPI:
OS << "ROPI_RWPI";
break;
}
} else
OS << "unspecified";
OS << ", Code Model = ";
if (JTMB.CM) {
switch (*JTMB.CM) {
case CodeModel::Tiny:
OS << "Tiny";
break;
case CodeModel::Small:
OS << "Small";
break;
case CodeModel::Kernel:
OS << "Kernel";
break;
case CodeModel::Medium:
OS << "Medium";
break;
case CodeModel::Large:
OS << "Large";
break;
}
} else
OS << "unspecified";
OS << ", Optimization Level = ";
switch (JTMB.OptLevel) {
case CodeGenOpt::None:
OS << "None";
break;
case CodeGenOpt::Less:
OS << "Less";
break;
case CodeGenOpt::Default:
OS << "Default";
break;
case CodeGenOpt::Aggressive:
OS << "Aggressive";
break;
}
OS << " }";
return OS;
}
#endif // NDEBUG
} // End namespace orc.
} // End namespace llvm.

View File

@ -927,13 +927,42 @@ LLJIT::PlatformSupport::~PlatformSupport() {}
Error LLJITBuilderState::prepareForConstruction() {
LLVM_DEBUG(dbgs() << "Preparing to create LLIT instance...\n");
if (!JTMB) {
LLVM_DEBUG({
dbgs() << " No explicitly set JITTargetMachineBuilder. "
"Detecting host...\n";
});
if (auto JTMBOrErr = JITTargetMachineBuilder::detectHost())
JTMB = std::move(*JTMBOrErr);
else
return JTMBOrErr.takeError();
}
LLVM_DEBUG({
dbgs() << " JITTargetMachineBuilder is " << JTMB << "\n"
<< " Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
<< "\n"
<< " DataLayout: ";
if (DL)
dbgs() << DL->getStringRepresentation() << "\n";
else
dbgs() << "None (will be created by JITTargetMachineBuilder)\n";
dbgs() << " Custom object-linking-layer creator: "
<< (CreateObjectLinkingLayer ? "Yes" : "No") << "\n"
<< " Custom compile-function creator: "
<< (CreateCompileFunction ? "Yes" : "No") << "\n"
<< " Custom platform-setup function: "
<< (SetUpPlatform ? "Yes" : "No") << "\n"
<< " Number of compile threads: " << NumCompileThreads;
if (!NumCompileThreads)
dbgs() << " (code will be compiled on the execution thread)\n";
else
dbgs() << "\n";
});
// If the client didn't configure any linker options then auto-configure the
// JIT linker.
if (!CreateObjectLinkingLayer && JTMB->getCodeModel() == None &&