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

Matthias Gehre llvmlistbot at llvm.org
Thu May 9 22:33:13 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);
----------------
mgehre-amd wrote:

Why is the move required? The code isn't clear to me from the context.

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


More information about the Mlir-commits mailing list