-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][acc] Introduce createAndPopulate for recipe creation #162917
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
Changes from 5 commits
156cc69
cf2dbb6
b6cc6e5
417e586
a12edd1
2d4e9ba
493b72a
e65937f
127b05f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1316,6 +1316,22 @@ def OpenACC_PrivateRecipeOp | |
| }]; | ||
|
|
||
| let hasRegionVerifier = 1; | ||
|
|
||
| let extraClassDeclaration = [{ | ||
| /// Creates a PrivateRecipeOp and populates its regions based on the | ||
| /// variable type as long as the type implements MappableType or | ||
| /// PointerLikeType interface. If a type implements both, the MappableType | ||
| /// API will be preferred. Returns std::nullopt if the recipe cannot be | ||
| /// created or populated. The builder's current insertion point will be used | ||
| /// and it must be a valid place for this operation to be inserted. | ||
| static std::optional<PrivateRecipeOp> createAndPopulate( | ||
| ::mlir::OpBuilder &builder, | ||
| ::mlir::Location loc, | ||
| ::llvm::StringRef recipeName, | ||
| ::mlir::Value var, | ||
|
||
| ::llvm::StringRef varName = "", | ||
| ::mlir::ValueRange bounds = {}); | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
|
|
@@ -1410,6 +1426,22 @@ def OpenACC_FirstprivateRecipeOp | |
| }]; | ||
|
|
||
| let hasRegionVerifier = 1; | ||
|
|
||
| let extraClassDeclaration = [{ | ||
| /// Creates a FirstprivateRecipeOp and populates its regions based on the | ||
| /// variable type as long as the type implements MappableType or | ||
| /// PointerLikeType interface. If a type implements both, the MappableType | ||
| /// API will be preferred. Returns std::nullopt if the recipe cannot be | ||
| /// created or populated. The builder's current insertion point will be used | ||
| /// and it must be a valid place for this operation to be inserted. | ||
| static std::optional<FirstprivateRecipeOp> createAndPopulate( | ||
| ::mlir::OpBuilder &builder, | ||
| ::mlir::Location loc, | ||
| ::llvm::StringRef recipeName, | ||
| ::mlir::Value var, | ||
| ::llvm::StringRef varName = "", | ||
| ::mlir::ValueRange bounds = {}); | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
|
|
||
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 it up to the caller to ensure recipe with that name have not been created yet/what happens if it already exists?
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.
Great question! The code wasn't handling this case previously.
Contrary to my initial belief, MLIR does not automatically make symbol names unique. Instead, it allows construction of IR that will later fail verification with a "redefinition of symbol" error.
I've updated
createAndPopulateto returnstd::nulloptwhen a symbol with the requested name already exists. This indicates to the caller that the operation cannot be created.I considered two alternative approaches:
By returning
std::nullopt, the caller receives clear feedback that the requested name conflicts with an existing symbol and can handle it appropriately (e.g., use a different name, check if the existing recipe is suitable, etc.).