// AbsFOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::AbsFOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<FloatAttr>(operands,
+OpFoldResult math::AbsFOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<FloatAttr>(adaptor.getOperands(),
[](const APFloat &a) { return abs(a); });
}
// AbsIOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::AbsIOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<IntegerAttr>(operands,
+OpFoldResult math::AbsIOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<IntegerAttr>(adaptor.getOperands(),
[](const APInt &a) { return a.abs(); });
}
// AtanOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::AtanOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::AtanOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(atan(a.convertToDouble()));
// Atan2Op folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::Atan2Op::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::Atan2Op::fold(FoldAdaptor adaptor) {
return constFoldBinaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a, const APFloat &b) -> Optional<APFloat> {
+ adaptor.getOperands(),
+ [](const APFloat &a, const APFloat &b) -> Optional<APFloat> {
if (a.isZero() && b.isZero())
return llvm::APFloat::getNaN(a.getSemantics());
// CeilOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CeilOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<FloatAttr>(operands, [](const APFloat &a) {
- APFloat result(a);
- result.roundToIntegral(llvm::RoundingMode::TowardPositive);
- return result;
- });
+OpFoldResult math::CeilOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<FloatAttr>(
+ adaptor.getOperands(), [](const APFloat &a) {
+ APFloat result(a);
+ result.roundToIntegral(llvm::RoundingMode::TowardPositive);
+ return result;
+ });
}
//===----------------------------------------------------------------------===//
// CopySignOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CopySignOp::fold(ArrayRef<Attribute> operands) {
- return constFoldBinaryOp<FloatAttr>(operands,
+OpFoldResult math::CopySignOp::fold(FoldAdaptor adaptor) {
+ return constFoldBinaryOp<FloatAttr>(adaptor.getOperands(),
[](const APFloat &a, const APFloat &b) {
APFloat result(a);
result.copySign(b);
// CosOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CosOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::CosOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(cos(a.convertToDouble()));
// SinOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::SinOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::SinOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(sin(a.convertToDouble()));
// CountLeadingZerosOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CountLeadingZerosOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<IntegerAttr>(operands, [](const APInt &a) {
- return APInt(a.getBitWidth(), a.countLeadingZeros());
- });
+OpFoldResult math::CountLeadingZerosOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<IntegerAttr>(
+ adaptor.getOperands(), [](const APInt &a) {
+ return APInt(a.getBitWidth(), a.countLeadingZeros());
+ });
}
//===----------------------------------------------------------------------===//
// CountTrailingZerosOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CountTrailingZerosOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<IntegerAttr>(operands, [](const APInt &a) {
- return APInt(a.getBitWidth(), a.countTrailingZeros());
- });
+OpFoldResult math::CountTrailingZerosOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<IntegerAttr>(
+ adaptor.getOperands(), [](const APInt &a) {
+ return APInt(a.getBitWidth(), a.countTrailingZeros());
+ });
}
//===----------------------------------------------------------------------===//
// CtPopOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::CtPopOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<IntegerAttr>(operands, [](const APInt &a) {
- return APInt(a.getBitWidth(), a.countPopulation());
- });
+OpFoldResult math::CtPopOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<IntegerAttr>(
+ adaptor.getOperands(), [](const APInt &a) {
+ return APInt(a.getBitWidth(), a.countPopulation());
+ });
}
//===----------------------------------------------------------------------===//
// ErfOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::ErfOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::ErfOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(erf(a.convertToDouble()));
// IPowIOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::IPowIOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::IPowIOp::fold(FoldAdaptor adaptor) {
return constFoldBinaryOpConditional<IntegerAttr>(
- operands, [](const APInt &base, const APInt &power) -> Optional<APInt> {
+ adaptor.getOperands(),
+ [](const APInt &base, const APInt &power) -> Optional<APInt> {
unsigned width = base.getBitWidth();
auto zeroValue = APInt::getZero(width);
APInt oneValue{width, 1ULL, /*isSigned=*/true};
// LogOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::LogOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::LogOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
if (a.isNegative())
return {};
// Log2Op folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::Log2Op::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::Log2Op::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
if (a.isNegative())
return {};
// Log10Op folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::Log10Op::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::Log10Op::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
if (a.isNegative())
return {};
// Log1pOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::Log1pOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::Log1pOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
if ((a + APFloat(1.0)).isNegative())
// PowFOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::PowFOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::PowFOp::fold(FoldAdaptor adaptor) {
return constFoldBinaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a, const APFloat &b) -> Optional<APFloat> {
+ adaptor.getOperands(),
+ [](const APFloat &a, const APFloat &b) -> Optional<APFloat> {
if (a.getSizeInBits(a.getSemantics()) == 64 &&
b.getSizeInBits(b.getSemantics()) == 64)
return APFloat(pow(a.convertToDouble(), b.convertToDouble()));
// SqrtOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::SqrtOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::SqrtOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
if (a.isNegative())
return {};
// ExpOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::ExpOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::ExpOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(exp(a.convertToDouble()));
// Exp2Op folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::Exp2Op::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::Exp2Op::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(exp2(a.convertToDouble()));
// ExpM1Op folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::ExpM1Op::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::ExpM1Op::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(expm1(a.convertToDouble()));
// TanOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::TanOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::TanOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(tan(a.convertToDouble()));
// TanhOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::TanhOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::TanhOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(tanh(a.convertToDouble()));
// RoundEvenOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::RoundEvenOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<FloatAttr>(operands, [](const APFloat &a) {
- APFloat result(a);
- result.roundToIntegral(llvm::RoundingMode::NearestTiesToEven);
- return result;
- });
+OpFoldResult math::RoundEvenOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<FloatAttr>(
+ adaptor.getOperands(), [](const APFloat &a) {
+ APFloat result(a);
+ result.roundToIntegral(llvm::RoundingMode::NearestTiesToEven);
+ return result;
+ });
}
//===----------------------------------------------------------------------===//
// FloorOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::FloorOp::fold(ArrayRef<Attribute> operands) {
- return constFoldUnaryOp<FloatAttr>(operands, [](const APFloat &a) {
- APFloat result(a);
- result.roundToIntegral(llvm::RoundingMode::TowardNegative);
- return result;
- });
+OpFoldResult math::FloorOp::fold(FoldAdaptor adaptor) {
+ return constFoldUnaryOp<FloatAttr>(
+ adaptor.getOperands(), [](const APFloat &a) {
+ APFloat result(a);
+ result.roundToIntegral(llvm::RoundingMode::TowardNegative);
+ return result;
+ });
}
//===----------------------------------------------------------------------===//
// RoundOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::RoundOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::RoundOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(round(a.convertToDouble()));
// TruncOp folder
//===----------------------------------------------------------------------===//
-OpFoldResult math::TruncOp::fold(ArrayRef<Attribute> operands) {
+OpFoldResult math::TruncOp::fold(FoldAdaptor adaptor) {
return constFoldUnaryOpConditional<FloatAttr>(
- operands, [](const APFloat &a) -> Optional<APFloat> {
+ adaptor.getOperands(), [](const APFloat &a) -> Optional<APFloat> {
switch (a.getSizeInBits(a.getSemantics())) {
case 64:
return APFloat(trunc(a.convertToDouble()));