[PATCH] D69124: [clang][driver] Print compilation phases with indentation.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 18 07:51:05 PDT 2019


hliao updated this revision to Diff 225620.
hliao added a comment.

revise the output by drawing tree lines. now, the output looks like

  $ clang -x cuda -ccc-print-phases --cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_60 -c dummy.cpp
              +- 0: input, "/home/michliao/dummy.cpp", cuda, (host-cuda)
           +- 1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
        +- 2: compiler, {1}, ir, (host-cuda)
        |                 +- 3: input, "/home/michliao/dummy.cpp", cuda, (device-cuda, sm_30)
        |              +- 4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_30)
        |           +- 5: compiler, {4}, ir, (device-cuda, sm_30)
        |        +- 6: backend, {5}, assembler, (device-cuda, sm_30)
        |     +- 7: assembler, {6}, object, (device-cuda, sm_30)
        |  +- 8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_30)" {7}, object
        |  |- 9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_30)" {6}, assembler
        |  |              +- 10: input, "/home/michliao/dummy.cpp", cuda, (device-cuda, sm_60)
        |  |           +- 11: preprocessor, {10}, cuda-cpp-output, (device-cuda, sm_60)
        |  |        +- 12: compiler, {11}, ir, (device-cuda, sm_60)
        |  |     +- 13: backend, {12}, assembler, (device-cuda, sm_60)
        |  |  +- 14: assembler, {13}, object, (device-cuda, sm_60)
        |  |- 15: offload, "device-cuda (nvptx64-nvidia-cuda:sm_60)" {14}, object
        |  |- 16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_60)" {13}, assembler
        |- 17: linker, {8, 9, 15, 16}, cuda-fatbin, (device-cuda)
     +- 18: offload, "host-cuda (x86_64-unknown-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {17}, ir
  +- 19: backend, {18}, assembler, (host-cuda)
  20: assembler, {19}, object, (host-cuda)



  $ clang -x hip -ccc-print-phases --cuda-gpu-arch=gfx900 --cuda-gpu-arch=gfx906 -c dummy.cpp
              +- 0: input, "/home/michliao/dummy.cpp", hip, (host-hip)
           +- 1: preprocessor, {0}, hip-cpp-output, (host-hip)
        +- 2: compiler, {1}, ir, (host-hip)
        |              +- 3: input, "/home/michliao/dummy.cpp", hip, (device-hip, gfx900)
        |           +- 4: preprocessor, {3}, hip-cpp-output, (device-hip, gfx900)
        |        +- 5: compiler, {4}, ir, (device-hip, gfx900)
        |     +- 6: linker, {5}, image, (device-hip, gfx900)
        |  +- 7: offload, "device-hip (amdgcn-amd-amdhsa:gfx900)" {6}, image
        |  |           +- 8: input, "/home/michliao/dummy.cpp", hip, (device-hip, gfx906)
        |  |        +- 9: preprocessor, {8}, hip-cpp-output, (device-hip, gfx906)
        |  |     +- 10: compiler, {9}, ir, (device-hip, gfx906)
        |  |  +- 11: linker, {10}, image, (device-hip, gfx906)
        |  |- 12: offload, "device-hip (amdgcn-amd-amdhsa:gfx906)" {11}, image
        |- 13: linker, {7, 12}, hip-fatbin, (device-hip)
     +- 14: offload, "host-hip (x86_64-unknown-linux-gnu)" {2}, "device-hip (amdgcn-amd-amdhsa)" {13}, ir
  +- 15: backend, {14}, assembler, (host-hip)
  16: assembler, {15}, object, (host-hip)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69124/new/

https://reviews.llvm.org/D69124

Files:
  clang/lib/Driver/Driver.cpp


Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1802,23 +1802,36 @@
   return true;
 }
 
+enum {
+  TopLevelAction = 0,
+  HeadSibAction = 1,
+  OtherSibAction = 2,
+};
+
 // Display an action graph human-readably.  Action A is the "sink" node
 // and latest-occuring action. Traversal is in pre-order, visiting the
 // inputs to each action before printing the action itself.
 static unsigned PrintActions1(const Compilation &C, Action *A,
-                              std::map<Action *, unsigned> &Ids) {
+                              std::map<Action *, unsigned> &Ids,
+                              Twine Indent = {}, int Kind = TopLevelAction) {
   if (Ids.count(A)) // A was already visited.
     return Ids[A];
 
   std::string str;
   llvm::raw_string_ostream os(str);
 
+  auto getSibIndent = [](int K) -> Twine {
+    return (K == HeadSibAction) ? "   " : (K == OtherSibAction) ? "|  " : "";
+  };
+
+  Twine SibIndent = Indent + getSibIndent(Kind);
+  int SibKind = HeadSibAction;
   os << Action::getClassName(A->getKind()) << ", ";
   if (InputAction *IA = dyn_cast<InputAction>(A)) {
     os << "\"" << IA->getInputArg().getValue() << "\"";
   } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
     os << '"' << BIA->getArchName() << '"' << ", {"
-       << PrintActions1(C, *BIA->input_begin(), Ids) << "}";
+       << PrintActions1(C, *BIA->input_begin(), Ids, SibIndent, SibKind) << "}";
   } else if (OffloadAction *OA = dyn_cast<OffloadAction>(A)) {
     bool IsFirst = true;
     OA->doOnEachDependence(
@@ -1841,8 +1854,9 @@
             os << ":" << BoundArch;
           os << ")";
           os << '"';
-          os << " {" << PrintActions1(C, A, Ids) << "}";
+          os << " {" << PrintActions1(C, A, Ids, SibIndent, SibKind) << "}";
           IsFirst = false;
+          SibKind = OtherSibAction;
         });
   } else {
     const ActionList *AL = &A->getInputs();
@@ -1850,8 +1864,9 @@
     if (AL->size()) {
       const char *Prefix = "{";
       for (Action *PreRequisite : *AL) {
-        os << Prefix << PrintActions1(C, PreRequisite, Ids);
+        os << Prefix << PrintActions1(C, PreRequisite, Ids, SibIndent, SibKind);
         Prefix = ", ";
+        SibKind = OtherSibAction;
       }
       os << "}";
     } else
@@ -1872,9 +1887,13 @@
     }
   }
 
+  auto getSelfIndent = [](int K) -> Twine {
+    return (K == HeadSibAction) ? "+- " : (K == OtherSibAction) ? "|- " : "";
+  };
+
   unsigned Id = Ids.size();
   Ids[A] = Id;
-  llvm::errs() << Id << ": " << os.str() << ", "
+  llvm::errs() << Indent + getSelfIndent(Kind) << Id << ": " << os.str() << ", "
                << types::getTypeName(A->getType()) << offload_os.str() << "\n";
 
   return Id;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69124.225620.patch
Type: text/x-patch
Size: 2843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191018/0d674aee/attachment.bin>


More information about the cfe-commits mailing list