diff options
author | Jaden Angella <ajaden@google.com> | 2025-07-28 18:48:26 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-28 18:48:26 -0700 |
commit | 5949f4596ea0f01c8072713c0a082b0e09c459cc (patch) | |
tree | 25349286e70e0fd6e0c58390df9e227ed407faf5 /llvm/lib/CodeGen/MachineFunction.cpp | |
parent | 0d05e55f69426c38f42f911a11ac540896577e06 (diff) | |
download | llvm-5949f4596ea0f01c8072713c0a082b0e09c459cc.zip llvm-5949f4596ea0f01c8072713c0a082b0e09c459cc.tar.gz llvm-5949f4596ea0f01c8072713c0a082b0e09c459cc.tar.bz2 |
[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;
}
```
Diffstat (limited to 'llvm/lib/CodeGen/MachineFunction.cpp')
0 files changed, 0 insertions, 0 deletions