-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RFC][mlir] Conditional support for fast-math attributes. #125620
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,31 +22,63 @@ def ArithFastMathInterface : OpInterface<"ArithFastMathInterface"> { | |
|
||
let cppNamespace = "::mlir::arith"; | ||
|
||
let methods = [ | ||
InterfaceMethod< | ||
/*desc=*/ "Returns a FastMathFlagsAttr attribute for the operation", | ||
/*returnType=*/ "FastMathFlagsAttr", | ||
/*methodName=*/ "getFastMathFlagsAttr", | ||
/*args=*/ (ins), | ||
/*methodBody=*/ [{}], | ||
/*defaultImpl=*/ [{ | ||
let methods = | ||
[InterfaceMethod< | ||
/*desc=*/"Returns a FastMathFlagsAttr attribute for the operation", | ||
/*returnType=*/"FastMathFlagsAttr", | ||
/*methodName=*/"getFastMathFlagsAttr", | ||
/*args=*/(ins), | ||
/*methodBody=*/[{}], | ||
/*defaultImpl=*/[{ | ||
ConcreteOp op = cast<ConcreteOp>(this->getOperation()); | ||
return op.getFastmathAttr(); | ||
}] | ||
>, | ||
StaticInterfaceMethod< | ||
/*desc=*/ [{Returns the name of the FastMathFlagsAttr attribute | ||
}]>, | ||
StaticInterfaceMethod< | ||
/*desc=*/[{Returns the name of the FastMathFlagsAttr attribute | ||
for the operation}], | ||
/*returnType=*/ "StringRef", | ||
/*methodName=*/ "getFastMathAttrName", | ||
/*args=*/ (ins), | ||
/*methodBody=*/ [{}], | ||
/*defaultImpl=*/ [{ | ||
/*returnType=*/"StringRef", | ||
/*methodName=*/"getFastMathAttrName", | ||
/*args=*/(ins), | ||
/*methodBody=*/[{}], | ||
/*defaultImpl=*/[{ | ||
return "fastmath"; | ||
}] | ||
> | ||
}]>, | ||
InterfaceMethod< | ||
/*desc=*/[{Returns true iff FastMathFlagsAttr attribute | ||
is applicable to the operation that supports | ||
ArithFastMathInterface. If it returns false, | ||
then the FastMathFlagsAttr of the operation | ||
must be nullptr or have 'none' value}], | ||
/*returnType=*/"bool", | ||
/*methodName=*/"isArithFastMathApplicable", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should I think of this as a sort of "verifier" for fastMath flags for the given operation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its intention is to tell whether fast-math flags are applicable. It is used in the verified code below, but it may also be used by the passes/builders the create new operations supporting |
||
/*args=*/(ins), | ||
/*methodBody=*/[{}], | ||
/*defaultImpl=*/[{ | ||
return ::mlir::cast<::mlir::arith::ArithFastMathInterface>(this->getOperation()).isApplicableImpl(); | ||
}]>]; | ||
|
||
]; | ||
let extraClassDeclaration = [{ | ||
/// Returns true iff the given type is a floating point type | ||
/// or contains one. | ||
static bool isCompatibleType(::mlir::Type); | ||
|
||
/// Default implementation of isArithFastMathApplicable(). | ||
/// It returns true iff any of the results of the operations | ||
/// has a type that is compatible with fast-math. | ||
bool isApplicableImpl(); | ||
}]; | ||
|
||
let verify = [{ | ||
auto fmi = ::mlir::cast<::mlir::arith::ArithFastMathInterface>($_op); | ||
auto attr = fmi.getFastMathFlagsAttr(); | ||
if (attr && attr.getValue() != ::mlir::arith::FastMathFlags::none && | ||
!fmi.isArithFastMathApplicable()) | ||
return $_op->emitOpError() | ||
<< "has flag(s) `" << stringifyEnum(attr.getValue()) | ||
<< "`, but fast-math flags are not applicable " | ||
"(`isArithFastMathApplicable()` returns false)"; | ||
return ::mlir::success(); | ||
}]; | ||
} | ||
|
||
def ArithIntegerOverflowFlagsInterface : OpInterface<"ArithIntegerOverflowFlagsInterface"> { | ||
|
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.
I will change this to
false
after fixing the lowering tests.