From e6f2eb1cd1c2269ea2471d1dc8da045e7f9e4df6 Mon Sep 17 00:00:00 2001 From: Alexander Evgin Date: Thu, 21 Dec 2023 18:10:47 +0000 Subject: [PATCH] Add more memory management built-ins Added `calloc`, `realloc` and `aligned_alloc` intrinsics --- clang/include/clang/Basic/BuiltinsAssigner.def | 3 +++ clang/lib/CodeGen/CGBuiltin.cpp | 9 +++++++++ llvm/include/llvm/IR/IntrinsicsAssigner.td | 3 +++ 3 files changed, 15 insertions(+) diff --git a/clang/include/clang/Basic/BuiltinsAssigner.def b/clang/include/clang/Basic/BuiltinsAssigner.def index 16f7a8b439fd..f69c36f04bc6 100644 --- a/clang/include/clang/Basic/BuiltinsAssigner.def +++ b/clang/include/clang/Basic/BuiltinsAssigner.def @@ -38,6 +38,9 @@ // letters: https://github.com/NilFoundation/zkllvm-circifier/blob/master/clang/include/clang/Basic/Builtins.def#L20 // numbers: https://github.com/NilFoundation/zkllvm-circifier/blob/master/clang/lib/AST/ASTContext.cpp#L11086-L11118 BUILTIN(__builtin_assigner_malloc, "v*z", "n") +BUILTIN(__builtin_assigner_aligned_alloc, "v*zz", "n") +BUILTIN(__builtin_assigner_calloc, "v*zz", "n") +BUILTIN(__builtin_assigner_realloc, "v*v*z", "n") BUILTIN(__builtin_assigner_free, "vv*", "n") BUILTIN(__builtin_assigner_poseidon_pallas_base, "E3g1E3g1", "n") BUILTIN(__builtin_assigner_sha2_256_pallas_base, "E2g1E2g1E2g1", "n") diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 79b8d73b2754..6d418f59ff0a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -20563,6 +20563,15 @@ Value *CodeGenFunction::EmitAssignerBuiltinExpr(unsigned int BuiltinID, case assigner::BI__builtin_assigner_malloc: ID = Intrinsic::assigner_malloc; break; + case assigner::BI__builtin_assigner_aligned_alloc: + ID = Intrinsic::assigner_aligned_alloc; + break; + case assigner::BI__builtin_assigner_calloc: + ID = Intrinsic::assigner_calloc; + break; + case assigner::BI__builtin_assigner_realloc: + ID = Intrinsic::assigner_realloc; + break; case assigner::BI__builtin_assigner_free: ID = Intrinsic::assigner_free; break; diff --git a/llvm/include/llvm/IR/IntrinsicsAssigner.td b/llvm/include/llvm/IR/IntrinsicsAssigner.td index 89b4f5ba81f2..b300b055c271 100644 --- a/llvm/include/llvm/IR/IntrinsicsAssigner.td +++ b/llvm/include/llvm/IR/IntrinsicsAssigner.td @@ -11,6 +11,9 @@ //===----------------------------------------------------------------------===// def int_assigner_malloc: Intrinsic<[llvm_ptr_ty], [llvm_i64_ty]>; +def int_assigner_aligned_alloc: Intrinsic<[llvm_ptr_ty], [llvm_i64_ty, llvm_i64_ty]>; +def int_assigner_calloc: Intrinsic<[llvm_ptr_ty], [llvm_i64_ty, llvm_i64_ty]>; +def int_assigner_realloc: Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty, llvm_i64_ty]>; def int_assigner_free: Intrinsic<[], [llvm_ptr_ty]>; def int_assigner_poseidon: Intrinsic<[llvm_anyvector_ty], [LLVMMatchType<0>]>; def int_assigner_sha2_256: Intrinsic<[llvm_anyvector_ty], [LLVMMatchType<0>, LLVMMatchType<0>]>;