-
Notifications
You must be signed in to change notification settings - Fork 192
MLIR: alias classes for globals, and alloc-like effect handling #3191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
burakSemih
wants to merge
3
commits into
main
Choose a base branch
from
sb/enzyme-alias-globals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // RUN: %eopt --test-print-alias-analysis --split-input-file %s 2>&1 | FileCheck %s | ||
|
|
||
| // The address of a global is a concrete alias class. Before, `llvm.mlir.addressof` | ||
| // had no transfer function at all, so its lattice stayed undefined and any query | ||
| // against it hit the "incomplete alias analysis" assertion. | ||
|
|
||
| // Two distinct globals are distinct objects: taking the address of one can never | ||
| // produce a pointer into the other, whatever their linkage. | ||
|
|
||
| // CHECK: "a" and "b": NoAlias | ||
| llvm.mlir.global external @ext1(0 : i64) : i64 | ||
| llvm.mlir.global external @ext2(0 : i64) : i64 | ||
| func.func @two_external_globals() { | ||
| %a = llvm.mlir.addressof @ext1 {tag = "a"} : !llvm.ptr | ||
| %b = llvm.mlir.addressof @ext2 {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // CHECK: "a" and "b": NoAlias | ||
| llvm.mlir.global internal @g1(0 : i64) : i64 | ||
| llvm.mlir.global internal @g2(0 : i64) : i64 | ||
| func.func @two_internal_globals() { | ||
| %a = llvm.mlir.addressof @g1 {tag = "a"} : !llvm.ptr | ||
| %b = llvm.mlir.addressof @g2 {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Mixed linkage is no different: still two separate objects. | ||
|
|
||
| // CHECK: "a" and "b": NoAlias | ||
| llvm.mlir.global external @pub(0 : i64) : i64 | ||
| llvm.mlir.global internal @priv(0 : i64) : i64 | ||
| func.func @mixed_linkage() { | ||
| %a = llvm.mlir.addressof @pub {tag = "a"} : !llvm.ptr | ||
| %b = llvm.mlir.addressof @priv {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Conversely, two addresses of the *same* global are the same object. The class | ||
| // is keyed on the symbol rather than on the `llvm.mlir.addressof` result, which | ||
| // matters because the LLVM importer emits one `addressof` per use. | ||
|
|
||
| // CHECK: "a" and "b": MayAlias | ||
| llvm.mlir.global external @same(0 : i64) : i64 | ||
| func.func @same_global_twice() { | ||
| %a = llvm.mlir.addressof @same {tag = "a"} : !llvm.ptr | ||
| %b = llvm.mlir.addressof @same {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // A global keeps its own class across functions too. | ||
|
|
||
| // CHECK: "a" and "b": MayAlias | ||
| llvm.mlir.global external @shared(0 : i64) : i64 | ||
| func.func @user1() { | ||
| %a = llvm.mlir.addressof @shared {tag = "a"} : !llvm.ptr | ||
| return | ||
| } | ||
| func.func @user2() { | ||
| %b = llvm.mlir.addressof @shared {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // An `llvm.mlir.addressof` of a function is not data storage; it stays in the | ||
| // shared entry class when the function may be defined elsewhere. | ||
|
|
||
| // CHECK: "a" and "b": MayAlias | ||
| llvm.func external @decl() | ||
| func.func @address_of_external_func() { | ||
| %a = llvm.mlir.addressof @decl {tag = "a"} : !llvm.ptr | ||
| %b = llvm.mlir.addressof @decl {tag = "b"} : !llvm.ptr | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // A global does not alias an unannotated pointer argument: argument classes and | ||
| // global classes are disjoint. Note that this asserts no incoming pointer points | ||
| // into a global, which a caller passing `&g` would violate. The analysis answered | ||
| // NoAlias here before this file existed too, but only because the addressof side | ||
| // was undefined rather than because anything had decided it. | ||
|
|
||
| // CHECK: "arg" and "glob": NoAlias | ||
| llvm.mlir.global external @escapes(0 : i64) : i64 | ||
| func.func @global_vs_argument(%arg0: !llvm.ptr {enzyme.tag = "arg"}) { | ||
| %glob = llvm.mlir.addressof @escapes {tag = "glob"} : !llvm.ptr | ||
| return | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions regarding the signature of this function:
std::optional<Value>rather than a potentially nullValue?effectsfrom theop? This could potentially be called with effects that don't come from the op, unless that is intended.