[all-commits] [llvm/llvm-project] 5949f4: [mlir][EmitC]Expand the MemRefToEmitC pass - Lower...

Jaden Angella via All-commits all-commits at lists.llvm.org
Mon Jul 28 18:48:48 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5949f4596ea0f01c8072713c0a082b0e09c459cc
      https://github.com/llvm/llvm-project/commit/5949f4596ea0f01c8072713c0a082b0e09c459cc
  Author: Jaden Angella <ajaden at google.com>
  Date:   2025-07-28 (Mon, 28 Jul 2025)

  Changed paths:
    M mlir/docs/Dialects/emitc.md
    M mlir/include/mlir/Conversion/MemRefToEmitC/MemRefToEmitC.h
    M mlir/include/mlir/Conversion/Passes.td
    M mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitC.cpp
    M mlir/lib/Conversion/MemRefToEmitC/MemRefToEmitCPass.cpp
    A mlir/test/Conversion/MemRefToEmitC/memref-to-emitc-alloc.mlir

  Log Message:
  -----------
  [mlir][EmitC]Expand the MemRefToEmitC pass - Lowering `AllocOp` (#148257)

This aims to lower `memref.alloc` to `emitc.call_opaque “malloc” ` or
`emitc.call_opaque “aligned_alloc” `
From:
```
module{
  func.func @allocating() {
  %alloc_5 = memref.alloc() : memref<999xi32>
  return
  }
}
```

To:
```
module {
  emitc.include <"stdlib.h">
  func.func @allocating() {
    %0 = emitc.call_opaque "sizeof"() {args = [i32]} : () -> !emitc.size_t
    %1 = "emitc.constant"() <{value = 999 : index}> : () -> index
    %2 = emitc.mul %0, %1 : (!emitc.size_t, index) -> !emitc.size_t
    %3 = emitc.call_opaque "malloc"(%2) : (!emitc.size_t) -> !emitc.ptr<!emitc.opaque<"void">>
    %4 = emitc.cast %3 : !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<i32>
    return
  }
}
```
Which is then translated as:
```
#include <stdlib.h>
void allocating() {
  size_t v1 = sizeof(int32_t);
  size_t v2 = 999;
  size_t v3 = v1 * v2;
  void* v4 = malloc(v3);
  int32_t* v5 = (int32_t*) v4;
  return;
}
```



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list