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

Matthias Gehre llvmlistbot at llvm.org
Mon May 13 02:13:49 PDT 2024


================
@@ -698,6 +703,47 @@ LogicalResult emitc::LiteralOp::verify() {
     return emitOpError() << "value must not be empty";
   return success();
 }
+
+//===----------------------------------------------------------------------===//
+// LValueToRValueOp
+//===----------------------------------------------------------------------===//
+
+LogicalResult emitc::LValueToRValueOp::verify() {
+  Type operandType = getOperand().getType();
+  Type resultType = getResult().getType();
+  if (!llvm::isa<emitc::LValueType>(operandType))
+    return emitOpError("operand must be a lvalue");
+  if (llvm::cast<emitc::LValueType>(operandType).getValue() != resultType)
+    return emitOpError("types must match");
+
+  Value result = getResult();
+  if (!result.hasOneUse()) {
----------------
mgehre-amd wrote:

I think assigning to a local variable is the right thing to do here because it's consistent how emitc behaves everywhere.
E.g. if I do `emitc.add %a, %b : !emitc.opaque<"myclass">` then the translation will already not only call the overloaded `operator+` on my class, but also assign it to a variable (which might copy memory / call constructors).
If users don't want this, they need to use `emitc.expression`.

I have concerns about special requirements like `only single use` and must immediately precede its user that don't seem to exist in other parts of MLIR and thus will be surprising to developers.

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


More information about the Mlir-commits mailing list