-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][GPU] Add FunctionOpInterface check for OpToFuncCallLowering
#113449
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
|
@llvm/pr-subscribers-mlir-gpu Author: Longsheng Mou (CoTinker) ChangesThis PR adds a Full diff: https://github.com/llvm/llvm-project/pull/113449.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
index 1cf8a1acb31935..3b94abd88f9ed2 100644
--- a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
+++ b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
@@ -61,6 +61,11 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
SourceOp>::value,
"expected op with same operand and result types");
+ if (!op->template getParentOfType<FunctionOpInterface>()) {
+ return rewriter.notifyMatchFailure(
+ op, "expected op to be within a function region");
+ }
+
SmallVector<Value, 1> castedOperands;
for (Value operand : adaptor.getOperands())
castedOperands.push_back(maybeCast(operand, rewriter));
diff --git a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
index ddd96bf797e6e7..c1b2407a66d915 100644
--- a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
+++ b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
@@ -481,3 +481,17 @@ module @test_module {
func.return %resultf16, %resultf32, %resultf64, %resultbf16 : f16, f32, f64, bf16
}
}
+
+// -----
+
+// Math operation not inside function
+// Ensure it not crash
+
+module {
+ "test.some_op_with_region"() ({
+ ^bb0(%arg0: f64):
+ // CHECK: math.atan
+ %0 = math.atan %arg0 : f64
+ "test.possible_terminator"() : () -> ()
+ }) : () -> ()
+}
|
|
@llvm/pr-subscribers-mlir Author: Longsheng Mou (CoTinker) ChangesThis PR adds a Full diff: https://github.com/llvm/llvm-project/pull/113449.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
index 1cf8a1acb31935..3b94abd88f9ed2 100644
--- a/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
+++ b/mlir/lib/Conversion/GPUCommon/OpToFuncCallLowering.h
@@ -61,6 +61,11 @@ struct OpToFuncCallLowering : public ConvertOpToLLVMPattern<SourceOp> {
SourceOp>::value,
"expected op with same operand and result types");
+ if (!op->template getParentOfType<FunctionOpInterface>()) {
+ return rewriter.notifyMatchFailure(
+ op, "expected op to be within a function region");
+ }
+
SmallVector<Value, 1> castedOperands;
for (Value operand : adaptor.getOperands())
castedOperands.push_back(maybeCast(operand, rewriter));
diff --git a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
index ddd96bf797e6e7..c1b2407a66d915 100644
--- a/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
+++ b/mlir/test/Conversion/MathToROCDL/math-to-rocdl.mlir
@@ -481,3 +481,17 @@ module @test_module {
func.return %resultf16, %resultf32, %resultf64, %resultbf16 : f16, f32, f64, bf16
}
}
+
+// -----
+
+// Math operation not inside function
+// Ensure it not crash
+
+module {
+ "test.some_op_with_region"() ({
+ ^bb0(%arg0: f64):
+ // CHECK: math.atan
+ %0 = math.atan %arg0 : f64
+ "test.possible_terminator"() : () -> ()
+ }) : () -> ()
+}
|
nirvedhmeshram
left a comment
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, also can we add -allow-unregistered-dialect to the test. In certain build set ups it can give an error about operation being parsed with an unregistered dialect
This PR adds a `FunctionOpInterface` check in `OpToFuncCallLowering` to resolve a crash when ops not in function.
Done |
…lvm#113449) This PR adds a `FunctionOpInterface` check in `OpToFuncCallLowering` to resolve a crash when ops not in function. Fixes llvm#113334.
…lvm#113449) This PR adds a `FunctionOpInterface` check in `OpToFuncCallLowering` to resolve a crash when ops not in function. Fixes llvm#113334.
This PR adds a
FunctionOpInterfacecheck inOpToFuncCallLoweringto resolve a crash when ops not in function. Fixes #113334.