hliao created this revision.
hliao added reviewers: tra, sfantao, echristo.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
hliao added a comment.

this patch enables the dumping of actions in the hierarchy or tree. In most 
cases, it's a linear list but, for offload compilation, a tree representation 
is more intuitive. Even though there are cross-subtree edges, they are rare and 
also noted in the corresponding actions.


Repository:
  rG LLVM Github Monorepo

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
@@ -1806,7 +1806,8 @@
 // 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,
+                              unsigned Ident = 0) {
   if (Ids.count(A)) // A was already visited.
     return Ids[A];
 
@@ -1818,7 +1819,7 @@
     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, Ident + 1) << "}";
   } else if (OffloadAction *OA = dyn_cast<OffloadAction>(A)) {
     bool IsFirst = true;
     OA->doOnEachDependence(
@@ -1841,7 +1842,7 @@
             os << ":" << BoundArch;
           os << ")";
           os << '"';
-          os << " {" << PrintActions1(C, A, Ids) << "}";
+          os << " {" << PrintActions1(C, A, Ids, Ident + 1) << "}";
           IsFirst = false;
         });
   } else {
@@ -1850,7 +1851,7 @@
     if (AL->size()) {
       const char *Prefix = "{";
       for (Action *PreRequisite : *AL) {
-        os << Prefix << PrintActions1(C, PreRequisite, Ids);
+        os << Prefix << PrintActions1(C, PreRequisite, Ids, Ident + 1);
         Prefix = ", ";
       }
       os << "}";
@@ -1874,8 +1875,9 @@
 
   unsigned Id = Ids.size();
   Ids[A] = Id;
-  llvm::errs() << Id << ": " << os.str() << ", "
-               << types::getTypeName(A->getType()) << offload_os.str() << "\n";
+  llvm::errs().indent(Ident)
+      << Id << ": " << os.str() << ", " << types::getTypeName(A->getType())
+      << offload_os.str() << "\n";
 
   return Id;
 }


Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -1806,7 +1806,8 @@
 // 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,
+                              unsigned Ident = 0) {
   if (Ids.count(A)) // A was already visited.
     return Ids[A];
 
@@ -1818,7 +1819,7 @@
     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, Ident + 1) << "}";
   } else if (OffloadAction *OA = dyn_cast<OffloadAction>(A)) {
     bool IsFirst = true;
     OA->doOnEachDependence(
@@ -1841,7 +1842,7 @@
             os << ":" << BoundArch;
           os << ")";
           os << '"';
-          os << " {" << PrintActions1(C, A, Ids) << "}";
+          os << " {" << PrintActions1(C, A, Ids, Ident + 1) << "}";
           IsFirst = false;
         });
   } else {
@@ -1850,7 +1851,7 @@
     if (AL->size()) {
       const char *Prefix = "{";
       for (Action *PreRequisite : *AL) {
-        os << Prefix << PrintActions1(C, PreRequisite, Ids);
+        os << Prefix << PrintActions1(C, PreRequisite, Ids, Ident + 1);
         Prefix = ", ";
       }
       os << "}";
@@ -1874,8 +1875,9 @@
 
   unsigned Id = Ids.size();
   Ids[A] = Id;
-  llvm::errs() << Id << ": " << os.str() << ", "
-               << types::getTypeName(A->getType()) << offload_os.str() << "\n";
+  llvm::errs().indent(Ident)
+      << Id << ": " << os.str() << ", " << types::getTypeName(A->getType())
+      << offload_os.str() << "\n";
 
   return Id;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to