forked from OSchip/llvm-project
[mlir][Complex] Add convenience builder for complex.number attribute.
Differential Revision: https://reviews.llvm.org/D130756
This commit is contained in:
parent
a0f1304616
commit
6e951b3ec9
|
@ -37,8 +37,25 @@ def Complex_NumberAttr : Complex_Attr<"Number", "number"> {
|
|||
let parameters = (ins APFloatParameter<"">:$real,
|
||||
APFloatParameter<"">:$imag,
|
||||
AttributeSelfTypeParameter<"">:$type);
|
||||
let builders = [
|
||||
AttrBuilderWithInferredContext<(ins "mlir::ComplexType":$type,
|
||||
"double":$real,
|
||||
"double":$imag), [{
|
||||
auto elementType = type.getElementType().cast<FloatType>();
|
||||
APFloat realFloat(real);
|
||||
bool unused;
|
||||
realFloat.convert(elementType.getFloatSemantics(),
|
||||
APFloat::rmNearestTiesToEven, &unused);
|
||||
APFloat imagFloat(imag);
|
||||
imagFloat.convert(elementType.getFloatSemantics(),
|
||||
APFloat::rmNearestTiesToEven, &unused);
|
||||
return $_get(type.getContext(), realFloat, imagFloat, type);
|
||||
}]>
|
||||
];
|
||||
|
||||
let genVerifyDecl = 1;
|
||||
let hasCustomAssemblyFormat = 1;
|
||||
let skipDefaultBuilders = 1;
|
||||
}
|
||||
|
||||
#endif // COMPLEX_ATTRIBUTE
|
||||
|
|
|
@ -81,13 +81,5 @@ Attribute complex::NumberAttr::parse(AsmParser &parser, Type odsType) {
|
|||
parser.parseFloat(imag) || parser.parseGreater())
|
||||
return {};
|
||||
|
||||
bool unused = false;
|
||||
APFloat realFloat(real);
|
||||
realFloat.convert(type.cast<FloatType>().getFloatSemantics(),
|
||||
APFloat::rmNearestTiesToEven, &unused);
|
||||
APFloat imagFloat(imag);
|
||||
imagFloat.convert(type.cast<FloatType>().getFloatSemantics(),
|
||||
APFloat::rmNearestTiesToEven, &unused);
|
||||
return NumberAttr::get(parser.getContext(), realFloat, imagFloat,
|
||||
ComplexType::get(type));
|
||||
return NumberAttr::get(ComplexType::get(type), real, imag);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue