Skip to content

Commit

Permalink
[gccjit][memref] fix alloca builtin names
Browse files Browse the repository at this point in the history
It is still not working due to ICE inside `libgccjit`, but it resolves all the builtins now.
  • Loading branch information
SchrodingerZhu committed Nov 9, 2024
1 parent 9f64961 commit 795d97f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions src/Conversion/ConvertMemrefToGCCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,23 +555,24 @@ struct AllocaOpLowering : public AllocationLowering<memref::AllocaOp> {
if (auto align = op.getAlignment()) {
auto alignment =
createIndexAttrConstant(rewriter, loc, getIndexType(), *align);
alloca =
rewriter
.create<CallOp>(loc, getVoidPtrType(),
SymbolRefAttr::get(rewriter.getContext(),
"__builtin_alloca_with_align"),
ValueRange{size, alignment},
/* tailcall */ nullptr,
/* builtin */ rewriter.getUnitAttr())
.getResult();
} else {
alloca = rewriter
.create<CallOp>(loc, getVoidPtrType(),
SymbolRefAttr::get(rewriter.getContext(),
"alloca_with_align"),
ValueRange{size, alignment},
"__builtin_alloca"),
ValueRange{size},
/* tailcall */ nullptr,
/* builtin */ rewriter.getUnitAttr())
.getResult();
} else {
alloca = rewriter
.create<CallOp>(
loc, getVoidPtrType(),
SymbolRefAttr::get(rewriter.getContext(), "alloca"),
ValueRange{size},
/* tailcall */ nullptr,
/* builtin */ rewriter.getUnitAttr())
.getResult();
}
alloca = rewriter.create<BitCastOp>(loc, elementPtrType, alloca);
rewriter.create<ReturnOp>(loc, alloca);
Expand Down
6 changes: 3 additions & 3 deletions test/lowering/alloca.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ module @test
{

func.func @foo() {
// CHECK: gccjit.call builtin @alloca(%{{[0-9]+}}) : (!gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
// CHECK: gccjit.call builtin @__builtin_alloca(%{{[0-9]+}}) : (!gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
%a = memref.alloca () : memref<100x100xf32>
return
}

func.func @bar(%arg0 : index) {
// // CHECK: gccjit.call builtin @alloca(%{{[0-9]+}}) : (!gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
// // CHECK: gccjit.call builtin @__builtin_alloca(%{{[0-9]+}}) : (!gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
%a = memref.alloca (%arg0) : memref<133x723x?xf32>
return
}

func.func @baz(%arg0 : index) {
// CHECK: gccjit.call builtin @alloca_with_align(%{{[0-9]+}}, %{{[0-9]+}}) : (!gccjit.int<size_t>, !gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
// CHECK: gccjit.call builtin @__builtin_alloca_with_align(%{{[0-9]+}}, %{{[0-9]+}}) : (!gccjit.int<size_t>, !gccjit.int<size_t>) -> !gccjit.ptr<!gccjit.void>
%a = memref.alloca (%arg0) {alignment = 128} : memref<133x723x?xf32>
return
}
Expand Down

0 comments on commit 795d97f

Please sign in to comment.