From b06ad5d6641fae88a0a7487b376bc642a50c9157 Mon Sep 17 00:00:00 2001 From: Corentin Ferry Date: Fri, 17 May 2024 07:05:18 +0100 Subject: [PATCH] Revert "[FXML-4614] Add EmitC index types, lower arith.index_cast, arith.index_castui (#183)" This commit breaks pipelines using ArithToEmitC on programsusing index variables both inside and outside the arith dialect. --- mlir/include/mlir/Dialect/EmitC/IR/EmitC.h | 4 - mlir/include/mlir/Dialect/EmitC/IR/EmitC.td | 6 +- .../mlir/Dialect/EmitC/IR/EmitCTypes.td | 8 - .../EmitC/Transforms/TypeConversions.h | 13 -- .../Conversion/ArithToEmitC/ArithToEmitC.cpp | 174 +++++++----------- .../Conversion/ArithToEmitC/CMakeLists.txt | 1 - mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 31 +--- .../Dialect/EmitC/Transforms/CMakeLists.txt | 1 - .../EmitC/Transforms/TypeConversions.cpp | 18 -- mlir/lib/Target/Cpp/TranslateToCpp.cpp | 4 - .../arith-to-emitc-unsupported.mlir | 20 ++ .../ArithToEmitC/arith-to-emitc.mlir | 108 ++--------- mlir/test/Dialect/EmitC/invalid_ops.mlir | 8 +- mlir/test/Dialect/EmitC/invalid_types.mlir | 4 +- mlir/test/Dialect/EmitC/types.mlir | 10 - mlir/test/Target/Cpp/types.mlir | 10 - 16 files changed, 119 insertions(+), 301 deletions(-) delete mode 100644 mlir/include/mlir/Dialect/EmitC/Transforms/TypeConversions.h delete mode 100644 mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.h b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.h index 575b91516b919..5d9531cd12415 100644 --- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.h +++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.h @@ -43,10 +43,6 @@ bool isIntegerIndexOrOpaqueType(Type type); /// Determines whether \p type is a valid floating-point type in EmitC. bool isSupportedFloatType(mlir::Type type); - -/// Determines whether \p type is a emitc.size_t/ssize_t type. -bool isAnySizeTType(mlir::Type type); - } // namespace emitc } // namespace mlir diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td index e664a1749216d..5da8593f59563 100644 --- a/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td +++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitC.td @@ -51,8 +51,7 @@ class EmitC_BinaryOp traits = []> : def CExpression : NativeOpTrait<"emitc::CExpression">; // Types only used in binary arithmetic operations. -def IntegerIndexOrOpaqueType : AnyTypeOf<[EmitCIntegerType, Index, - EmitC_SignedSizeT, EmitC_SizeT, EmitC_OpaqueType]>; +def IntegerIndexOrOpaqueType : AnyTypeOf<[EmitCIntegerType, Index, EmitC_OpaqueType]>; def FloatIntegerIndexOrOpaqueType : AnyTypeOf<[EmitCFloatType, IntegerIndexOrOpaqueType]>; def EmitC_AddOp : EmitC_BinaryOp<"add", [CExpression]> { @@ -288,7 +287,6 @@ def EmitC_CastOp : EmitC_Op<"cast", let arguments = (ins EmitCType:$source); let results = (outs EmitCType:$dest); let assemblyFormat = "$source attr-dict `:` type($source) `to` type($dest)"; - let hasFolder = 1; } def EmitC_CmpOp : EmitC_BinaryOp<"cmp", [CExpression]> { @@ -472,7 +470,7 @@ def EmitC_ForOp : EmitC_Op<"for", upper bound and step respectively, and defines an SSA value for its induction variable. It has one region capturing the loop body. The induction variable is represented as an argument of this region. This SSA value is a - signless integer, or an index. The step is a value of same type. + signless integer or index. The step is a value of same type. This operation has no result. The body region must contain exactly one block that terminates with `emitc.yield`. Calling ForOp::build will create such a diff --git a/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td b/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td index 0f080ac443327..444395b915e25 100644 --- a/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td +++ b/mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td @@ -130,12 +130,4 @@ def EmitC_PointerType : EmitC_Type<"Pointer", "ptr"> { let assemblyFormat = "`<` qualified($pointee) `>`"; } -def EmitC_SignedSizeT : EmitC_Type<"SignedSizeT", "ssize_t"> { - let summary = "EmitC signed size type"; -} - -def EmitC_SizeT : EmitC_Type<"SizeT", "size_t"> { - let summary = "EmitC unsigned size type"; -} - #endif // MLIR_DIALECT_EMITC_IR_EMITCTYPES diff --git a/mlir/include/mlir/Dialect/EmitC/Transforms/TypeConversions.h b/mlir/include/mlir/Dialect/EmitC/Transforms/TypeConversions.h deleted file mode 100644 index da16b336b8bc3..0000000000000 --- a/mlir/include/mlir/Dialect/EmitC/Transforms/TypeConversions.h +++ /dev/null @@ -1,13 +0,0 @@ -//===- TypeConversions.h - Convert signless types into C/C++ types -------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "mlir/Transforms/DialectConversion.h" - -namespace mlir { -void populateEmitCSizeTypeConversionPatterns(mlir::TypeConverter &converter); -} // namespace mlir diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp index 62067c5e25644..5fe4fc8695017 100644 --- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp +++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp @@ -15,7 +15,6 @@ #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/EmitC/IR/EmitC.h" -#include "mlir/Dialect/EmitC/Transforms/TypeConversions.h" #include "mlir/IR/BuiltinAttributes.h" #include "mlir/IR/BuiltinTypes.h" #include "mlir/Support/LogicalResult.h" @@ -37,11 +36,8 @@ class ArithConstantOpConversionPattern matchAndRewrite(arith::ConstantOp arithConst, arith::ConstantOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override { - Type newTy = this->getTypeConverter()->convertType(arithConst.getType()); - if (!newTy) - return rewriter.notifyMatchFailure(arithConst, "type conversion failed"); - rewriter.replaceOpWithNewOp(arithConst, newTy, - adaptor.getValue()); + rewriter.replaceOpWithNewOp( + arithConst, arithConst.getType(), adaptor.getValue()); return success(); } }; @@ -205,35 +201,6 @@ class CmpFOpConversion : public OpConversionPattern { } }; -/// Check if the signedness of type \p ty matches the expected -/// signedness, and issue a type with the correct signedness if -/// necessary. -Type adaptIntegralTypeSignedness(Type ty, bool needsUnsigned) { - if (isa(ty)) { - // Turns signless integers into signed integers. - if (ty.isUnsignedInteger() != needsUnsigned) { - auto signedness = needsUnsigned - ? IntegerType::SignednessSemantics::Unsigned - : IntegerType::SignednessSemantics::Signed; - return IntegerType::get(ty.getContext(), ty.getIntOrFloatBitWidth(), - signedness); - } - } else if (emitc::isAnySizeTType(ty)) { - if (isa(ty) != needsUnsigned) { - if (needsUnsigned) - return emitc::SizeTType::get(ty.getContext()); - return emitc::SignedSizeTType::get(ty.getContext()); - } - } - return ty; -} - -/// Insert a cast operation to type \p ty if \p val -/// does not have this type. -Value adaptValueType(Value val, ConversionPatternRewriter &rewriter, Type ty) { - return rewriter.createOrFold(val.getLoc(), ty, val); -} - class CmpIOpConversion : public OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; @@ -283,25 +250,31 @@ class CmpIOpConversion : public OpConversionPattern { ConversionPatternRewriter &rewriter) const override { Type type = adaptor.getLhs().getType(); - if (!isa_and_nonnull( - type)) { - return rewriter.notifyMatchFailure( - op, "expected integer or size_t/ssize_t type"); + if (!isa_and_nonnull(type)) { + return rewriter.notifyMatchFailure(op, "expected integer or index type"); } bool needsUnsigned = needsUnsignedCmp(op.getPredicate()); emitc::CmpPredicate pred = toEmitCPred(op.getPredicate()); - - Type arithmeticType = adaptIntegralTypeSignedness(type, needsUnsigned); - Value lhs = adaptValueType(adaptor.getLhs(), rewriter, arithmeticType); - Value rhs = adaptValueType(adaptor.getRhs(), rewriter, arithmeticType); - + Type arithmeticType = type; + if (type.isUnsignedInteger() != needsUnsigned) { + arithmeticType = rewriter.getIntegerType(type.getIntOrFloatBitWidth(), + /*isSigned=*/!needsUnsigned); + } + Value lhs = adaptor.getLhs(); + Value rhs = adaptor.getRhs(); + if (arithmeticType != type) { + lhs = rewriter.template create(op.getLoc(), arithmeticType, + lhs); + rhs = rewriter.template create(op.getLoc(), arithmeticType, + rhs); + } rewriter.replaceOpWithNewOp(op, op.getType(), pred, lhs, rhs); return success(); } }; -template +template class CastConversion : public OpConversionPattern { public: using OpConversionPattern::OpConversionPattern; @@ -311,10 +284,9 @@ class CastConversion : public OpConversionPattern { ConversionPatternRewriter &rewriter) const override { Type opReturnType = this->getTypeConverter()->convertType(op.getType()); - if (!isa_and_nonnull( - opReturnType)) - return rewriter.notifyMatchFailure( - op, "expected integer or size_t/ssize_t result type"); + if (!isa_and_nonnull(opReturnType)) { + return rewriter.notifyMatchFailure(op, "expected integer result type"); + } if (adaptor.getOperands().size() != 1) { return rewriter.notifyMatchFailure( @@ -322,47 +294,42 @@ class CastConversion : public OpConversionPattern { } Type operandType = adaptor.getIn().getType(); - if (!isa_and_nonnull( - operandType)) - return rewriter.notifyMatchFailure( - op, "expected integer or size_t/ssize_t operand type"); - - // to-i1 conversions: arith semantics want truncation, whereas (bool)(v) is - // equivalent to (v != 0). Implementing as (bool)(v & 0x01) gives - // truncation. - if (opReturnType.isInteger(1)) { - Type attrType = (emitc::isAnySizeTType(operandType)) - ? rewriter.getIndexType() - : operandType; - auto constOne = rewriter.create( - op.getLoc(), operandType, rewriter.getIntegerAttr(attrType, 1)); - auto oneAndOperand = rewriter.create( - op.getLoc(), operandType, adaptor.getIn(), constOne); - rewriter.replaceOpWithNewOp(op, opReturnType, - oneAndOperand); - return success(); + if (!isa_and_nonnull(operandType)) { + return rewriter.notifyMatchFailure(op, "expected integer operand type"); } - bool isTruncation = - (isa(operandType) && isa(opReturnType) && - operandType.getIntOrFloatBitWidth() > - opReturnType.getIntOrFloatBitWidth()); - bool doUnsigned = castToUnsigned || isTruncation; - - // Adapt the signedness of the result (bitwidth-preserving cast) - // This is needed e.g., if the return type is signless. - Type castDestType = adaptIntegralTypeSignedness(opReturnType, doUnsigned); + bool isTruncation = operandType.getIntOrFloatBitWidth() > + opReturnType.getIntOrFloatBitWidth(); + bool doUnsigned = needsUnsigned || isTruncation; + + Type castType = opReturnType; + // For int conversions: if the op is a ui variant and the type wanted as + // return type isn't unsigned, we need to issue an unsigned type to do + // the conversion. + if (castType.isUnsignedInteger() != doUnsigned) { + castType = rewriter.getIntegerType(opReturnType.getIntOrFloatBitWidth(), + /*isSigned=*/!doUnsigned); + } - // Adapt the signedness of the operand (bitwidth-preserving cast) - Type castSrcType = adaptIntegralTypeSignedness(operandType, doUnsigned); - Value actualOp = adaptValueType(adaptor.getIn(), rewriter, castSrcType); + Value actualOp = adaptor.getIn(); + // Fix the signedness of the operand if necessary + if (operandType.isUnsignedInteger() != doUnsigned) { + Type correctSignednessType = + rewriter.getIntegerType(operandType.getIntOrFloatBitWidth(), + /*isSigned=*/!doUnsigned); + actualOp = rewriter.template create( + op.getLoc(), correctSignednessType, actualOp); + } - // Actual cast (may change bitwidth) - auto cast = rewriter.template create(op.getLoc(), - castDestType, actualOp); + auto result = rewriter.template create(op.getLoc(), castType, + actualOp); - // Cast to the expected output type - auto result = adaptValueType(cast, rewriter, opReturnType); + // Fix the signedness of what this operation returns (for integers, + // the arith ops want signless results) + if (castType != opReturnType) { + result = rewriter.template create(op.getLoc(), + opReturnType, result); + } rewriter.replaceOp(op, result); return success(); @@ -388,11 +355,7 @@ class ArithOpConversion final : public OpConversionPattern { matchAndRewrite(ArithOp arithOp, typename ArithOp::Adaptor adaptor, ConversionPatternRewriter &rewriter) const override { - Type newTy = this->getTypeConverter()->convertType(arithOp.getType()); - if (!newTy) - return rewriter.notifyMatchFailure(arithOp, - "converting result type failed"); - rewriter.template replaceOpWithNewOp(arithOp, newTy, + rewriter.template replaceOpWithNewOp(arithOp, arithOp.getType(), adaptor.getOperands()); return success(); @@ -409,10 +372,8 @@ class IntegerOpConversion final : public OpConversionPattern { ConversionPatternRewriter &rewriter) const override { Type type = this->getTypeConverter()->convertType(op.getType()); - if (!isa_and_nonnull( - type)) { - return rewriter.notifyMatchFailure( - op, "expected integer or size_t/ssize_t type"); + if (!isa_and_nonnull(type)) { + return rewriter.notifyMatchFailure(op, "expected integer type"); } if (type.isInteger(1)) { @@ -420,6 +381,8 @@ class IntegerOpConversion final : public OpConversionPattern { return rewriter.notifyMatchFailure(op, "i1 type is not implemented"); } + Value lhs = adaptor.getLhs(); + Value rhs = adaptor.getRhs(); Type arithmeticType = type; if ((type.isSignlessInteger() || type.isSignedInteger()) && !bitEnumContainsAll(op.getOverflowFlags(), @@ -429,15 +392,20 @@ class IntegerOpConversion final : public OpConversionPattern { arithmeticType = rewriter.getIntegerType(type.getIntOrFloatBitWidth(), /*isSigned=*/false); } + if (arithmeticType != type) { + lhs = rewriter.template create(op.getLoc(), arithmeticType, + lhs); + rhs = rewriter.template create(op.getLoc(), arithmeticType, + rhs); + } - Value lhs = adaptValueType(adaptor.getLhs(), rewriter, arithmeticType); - Value rhs = adaptValueType(adaptor.getRhs(), rewriter, arithmeticType); - - Value arithmeticResult = rewriter.template create( - op.getLoc(), arithmeticType, lhs, rhs); - - Value result = adaptValueType(arithmeticResult, rewriter, type); + Value result = rewriter.template create(op.getLoc(), + arithmeticType, lhs, rhs); + if (arithmeticType != type) { + result = + rewriter.template create(op.getLoc(), type, result); + } rewriter.replaceOp(op, result); return success(); } @@ -567,8 +535,6 @@ void mlir::populateArithToEmitCPatterns(TypeConverter &typeConverter, RewritePatternSet &patterns) { MLIRContext *ctx = patterns.getContext(); - mlir::populateEmitCSizeTypeConversionPatterns(typeConverter); - // clang-format off patterns.add< ArithConstantOpConversionPattern, @@ -588,8 +554,6 @@ void mlir::populateArithToEmitCPatterns(TypeConverter &typeConverter, UnsignedCastConversion, SignedCastConversion, UnsignedCastConversion, - SignedCastConversion, - UnsignedCastConversion, ItoFCastOpConversion, ItoFCastOpConversion, FtoICastOpConversion, diff --git a/mlir/lib/Conversion/ArithToEmitC/CMakeLists.txt b/mlir/lib/Conversion/ArithToEmitC/CMakeLists.txt index 730a4b341673d..a3784f47c3bc2 100644 --- a/mlir/lib/Conversion/ArithToEmitC/CMakeLists.txt +++ b/mlir/lib/Conversion/ArithToEmitC/CMakeLists.txt @@ -11,7 +11,6 @@ add_mlir_conversion_library(MLIRArithToEmitC LINK_LIBS PUBLIC MLIRArithDialect MLIREmitCDialect - MLIREmitCTransforms MLIRPass MLIRTransformUtils ) diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index 71d354885a900..ef7b7a19489d4 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -68,8 +68,7 @@ bool mlir::emitc::isSupportedEmitCType(Type type) { return !llvm::isa(elemType) && isSupportedEmitCType(elemType); } - if (type.isIndex() || - llvm::isa(type)) + if (type.isIndex()) return true; if (llvm::isa(type)) return isSupportedIntegerType(type); @@ -110,8 +109,7 @@ bool mlir::emitc::isSupportedIntegerType(Type type) { } bool mlir::emitc::isIntegerIndexOrOpaqueType(Type type) { - return llvm::isa(type) || + return llvm::isa(type) || isSupportedIntegerType(type); } @@ -128,10 +126,6 @@ bool mlir::emitc::isSupportedFloatType(Type type) { return false; } -bool mlir::emitc::isAnySizeTType(Type type) { - return isa(type); -} - /// Check that the type of the initial value is compatible with the operations /// result type. static LogicalResult verifyInitializationAttribute(Operation *op, @@ -148,10 +142,6 @@ static LogicalResult verifyInitializationAttribute(Operation *op, Type resultType = op->getResult(0).getType(); Type attrType = cast(value).getType(); - if (isa(resultType) && - attrType.isIndex()) - return success(); - if (resultType != attrType) return op->emitOpError() << "requires attribute to either be an #emitc.opaque attribute or " @@ -236,19 +226,10 @@ LogicalResult emitc::AssignOp::verify() { bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) { Type input = inputs.front(), output = outputs.front(); - return ( - (llvm::isa( - input)) && - (llvm::isa( - output))); -} - -OpFoldResult emitc::CastOp::fold(FoldAdaptor adaptor) { - if (getOperand().getType() == getResult().getType()) - return getOperand(); - return nullptr; + return ((llvm::isa(input)) && + (llvm::isa(output))); } //===----------------------------------------------------------------------===// diff --git a/mlir/lib/Dialect/EmitC/Transforms/CMakeLists.txt b/mlir/lib/Dialect/EmitC/Transforms/CMakeLists.txt index 69e6ae1095e6e..97f616f2ee31a 100644 --- a/mlir/lib/Dialect/EmitC/Transforms/CMakeLists.txt +++ b/mlir/lib/Dialect/EmitC/Transforms/CMakeLists.txt @@ -2,7 +2,6 @@ add_mlir_dialect_library(MLIREmitCTransforms Transforms.cpp FormExpressions.cpp EliminateLibm.cpp - TypeConversions.cpp ADDITIONAL_HEADER_DIRS ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/EmitC/Transforms diff --git a/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp b/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp deleted file mode 100644 index d896f95b0ab8f..0000000000000 --- a/mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp +++ /dev/null @@ -1,18 +0,0 @@ -//===- TypeConversions.cpp - Convert signless types into C/C++ types ------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "mlir/Dialect/EmitC/Transforms/TypeConversions.h" -#include "mlir/Dialect/EmitC/IR/EmitC.h" -#include "mlir/IR/BuiltinTypes.h" - -using namespace mlir; - -void mlir::populateEmitCSizeTypeConversionPatterns(TypeConverter &converter) { - converter.addConversion( - [](IndexType type) { return emitc::SizeTType::get(type.getContext()); }); -} diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp index 39eb28300c0ca..1bdb74cd8bf2e 100644 --- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp +++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp @@ -1563,10 +1563,6 @@ LogicalResult CppEmitter::emitType(Location loc, Type type) { } if (auto iType = dyn_cast(type)) return (os << "size_t"), success(); - if (auto iType = dyn_cast(type)) - return (os << "size_t"), success(); - if (auto iType = dyn_cast(type)) - return (os << "ssize_t"), success(); if (auto tType = dyn_cast(type)) { if (!tType.hasRank()) return emitError(loc, "cannot emit unranked tensor type"); diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-unsupported.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-unsupported.mlir index 6d52c73af37e4..5fcb2b3a553e5 100644 --- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-unsupported.mlir +++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc-unsupported.mlir @@ -78,3 +78,23 @@ func.func @arith_cast_fptoui_i1(%arg0: f32) -> i1 { %t = arith.fptoui %arg0 : f32 to i1 return %t: i1 } + +// ----- + +func.func @index_cast(%arg0: i32) -> i32 { + // expected-error @+1 {{failed to legalize operation 'arith.index_cast'}} + %idx = arith.index_cast %arg0 : i32 to index + %int = arith.index_cast %idx : index to i32 + + return %int : i32 +} + +// ----- + +func.func @index_castui(%arg0: i32) -> i32 { + // expected-error @+1 {{failed to legalize operation 'arith.index_castui'}} + %idx = arith.index_castui %arg0 : i32 to index + %int = arith.index_castui %idx : index to i32 + + return %int : i32 +} diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir index d3f2dcafd180a..bda1180282142 100644 --- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir +++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir @@ -3,8 +3,7 @@ // CHECK-LABEL: arith_constants func.func @arith_constants() { // CHECK: emitc.constant - // CHECK-SAME: value = 0 - // CHECK-SAME: () -> !emitc.size_t + // CHECK-SAME: value = 0 : index %c_index = arith.constant 0 : index // CHECK: emitc.constant // CHECK-SAME: value = 0 : i32 @@ -76,18 +75,13 @@ func.func @arith_integer_ops_signed_nsw(%arg0: i32, %arg1: i32) { // ----- // CHECK-LABEL: arith_index -func.func @arith_index(%arg0: i32, %arg1: i32) { - // CHECK: %[[CST0:.*]] = emitc.cast %{{.*}} : {{.*}} to !emitc.size_t - %cst0 = arith.index_cast %arg0 : i32 to index - // CHECK: %[[CST1:.*]] = emitc.cast %{{.*}} : {{.*}} to !emitc.size_t - %cst1 = arith.index_cast %arg1 : i32 to index - - // CHECK: emitc.add %[[CST0]], %[[CST1]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t - %0 = arith.addi %cst0, %cst1 : index - // CHECK: emitc.sub %[[CST0]], %[[CST1]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t - %1 = arith.subi %cst0, %cst1 : index - // CHECK: emitc.mul %[[CST0]], %[[CST1]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t - %2 = arith.muli %cst0, %cst1 : index +func.func @arith_index(%arg0: index, %arg1: index) { + // CHECK: emitc.add %arg0, %arg1 : (index, index) -> index + %0 = arith.addi %arg0, %arg1 : index + // CHECK: emitc.sub %arg0, %arg1 : (index, index) -> index + %1 = arith.subi %arg0, %arg1 : index + // CHECK: emitc.mul %arg0, %arg1 : (index, index) -> index + %2 = arith.muli %arg0, %arg1 : index return } @@ -361,27 +355,6 @@ func.func @arith_cmpi_predicates(%arg0: i32, %arg1: i32) { return } -func.func @arith_cmpi_index(%arg0: i32, %arg1: i32) -> i1 { - // CHECK-LABEL: arith_cmpi_index - - // CHECK: %[[Cst0:.*]] = emitc.cast %{{.*}} : {{.*}} to !emitc.size_t - %idx0 = arith.index_cast %arg0 : i32 to index - // CHECK: %[[Cst1:.*]] = emitc.cast %{{.*}} : {{.*}} to !emitc.size_t - %idx1 = arith.index_cast %arg0 : i32 to index - - // CHECK-DAG: [[ULT:[^ ]*]] = emitc.cmp lt, %[[Cst0]], %[[Cst1]] : (!emitc.size_t, !emitc.size_t) -> i1 - %ult = arith.cmpi ult, %idx0, %idx1 : index - - // CHECK-DAG: %[[CastArg0:[^ ]*]] = emitc.cast %[[Cst0]] : !emitc.size_t to !emitc.ssize_t - // CHECK-DAG: %[[CastArg1:[^ ]*]] = emitc.cast %[[Cst1]] : !emitc.size_t to !emitc.ssize_t - // CHECK-DAG: %[[SLT:[^ ]*]] = emitc.cmp lt, %[[CastArg0]], %[[CastArg1]] : (!emitc.ssize_t, !emitc.ssize_t) -> i1 - %slt = arith.cmpi slt, %idx0, %idx1 : index - - // CHECK: return %[[SLT]] - return %slt: i1 -} - - // ----- func.func @arith_float_to_int_cast_ops(%arg0: f32, %arg1: f64) { @@ -420,30 +393,24 @@ func.func @arith_int_to_float_cast_ops(%arg0: i8, %arg1: i64) { // ----- -func.func @arith_trunci(%arg0: i32) -> i8 { - // CHECK-LABEL: arith_trunci +func.func @trunci(%arg0: i32) -> i8 { + // CHECK-LABEL: trunci // CHECK-SAME: (%[[Arg0:[^ ]*]]: i32) // CHECK: %[[CastUI:.*]] = emitc.cast %[[Arg0]] : i32 to ui32 // CHECK: %[[Trunc:.*]] = emitc.cast %[[CastUI]] : ui32 to ui8 // CHECK: emitc.cast %[[Trunc]] : ui8 to i8 %truncd = arith.trunci %arg0 : i32 to i8 - // CHECK: %[[Const:.*]] = "emitc.constant" - // CHECK-SAME: value = 1 - // CHECK-SAME: () -> i32 - // CHECK: %[[AndOne:.*]] = emitc.bitwise_and %[[Arg0]], %[[Const]] : (i32, i32) -> i32 - // CHECK: %[[Conv:.*]] = emitc.cast %[[AndOne]] : i32 to i1 - %bool = arith.trunci %arg0 : i32 to i1 - return %truncd : i8 } // ----- -func.func @arith_extsi(%arg0: i32) { - // CHECK-LABEL: arith_extsi +func.func @extsi(%arg0: i32) { + // CHECK-LABEL: extsi // CHECK-SAME: ([[Arg0:[^ ]*]]: i32) // CHECK: emitc.cast [[Arg0]] : i32 to i64 + %extd = arith.extsi %arg0 : i32 to i64 return @@ -451,57 +418,14 @@ func.func @arith_extsi(%arg0: i32) { // ----- -func.func @arith_extui(%arg0: i32) { - // CHECK-LABEL: arith_extui +func.func @extui(%arg0: i32) { + // CHECK-LABEL: extui // CHECK-SAME: (%[[Arg0:[^ ]*]]: i32) // CHECK: %[[Conv0:.*]] = emitc.cast %[[Arg0]] : i32 to ui32 // CHECK: %[[Conv1:.*]] = emitc.cast %[[Conv0]] : ui32 to ui64 // CHECK: emitc.cast %[[Conv1]] : ui64 to i64 + %extd = arith.extui %arg0 : i32 to i64 return } - -// ----- - -func.func @arith_index_cast(%arg0: i32) -> i32 { - // CHECK-LABEL: arith_index_cast - // CHECK-SAME: (%[[Arg0:[^ ]*]]: i32) - // CHECK: %[[Conv0:.*]] = emitc.cast %[[Arg0]] : i32 to !emitc.ssize_t - // CHECK: %[[Conv1:.*]] = emitc.cast %[[Conv0]] : !emitc.ssize_t to !emitc.size_t - %idx = arith.index_cast %arg0 : i32 to index - // CHECK: %[[Conv2:.*]] = emitc.cast %[[Conv1]] : !emitc.size_t to !emitc.ssize_t - // CHECK: %[[Conv3:.*]] = emitc.cast %[[Conv2]] : !emitc.ssize_t to i32 - %int = arith.index_cast %idx : index to i32 - - // CHECK: %[[Const:.*]] = "emitc.constant" - // CHECK-SAME: value = 1 - // CHECK-SAME: () -> !emitc.size_t - // CHECK: %[[AndOne:.*]] = emitc.bitwise_and %[[Conv1]], %[[Const]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t - // CHECK: %[[Conv4:.*]] = emitc.cast %[[AndOne]] : !emitc.size_t to i1 - %bool = arith.index_cast %idx : index to i1 - - return %int : i32 -} - -// ----- - -func.func @arith_index_castui(%arg0: i32) -> i32 { - // CHECK-LABEL: arith_index_castui - // CHECK-SAME: (%[[Arg0:[^ ]*]]: i32) - // CHECK: %[[Conv0:.*]] = emitc.cast %[[Arg0]] : i32 to ui32 - // CHECK: %[[Conv1:.*]] = emitc.cast %[[Conv0]] : ui32 to !emitc.size_t - %idx = arith.index_castui %arg0 : i32 to index - // CHECK: %[[Conv2:.*]] = emitc.cast %[[Conv1]] : !emitc.size_t to ui32 - // CHECK: %[[Conv3:.*]] = emitc.cast %[[Conv2]] : ui32 to i32 - %int = arith.index_castui %idx : index to i32 - - // CHECK: %[[Const:.*]] = "emitc.constant" - // CHECK-SAME: value = 1 - // CHECK-SAME: () -> !emitc.size_t - // CHECK: %[[AndOne:.*]] = emitc.bitwise_and %[[Conv1]], %[[Const]] : (!emitc.size_t, !emitc.size_t) -> !emitc.size_t - // CHECK: %[[Conv4:.*]] = emitc.cast %[[AndOne]] : !emitc.size_t to i1 - %bool = arith.index_castui %idx : index to i1 - - return %int : i32 -} diff --git a/mlir/test/Dialect/EmitC/invalid_ops.mlir b/mlir/test/Dialect/EmitC/invalid_ops.mlir index 3eede2c72dca4..21ea6a5df91b9 100644 --- a/mlir/test/Dialect/EmitC/invalid_ops.mlir +++ b/mlir/test/Dialect/EmitC/invalid_ops.mlir @@ -170,7 +170,7 @@ func.func @add_float_pointer(%arg0: f32, %arg1: !emitc.ptr) { // ----- func.func @div_tensor(%arg0: tensor, %arg1: tensor) { - // expected-error @+1 {{'emitc.div' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'tensor'}} + // expected-error @+1 {{'emitc.div' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC opaque type, but got 'tensor'}} %1 = "emitc.div" (%arg0, %arg1) : (tensor, tensor) -> tensor return } @@ -178,7 +178,7 @@ func.func @div_tensor(%arg0: tensor, %arg1: tensor) { // ----- func.func @mul_tensor(%arg0: tensor, %arg1: tensor) { - // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'tensor'}} + // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC opaque type, but got 'tensor'}} %1 = "emitc.mul" (%arg0, %arg1) : (tensor, tensor) -> tensor return } @@ -186,7 +186,7 @@ func.func @mul_tensor(%arg0: tensor, %arg1: tensor) { // ----- func.func @rem_tensor(%arg0: tensor, %arg1: tensor) { - // expected-error @+1 {{'emitc.rem' op operand #0 must be integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'tensor'}} + // expected-error @+1 {{'emitc.rem' op operand #0 must be integer type supported by EmitC or index or EmitC opaque type, but got 'tensor'}} %1 = "emitc.rem" (%arg0, %arg1) : (tensor, tensor) -> tensor return } @@ -194,7 +194,7 @@ func.func @rem_tensor(%arg0: tensor, %arg1: tensor) { // ----- func.func @rem_float(%arg0: f32, %arg1: f32) { - // expected-error @+1 {{'emitc.rem' op operand #0 must be integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'f32'}} + // expected-error @+1 {{'emitc.rem' op operand #0 must be integer type supported by EmitC or index or EmitC opaque type, but got 'f32'}} %1 = "emitc.rem" (%arg0, %arg1) : (f32, f32) -> f32 return } diff --git a/mlir/test/Dialect/EmitC/invalid_types.mlir b/mlir/test/Dialect/EmitC/invalid_types.mlir index 111fbc7de640b..0ad8d4eabe6b8 100644 --- a/mlir/test/Dialect/EmitC/invalid_types.mlir +++ b/mlir/test/Dialect/EmitC/invalid_types.mlir @@ -85,7 +85,7 @@ func.func @illegal_array_with_tensor_element_type( // ----- func.func @illegal_integer_type(%arg0: i11, %arg1: i11) -> i11 { - // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'i11'}} + // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC opaque type, but got 'i11'}} %mul = "emitc.mul" (%arg0, %arg1) : (i11, i11) -> i11 return } @@ -93,7 +93,7 @@ func.func @illegal_integer_type(%arg0: i11, %arg1: i11) -> i11 { // ----- func.func @illegal_float_type(%arg0: f80, %arg1: f80) { - // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC signed size type or EmitC unsigned size type or EmitC opaque type, but got 'f80'}} + // expected-error @+1 {{'emitc.mul' op operand #0 must be floating-point type supported by EmitC or integer type supported by EmitC or index or EmitC opaque type, but got 'f80'}} %mul = "emitc.mul" (%arg0, %arg1) : (f80, f80) -> f80 return } diff --git a/mlir/test/Dialect/EmitC/types.mlir b/mlir/test/Dialect/EmitC/types.mlir index 8b630d5a320f4..752f2c10c17be 100644 --- a/mlir/test/Dialect/EmitC/types.mlir +++ b/mlir/test/Dialect/EmitC/types.mlir @@ -53,13 +53,3 @@ func.func @pointer_types() { return } - -// CHECK-LABEL: func @index_types() -func.func @index_types() { - // CHECK-NEXT: !emitc.ssize_t - emitc.call_opaque "f"() {template_args = [!emitc.ssize_t]} : () -> () - // CHECK-NEXT: !emitc.size_t - emitc.call_opaque "f"() {template_args = [!emitc.size_t]} : () -> () - - return -} diff --git a/mlir/test/Target/Cpp/types.mlir b/mlir/test/Target/Cpp/types.mlir index 647777c8ac718..0585b27eb6c22 100644 --- a/mlir/test/Target/Cpp/types.mlir +++ b/mlir/test/Target/Cpp/types.mlir @@ -35,13 +35,3 @@ func.func @ptr_types() { return } - -// CHECK-LABEL: void size_types() { -func.func @size_types() { - // CHECK-NEXT: f(); - emitc.call_opaque "f"() {template_args = [!emitc.ssize_t]} : () -> () - // CHECK-NEXT: f(); - emitc.call_opaque "f"() {template_args = [!emitc.size_t]} : () -> () - - return -}