[Mlir-commits] [mlir] 552ef9f - [mlir][DialectConversion] Add overload of addDynamicallyLegalDialect to support lambdas
River Riddle
llvmlistbot at llvm.org
Mon Jun 15 15:58:03 PDT 2020
Author: River Riddle
Date: 2020-06-15T15:57:44-07:00
New Revision: 552ef9fc094f7c0b0d7bf7a9b4d5da1319a2a67a
URL: https://github.com/llvm/llvm-project/commit/552ef9fc094f7c0b0d7bf7a9b4d5da1319a2a67a
DIFF: https://github.com/llvm/llvm-project/commit/552ef9fc094f7c0b0d7bf7a9b4d5da1319a2a67a.diff
LOG: [mlir][DialectConversion] Add overload of addDynamicallyLegalDialect to support lambdas
This allows for passing a lambda to addDynamicallyLegalDialect without needing to explicit wrap with Optional<DynamicLegalityCallbackFn>.
Differential Revision: https://reviews.llvm.org/D81680
Added:
Modified:
mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
mlir/test/lib/Transforms/TestBufferPlacement.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h
index f9d6671ae6fb..3e7d50380fe1 100644
--- a/mlir/include/mlir/Transforms/DialectConversion.h
+++ b/mlir/include/mlir/Transforms/DialectConversion.h
@@ -607,6 +607,12 @@ class ConversionTarget {
if (callback)
setLegalityCallback(dialectNames, *callback);
}
+ template <typename... Args>
+ void addDynamicallyLegalDialect(DynamicLegalityCallbackFn callback) {
+ SmallVector<StringRef, 2> dialectNames({Args::getDialectNamespace()...});
+ setDialectAction(dialectNames, LegalizationAction::Dynamic);
+ setLegalityCallback(dialectNames, callback);
+ }
/// Register unknown operations as dynamically legal. For operations(and
/// dialects) that do not have a set legalization action, treat them as
diff --git a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
index 490e670dda94..7df2be9c61b7 100644
--- a/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
+++ b/mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
@@ -657,10 +657,9 @@ spirv::SPIRVConversionTarget::get(spirv::TargetEnvAttr targetAttr) {
new SPIRVConversionTarget(targetAttr));
SPIRVConversionTarget *targetPtr = target.get();
target->addDynamicallyLegalDialect<SPIRVDialect>(
- Optional<ConversionTarget::DynamicLegalityCallbackFn>(
- // We need to capture the raw pointer here because it is stable:
- // target will be destroyed once this function is returned.
- [targetPtr](Operation *op) { return targetPtr->isLegalOp(op); }));
+ // We need to capture the raw pointer here because it is stable:
+ // target will be destroyed once this function is returned.
+ [targetPtr](Operation *op) { return targetPtr->isLegalOp(op); });
return target;
}
diff --git a/mlir/test/lib/Transforms/TestBufferPlacement.cpp b/mlir/test/lib/Transforms/TestBufferPlacement.cpp
index cbccb7dbb1a4..0976f71c0fd3 100644
--- a/mlir/test/lib/Transforms/TestBufferPlacement.cpp
+++ b/mlir/test/lib/Transforms/TestBufferPlacement.cpp
@@ -127,9 +127,7 @@ struct TestBufferPlacementPreparationPass
auto isLegalOperation = [&](Operation *op) {
return converter.isLegal(op);
};
- target.addDynamicallyLegalDialect<linalg::LinalgDialect>(
- Optional<ConversionTarget::DynamicLegalityCallbackFn>(
- isLegalOperation));
+ target.addDynamicallyLegalDialect<linalg::LinalgDialect>(isLegalOperation);
// Mark Standard Return operations illegal as long as one operand is tensor.
target.addDynamicallyLegalOp<mlir::ReturnOp>([&](mlir::ReturnOp returnOp) {
More information about the Mlir-commits
mailing list