diff options
author | Tina Jung <tinamaria.jung@amd.com> | 2024-03-20 16:00:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-20 16:00:05 +0100 |
commit | 647d75d3a883c008c19a79bce265388b3c95e742 (patch) | |
tree | f723c26d98964b3bb6620bec799663f1fbf390df /mlir/lib | |
parent | 972f65a83f933b0f90cf975ef89452f4210e9b06 (diff) | |
download | llvm-647d75d3a883c008c19a79bce265388b3c95e742.zip llvm-647d75d3a883c008c19a79bce265388b3c95e742.tar.gz llvm-647d75d3a883c008c19a79bce265388b3c95e742.tar.bz2 |
[mlir][emitc] Restrict integer and float types (#85788)
Restrict which integers and floating-point types are valid in EmitC.
This should cover the types which are supported in C++ and is aligned
with what the emitter currently supports.
The checks are implemented as functions and not fully in tablegen to
allow them to be re-used by conversions to EmitC.
Diffstat (limited to 'mlir/lib')
-rw-r--r-- | mlir/lib/Dialect/EmitC/IR/EmitC.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp index e401a83..ab5c418 100644 --- a/mlir/lib/Dialect/EmitC/IR/EmitC.cpp +++ b/mlir/lib/Dialect/EmitC/IR/EmitC.cpp @@ -54,6 +54,35 @@ void mlir::emitc::buildTerminatedBody(OpBuilder &builder, Location loc) { builder.create<emitc::YieldOp>(loc); } +bool mlir::emitc::isSupportedIntegerType(Type type) { + if (auto intType = llvm::dyn_cast<IntegerType>(type)) { + switch (intType.getWidth()) { + case 1: + case 8: + case 16: + case 32: + case 64: + return true; + default: + return false; + } + } + return false; +} + +bool mlir::emitc::isSupportedFloatType(Type type) { + if (auto floatType = llvm::dyn_cast<FloatType>(type)) { + switch (floatType.getWidth()) { + case 32: + case 64: + return true; + default: + return false; + } + } + return false; +} + /// Check that the type of the initial value is compatible with the operations /// result type. static LogicalResult verifyInitializationAttribute(Operation *op, |