Teach GlobalOpt to handle atomic accesses to globals.
authorNick Lewycky <nicholas@mxc.ca>
Sun, 5 Feb 2012 19:56:38 +0000 (19:56 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Sun, 5 Feb 2012 19:56:38 +0000 (19:56 +0000)
commitfad4d40f3792b0d9e101c40738e1f691131007d2
treef16de5d50c2ef2d196835d461609c35331a7a25e
parentdc7c716a1cfc27a12f3bbfa44bd80904ee782779
Teach GlobalOpt to handle atomic accesses to globals.

 * Most of the transforms come through intact by having each transformed load or
store copy the ordering and synchronization scope of the original.
 * The transform that turns a global only accessed in main() into an alloca
(since main is non-recursive) with a store of the initial value uses an
unordered store, since it's guaranteed to be the first thing to happen in main.
(Threads may have started before main (!) but they can't have the address of a
function local before the point in the entry block we insert our code.)
 * The heap-SRoA transforms are disabled in the face of atomic operations. This
can probably be improved; it seems odd to have atomic accesses to an alloca
that doesn't have its address taken.

AnalyzeGlobal keeps track of the strongest ordering found in any use of the
global. This is more information than we need right now, but it's cheap to
compute and likely to be useful.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149847 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/IPO/GlobalOpt.cpp
test/Transforms/GlobalOpt/atomic.ll [new file with mode: 0644]