-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[mlir][llvmir] Added extra builders for CallInstrinsicOp #111664
Conversation
@llvm/pr-subscribers-mlir Author: Finlay (FMarno) ChangesI've added the extra builders I would like to see for CallIntrinsicOp. Full diff: https://github.com/llvm/llvm-project/pull/111664.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 88e82ce48959b0..ff5199fe40d124 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1943,6 +1943,11 @@ def LLVM_CallIntrinsicOp
attr-dict
}];
+ let builders = [
+ OpBuilder<(ins "Type": $results, "StringAttr":$intrin, "ValueRange":$args)>,
+ OpBuilder<(ins "TypeRange": $results, "StringAttr":$intrin, "ValueRange":$args, "FastmathFlagsAttr":$fastMathFlags)>
+ ];
+
let hasVerifier = 1;
}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index fb7024a14f8d4e..27cbd77f110326 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3353,6 +3353,25 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
};
} // namespace
+//===----------------------------------------------------------------------===//
+// CallIntrinsicOp
+//===----------------------------------------------------------------------===//
+
+void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
+ mlir::TypeRange results, mlir::StringAttr intrin,
+ mlir::ValueRange args,
+ mlir::LLVM::FastmathFlagsAttr fastMathFlags) {
+
+ build(builder, state, results, intrin, args, fastMathFlags,
+ llvm::ArrayRef<mlir::ValueRange>{});
+}
+void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
+ mlir::Type results, mlir::StringAttr intrin,
+ mlir::ValueRange args) {
+ build(builder, state, {results}, intrin, args, FastmathFlagsAttr{},
+ llvm::ArrayRef<mlir::ValueRange>{});
+}
+
//===----------------------------------------------------------------------===//
// LinkerOptionsOp
//===----------------------------------------------------------------------===//
|
@llvm/pr-subscribers-mlir-llvm Author: Finlay (FMarno) ChangesI've added the extra builders I would like to see for CallIntrinsicOp. Full diff: https://github.com/llvm/llvm-project/pull/111664.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 88e82ce48959b0..ff5199fe40d124 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -1943,6 +1943,11 @@ def LLVM_CallIntrinsicOp
attr-dict
}];
+ let builders = [
+ OpBuilder<(ins "Type": $results, "StringAttr":$intrin, "ValueRange":$args)>,
+ OpBuilder<(ins "TypeRange": $results, "StringAttr":$intrin, "ValueRange":$args, "FastmathFlagsAttr":$fastMathFlags)>
+ ];
+
let hasVerifier = 1;
}
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index fb7024a14f8d4e..27cbd77f110326 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -3353,6 +3353,25 @@ struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface {
};
} // namespace
+//===----------------------------------------------------------------------===//
+// CallIntrinsicOp
+//===----------------------------------------------------------------------===//
+
+void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
+ mlir::TypeRange results, mlir::StringAttr intrin,
+ mlir::ValueRange args,
+ mlir::LLVM::FastmathFlagsAttr fastMathFlags) {
+
+ build(builder, state, results, intrin, args, fastMathFlags,
+ llvm::ArrayRef<mlir::ValueRange>{});
+}
+void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
+ mlir::Type results, mlir::StringAttr intrin,
+ mlir::ValueRange args) {
+ build(builder, state, {results}, intrin, args, FastmathFlagsAttr{},
+ llvm::ArrayRef<mlir::ValueRange>{});
+}
+
//===----------------------------------------------------------------------===//
// LinkerOptionsOp
//===----------------------------------------------------------------------===//
|
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.
Thanks it makes sense adding such builders!
Did you test it downstream? It is a bit hard to see from the code if all the necessary fields of the default constructor are set.
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.
Thanks for improving this!
let builders = [ | ||
OpBuilder<(ins "Type": $results, "StringAttr":$intrin, "ValueRange":$args)>, | ||
OpBuilder<(ins "TypeRange": $results, "StringAttr":$intrin, "ValueRange":$args, "FastmathFlagsAttr":$fastMathFlags)> | ||
]; |
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.
Maybe we could also include builders for intrinsics that do not have a result type?
OpBuilder<(ins "StringAttr":$intrin, "ValueRange":$args)>
OpBuilder<(ins "StringAttr":$intrin, "ValueRange":$args, "FastmathFlagsAttr":$fastMathFlags)>
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.
Thanks for the review.
I've added those in. Do you know how I could confirm they work? I don't really have a use cause so I was just guessing.
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.
Another approach might be adding a unit test under mlir/unittests/Dialect/LLVMIR
. But it seems like few people ever do this ... Anyway this builder is fairly simple and I believe it should be OK if no reviewers have problems about it.
@gysit Thank you for the review, I've addressed all your comments.
Yes, it works for code gen in Triton. If there is a better way to test builders then I'd love to know. |
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 modulo nits!
The only easy way to test builders is using them in a pass/canonicalization AFAIK. Since there are not many uses of this op upstream that does probably not work here.
@@ -3324,6 +3324,34 @@ LogicalResult CallIntrinsicOp::verify() { | |||
return success(); | |||
} | |||
|
|||
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state, | |||
mlir::StringAttr intrin, mlir::ValueRange args) { | |||
build(builder, state, /*results=*/Type{}, intrin, args, FastmathFlagsAttr{}, |
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.
build(builder, state, /*results=*/Type{}, intrin, args, FastmathFlagsAttr{}, | |
build(builder, state, /*results=*/TypeRange{}, intrin, args, FastmathFlagsAttr{}, |
I think this is a type range (probably Type converts to TypeRange)?
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.
Thanks, I've addressed that.
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state, | ||
mlir::StringAttr intrin, mlir::ValueRange args, | ||
mlir::LLVM::FastmathFlagsAttr fastMathFlags) { | ||
build(builder, state, /*results=*/Type{}, intrin, args, fastMathFlags, |
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.
build(builder, state, /*results=*/Type{}, intrin, args, fastMathFlags, | |
build(builder, state, /*results=*/TypeRange{}, intrin, args, fastMathFlags, |
Extra builders for CallIntrinsicOp. This is inspired by the comment from @antiagainst from [here](llvm#108933 (comment)).
I've added the extra builders I would like to see for CallIntrinsicOp.
This is inspired by the comment from @antiagainst from here. I am also building Triton.