Add scoped-noalias metadata
authorHal Finkel <hfinkel@anl.gov>
Thu, 24 Jul 2014 14:25:39 +0000 (14:25 +0000)
committerHal Finkel <hfinkel@anl.gov>
Thu, 24 Jul 2014 14:25:39 +0000 (14:25 +0000)
commit16fd27b2c37d78cde979c7523f3d37a991407209
treed400145136df937a3ba1566bb56347068965462e
parente8d5c379ac8eda9f375eb306f465e333ab28cd61
Add scoped-noalias metadata

This commit adds scoped noalias metadata. The primary motivations for this
feature are:
  1. To preserve noalias function attribute information when inlining
  2. To provide the ability to model block-scope C99 restrict pointers

Neither of these two abilities are added here, only the necessary
infrastructure. In fact, there should be no change to existing functionality,
only the addition of new features. The logic that converts noalias function
parameters into this metadata during inlining will come in a follow-up commit.

What is added here is the ability to generally specify noalias memory-access
sets. Regarding the metadata, alias-analysis scopes are defined similar to TBAA
nodes:

!scope0 = metadata !{ metadata !"scope of foo()" }
!scope1 = metadata !{ metadata !"scope 1", metadata !scope0 }
!scope2 = metadata !{ metadata !"scope 2", metadata !scope0 }
!scope3 = metadata !{ metadata !"scope 2.1", metadata !scope2 }
!scope4 = metadata !{ metadata !"scope 2.2", metadata !scope2 }

Loads and stores can be tagged with an alias-analysis scope, and also, with a
noalias tag for a specific scope:

... = load %ptr1, !alias.scope !{ !scope1 }
... = load %ptr2, !alias.scope !{ !scope1, !scope2 }, !noalias !{ !scope1 }

When evaluating an aliasing query, if one of the instructions is associated
with an alias.scope id that is identical to the noalias scope associated with
the other instruction, or is a descendant (in the scope hierarchy) of the
noalias scope associated with the other instruction, then the two memory
accesses are assumed not to alias.

Note that is the first element of the scope metadata is a string, then it can
be combined accross functions and translation units. The string can be replaced
by a self-reference to create globally unqiue scope identifiers.

[Note: This overview is slightly stylized, since the metadata nodes really need
to just be numbers (!0 instead of !scope0), and the scope lists are also global
unnamed metadata.]

Existing noalias metadata in a callee is "cloned" for use by the inlined code.
This is necessary because the aliasing scopes are unique to each call site
(because of possible control dependencies on the aliasing properties). For
example, consider a function: foo(noalias a, noalias b) { *a = *b; } that gets
inlined into bar() { ... if (...) foo(a1, b1); ... if (...) foo(a2, b2); } --
now just because we know that a1 does not alias with b1 at the first call site,
and a2 does not alias with b2 at the second call site, we cannot let inlining
these functons have the metadata imply that a1 does not alias with b2.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213864 91177308-0d34-0410-b5e6-96231b3b80d8
31 files changed:
docs/LangRef.rst
include/llvm-c/Transforms/Scalar.h
include/llvm/Analysis/Passes.h
include/llvm/IR/IRBuilder.h
include/llvm/IR/LLVMContext.h
include/llvm/IR/MDBuilder.h
include/llvm/IR/Metadata.h
include/llvm/InitializePasses.h
include/llvm/LinkAllPasses.h
lib/Analysis/Analysis.cpp
lib/Analysis/CMakeLists.txt
lib/Analysis/ScopedNoAliasAA.cpp [new file with mode: 0644]
lib/Analysis/TypeBasedAliasAnalysis.cpp
lib/CodeGen/MachineInstr.cpp
lib/CodeGen/Passes.cpp
lib/IR/IRBuilder.cpp
lib/IR/LLVMContext.cpp
lib/IR/MDBuilder.cpp
lib/IR/Metadata.cpp
lib/Transforms/IPO/PassManagerBuilder.cpp
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Scalar/Scalar.cpp
lib/Transforms/Scalar/Scalarizer.cpp
lib/Transforms/Utils/InlineFunction.cpp
lib/Transforms/Vectorize/BBVectorize.cpp
lib/Transforms/Vectorize/LoopVectorize.cpp
lib/Transforms/Vectorize/SLPVectorizer.cpp
test/Analysis/ScopedNoAliasAA/basic-hierarchy.ll [new file with mode: 0644]
test/Analysis/ScopedNoAliasAA/basic.ll [new file with mode: 0644]
test/Analysis/ScopedNoAliasAA/basic2.ll [new file with mode: 0644]
test/Transforms/GVN/noalias.ll [new file with mode: 0644]