[llvm] 0469256 - [ORC] Print CPU feature string in JITTargetMachineBuilder debugging output.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 18 20:18:28 PST 2021


Author: Lang Hames
Date: 2021-02-19T15:18:19+11:00
New Revision: 0469256d35e7dce12db1ff479bac9946c344d31f

URL: https://github.com/llvm/llvm-project/commit/0469256d35e7dce12db1ff479bac9946c344d31f
DIFF: https://github.com/llvm/llvm-project/commit/0469256d35e7dce12db1ff479bac9946c344d31f.diff

LOG: [ORC] Print CPU feature string in JITTargetMachineBuilder debugging output.

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h
    llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
    llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h
index c4109a8de82e..e3cfbfe421fa 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h
@@ -32,6 +32,9 @@ namespace orc {
 
 /// A utility class for building TargetMachines for JITs.
 class JITTargetMachineBuilder {
+#ifndef NDEBUG
+  friend class JITTargetMachineBuilderPrinter;
+#endif
 public:
   /// Create a JITTargetMachineBuilder based on the given triple.
   ///
@@ -139,12 +142,6 @@ class JITTargetMachineBuilder {
   /// 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;
@@ -155,6 +152,26 @@ class JITTargetMachineBuilder {
   CodeGenOpt::Level OptLevel = CodeGenOpt::Default;
 };
 
+#ifndef NDEBUG
+class JITTargetMachineBuilderPrinter {
+public:
+  JITTargetMachineBuilderPrinter(JITTargetMachineBuilder &JTMB,
+                                 StringRef Indent)
+      : JTMB(JTMB), Indent(Indent) {}
+  void print(raw_ostream &OS) const;
+
+  friend raw_ostream &operator<<(raw_ostream &OS,
+                                 const JITTargetMachineBuilderPrinter &JTMBP) {
+    JTMBP.print(OS);
+    return OS;
+  }
+
+private:
+  JITTargetMachineBuilder &JTMB;
+  StringRef Indent;
+};
+#endif // NDEBUG
+
 } // end namespace orc
 } // end namespace llvm
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
index 8cf66c9e759a..4257137a2212 100644
--- a/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/JITTargetMachineBuilder.cpp
@@ -65,9 +65,13 @@ JITTargetMachineBuilder &JITTargetMachineBuilder::addFeatures(
 }
 
 #ifndef NDEBUG
-raw_ostream &operator<<(raw_ostream &OS, const JITTargetMachineBuilder &JTMB) {
-  OS << "{ Triple = \"" << JTMB.TT.str() << "\", CPU = \"" << JTMB.CPU
-     << "\", Options = <not-printable>, Relocation Model = ";
+void JITTargetMachineBuilderPrinter::print(raw_ostream &OS) const {
+  OS << Indent << "{\n"
+     << Indent << "  Triple = \"" << JTMB.TT.str() << "\"\n"
+     << Indent << "  CPU = \"" << JTMB.CPU << "\"\n"
+     << Indent << "  Features = \"" << JTMB.Features.getString() << "\"\n"
+     << Indent << "  Options = <not-printable>\n"
+     << Indent << "  Relocation Model = ";
 
   if (JTMB.RM) {
     switch (*JTMB.RM) {
@@ -91,9 +95,10 @@ raw_ostream &operator<<(raw_ostream &OS, const JITTargetMachineBuilder &JTMB) {
       break;
     }
   } else
-    OS << "unspecified";
+    OS << "unspecified (will use target default)";
 
-  OS << ", Code Model = ";
+  OS << "\n"
+     << Indent << "  Code Model = ";
 
   if (JTMB.CM) {
     switch (*JTMB.CM) {
@@ -114,9 +119,10 @@ raw_ostream &operator<<(raw_ostream &OS, const JITTargetMachineBuilder &JTMB) {
       break;
     }
   } else
-    OS << "unspecified";
+    OS << "unspecified (will use target default)";
 
-  OS << ", Optimization Level = ";
+  OS << "\n"
+     << Indent << "  Optimization Level = ";
   switch (JTMB.OptLevel) {
   case CodeGenOpt::None:
     OS << "None";
@@ -132,8 +138,7 @@ raw_ostream &operator<<(raw_ostream &OS, const JITTargetMachineBuilder &JTMB) {
     break;
   }
 
-  OS << " }";
-  return OS;
+  OS << "\n" << Indent << "}\n";
 }
 #endif // NDEBUG
 

diff  --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index c368c1e37134..fb6d87a51402 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -922,7 +922,8 @@ Error LLJITBuilderState::prepareForConstruction() {
   }
 
   LLVM_DEBUG({
-    dbgs() << "  JITTargetMachineBuilder is " << JTMB << "\n"
+    dbgs() << "  JITTargetMachineBuilder is "
+           << JITTargetMachineBuilderPrinter(*JTMB, "  ")
            << "  Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
            << "\n"
            << "  DataLayout: ";


        


More information about the llvm-commits mailing list