-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][acc] Clean up TypedValue builders #126968
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
Conversation
When MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a `TypedValue` of one of the two type options. However, the underlying builder takes a `Value` and this difference is not relevant for it. The only difference is that `varType` is set differently depending on the type. Having two duplicated builders can lead to clunky building since a `Value` must always be cast to one of the two options. Thus, simply clean this up - the verifier already checks that it is a type that implements one of the two interfaces.
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-openacc Author: Razvan Lupusoru (razvanlupusoru) ChangesWhen MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a Having two duplicated builders can lead to clunky building since a Full diff: https://github.com/llvm/llvm-project/pull/126968.diff 1 Files Affected:
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 42da20251c190..70a2ba0919952 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -562,53 +562,33 @@ class OpenACC_DataEntryOp<string mnemonic, string clause, string extraDescriptio
let hasVerifier = 1;
let builders = [
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$varPtr,
- "bool":$structured, "bool":$implicit,
- CArg<"::mlir::ValueRange", "{}">:$bounds),
- [{
- build($_builder, $_state, varPtr.getType(), varPtr,
- /*varType=*/::mlir::TypeAttr::get(
- varPtr.getType().getElementType()),
- /*varPtrPtr=*/{}, bounds, /*asyncOperands=*/{},
- /*asyncOperandsDeviceType=*/nullptr,
- /*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
- /*structured=*/$_builder.getBoolAttr(structured),
- /*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
- }]>,
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$varPtr,
- "bool":$structured, "bool":$implicit,
- "const ::llvm::Twine &":$name,
- CArg<"::mlir::ValueRange", "{}">:$bounds),
- [{
- build($_builder, $_state, varPtr.getType(), varPtr,
- /*varType=*/::mlir::TypeAttr::get(
- varPtr.getType().getElementType()),
- /*varPtrPtr=*/{}, bounds, /*asyncOperands=*/{},
- /*asyncOperandsDeviceType=*/nullptr,
- /*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
- /*structured=*/$_builder.getBoolAttr(structured),
- /*implicit=*/$_builder.getBoolAttr(implicit),
- /*name=*/$_builder.getStringAttr(name));
- }]>,
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::MappableType>":$var,
+ OpBuilder<(ins "::mlir::Value":$var,
"bool":$structured, "bool":$implicit,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
+ auto ptrLikeTy = ::mlir::dyn_cast<::mlir::acc::PointerLikeType>(
+ var.getType());
build($_builder, $_state, var.getType(), var,
- /*varType=*/::mlir::TypeAttr::get(var.getType()),
+ /*varType=*/ptrLikeTy ?
+ ::mlir::TypeAttr::get(ptrLikeTy.getElementType()) :
+ ::mlir::TypeAttr::get(var.getType()),
/*varPtrPtr=*/{}, bounds, /*asyncOperands=*/{},
/*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
/*structured=*/$_builder.getBoolAttr(structured),
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
}]>,
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::MappableType>":$var,
+ OpBuilder<(ins "::mlir::Value":$var,
"bool":$structured, "bool":$implicit,
"const ::llvm::Twine &":$name,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
+ auto ptrLikeTy = ::mlir::dyn_cast<::mlir::acc::PointerLikeType>(
+ var.getType());
build($_builder, $_state, var.getType(), var,
- /*varType=*/::mlir::TypeAttr::get(var.getType()),
+ /*varType=*/ptrLikeTy ?
+ ::mlir::TypeAttr::get(ptrLikeTy.getElementType()) :
+ ::mlir::TypeAttr::get(var.getType()),
/*varPtrPtr=*/{}, bounds, /*asyncOperands=*/{},
/*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
@@ -942,28 +922,34 @@ class OpenACC_DataExitOpWithVarPtr<string mnemonic, string clause>
}];
let builders = [
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$accPtr,
- "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$varPtr,
+ OpBuilder<(ins "::mlir::Value":$accVar,
+ "::mlir::Value":$var,
"bool":$structured, "bool":$implicit,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
- build($_builder, $_state, accPtr, varPtr,
- /*varType=*/::mlir::TypeAttr::get(
- varPtr.getType().getElementType()),
+ auto ptrLikeTy = ::mlir::dyn_cast<::mlir::acc::PointerLikeType>(
+ var.getType());
+ build($_builder, $_state, accVar, var,
+ /*varType=*/ptrLikeTy ?
+ ::mlir::TypeAttr::get(ptrLikeTy.getElementType()) :
+ ::mlir::TypeAttr::get(var.getType()),
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
/*structured=*/$_builder.getBoolAttr(structured),
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
}]>,
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$accPtr,
- "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$varPtr,
+ OpBuilder<(ins "::mlir::Value":$accVar,
+ "::mlir::Value":$var,
"bool":$structured, "bool":$implicit,
"const ::llvm::Twine &":$name,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
- build($_builder, $_state, accPtr, varPtr,
- /*varType=*/::mlir::TypeAttr::get(
- varPtr.getType().getElementType()),
+ auto ptrLikeTy = ::mlir::dyn_cast<::mlir::acc::PointerLikeType>(
+ var.getType());
+ build($_builder, $_state, accVar, var,
+ /*varType=*/ptrLikeTy ?
+ ::mlir::TypeAttr::get(ptrLikeTy.getElementType()) :
+ ::mlir::TypeAttr::get(var.getType()),
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
/*structured=*/$_builder.getBoolAttr(structured),
@@ -996,22 +982,22 @@ class OpenACC_DataExitOpNoVarPtr<string mnemonic, string clause> :
}];
let builders = [
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$accPtr,
+ OpBuilder<(ins "::mlir::Value":$accVar,
"bool":$structured, "bool":$implicit,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
- build($_builder, $_state, accPtr,
+ build($_builder, $_state, accVar,
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
/*structured=*/$_builder.getBoolAttr(structured),
/*implicit=*/$_builder.getBoolAttr(implicit), /*name=*/nullptr);
}]>,
- OpBuilder<(ins "::mlir::TypedValue<::mlir::acc::PointerLikeType>":$accPtr,
+ OpBuilder<(ins "::mlir::Value":$accVar,
"bool":$structured, "bool":$implicit,
"const ::llvm::Twine &":$name,
CArg<"::mlir::ValueRange", "{}">:$bounds),
[{
- build($_builder, $_state, accPtr,
+ build($_builder, $_state, accVar,
bounds, /*asyncOperands=*/{}, /*asyncOperandsDeviceType=*/nullptr,
/*asyncOnly=*/nullptr, /*dataClause=*/nullptr,
/*structured=*/$_builder.getBoolAttr(structured),
|
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.
LGTM
When MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a `TypedValue` of one of the two type options. However, the underlying builder takes a `Value` and this difference is not relevant for it. The only difference is that `varType` is set differently depending on the type. Having two duplicated builders can lead to clunky building since a `Value` must always be cast to one of the two options. Thus, simply clean this up - the verifier already checks that it is a type that implements one of the two interfaces.
When MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a `TypedValue` of one of the two type options. However, the underlying builder takes a `Value` and this difference is not relevant for it. The only difference is that `varType` is set differently depending on the type. Having two duplicated builders can lead to clunky building since a `Value` must always be cast to one of the two options. Thus, simply clean this up - the verifier already checks that it is a type that implements one of the two interfaces.
When MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a `TypedValue` of one of the two type options. However, the underlying builder takes a `Value` and this difference is not relevant for it. The only difference is that `varType` is set differently depending on the type. Having two duplicated builders can lead to clunky building since a `Value` must always be cast to one of the two options. Thus, simply clean this up - the verifier already checks that it is a type that implements one of the two interfaces.
When MappableType was introduced alongside PointerLikeType, the data clause operation builders were duplicated to accept a
TypedValue
of one of the two type options. However, the underlying builder takes aValue
and this difference is not relevant for it. The only difference is thatvarType
is set differently depending on the type.Having two duplicated builders can lead to clunky building since a
Value
must always be cast to one of the two options. Thus, simply clean this up - the verifier already checks that it is a type that implements one of the two interfaces.