forked from OSchip/llvm-project
[mlir][Complex] Change complex.number attribute type to ComplexType.
It is more useful to use ComplexType as type of the attribute than to use the element type as attribute type. This means when using this attribute in complex::ConstantOp, we just need to check whether the types match. Reviewed By: pifon2a Differential Revision: https://reviews.llvm.org/D130703
This commit is contained in:
parent
0287170140
commit
23c3eb7cdf
|
@ -48,11 +48,16 @@ LogicalResult complex::NumberAttr::verify(
|
|||
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
|
||||
::llvm::APFloat real, ::llvm::APFloat imag, ::mlir::Type type) {
|
||||
|
||||
if (!type.isa<FloatType>())
|
||||
return emitError()
|
||||
<< "element of the complex attribute must be float like type.";
|
||||
if (!type.isa<ComplexType>())
|
||||
return emitError() << "complex attribute must be a complex type.";
|
||||
|
||||
const auto &typeFloatSemantics = type.cast<FloatType>().getFloatSemantics();
|
||||
Type elementType = type.cast<ComplexType>().getElementType();
|
||||
if (!elementType.isa<FloatType>())
|
||||
return emitError()
|
||||
<< "element type of the complex attribute must be float like type.";
|
||||
|
||||
const auto &typeFloatSemantics =
|
||||
elementType.cast<FloatType>().getFloatSemantics();
|
||||
if (&real.getSemantics() != &typeFloatSemantics)
|
||||
return emitError()
|
||||
<< "type doesn't match the type implied by its `real` value";
|
||||
|
@ -64,7 +69,8 @@ LogicalResult complex::NumberAttr::verify(
|
|||
}
|
||||
|
||||
void complex::NumberAttr::print(AsmPrinter &printer) const {
|
||||
printer << "<:" << getType() << " " << getReal() << ", " << getImag() << ">";
|
||||
printer << "<:" << getType().cast<ComplexType>().getElementType() << " "
|
||||
<< getReal() << ", " << getImag() << ">";
|
||||
}
|
||||
|
||||
Attribute complex::NumberAttr::parse(AsmParser &parser, Type odsType) {
|
||||
|
@ -82,5 +88,6 @@ Attribute complex::NumberAttr::parse(AsmParser &parser, Type odsType) {
|
|||
APFloat imagFloat(imag);
|
||||
imagFloat.convert(type.cast<FloatType>().getFloatSemantics(),
|
||||
APFloat::rmNearestTiesToEven, &unused);
|
||||
return NumberAttr::get(parser.getContext(), realFloat, imagFloat, type);
|
||||
return NumberAttr::get(parser.getContext(), realFloat, imagFloat,
|
||||
ComplexType::get(type));
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
func.func @number_attr_f64() {
|
||||
"test.number_attr"() {
|
||||
// CHECK: attr = #complex.number<:f64 1.000000e+00, 0.000000e+00> : f64
|
||||
// CHECK: attr = #complex.number<:f64 1.000000e+00, 0.000000e+00> : complex<f64>
|
||||
attr = #complex.number<:f64 1.0, 0.0>
|
||||
} : () -> ()
|
||||
|
||||
|
@ -11,7 +11,7 @@ func.func @number_attr_f64() {
|
|||
|
||||
func.func @number_attr_f32() {
|
||||
"test.number_attr"() {
|
||||
// CHECK: attr = #complex.number<:f32 1.000000e+00, 0.000000e+00> : f32
|
||||
// CHECK: attr = #complex.number<:f32 1.000000e+00, 0.000000e+00> : complex<f32>
|
||||
attr = #complex.number<:f32 1.0, 0.0>
|
||||
} : () -> ()
|
||||
|
||||
|
|
Loading…
Reference in New Issue