[Mlir-commits] [mlir] [mlir][emitc] Add 'emitc.switch' op to the dialect (PR #102331)
Andrey Timonin
llvmlistbot at llvm.org
Thu Aug 8 03:00:14 PDT 2024
================
@@ -131,6 +131,12 @@ bool mlir::emitc::isPointerWideType(Type type) {
type);
}
+bool mlir::emitc::isSwitchOperandType(Type type) {
+ auto intType = llvm::dyn_cast<IntegerType>(type);
----------------
EtoAndruwa wrote:
> Why do we exclude 1 and 8 bit integers?
- We have excluded the 1-bit integer due to the fact that we have [emitc::IfOp](https://mlir.llvm.org/docs/Dialects/EmitC/#emitcif-emitcifop), which takes only a 1-bit signless integer for its condition. We thought that for `i1`, `emitc::IfOp` must be preferred.
- We can support `i8`, but we need to add the `emitc::CastOp` to convert to `i32` before the switch statement, otherwise it will fail during `resolveOperand`(?). We have excluded it because, for example, clang's AST shows implicit cast to `i32` of the char.
Code:
![image](https://github.com/user-attachments/assets/6eb736ba-c8e2-4900-9a0d-b482e4a21df4)
AST:
![image](https://github.com/user-attachments/assets/14b6e015-8c13-4823-a628-ba665baf9b3e)
> Can we allow emitc::OpaqueType (which is often a class type)?
We can support this option. It will require a few changes to `bool mlir::emitc::isSwitchOperandType(Type type)`.
https://github.com/llvm/llvm-project/pull/102331
More information about the Mlir-commits
mailing list