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

Simon Camphausen llvmlistbot at llvm.org
Mon May 13 01:46:31 PDT 2024


================
@@ -76,57 +77,98 @@ static SmallVector<Value> createVariablesForResults(T op,
 // the current insertion point of given rewriter.
 static void assignValues(ValueRange values, SmallVector<Value> &variables,
                          PatternRewriter &rewriter, Location loc) {
-  for (auto [value, var] : llvm::zip(values, variables))
-    rewriter.create<emitc::AssignOp>(loc, var, value);
+  for (auto [value, var] : llvm::zip(values, variables)) {
+    assert(isa<emitc::LValueType>(var.getType()) &&
+           "expected var to be an lvalue type");
+    assert(!isa<emitc::LValueType>(value.getType()) &&
+           "expected value to not be an lvalue type");
+    auto assign = rewriter.create<emitc::AssignOp>(loc, var, value);
+
+    // TODO: Make sure this is safe, as this moves operations with memory
+    // effects.
+    if (auto op = dyn_cast_if_present<emitc::LValueToRValueOp>(
+            value.getDefiningOp())) {
+      rewriter.moveOpBefore(op, assign);
----------------
simon-camp wrote:

As described below, this op should immediately precede it's users currently. So the conversion inserts these ops before every use. 

If I remember correctly in one of the tests one of these uses was an init arg for another scf.for op. As these get lowered to variable, assign pairs the conversion op was separated from it's user (the generated assign).

```
...
%0 = emitc.lvalue_to_rvalue %x
%1 = emitc.variable
emitc.assign %o to %1
emitc.for ...
```
So this is currently a workaround to get the tests running.

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


More information about the Mlir-commits mailing list