Skip to content

Commit c6a666f

Browse files
authored
Merge pull request #405 from Xilinx/matthias.emitc_opaque_float
ArithToEmitC: Support using opaque types for floating point
2 parents 7cba618 + 5de72c7 commit c6a666f

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ bool isIntegerIndexOrOpaqueType(Type type);
4646
/// Determines whether \p type is a valid floating-point type in EmitC.
4747
bool isSupportedFloatType(mlir::Type type);
4848

49+
/// Determines whether \p type is a valid floating-point or opaque type in
50+
/// EmitC.
51+
bool isFloatOrOpaqueType(mlir::Type type);
52+
4953
/// Determines whether \p type is a emitc.size_t/ssize_t type.
5054
bool isPointerWideType(mlir::Type type);
5155

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class NegFOpConversion : public OpConversionPattern<arith::NegFOp> {
307307
"negf currently only supports scalar types, not vectors or tensors");
308308
}
309309

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

657657
Type operandType = adaptor.getIn().getType();
658-
if (!emitc::isSupportedFloatType(operandType))
658+
if (!emitc::isFloatOrOpaqueType(operandType))
659659
return rewriter.notifyMatchFailure(castOp,
660660
"unsupported cast source type");
661661

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

713-
if (!emitc::isSupportedFloatType(dstType))
713+
if (!emitc::isFloatOrOpaqueType(dstType))
714714
return rewriter.notifyMatchFailure(castOp,
715715
"unsupported cast destination type");
716716

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

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

756-
if (!emitc::isSupportedFloatType(dstType))
756+
if (!emitc::isFloatOrOpaqueType(dstType))
757757
return rewriter.notifyMatchFailure(castOp,
758758
"unsupported cast destination type");
759759

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

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

786-
if (!emitc::isSupportedFloatType(dstType))
786+
if (!emitc::isFloatOrOpaqueType(dstType))
787787
return rewriter.notifyMatchFailure(castOp,
788788
"unsupported cast destination type");
789789

mlir/lib/Dialect/EmitC/IR/EmitC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ bool mlir::emitc::isSupportedFloatType(Type type) {
119119
return isa<Float32Type, Float64Type>(type);
120120
}
121121

122+
bool mlir::emitc::isFloatOrOpaqueType(Type type) {
123+
return isa<emitc::OpaqueType>(type) || isSupportedFloatType(type);
124+
}
125+
122126
bool mlir::emitc::isPointerWideType(Type type) {
123127
return isa<emitc::SignedSizeTType, emitc::SizeTType, emitc::PtrDiffTType>(
124128
type);

0 commit comments

Comments
 (0)