Skip to content

[MLIR][LLVM] Fix CallOp asm parser for attr-dict #74372

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
merged 3 commits into from
Dec 5, 2023

Conversation

zyx-billy
Copy link
Contributor

@zyx-billy zyx-billy commented Dec 4, 2023

Currently the parser & printer of CallOp do not match when both varargs and attr-dict are present (round tripping is broken). This fixes the parser so that it conforms to the written asm format in the comments.

@llvmbot
Copy link
Member

llvmbot commented Dec 4, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-llvm

Author: Billy Zhu (zyx-billy)

Changes

Currently the parser & printer of CallOp do not match when both varargs and attr-dict are present. This fixes the parser so that it conforms to the written asm format in the comments.


Full diff: https://github.com/llvm/llvm-project/pull/74372.diff

2 Files Affected:

  • (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp (+4-2)
  • (modified) mlir/test/Target/LLVMIR/llvmir.mlir (+4)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 28445945f07d6..4c3367336fa79 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -1219,8 +1219,7 @@ ParseResult CallOp::parse(OpAsmParser &parser, OperationState &result) {
       return failure();
 
   // Parse the function arguments.
-  if (parser.parseOperandList(operands, OpAsmParser::Delimiter::Paren) ||
-      parser.parseOptionalAttrDict(result.attributes))
+  if (parser.parseOperandList(operands, OpAsmParser::Delimiter::Paren))
     return failure();
 
   bool isVarArg = parser.parseOptionalKeyword("vararg").succeeded();
@@ -1232,6 +1231,9 @@ ParseResult CallOp::parse(OpAsmParser &parser, OperationState &result) {
       return failure();
   }
 
+  if (parser.parseOptionalAttrDict(result.attributes))
+    return failure();
+
   // Parse the trailing type list and resolve the operands.
   return parseCallTypeAndResolveOperands(parser, result, isDirect, operands);
 }
diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir
index 3f84f9dc5a9b8..3ec8aa0e8bb12 100644
--- a/mlir/test/Target/LLVMIR/llvmir.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir.mlir
@@ -1227,15 +1227,19 @@ llvm.func @varargs(...)
 
 // CHECK-LABEL: define void @varargs_call
 llvm.func @varargs_call(%arg0 : i32) {
+// CHECK:  call void (...) @varargs(i32 %{{.*}})
 // CHECK:  call void (...) @varargs(i32 %{{.*}})
   llvm.call @varargs(%arg0) vararg(!llvm.func<void (...)>) : (i32) -> ()
+  llvm.call @varargs(%arg0) vararg(!llvm.func<void (...)>) {fastmathFlags = #llvm.fastmath<none>} : (i32) -> ()
   llvm.return
 }
 
 // CHECK-LABEL: define void @indirect_varargs_call(ptr %0, i32 %1)
 llvm.func @indirect_varargs_call(%arg0 : !llvm.ptr, %arg1 : i32) {
+// CHECK:  call void (...) %0(i32 %1)
 // CHECK:  call void (...) %0(i32 %1)
   llvm.call %arg0(%arg1) vararg(!llvm.func<void (...)>) : !llvm.ptr, (i32) -> ()
+  llvm.call %arg0(%arg1) vararg(!llvm.func<void (...)>) {fastmathFlags = #llvm.fastmath<none>} : !llvm.ptr, (i32) -> ()
   llvm.return
 }
 

llvm.return
}

// CHECK-LABEL: define void @indirect_varargs_call(ptr %0, i32 %1)
llvm.func @indirect_varargs_call(%arg0 : !llvm.ptr, %arg1 : i32) {
// CHECK: call void (...) %0(i32 %1)
// CHECK: call void (...) %0(i32 %1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would thinks you would check the attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh there was no result to show any difference, I was just trying to test parsing. But let me change this to make the attribute show up in the conversion result.

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test to the LLVM dialect roundtrip test for this?

Copy link
Contributor

@Dinistro Dinistro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix 🙂

Let me know when we should land this for you.

@zyx-billy
Copy link
Contributor Author

Thank you for the suggestions! Please feel free to just land it any time now 🙏 thanks!

@Dinistro Dinistro merged commit 12e5148 into llvm:main Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants