-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[NFC][flang] Introduce FortranObjectViewOpInterface. #166841
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
Merged
+230
−58
Merged
Changes from 2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -265,4 +265,59 @@ def fir_FortranVariableStorageOpInterface | |
| [{ return detail::verifyFortranVariableStorageOpInterface($_op); }]; | ||
| } | ||
|
|
||
| def fir_FortranObjectViewOpInterface | ||
| : OpInterface<"FortranObjectViewOpInterface"> { | ||
| let description = [{ | ||
| Interface for operations that may produce results that allow accessing | ||
| objects in memory based on the operands of these operations. | ||
| For example: | ||
| ``` | ||
| %0 = fir.convert %x : (!llvm.ptr) -> !fir.llvm_ptr<i32> | ||
| ``` | ||
| When the result of `fir.convert` is used to access an object in memory, | ||
| FIR alias analysis may want to pass through `fir.convert` to be able | ||
| to find the original Fortran object that is being accessed. | ||
| This interface provides methods that allow discovering information | ||
| about the accessed object and the characteristics of the resulting | ||
| "view" of the object, e.g. whether the result and the input | ||
| access the object from the same location within the object or | ||
| whether they are offsetted (which may happen, for example, in case of | ||
| `fir.array_coor` operation). | ||
| }]; | ||
| let cppNamespace = "::fir"; | ||
|
|
||
| let methods = | ||
| [InterfaceMethod< | ||
| /*desc=*/ | ||
| [{ Returns the operand which the given OpResult is based on. }], | ||
| /*retTy=*/"::mlir::Value", | ||
| /*methodName=*/"getViewSource", | ||
| /*args=*/(ins "::mlir::OpResult":$resultView), | ||
| /*methodBody=*/"", | ||
| /*defaultImplementation=*/[{ | ||
| assert($_op.getOperation() == resultView.getOwner() && | ||
| "resultView must be a result of this operation"); | ||
| return $_op.getViewSource(resultView); | ||
| }]>, | ||
| InterfaceMethod< | ||
| /*desc=*/[{ | ||
| Returns the constant offset (in bytes) applied to the corresponding | ||
| operand to produce the resulting view. | ||
| If it is not possible to identify the constant offset, | ||
| the result in nullopt. | ||
|
||
| Note that the offset may be negative, e.g. when addressing | ||
| an array section with a negative stride. | ||
| }], | ||
| /*retTy=*/"std::optional<std::int64_t>", | ||
| /*methodName=*/"getViewOffset", | ||
| /*args=*/(ins "::mlir::OpResult":$resultView), | ||
| /*methodBody=*/"", | ||
| /*defaultImplementation=*/[{ | ||
| assert($_op.getOperation() == resultView.getOwner() && | ||
| "resultView must be a result of this operation"); | ||
| return $_op.getViewOffset(resultView); | ||
| }]>, | ||
| ]; | ||
| } | ||
|
|
||
| #endif // FORTRANVARIABLEINTERFACE | ||
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
Oops, something went wrong.
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.
Is this correct for common block variables?
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.
Good question! Yes, it should be valid.
For example:
Basically,
[hl]fir.declaredoes not apply any offset to its operand on its own. The offset is applied to the operands of[hl]fir.declarebyfir.coordinate_of. It is also the case for EQUIVALENCE variables.