From dd275cd749fb33e272004cd946eff18ec4d10281 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Thu, 17 Nov 2011 11:51:25 -0800 Subject: [PATCH] Stop using temporary intrinsic_2 functions --- src/comp/middle/trans.rs | 2 +- src/rt/intrinsics/intrinsics.cpp | 126 ++++++----- src/rt/intrinsics/intrinsics.i386.ll.in | 260 +++++++++++----------- src/rt/intrinsics/intrinsics.x86_64.ll.in | 182 ++++++++------- 4 files changed, 300 insertions(+), 270 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index e2d8811a4ad..3e6eda110d8 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -5724,7 +5724,7 @@ fn register_native_fn(ccx: @crate_ctxt, sp: span, _path: [str], name: str, ast::native_abi_rust_intrinsic. { let num_ty_param = native_fn_ty_param_count(ccx, id); let fn_type = native_fn_wrapper_type(ccx, sp, num_ty_param, fn_type); - let ri_name = "rust_intrinsic_2_" + name; + let ri_name = "rust_intrinsic_" + name; let llnativefn = get_extern_fn(ccx.externs, ccx.llmod, ri_name, lib::llvm::LLVMCCallConv, fn_type); ccx.item_ids.insert(id, llnativefn); diff --git a/src/rt/intrinsics/intrinsics.cpp b/src/rt/intrinsics/intrinsics.cpp index dd08fd85216..8806ee45031 100644 --- a/src/rt/intrinsics/intrinsics.cpp +++ b/src/rt/intrinsics/intrinsics.cpp @@ -15,6 +15,72 @@ port_recv(uintptr_t *dptr, rust_port *port); extern "C" CDECL void rust_task_sleep(size_t time_in_us); +extern "C" void +rust_intrinsic_vec_len(size_t *retptr, + void *env, + type_desc *ty, + rust_vec **vp) +{ + *retptr = (*vp)->fill / ty->size; +} + +extern "C" void +rust_intrinsic_ptr_offset(void **retptr, + void *env, + type_desc *ty, + void *ptr, + uintptr_t count) +{ + *retptr = &((uint8_t *)ptr)[ty->size * count]; +} + +extern "C" void +rust_intrinsic_cast(void *retptr, + void *env, + type_desc *t1, + type_desc *t2, + void *src) +{ + if (t1->size != t2->size) { + upcall_fail("attempt to cast values of differing sizes", + __FILE__, __LINE__); + return; + } + + memmove(retptr, src, t1->size); +} + +extern "C" void +rust_intrinsic_addr_of(void **retptr, + void *env, + type_desc *ty, + void *valptr) { + *retptr = valptr; +} + +extern "C" void +rust_intrinsic_recv(void **retptr, + void *env, + type_desc *ty, + rust_port *port) { + port_recv((uintptr_t*)retptr, port); +} + +extern "C" void +rust_intrinsic_get_type_desc(void **retptr, + void *env, + type_desc* ty) { + *(type_desc**)retptr = ty; +} + +extern "C" void +rust_intrinsic_task_sleep(void **retptr, + void *env, + size_t time_in_us) { + rust_task_sleep(time_in_us); +} + + extern "C" void rust_intrinsic_2_vec_len(size_t *retptr, void *env, @@ -79,63 +145,3 @@ rust_intrinsic_2_task_sleep(void **retptr, size_t time_in_us) { rust_task_sleep(time_in_us); } - -extern "C" void -rust_intrinsic_vec_len(void *task, - size_t *retptr, - type_desc *ty, - rust_vec **vp) -{ - rust_intrinsic_2_vec_len(retptr, NULL, ty, vp); -} - -extern "C" void -rust_intrinsic_ptr_offset(void *task, - void **retptr, - type_desc *ty, - void *ptr, - uintptr_t count) -{ - rust_intrinsic_2_ptr_offset(retptr, NULL, ty, ptr, count); -} - -extern "C" void -rust_intrinsic_cast(void *task, - void *retptr, - type_desc *t1, - type_desc *t2, - void *src) -{ - rust_intrinsic_2_cast(retptr, NULL, t1, t2, src); -} - -extern "C" void -rust_intrinsic_addr_of(void *task, - void **retptr, - type_desc *ty, - void *valptr) { - rust_intrinsic_2_addr_of(retptr, NULL, ty, valptr); -} - -extern "C" void -rust_intrinsic_recv(void *task, - void **retptr, - type_desc *ty, - rust_port *port) { - rust_intrinsic_2_recv(retptr, NULL, ty, port); -} - -extern "C" void -rust_intrinsic_get_type_desc(void *task, - void **retptr, - type_desc* ty) { - rust_intrinsic_2_get_type_desc(retptr, NULL, ty); -} - -extern "C" void -rust_intrinsic_task_sleep(void *task, - void **retptr, - size_t time_in_us) { - rust_task_sleep(time_in_us); -} - diff --git a/src/rt/intrinsics/intrinsics.i386.ll.in b/src/rt/intrinsics/intrinsics.i386.ll.in index a45c6b1ff6b..acf42dd603e 100644 --- a/src/rt/intrinsics/intrinsics.i386.ll.in +++ b/src/rt/intrinsics/intrinsics.i386.ll.in @@ -1,83 +1,90 @@ ; ModuleID = 'src/rt/intrinsics/intrinsics.cpp' -; target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" +; target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128" target triple = "@CFG_TARGET_TRIPLE@" -%0 = type { i32, %"struct.memory_region::alloc_header"**, i32 } -%1 = type { i32, %struct.rust_scheduler**, i32 } -%2 = type { %"struct.hash_map::map_entry"* } -%class.array_list = type { i32, %struct.rust_task**, i32 } -%class.circular_buffer = type { %class.rust_kernel*, i32, i32, i32, i32, i8* } -%class.context = type { %struct.registers_t, %class.context* } -%"class.debug::task_debug_info" = type { %"class.std::map" } -%class.hash_map = type { %"struct.hash_map::map_entry"* } -%class.indexed_list = type { i32 (...)**, %class.array_list } -%class.lock_and_signal = type { i32 (...)**, %struct._opaque_pthread_cond_t, %struct._opaque_pthread_mutex_t, %struct._opaque_pthread_t*, i8, i8 } -%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %0, i8, i8, %class.lock_and_signal } -%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_scheduler*, i32 } -%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %1, %struct.randctx, i32, %2, i32, i32, i32, %struct.rust_env* } -%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 } -%class.rust_obstack = type { %struct.rust_obstack_chunk*, %struct.rust_task* } -%class.rust_port = type { i32, i32, %class.rust_kernel*, %struct.rust_task*, i32, %class.circular_buffer, %class.lock_and_signal } -%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region } -%"class.rust_task::wakeup_callback" = type { i32 (...)** } -%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* } -%class.rust_thread = type { i32 (...)**, i8, %struct._opaque_pthread_t* } -%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_Rb_tree_impl" } -%"class.std::map" = type { %"class.std::_Rb_tree" } -%class.timer = type { i32 (...)**, i64, i64 } -%struct.UT_hash_bucket = type { %struct.UT_hash_handle*, i32, i32 } +%struct.type_desc = type { %struct.type_desc**, i32, i32, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, i8*, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, i32, void (i8*, i8*, %struct.type_desc**, i8*, i8*, i8)*, i8*, %struct.rust_shape_tables*, i32, i32, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] } +%struct.rust_shape_tables = type { i8*, i8* } %struct.UT_hash_handle = type { %struct.UT_hash_table*, i8*, i8*, %struct.UT_hash_handle*, %struct.UT_hash_handle*, i8*, i32, i32 } %struct.UT_hash_table = type { %struct.UT_hash_bucket*, i32, i32, i32, %struct.UT_hash_handle*, i32, i32, i32, i32, i32 } -%struct.__darwin_pthread_handler_rec = type { void (i8*)*, i8*, %struct.__darwin_pthread_handler_rec* } -%struct._opaque_pthread_attr_t = type { i32, [36 x i8] } -%struct._opaque_pthread_cond_t = type { i32, [24 x i8] } -%struct._opaque_pthread_mutex_t = type { i32, [40 x i8] } -%struct._opaque_pthread_t = type { i32, %struct.__darwin_pthread_handler_rec*, [596 x i8] } -%struct.chan_handle = type { i32, i32 } -%"struct.hash_map::map_entry" = type opaque -%"struct.hash_map::map_entry" = type opaque -%"struct.memory_region::alloc_header" = type { i8 } -%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 } -%struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32 } -%struct.rust_env = type { i32, i32, i8*, i8, i8, i8* } -%struct.rust_obstack_chunk = type { %struct.rust_obstack_chunk*, i32, i32, i32, [0 x i8] } -%struct.rust_scheduler = type { %class.rust_thread, i32, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i32, %struct._opaque_pthread_attr_t, %struct.rust_env*, %class.context } -%struct.rust_shape_tables = type { i8*, i8* } -%struct.rust_task = type { %struct.rust_task_user, i32, %class.context, %struct.rust_obstack_chunk*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %"struct.memory_region::alloc_header"*, i8*, %struct.rust_task*, i32, i32, %class.timer, i32*, %class.array_list, i32, i32, %class.memory_region, %"class.rust_task::wakeup_callback"*, i8, i8, i8, %class.lock_and_signal, %class.hash_map, %class.rust_obstack, %"class.std::map", i32, %"class.debug::task_debug_info" } -%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 } +%struct.UT_hash_bucket = type { %struct.UT_hash_handle*, i32, i32 } %struct.rust_vec = type { i32, i32, [0 x i8] } -%"struct.std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_Rb_tree_impl" = type { %"struct.memory_region::alloc_header", %"struct.std::_Rb_tree_node_base", i32 } +%class.rust_port = type { i32, i32, %class.rust_kernel*, %struct.rust_task*, i32, %class.circular_buffer, %class.lock_and_signal } +%class.rust_kernel = type { i32 (...)**, %class.memory_region, %class.rust_log, %class.rust_srv*, %class.lock_and_signal, %class.array_list.0, %struct.randctx, i32, %class.hash_map, i32, i32, i32, %struct.rust_env* } +%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %class.array_list, i8, i8, %class.lock_and_signal } +%class.rust_srv = type { i32 (...)**, %struct.rust_env*, %class.memory_region } +%struct.rust_env = type { i32, i32, i8*, i8, i8, i8* } +%class.array_list = type { i32, %"struct.memory_region::alloc_header"**, i32 } +%"struct.memory_region::alloc_header" = type { i8 } +%class.lock_and_signal = type { i32 (...)**, %union.pthread_cond_t, %union.pthread_mutex_t, i32, i8, i8 } +%union.pthread_cond_t = type { %struct.anon, [4 x i8] } +%struct.anon = type { i32, i32, i64, i64, i64, i8*, i32, i32 } +%union.pthread_mutex_t = type { %"struct.::__pthread_mutex_s" } +%"struct.::__pthread_mutex_s" = type { i32, i32, i32, i32, i32, %union.anon } +%union.anon = type { i32 } +%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8 } +%struct.rust_scheduler = type { %class.rust_thread, i32, i32, %class.rust_log, i32, %class.rust_srv*, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %class.rust_kernel*, i32, i32, %class.lock_and_signal, i32, %union.pthread_attr_t, %struct.rust_env*, %class.context } +%class.rust_thread = type { i32 (...)**, i8, i32 } +%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* } +%class.indexed_list = type { i32 (...)**, %class.array_list.2 } +%class.array_list.2 = type { i32, %struct.rust_task**, i32 } +%struct.rust_task = type { %struct.rust_task_user, i32, %class.context, %struct.stk_seg*, i32, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, %class.timer, i32*, i32, i32, %class.memory_region, %"class.rust_task::wakeup_callback"*, i8, i8, i8, %class.lock_and_signal, %class.hash_map.4, %class.rust_obstack, %"class.std::map", i32, %"class.debug::task_debug_info" } +%struct.rust_task_user = type { i32, i32, %struct.chan_handle, i32 } +%struct.chan_handle = type { i32, i32 } +%class.context = type { %struct.registers_t, %class.context* } +%struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32 } +%struct.stk_seg = type { %struct.stk_seg*, i32, i32, i32, [0 x i8] } +%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_scheduler*, i32 } +%struct.rust_cond = type { i8 } +%class.timer = type { i32 (...)**, i64, i64 } +%"class.rust_task::wakeup_callback" = type { i32 (...)** } +%class.hash_map.4 = type { %"struct.hash_map::map_entry"* } +%"struct.hash_map::map_entry" = type opaque +%class.rust_obstack = type { %struct.rust_obstack_chunk*, %struct.rust_task* } +%struct.rust_obstack_chunk = type { %struct.rust_obstack_chunk*, i32, i32, i32, [0 x i8] } +%"class.std::map" = type { %"class.std::_Rb_tree" } +%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_Rb_tree_impl" } +%"struct.std::_Rb_tree, std::_Select1st >, std::less, std::allocator > >::_Rb_tree_impl" = type { %"struct.std::less", %"struct.std::_Rb_tree_node_base", i32 } +%"struct.std::less" = type { i8 } %"struct.std::_Rb_tree_node_base" = type { i32, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"*, %"struct.std::_Rb_tree_node_base"* } -%struct.type_desc = type { %struct.type_desc**, i32, i32, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, i8*, void (i8*, i8*, %struct.type_desc**, i8*)*, void (i8*, i8*, %struct.type_desc**, i8*)*, i32, void (i8*, i8*, %struct.type_desc**, i8*, i8*, i8)*, i8*, %struct.rust_shape_tables*, i32, i32, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] } +%"class.debug::task_debug_info" = type { %"class.std::map.5" } +%"class.std::map.5" = type { %"class.std::_Rb_tree.6" } +%"class.std::_Rb_tree.6" = type { %"struct.std::_Rb_tree >, std::_Select1st > >, std::less, std::allocator > > >::_Rb_tree_impl" } +%"struct.std::_Rb_tree >, std::_Select1st > >, std::less, std::allocator > > >::_Rb_tree_impl" = type { %"struct.std::less", %"struct.std::_Rb_tree_node_base", i32 } +%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 } +%union.pthread_attr_t = type { i32, [32 x i8] } +%class.array_list.0 = type { i32, %struct.rust_scheduler**, i32 } +%class.hash_map = type { %"struct.hash_map::map_entry"* } +%"struct.hash_map::map_entry" = type opaque +%class.circular_buffer = type { %class.rust_kernel*, i32, i32, i32, i32, i8* } -@.str = private unnamed_addr constant [42 x i8] c"attempt to cast values of differing sizes\00" -@.str1 = private unnamed_addr constant [33 x i8] c"src/rt/intrinsics/intrinsics.cpp\00" +@.str = private unnamed_addr constant [42 x i8] c"attempt to cast values of differing sizes\00", align 1 +@.str1 = private unnamed_addr constant [33 x i8] c"src/rt/intrinsics/intrinsics.cpp\00", align 1 -define void @rust_intrinsic_2_vec_len(i32* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %vp) nounwind { - %1 = load %struct.rust_vec** %vp, align 4 +define void @rust_intrinsic_vec_len(i32* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %vp) nounwind { + %1 = load %struct.rust_vec** %vp, align 4, !tbaa !0 %2 = getelementptr inbounds %struct.rust_vec* %1, i32 0, i32 0 - %3 = load i32* %2, align 4 + %3 = load i32* %2, align 4, !tbaa !3 %4 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1 - %5 = load i32* %4, align 4 + %5 = load i32* %4, align 4, !tbaa !3 %6 = udiv i32 %3, %5 - store i32 %6, i32* %retptr, align 4 + store i32 %6, i32* %retptr, align 4, !tbaa !3 ret void } -define void @rust_intrinsic_2_ptr_offset(i8** nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind { +define void @rust_intrinsic_ptr_offset(i8** nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind { %1 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1 - %2 = load i32* %1, align 4 + %2 = load i32* %1, align 4, !tbaa !3 %3 = mul i32 %2, %count %4 = getelementptr inbounds i8* %ptr, i32 %3 - store i8* %4, i8** %retptr, align 4 + store i8* %4, i8** %retptr, align 4, !tbaa !0 ret void } -define void @rust_intrinsic_2_cast(i8* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) { +define void @rust_intrinsic_cast(i8* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) { %1 = getelementptr inbounds %struct.type_desc* %t1, i32 0, i32 1 - %2 = load i32* %1, align 4 + %2 = load i32* %1, align 4, !tbaa !3 %3 = getelementptr inbounds %struct.type_desc* %t2, i32 0, i32 1 - %4 = load i32* %3, align 4 + %4 = load i32* %3, align 4, !tbaa !3 %5 = icmp eq i32 %2, %4 br i1 %5, label %7, label %6 @@ -97,8 +104,74 @@ declare void @upcall_fail(i8*, i8*, i32) declare void @llvm.memmove.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind +define void @rust_intrinsic_addr_of(i8** nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, i8* %valptr) nounwind { + store i8* %valptr, i8** %retptr, align 4, !tbaa !0 + ret void +} + +define void @rust_intrinsic_recv(i8** %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, %class.rust_port* %port) { + %1 = bitcast i8** %retptr to i32* + tail call void @port_recv(i32* %1, %class.rust_port* %port) + ret void +} + +declare void @port_recv(i32*, %class.rust_port*) + +define void @rust_intrinsic_get_type_desc(i8** nocapture %retptr, i8* nocapture %env, %struct.type_desc* %ty) nounwind { + %ty.c = bitcast %struct.type_desc* %ty to i8* + store i8* %ty.c, i8** %retptr, align 4, !tbaa !0 + ret void +} + +define void @rust_intrinsic_task_sleep(i8** nocapture %retptr, i8* nocapture %env, i32 %time_in_us) { + tail call void @rust_task_sleep(i32 %time_in_us) + ret void +} + +declare void @rust_task_sleep(i32) + +define void @rust_intrinsic_2_vec_len(i32* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, %struct.rust_vec** nocapture %vp) nounwind { + %1 = load %struct.rust_vec** %vp, align 4, !tbaa !0 + %2 = getelementptr inbounds %struct.rust_vec* %1, i32 0, i32 0 + %3 = load i32* %2, align 4, !tbaa !3 + %4 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1 + %5 = load i32* %4, align 4, !tbaa !3 + %6 = udiv i32 %3, %5 + store i32 %6, i32* %retptr, align 4, !tbaa !3 + ret void +} + +define void @rust_intrinsic_2_ptr_offset(i8** nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind { + %1 = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1 + %2 = load i32* %1, align 4, !tbaa !3 + %3 = mul i32 %2, %count + %4 = getelementptr inbounds i8* %ptr, i32 %3 + store i8* %4, i8** %retptr, align 4, !tbaa !0 + ret void +} + +define void @rust_intrinsic_2_cast(i8* nocapture %retptr, i8* nocapture %env, %struct.type_desc* nocapture %t1, %struct.type_desc* nocapture %t2, i8* nocapture %src) { + %1 = getelementptr inbounds %struct.type_desc* %t1, i32 0, i32 1 + %2 = load i32* %1, align 4, !tbaa !3 + %3 = getelementptr inbounds %struct.type_desc* %t2, i32 0, i32 1 + %4 = load i32* %3, align 4, !tbaa !3 + %5 = icmp eq i32 %2, %4 + br i1 %5, label %7, label %6 + +;