Skip to content

ArithToEmitC: Support using opaque types for floating point #405

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

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ 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 valid floating-point or opaque type in
/// EmitC.
bool isFloatOrOpaqueType(mlir::Type type);

/// Determines whether \p type is a emitc.size_t/ssize_t type.
bool isPointerWideType(mlir::Type type);

Expand Down
14 changes: 7 additions & 7 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class NegFOpConversion : public OpConversionPattern<arith::NegFOp> {
"negf currently only supports scalar types, not vectors or tensors");
}

if (!emitc::isSupportedFloatType(adaptedOpType)) {
if (!emitc::isFloatOrOpaqueType(adaptedOpType)) {
return rewriter.notifyMatchFailure(
op.getLoc(), "floating-point type is not supported by EmitC");
}
Expand Down Expand Up @@ -655,7 +655,7 @@ class FtoICastOpConversion : public OpConversionPattern<CastOp> {
ConversionPatternRewriter &rewriter) const override {

Type operandType = adaptor.getIn().getType();
if (!emitc::isSupportedFloatType(operandType))
if (!emitc::isFloatOrOpaqueType(operandType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast source type");

Expand Down Expand Up @@ -710,7 +710,7 @@ class ItoFCastOpConversion : public OpConversionPattern<CastOp> {
if (!dstType)
return rewriter.notifyMatchFailure(castOp, "type conversion failed");

if (!emitc::isSupportedFloatType(dstType))
if (!emitc::isFloatOrOpaqueType(dstType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast destination type");

Expand Down Expand Up @@ -745,15 +745,15 @@ class TruncFConversion : public OpConversionPattern<arith::TruncFOp> {
// attribute that we need to check. For now, the behavior is the default,
// i.e. truncate.
Type operandType = adaptor.getIn().getType();
if (!emitc::isSupportedFloatType(operandType))
if (!emitc::isFloatOrOpaqueType(operandType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast source type");

Type dstType = this->getTypeConverter()->convertType(castOp.getType());
if (!dstType)
return rewriter.notifyMatchFailure(castOp, "type conversion failed");

if (!emitc::isSupportedFloatType(dstType))
if (!emitc::isFloatOrOpaqueType(dstType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast destination type");

Expand All @@ -775,15 +775,15 @@ class ExtFConversion : public OpConversionPattern<arith::ExtFOp> {
matchAndRewrite(arith::ExtFOp castOp, typename arith::ExtFOp::Adaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
Type operandType = adaptor.getIn().getType();
if (!emitc::isSupportedFloatType(operandType))
if (!emitc::isFloatOrOpaqueType(operandType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast source type");

Type dstType = this->getTypeConverter()->convertType(castOp.getType());
if (!dstType)
return rewriter.notifyMatchFailure(castOp, "type conversion failed");

if (!emitc::isSupportedFloatType(dstType))
if (!emitc::isFloatOrOpaqueType(dstType))
return rewriter.notifyMatchFailure(castOp,
"unsupported cast destination type");

Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ bool mlir::emitc::isSupportedFloatType(Type type) {
return isa<Float32Type, Float64Type>(type);
}

bool mlir::emitc::isFloatOrOpaqueType(Type type) {
return isa<emitc::OpaqueType>(type) || isSupportedFloatType(type);
}

bool mlir::emitc::isPointerWideType(Type type) {
return isa<emitc::SignedSizeTType, emitc::SizeTType, emitc::PtrDiffTType>(
type);
Expand Down