[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


================
@@ -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()) {
----------------
simon-camp wrote:

I can't think of a way to explicitly materialize lvalue to rvalue conversions in C. Assigning to a local variable would model the read, but could have other side effects (like copying memory for structs / calling constructors in C++).

So the emitter doesn't emit any code for this op immediately. It rather forwards the name lookup of the result to it's operand. If the lvalue comes from a subscript op for example it would emit the subscript expression on every use.

Therefore the conversion op should have one use in the IR and it should immediately precede its user. (This get's more complicated when an op uses multiple values coming from conversion ops).

I'm open to ideas on how to express these conversions syntactically in C/C++ and then adapt the semantics/verifier of the operation. 

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


More information about the Mlir-commits mailing list