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 86fd3f7
Show file tree
Hide file tree
Showing 2 changed files with 33 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
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 86fd3f7

Please sign in to comment.