[Mlir-commits] [mlir] [mlir][EmitC]Expand the MemRefToEmitC pass - Lowering `AllocOp` (PR #148257)

Marius Brehler llvmlistbot at llvm.org
Tue Jul 22 06:13:39 PDT 2025


================
@@ -30,6 +30,16 @@ struct ConvertMemRefToEmitCPass
     : public impl::ConvertMemRefToEmitCBase<ConvertMemRefToEmitCPass> {
   void runOnOperation() override {
     TypeConverter converter;
+    mlir::ModuleOp module = getOperation();
+    module.walk([&](mlir::Operation *op) {
+      if (llvm::isa<mlir::memref::AllocOp, mlir::memref::CopyOp>(op)) {
+        OpBuilder builder(module.getBody(), module.getBody()->begin());
+        builder.create<emitc::IncludeOp>(module.getLoc(),
+                                         builder.getStringAttr("stdlib.h"));
----------------
marbre wrote:

If one wants to generate C++ code this would need to be
```suggestion
                                         builder.getStringAttr("cstdlib"));
```
Maybe it is worth to add an optional flag to determine if the pass should lower to C or C++.

Furthermore, this should probably have the `is_standard_include` attribute set (https://mlir.llvm.org/docs/Dialects/EmitC/#attributes-14).

is_standard_include	

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


More information about the Mlir-commits mailing list