Skip to content

Commit

Permalink
Remove EmitC_SizeType
Browse files Browse the repository at this point in the history
  • Loading branch information
cferry-AMD committed May 14, 2024
1 parent e86a2dc commit 9e7be39
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
10 changes: 10 additions & 0 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitC.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ 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 isSizeTType(mlir::Type type);

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

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

} // namespace emitc
} // namespace mlir

Expand Down
8 changes: 2 additions & 6 deletions mlir/include/mlir/Dialect/EmitC/IR/EmitCTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,11 @@ def EmitC_PointerType : EmitC_Type<"Pointer", "ptr"> {
let assemblyFormat = "`<` qualified($pointee) `>`";
}

class EmitC_SizeType<string name, string typeMnemonic, list<Trait> traits = []>
: EmitC_Type<name, typeMnemonic, traits> {
}

def EmitC_SignedSizeT : EmitC_SizeType<"SignedSizeT", "ssize_t"> {
def EmitC_SignedSizeT : EmitC_Type<"SignedSizeT", "ssize_t"> {
let summary = "EmitC signed size type";
}

def EmitC_SizeT : EmitC_SizeType<"SizeT", "size_t"> {
def EmitC_SizeT : EmitC_Type<"SizeT", "size_t"> {
let summary = "EmitC unsigned size type";
}

Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ class CmpIOpConversion : public OpConversionPattern<arith::CmpIOp> {
if (isa<IntegerType>(type) && type.isUnsignedInteger() != needsUnsigned) {
arithmeticType = rewriter.getIntegerType(type.getIntOrFloatBitWidth(),
/*isSigned=*/!needsUnsigned);
} else if (isa<emitc::SignedSizeTType, emitc::SizeTType>(type) &&
isa<emitc::SizeTType>(type) != needsUnsigned) {
} else if (emitc::isSizeTType(type) &&
emitc::isUnsignedSizeTType(type) != needsUnsigned) {
if (needsUnsigned)
arithmeticType = emitc::SizeTType::get(op->getContext());
else
Expand Down Expand Up @@ -326,8 +326,8 @@ class CastConversion : public OpConversionPattern<ArithOp> {
castType.isUnsignedInteger() != doUnsigned) {
castType = rewriter.getIntegerType(opReturnType.getIntOrFloatBitWidth(),
/*isSigned=*/!doUnsigned);
} else if (isa<emitc::SizeTType, emitc::SignedSizeTType>(castType) &&
isa<emitc::SizeTType>(castType) != doUnsigned) {
} else if (emitc::isSizeTType(castType) &&
emitc::isUnsignedSizeTType(castType) != doUnsigned) {
if (doUnsigned)
castType = emitc::SizeTType::get(op.getContext());
else
Expand All @@ -343,8 +343,8 @@ class CastConversion : public OpConversionPattern<ArithOp> {
/*isSigned=*/!doUnsigned);
actualOp = rewriter.template create<emitc::CastOp>(
op.getLoc(), correctSignednessType, actualOp);
} else if (isa<emitc::SizeTType, emitc::SignedSizeTType>(operandType) &&
isa<emitc::SizeTType>(operandType) != doUnsigned) {
} else if (emitc::isSizeTType(operandType) &&
emitc::isUnsignedSizeTType(operandType) != doUnsigned) {
Type correctSignednessType;
if (doUnsigned)
correctSignednessType = emitc::SizeTType::get(op.getContext());
Expand Down
12 changes: 12 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ bool mlir::emitc::isSupportedFloatType(Type type) {
return false;
}

bool mlir::emitc::isSizeTType(Type type) {
return isa<emitc::SignedSizeTType, emitc::SizeTType>(type);
}

bool mlir::emitc::isSignedSizeTType(Type type) {
return isa<emitc::SignedSizeTType>(type);
}

bool mlir::emitc::isUnsignedSizeTType(Type type) {
return isa<emitc::SizeTType>(type);
}

/// Check that the type of the initial value is compatible with the operations
/// result type.
static LogicalResult verifyInitializationAttribute(Operation *op,
Expand Down

0 comments on commit 9e7be39

Please sign in to comment.