llvm-project/llvm
Chandler Carruth aaad9f84be [PM/LCG] Teach the LazyCallGraph how to replace a function without
disturbing the graph or having to update edges.

This is motivated by porting argument promotion to the new pass manager.
Because of how LLVM IR Function objects work, in order to change their
signature a new object needs to be created. This is efficient and
straight forward in the IR but previously was very hard to implement in
LCG. We could easily replace the function a node in the graph
represents. The challenging part is how to handle updating the edges in
the graph.

LCG previously used an edge to a raw function to represent a node that
had not yet been scanned for calls and references. This was the core
of its laziness. However, that model causes this kind of update to be
very hard:
1) The keys to lookup an edge need to be `Function*`s that would all
   need to be updated when we update the node.
2) There will be some unknown number of edges that haven't transitioned
   from `Function*` edges to `Node*` edges.

All of this complexity isn't necessary. Instead, we can always build
a node around any function, always pointing edges at it and always using
it as the key to lookup an edge. To maintain the laziness, we need to
sink the *edges* of a node into a secondary object and explicitly model
transitioning a node from empty to populated by scanning the function.
This design seems much cleaner in a number of ways, but importantly
there is now exactly *one* place where the `Function*` has to be
updated!

Some other cleanups that fall out of this include having something to
model the *entry* edges more accurately. Rather than hand rolling parts
of the node in the graph itself, we have an explicit `EdgeSequence`
object that gives us exactly the functionality needed. We also have
a consistent place to define the edge iterators and can use them for
both the entry edges and the internal edges of the graph.

The API used to model the separation between a node and its edges is
intentionally very thin as most clients are expected to deal with nodes
that have populated edges. We model this exactly as an optional does
with an additional method to populate the edges when that is
a reasonable thing for a client to do. This is based on API design
suggestions from Richard Smith and David Blaikie, credit goes to them
for helping pick how to model this without it being either too explicit
or too implicit.

The patch is somewhat noisy due to shifting around iterator types and
new syntax for walking the edges of a node, but most of the
functionality change is in the `Edge`, `EdgeSequence`, and `Node` types.

Differential Revision: https://reviews.llvm.org/D29577

llvm-svn: 294653
2017-02-09 23:24:13 +00:00
..
bindings
cmake [CMake] Fix standalone project builds broken in r294514 2017-02-09 18:14:12 +00:00
docs Don't try to link to the 4.0 release notes 2017-02-09 23:03:34 +00:00
examples Use print() instead of dump() in code 2017-01-28 02:47:46 +00:00
include [PM/LCG] Teach the LazyCallGraph how to replace a function without 2017-02-09 23:24:13 +00:00
lib [PM/LCG] Teach the LazyCallGraph how to replace a function without 2017-02-09 23:24:13 +00:00
projects
resources
runtimes [CMake] Handle common options for runtimes build 2017-01-10 19:47:05 +00:00
test [InstCombine] allow (X * C2) << C1 --> X * (C2 << C1) for vectors 2017-02-09 23:13:04 +00:00
tools [dsymutil] Fix handling of empty CUs in LTO links. 2017-02-09 19:41:55 +00:00
unittests [PM/LCG] Teach the LazyCallGraph how to replace a function without 2017-02-09 23:24:13 +00:00
utils [utils] coverage: Add help text about the --restrict flag (NFC) 2017-02-09 19:37:18 +00:00
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt [CMake] Allow overriding CMAKE_LIBTOOL 2017-02-07 23:32:56 +00:00
CODE_OWNERS.TXT CODE_OWNERS: Update email address 2017-02-09 21:29:12 +00:00
CREDITS.TXT Revert r294228 2017-02-06 19:40:56 +00:00
LICENSE.TXT Bump year to 2017 in LICENSE.txt 2017-01-12 18:02:42 +00:00
LLVMBuild.txt
README.txt Test commit: remove a blank line. 2017-02-03 10:56:57 +00:00
RELEASE_TESTERS.TXT Update the release tester for MIPS. NFC. 2017-01-17 11:00:28 +00:00
configure
llvm.spec.in

README.txt

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.