forked from OSchip/llvm-project
				
			[clang][driver] Print compilation phases with indentation.
Reviewers: tra, sfantao, echristo Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69124 llvm-svn: 375310
This commit is contained in:
		
							parent
							
								
									243ebfba17
								
							
						
					
					
						commit
						d7a487adfe
					
				| 
						 | 
					@ -1802,23 +1802,36 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 | 
				
			||||||
  return true;
 | 
					  return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum {
 | 
				
			||||||
 | 
					  TopLevelAction = 0,
 | 
				
			||||||
 | 
					  HeadSibAction = 1,
 | 
				
			||||||
 | 
					  OtherSibAction = 2,
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Display an action graph human-readably.  Action A is the "sink" node
 | 
					// Display an action graph human-readably.  Action A is the "sink" node
 | 
				
			||||||
// and latest-occuring action. Traversal is in pre-order, visiting the
 | 
					// and latest-occuring action. Traversal is in pre-order, visiting the
 | 
				
			||||||
// inputs to each action before printing the action itself.
 | 
					// inputs to each action before printing the action itself.
 | 
				
			||||||
static unsigned PrintActions1(const Compilation &C, Action *A,
 | 
					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.
 | 
					  if (Ids.count(A)) // A was already visited.
 | 
				
			||||||
    return Ids[A];
 | 
					    return Ids[A];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::string str;
 | 
					  std::string str;
 | 
				
			||||||
  llvm::raw_string_ostream os(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()) << ", ";
 | 
					  os << Action::getClassName(A->getKind()) << ", ";
 | 
				
			||||||
  if (InputAction *IA = dyn_cast<InputAction>(A)) {
 | 
					  if (InputAction *IA = dyn_cast<InputAction>(A)) {
 | 
				
			||||||
    os << "\"" << IA->getInputArg().getValue() << "\"";
 | 
					    os << "\"" << IA->getInputArg().getValue() << "\"";
 | 
				
			||||||
  } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
 | 
					  } else if (BindArchAction *BIA = dyn_cast<BindArchAction>(A)) {
 | 
				
			||||||
    os << '"' << BIA->getArchName() << '"' << ", {"
 | 
					    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)) {
 | 
					  } else if (OffloadAction *OA = dyn_cast<OffloadAction>(A)) {
 | 
				
			||||||
    bool IsFirst = true;
 | 
					    bool IsFirst = true;
 | 
				
			||||||
    OA->doOnEachDependence(
 | 
					    OA->doOnEachDependence(
 | 
				
			||||||
| 
						 | 
					@ -1841,8 +1854,9 @@ static unsigned PrintActions1(const Compilation &C, Action *A,
 | 
				
			||||||
            os << ":" << BoundArch;
 | 
					            os << ":" << BoundArch;
 | 
				
			||||||
          os << ")";
 | 
					          os << ")";
 | 
				
			||||||
          os << '"';
 | 
					          os << '"';
 | 
				
			||||||
          os << " {" << PrintActions1(C, A, Ids) << "}";
 | 
					          os << " {" << PrintActions1(C, A, Ids, SibIndent, SibKind) << "}";
 | 
				
			||||||
          IsFirst = false;
 | 
					          IsFirst = false;
 | 
				
			||||||
 | 
					          SibKind = OtherSibAction;
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    const ActionList *AL = &A->getInputs();
 | 
					    const ActionList *AL = &A->getInputs();
 | 
				
			||||||
| 
						 | 
					@ -1850,8 +1864,9 @@ static unsigned PrintActions1(const Compilation &C, Action *A,
 | 
				
			||||||
    if (AL->size()) {
 | 
					    if (AL->size()) {
 | 
				
			||||||
      const char *Prefix = "{";
 | 
					      const char *Prefix = "{";
 | 
				
			||||||
      for (Action *PreRequisite : *AL) {
 | 
					      for (Action *PreRequisite : *AL) {
 | 
				
			||||||
        os << Prefix << PrintActions1(C, PreRequisite, Ids);
 | 
					        os << Prefix << PrintActions1(C, PreRequisite, Ids, SibIndent, SibKind);
 | 
				
			||||||
        Prefix = ", ";
 | 
					        Prefix = ", ";
 | 
				
			||||||
 | 
					        SibKind = OtherSibAction;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      os << "}";
 | 
					      os << "}";
 | 
				
			||||||
    } else
 | 
					    } else
 | 
				
			||||||
| 
						 | 
					@ -1872,9 +1887,13 @@ static unsigned PrintActions1(const Compilation &C, Action *A,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  auto getSelfIndent = [](int K) -> Twine {
 | 
				
			||||||
 | 
					    return (K == HeadSibAction) ? "+- " : (K == OtherSibAction) ? "|- " : "";
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned Id = Ids.size();
 | 
					  unsigned Id = Ids.size();
 | 
				
			||||||
  Ids[A] = Id;
 | 
					  Ids[A] = Id;
 | 
				
			||||||
  llvm::errs() << Id << ": " << os.str() << ", "
 | 
					  llvm::errs() << Indent + getSelfIndent(Kind) << Id << ": " << os.str() << ", "
 | 
				
			||||||
               << types::getTypeName(A->getType()) << offload_os.str() << "\n";
 | 
					               << types::getTypeName(A->getType()) << offload_os.str() << "\n";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return Id;
 | 
					  return Id;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue