Skip to content

Commit 8735b7d

Browse files
authored
[mlir] do not inject malloc/free in to-LLVM translation (#73224)
In the early days of MLIR-to-LLVM IR translation, it had to forcefully inject declarations of `malloc` and `free` functions as then-standard (now `memref`) dialect ops were unconditionally lowering to libc calls. This is no longer the case. Even when they do lower to libc calls, the signatures of those methods are injected at lowering since calls must target declared functions in valid IR. Don't inject those declarations anymore.
1 parent bf353a7 commit 8735b7d

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,14 +1369,6 @@ prepareLLVMModule(Operation *m, llvm::LLVMContext &llvmContext,
13691369
m->getDiscardableAttr(LLVM::LLVMDialect::getTargetTripleAttrName()))
13701370
llvmModule->setTargetTriple(cast<StringAttr>(targetTripleAttr).getValue());
13711371

1372-
// Inject declarations for `malloc` and `free` functions that can be used in
1373-
// memref allocation/deallocation coming from standard ops lowering.
1374-
llvm::IRBuilder<> builder(llvmContext);
1375-
llvmModule->getOrInsertFunction("malloc", builder.getInt8PtrTy(),
1376-
builder.getInt64Ty());
1377-
llvmModule->getOrInsertFunction("free", builder.getVoidTy(),
1378-
builder.getInt8PtrTy());
1379-
13801372
return llvmModule;
13811373
}
13821374

mlir/test/Target/LLVMIR/llvmir.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ llvm.mlir.global internal constant @sectionvar("teststring") {section = ".mysec
179179
// CHECK: declare ptr @malloc(i64)
180180
llvm.func @malloc(i64) -> !llvm.ptr
181181
// CHECK: declare void @free(ptr)
182-
182+
llvm.func @free(!llvm.ptr)
183183

184184
//
185185
// Basic functionality: function and block conversion, function calls,

0 commit comments

Comments
 (0)