[PATCH] D48939: CallGraph passes: iterate over all functions rather than just externally visible ones

Tim Northover via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 4 06:52:27 PDT 2018


t.p.northover created this revision.
Herald added subscribers: dexonsmith, modocache, hiraditya, eraman, mcrosier.

>From https://llvm.org/PR38029, we were failing to always_inline a function that's called from a static function not otherwise referenced. Since libc++ uses always_inline for functions it doesn't want to build into the shared object, this caused the valid C++ code

  #include <string> 
  static std::string f() { return std::string(); } 
  int main() { (void) f; }

to fail with a linker error (there's no basic_string::basic_string in libc++.so). In the big scheme there are two ways this could be fixed. Either we somehow guarantee that unused internal functions are dropped, or we ensure that the always-inliner handles all functions.

This patch fixes the inliner (indirectly) since IMO there could be legitimate reasons to retain unused functions (e.g. debuggability) and some of the passes involved violate correctness contracts if not run on everything -- the AlwaysInliner and coroutine lowering pass for example.

What it actually does is put logic into CallGraphSCCPass to make sure that all nodes of the CallGraph are visited, not just the ones accessible from the externals node.

As an alternative I considered adapting scc_iterator to do this by default when the GraphTraits allow for it, but discarded that both because it involved nasty template magic and because it was inconsistent with the other graph iterators in ADT (which all only pursue nodes accessible from GraphTraits::getEntryNode).


Repository:
  rL LLVM

https://reviews.llvm.org/D48939

Files:
  llvm/include/llvm/ADT/SCCIterator.h
  llvm/lib/Analysis/CallGraphSCCPass.cpp
  llvm/test/Transforms/Inline/always-inline.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48939.154096.patch
Type: text/x-patch
Size: 3891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180704/ad21bb5e/attachment.bin>


More information about the llvm-commits mailing list