Skip to content

Commit

Permalink
[AutoBump] Merge with fixes of 3cead57 (Jun 17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgehre-amd committed Sep 12, 2024
2 parents 7e79490 + 3cead57 commit 94eb890
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mlir/include/mlir/Dialect/EmitC/Transforms/TypeConversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
#ifndef MLIR_DIALECT_EMITC_TRANSFORMS_TYPECONVERSIONS_H
#define MLIR_DIALECT_EMITC_TRANSFORMS_TYPECONVERSIONS_H

#include <optional>

namespace mlir {
class TypeConverter;
class Type;
void populateEmitCSizeTTypeConversions(TypeConverter &converter);

namespace emitc {
std::optional<Type> getUnsignedTypeFor(Type ty);
std::optional<Type> getSignedTypeFor(Type ty);
} // namespace emitc

} // namespace mlir

#endif // MLIR_DIALECT_EMITC_TRANSFORMS_TYPECONVERSIONS_H
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/EmitC/IR/EmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ bool mlir::emitc::isPointerWideType(Type type) {
type);
}

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

/// Check that the type of the initial value is compatible with the operations
/// result type.
static LogicalResult verifyInitializationAttribute(Operation *op,
Expand Down
25 changes: 25 additions & 0 deletions mlir/lib/Dialect/EmitC/Transforms/TypeConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,28 @@ void mlir::populateEmitCSizeTTypeConversions(TypeConverter &converter) {
converter.addTargetMaterialization(materializeAsUnrealizedCast);
converter.addArgumentMaterialization(materializeAsUnrealizedCast);
}

/// Get an unsigned integer or size data type corresponding to \p ty.
std::optional<Type> mlir::emitc::getUnsignedTypeFor(Type ty) {
if (ty.isInteger())
return IntegerType::get(ty.getContext(), ty.getIntOrFloatBitWidth(),
IntegerType::SignednessSemantics::Unsigned);
if (isa<PtrDiffTType, SignedSizeTType>(ty))
return SizeTType::get(ty.getContext());
if (isa<SizeTType>(ty))
return ty;
return {};
}

/// Get a signed integer or size data type corresponding to \p ty that supports
/// arithmetic on negative values.
std::optional<Type> mlir::emitc::getSignedTypeFor(Type ty) {
if (ty.isInteger())
return IntegerType::get(ty.getContext(), ty.getIntOrFloatBitWidth(),
IntegerType::SignednessSemantics::Signed);
if (isa<SizeTType, SignedSizeTType>(ty))
return PtrDiffTType::get(ty.getContext());
if (isa<PtrDiffTType>(ty))
return ty;
return {};
}

0 comments on commit 94eb890

Please sign in to comment.