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)
commit9414665a3b0bd525f84d76e24048ca60ebe6c710
treefff4d50eb94acea46f1e68190267ac924fe99ef9
parent99e0ea0aa846c4bf4d5018064a5dc24e0a07dac7
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.

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