[Mlir-commits] [mlir] [mlir][emitc][NFC] Add an example to the description of the emitc.literal operation (PR #128005)

Marius Brehler llvmlistbot at llvm.org
Fri Feb 21 06:41:52 PST 2025


================
@@ -798,6 +798,19 @@ def EmitC_LiteralOp : EmitC_Op<"literal", [Pure]> {
   let description = [{
     The `emitc.literal` operation produces an SSA value equal to some constant
     specified by an attribute.
+
+    Example:
+
+    ```mlir
+    %x = "emitc.variable"() <{value = #emitc.opaque<"">}> : () -> !emitc.lvalue<i32>
+    %one = literal "1" : i32
+    "emitc.assign"(%x, %one) : (!emitc.lvalue<i32>, i32) -> ()
+    ```
+    ```c++
+    // Code emitted for the operation above.
+    int32_t v1;
+    v1 = 1;
+    ```
----------------
marbre wrote:

Maybe we go for something easier and take what we have in the tests https://github.com/llvm/llvm-project/blob/bff6b926e2a42c15451058828fca313ff40e36dd/mlir/test/Target/Cpp/literal.mlir#L5-L6


```suggestion
    ```mlir
    %p0 = emitc.literal "M_PI" : f32
    %1 = "emitc.add" (%arg0, %p0) : (f32, f32) -> f32
    ```
    ```c++
    // Code emitted for the operation above.
    float v2 = v1 + M_PI;
    ```
```

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


More information about the Mlir-commits mailing list