[PATCH] D67388: Add a feature to dump dependency graph.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 02:50:46 PDT 2019


ruiu added a comment.

Here is an example of a simple post-link analysis using good old awk command. Assume file `graph` contains an output of `--print-dependency-graph` generated when linking `bin/llvm-strings`.

You noticed that Path.cpp.o in libLLVMSupport.a gets linked and were wondering why. You can get a list of files that depend on Path.cpp.o with the following command:

$ awk '$2 == "lib/libLLVMSupport.a(Path.cpp.o)" { print $1 }' graph | sort -u
lib/libLLVMSupport.a(CommandLine.cpp.o)
lib/libLLVMSupport.a(MD5.cpp.o)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o)
lib/libLLVMSupport.a(Process.cpp.o)
lib/libLLVMSupport.a(Program.cpp.o)
lib/libLLVMSupport.a(raw_ostream.cpp.o)
lib/libLLVMSupport.a(Signals.cpp.o)

Now you are wondering what symbols are shared between them, so you type in the following command.

$ awk -F'\t' '$2 == "lib/libLLVMSupport.a(Path.cpp.o)" { print $1 " " $3 }' graph | sort -u
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::fs::current_path(llvm::SmallVectorImpl<char>&)
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::fs::equivalent(llvm::Twine const&, llvm::Twine const&, bool&)
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::path::append(llvm::SmallVectorImpl<char>&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&)
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::path::filename(llvm::StringRef, llvm::sys::path::Style)
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::path::is_relative(llvm::Twine const&, llvm::sys::path::Style)
lib/libLLVMSupport.a(CommandLine.cpp.o) llvm::sys::path::parent_path(llvm::StringRef, llvm::sys::path::Style)
lib/libLLVMSupport.a(MD5.cpp.o) llvm::ArrayRef<unsigned char> llvm::makeArrayRef<unsigned char>(unsigned char const*, unsigned long)
lib/libLLVMSupport.a(MD5.cpp.o) void llvm::SmallVectorTemplateBase<char, true>::uninitialized_move<char*, char*>(char*, char*, char*)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::closeFile(int&)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::getStdinHandle()
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::mapped_file_region::alignment()
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::mapped_file_region::const_data() const
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::mapped_file_region::~mapped_file_region()
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::mapped_file_region::mapped_file_region(int, llvm::sys::fs::mapped_file_region::mapmode, unsigned long, unsigned long, std::error_code&)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::openNativeFileForRead(llvm::Twine const&, llvm::sys::fs::OpenFlags, llvm::SmallVectorImpl<char>*)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::openNativeFile(llvm::Twine const&, llvm::sys::fs::CreationDisposition, llvm::sys::fs::FileAccess, llvm::sys::fs::OpenFlags, unsigned int)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::readNativeFile(int, llvm::MutableArrayRef<char>)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::readNativeFileSlice(int, llvm::MutableArrayRef<char>, unsigned long)
lib/libLLVMSupport.a(MemoryBuffer.cpp.o) llvm::sys::fs::status(int, llvm::sys::fs::file_status&)
lib/libLLVMSupport.a(Process.cpp.o) llvm::SmallString<128u>::SmallString(llvm::StringRef)
lib/libLLVMSupport.a(Process.cpp.o) llvm::SmallVector<char, 128u>::SmallVector<char const*, void>(char const*, char const*)
lib/libLLVMSupport.a(Process.cpp.o) llvm::sys::fs::access(llvm::Twine const&, llvm::sys::fs::AccessMode)
lib/libLLVMSupport.a(Process.cpp.o) llvm::sys::fs::equivalent(llvm::Twine const&, llvm::Twine const&, bool&)
lib/libLLVMSupport.a(Process.cpp.o) llvm::sys::fs::exists(llvm::Twine const&)
lib/libLLVMSupport.a(Process.cpp.o) llvm::sys::path::append(llvm::SmallVectorImpl<char>&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&)
lib/libLLVMSupport.a(Process.cpp.o) llvm::sys::path::is_absolute(llvm::Twine const&, llvm::sys::path::Style)
lib/libLLVMSupport.a(Process.cpp.o) std::chrono::duration<long, std::ratio<1l, 1000000000l> >::count() const
lib/libLLVMSupport.a(Process.cpp.o) std::chrono::duration<long, std::ratio<1l, 1000000000l> >::duration<long, void>(long const&)
lib/libLLVMSupport.a(Process.cpp.o) std::chrono::duration<long, std::ratio<1l, 1l> >::count() const
lib/libLLVMSupport.a(Process.cpp.o) std::chrono::duration<long, std::ratio<1l, 1l> >::duration<long, void>(long const&)
lib/libLLVMSupport.a(Process.cpp.o) std::chrono::time_point<std::chrono::_V2::system_clock, std::chrono::duration<long, std::ratio<1l, 1000000000l> > >::time_since_epoch() const
lib/libLLVMSupport.a(Program.cpp.o) llvm::SmallString<128u>::SmallString(llvm::StringRef)
lib/libLLVMSupport.a(Program.cpp.o) llvm::SmallVector<char, 128u>::SmallVector<char const*, void>(char const*, char const*)
lib/libLLVMSupport.a(Program.cpp.o) llvm::SmallVectorTemplateCommon<llvm::StringRef, void>::back()
lib/libLLVMSupport.a(Program.cpp.o) llvm::sys::fs::access(llvm::Twine const&, llvm::sys::fs::AccessMode)
lib/libLLVMSupport.a(Program.cpp.o) llvm::sys::fs::can_execute(llvm::Twine const&)
lib/libLLVMSupport.a(Program.cpp.o) llvm::sys::fs::exists(llvm::Twine const&)
lib/libLLVMSupport.a(Program.cpp.o) llvm::sys::path::append(llvm::SmallVectorImpl<char>&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&, llvm::Twine const&)
lib/libLLVMSupport.a(raw_ostream.cpp.o) llvm::sys::fs::openFile(llvm::Twine const&, int&, llvm::sys::fs::CreationDisposition, llvm::sys::fs::FileAccess, llvm::sys::fs::OpenFlags, unsigned int)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::access(llvm::Twine const&, llvm::sys::fs::AccessMode)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::createTemporaryFile(llvm::Twine const&, llvm::StringRef, int&, llvm::SmallVectorImpl<char>&)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::createTemporaryFile(llvm::Twine const&, llvm::StringRef, llvm::SmallVectorImpl<char>&)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::exists(llvm::Twine const&)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::getMainExecutable[abi:cxx11](char const*, void*)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::fs::remove(llvm::Twine const&, bool)
lib/libLLVMSupport.a(Signals.cpp.o) llvm::sys::path::parent_path(llvm::StringRef, llvm::sys::path::Style)

You can repeat this process until you reach "<commandline>" file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67388





More information about the llvm-commits mailing list