From ff92d3c672e2bf0b885b67b0efebea691df9c5b9 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 28 May 2020 17:55:49 -0700 Subject: [PATCH] [ORC] Add debugging output for LLJIT construction. This can be handy for checking whether the LLJIT instance you're constructing matches your expectations. --- .../ExecutionEngine/Orc/JITTargetMachineBuilder.h | 9 +++ .../Orc/JITTargetMachineBuilder.cpp | 74 ++++++++++++++++++++++ llvm/lib/ExecutionEngine/Orc/LLJIT.cpp | 29 +++++++++ 3 files changed, 112 insertions(+) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h index 3b6becd28..c4109a8 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h @@ -25,6 +25,9 @@ #include 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; diff --git a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp index 3eda0fa..8cf66c9 100644 --- a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp +++ b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp @@ -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 = , 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. diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 79e5027..0e51ba1 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -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 && -- 2.7.4