[Mlir-commits] [mlir] [mlir][EmitC] Model lvalues as a type in EmitC (PR #91475)

Kirill Chibisov llvmlistbot at llvm.org
Wed Aug 21 09:43:01 PDT 2024


kchibisov wrote:

Is there a plan to minimize the amount of explicit assignments of loaded value or should I open an issue? In general

```mlir
func.func @cast_variables() -> i1 {
  %0 = "emitc.variable"(){value = 42 : i8} : () -> !emitc.lvalue<i8>
  %1 = emitc.load %0: !emitc.lvalue<i8>
  %2 = emitc.cast %1: i8 to i1
  return %2 : i1
}
```

being now

```cpp
bool cast_variables() {
  int8_t v1 = 42;
  int8_t v2 = v1;
  return (bool) v2;
}
```

with declare variables at top:

```cpp
bool cast_variables() {
  int8_t v1;
  int8_t v2;
  v1 = 42;
  v2 = v1;
  return (bool) v2;
}
```

Look really artificial and redundant compared to what it was before and I'm not sure how downstream(us) could deal with all these since a lot of that is inside the emitter and you can not really do anything about it with `verbatim`, etc.

Maybe the `emitc.load` could be allowed inside the `emitc.expression`, since it doesn't do anything _useful_ on its own and more of a type-system level safety? Then `form-expressions` pass will likely deal with it correctly. 

https://github.com/llvm/llvm-project/pull/91475


More information about the Mlir-commits mailing list