aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_proc.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-05-21 12:58:48 +0100
committergingerBill <bill@gingerbill.org>2022-05-21 12:58:48 +0100
commite48f41165c54913e07d1ab21bebb6a439524cf7c (patch)
tree904cce7fd75a4e72d34ad3f679bb0d8f9477e145 /src/llvm_backend_proc.cpp
parent9eb4cbcbd2e382a48cd612a3a22eb3ecdcff7df6 (diff)
Begin work on Atomics for wasm32 (wait and notify intrinsics)
Diffstat (limited to 'src/llvm_backend_proc.cpp')
-rw-r--r--src/llvm_backend_proc.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index a7f9eb013..2539e6e2e 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -2187,6 +2187,51 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
return res;
}
+ case BuiltinProc_wasm_memory_atomic_wait32:
+ {
+ char const *name = "llvm.wasm.memory.atomic.wait32";
+ LLVMTypeRef types[1] = {
+ lb_type(p->module, t_u32),
+ };
+ unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
+ GB_ASSERT_MSG(id != 0, "Unable to find %s", name, LLVMPrintTypeToString(types[0]));
+ LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
+
+ Type *t_u32_ptr = alloc_type_pointer(t_u32);
+
+ LLVMValueRef args[3] = {};
+ args[0] = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_u32_ptr).value;
+ args[1] = lb_emit_conv(p, lb_build_expr(p, ce->args[1]), t_u32).value;
+ args[2] = lb_emit_conv(p, lb_build_expr(p, ce->args[2]), t_i64).value;
+
+ lbValue res = {};
+ res.type = tv.type;
+ res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
+ return res;
+ }
+
+ case BuiltinProc_wasm_memory_atomic_notify32:
+ {
+ char const *name = "llvm.wasm.memory.atomic.notify";
+ LLVMTypeRef types[1] = {
+ lb_type(p->module, t_u32),
+ };
+ unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
+ GB_ASSERT_MSG(id != 0, "Unable to find %s", name, LLVMPrintTypeToString(types[0]));
+ LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
+
+ Type *t_u32_ptr = alloc_type_pointer(t_u32);
+
+ LLVMValueRef args[2] = {};
+ args[0] = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), t_u32_ptr).value;
+ args[1] = lb_emit_conv(p, lb_build_expr(p, ce->args[1]), t_u32).value;
+
+ lbValue res = {};
+ res.type = tv.type;
+ res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
+ return res;
+ }
+
}
GB_PANIC("Unhandled built-in procedure %.*s", LIT(builtin_procs[id].name));