mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-05 13:26:55 +00:00
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
This commit is contained in:
@@ -2829,6 +2829,59 @@ Note that the fields need not be contiguous. In this example, there is a
|
||||
4 byte gap between the two fields. This gap represents padding which
|
||||
does not carry useful data and need not be preserved.
|
||||
|
||||
'``noalias``' and '``alias.scope``' Metadata
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
``noalias`` and ``alias.scope`` metadata provide the ability to specify generic
|
||||
noalias memory-access sets. This means that some collection of memory access
|
||||
instructions (loads, stores, memory-accessing calls, etc.) that carry
|
||||
``noalias`` metadata can specifically be specified not to alias with some other
|
||||
collection of memory access instructions that carry ``alias.scope`` metadata.
|
||||
Each type of metadata specifies a list of scopes, and when evaluating an
|
||||
aliasing query, if one of the instructions has a scope in its ``alias.scope``
|
||||
list that is identical to a scope in the other instruction's ``noalias`` list,
|
||||
or is a descendant (in the scope hierarchy) of a scope in the other
|
||||
instruction's ``noalias`` list , then the two memory accesses are assumed not
|
||||
to alias.
|
||||
|
||||
The metadata identifying each scope is itself a list containing one or two
|
||||
entries. The first entry is the name of the scope. Note that if the name is a
|
||||
string then it can be combined accross functions and translation units. A
|
||||
self-reference can be used to create globally unique scope names.
|
||||
Optionally, a metadata reference to a parent scope can be provided as a second
|
||||
entry in the list.
|
||||
|
||||
For example,
|
||||
|
||||
.. code-block:: llvm
|
||||
|
||||
; A root scope (which doubles as a list of itself):
|
||||
!0 = metadata !{metadata !0}
|
||||
|
||||
; Two child scopes (which must be self-referential to avoid being "uniqued"):
|
||||
!1 = metadata !{metadata !2} ; A list containing only scope !2
|
||||
!2 = metadata !{metadata !2, metadata !0} ; Scope !2 is a descendant of scope !0
|
||||
|
||||
!3 = metadata !{metadata !4} ; A list containing only scope !4
|
||||
!4 = metadata !{metadata !4, metadata !0} ; Scope !4 is a descendant of scope !0
|
||||
|
||||
; These two instructions don't alias:
|
||||
%0 = load float* %c, align 4, !alias.scope !0
|
||||
store float %0, float* %arrayidx.i, align 4, !noalias !0
|
||||
|
||||
; These two instructions may alias (scope !2 and scope !4 are peers):
|
||||
%2 = load float* %c, align 4, !alias.scope !1
|
||||
store float %2, float* %arrayidx.i2, align 4, !noalias !3
|
||||
|
||||
; These two instructions don't alias (scope !2 is a descendant of scope !0
|
||||
; and the store does not alias with anything in scope !0 or any of its descendants):
|
||||
%2 = load float* %c, align 4, !alias.scope !1
|
||||
store float %0, float* %arrayidx.i, align 4, !noalias !0
|
||||
|
||||
; These two instructions may alias:
|
||||
%2 = load float* %c, align 4, !alias.scope !0
|
||||
store float %0, float* %arrayidx.i, align 4, !noalias !1
|
||||
|
||||
'``fpmath``' Metadata
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
Reference in New Issue
Block a user