Skip to content

Commit 13d0853

Browse files
committed
---
yaml --- r: 3758 b: refs/heads/master c: aa0f6f4 h: refs/heads/master v: v3
1 parent 2790188 commit 13d0853

File tree

5 files changed

+49
-24
lines changed

5 files changed

+49
-24
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7498d036935b9a7cbf651765783cbf92fa3e0f09
2+
refs/heads/master: aa0f6f49610962466972e659605e3c8e676ce7b5

trunk/src/lib/ptr.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Unsafe pointer utility functions.
2+
3+
native "rust-intrinsic" mod rusti {
4+
fn ptr_offset[T](*T ptr, uint count) -> *T;
5+
}
6+
7+
fn offset[T](*T ptr, uint count) -> *T { ret rusti::ptr_offset(ptr, count); }
8+

trunk/src/lib/std.rc

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ mod getopts;
8686
mod term;
8787
mod time;
8888
mod smallintmap;
89+
mod ptr;
8990

9091
// Local Variables:
9192
// mode: rust;

trunk/src/rt/intrinsics/intrinsics.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Use `clang++ -emit-llvm -S -arch i386 -O3 -I../isaac -I../uthash
2-
// -I../arch/i386 -o intrinsics.ll intrinsics.cpp`
2+
// -I../arch/i386 -fno-stack-protector -o intrinsics.ll intrinsics.cpp`
33

44
#include "../rust_internal.h"
55

@@ -22,3 +22,10 @@ rust_intrinsic_ivec_len(rust_task *task, type_desc *ty, rust_ivec *v)
2222
return fill / ty->size;
2323
}
2424

25+
extern "C" void *
26+
rust_intrinsic_ptr_offset(rust_task *task, type_desc *ty, void *ptr,
27+
uintptr_t count)
28+
{
29+
return &((uint8_t *)ptr)[ty->size * count];
30+
}
31+

trunk/src/rt/intrinsics/intrinsics.ll.in

+31-22
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@ target triple = "@CFG_LLVM_TRIPLE@"
44

55
%0 = type { i32, i8**, i32 }
66
%1 = type { i32, %struct.rust_task**, i32 }
7-
%2 = type { %"struct.hash_map<rust_task *, rust_handle<rust_task> *>::map_entry"* }
8-
%3 = type { %"struct.hash_map<rust_port *, rust_handle<rust_port> *>::map_entry"* }
9-
%4 = type { %"struct.hash_map<rust_dom *, rust_handle<rust_dom> *>::map_entry"* }
7+
%2 = type { %"struct.hash_map<rust_port *, rust_handle<rust_port> *>::map_entry"* }
8+
%3 = type { %"struct.hash_map<rust_scheduler *, rust_handle<rust_scheduler> *>::map_entry"* }
9+
%4 = type { i32, %class.rust_task_thread**, i32 }
1010
%5 = type { i32 (...)**, %6 }
11-
%6 = type { i32, %struct.rust_dom**, i32 }
12-
%7 = type { i32 (...)**, %8 }
13-
%8 = type { i32, %class.rust_message_queue**, i32 }
14-
%9 = type opaque
15-
%10 = type opaque
16-
%11 = type { %"struct.hash_map<rust_port *, rust_proxy<rust_port> *>::map_entry"* }
11+
%6 = type { i32, %class.rust_message_queue**, i32 }
12+
%7 = type opaque
13+
%8 = type opaque
14+
%9 = type { %"struct.hash_map<rust_task *, rust_proxy<rust_task> *>::map_entry"* }
15+
%10 = type { %"struct.hash_map<rust_port *, rust_proxy<rust_port> *>::map_entry"* }
1716
%class.array_list = type { i32, %struct.maybe_proxy**, i32 }
1817
%class.context = type { %struct.registers_t, %class.context* }
19-
%class.hash_map = type { %"struct.hash_map<rust_task *, rust_proxy<rust_task> *>::map_entry"* }
18+
%class.hash_map = type { %"struct.hash_map<rust_task *, rust_handle<rust_task> *>::map_entry"* }
2019
%class.indexed_list = type { i32 (...)**, %1 }
21-
%class.lock_and_signal = type { i32 (...)**, %struct._opaque_pthread_cond_t, %struct._opaque_pthread_mutex_t }
20+
%class.lock_and_signal = type { i32 (...)**, %struct._opaque_pthread_cond_t, %struct._opaque_pthread_mutex_t, %struct._opaque_pthread_t*, i8 }
2221
%class.lock_free_queue = type { i32 (...)**, %"struct.lock_free_queue<rust_message *>::pointer_t", %"struct.lock_free_queue<rust_message *>::pointer_t" }
2322
%class.memory_region = type { i32 (...)**, %class.rust_srv*, %class.memory_region*, i32, %0, i8, i8, %class.lock_and_signal }
24-
%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_dom*, i32 }
23+
%class.rust_crate_cache = type { %struct.type_desc*, %struct.rust_scheduler*, i32 }
2524
%class.rust_handle = type opaque
26-
%class.rust_kernel = type { %class.rust_thread, %class.memory_region*, %class.rust_log, %class.rust_srv*, %2, %3, %4, i8, %class.lock_and_signal, %5, %7 }
27-
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_dom*, i8, i8 }
28-
%class.rust_message_queue = type { %class.lock_free_queue, %class.memory_region, %class.rust_kernel*, %10*, i32 }
29-
%class.rust_srv = type { i32 (...)**, %class.memory_region, %class.memory_region }
30-
%class.rust_task_list = type { %class.indexed_list, %struct.rust_dom*, i8* }
25+
%class.rust_kernel = type { %class.rust_thread, %class.memory_region*, %class.rust_log, %class.rust_srv*, %class.hash_map, %2, %3, i8, %class.lock_and_signal, %4, %struct.rust_scheduler*, %class.lock_and_signal, %5 }
26+
%class.rust_log = type { i32 (...)**, %class.rust_srv*, %struct.rust_scheduler*, i8, i8 }
27+
%class.rust_message_queue = type { %class.lock_free_queue, %class.memory_region, %class.rust_kernel*, %8*, i32 }
28+
%class.rust_srv = type { i32 (...)**, %class.memory_region }
29+
%"class.rust_task::wakeup_callback" = type { i32 (...)** }
30+
%class.rust_task_list = type { %class.indexed_list, %struct.rust_scheduler*, i8* }
31+
%class.rust_task_thread = type { %class.rust_thread, i32, %class.rust_kernel* }
3132
%class.rust_thread = type { i32 (...)**, i8, %struct._opaque_pthread_t* }
3233
%class.timer = type { i32 (...)**, i64, i64 }
3334
%struct.UT_hash_bucket = type { %struct.UT_hash_handle*, i32, i32 }
@@ -39,23 +40,22 @@ target triple = "@CFG_LLVM_TRIPLE@"
3940
%struct._opaque_pthread_mutex_t = type { i32, [40 x i8] }
4041
%struct._opaque_pthread_t = type { i32, %struct.__darwin_pthread_handler_rec*, [596 x i8] }
4142
%struct.gc_alloc = type { %struct.gc_alloc*, %struct.gc_alloc*, i32, [0 x i8] }
42-
%"struct.hash_map<rust_dom *, rust_handle<rust_dom> *>::map_entry" = type opaque
4343
%"struct.hash_map<rust_port *, rust_handle<rust_port> *>::map_entry" = type opaque
4444
%"struct.hash_map<rust_port *, rust_proxy<rust_port> *>::map_entry" = type opaque
45+
%"struct.hash_map<rust_scheduler *, rust_handle<rust_scheduler> *>::map_entry" = type opaque
4546
%"struct.hash_map<rust_task *, rust_handle<rust_task> *>::map_entry" = type opaque
4647
%"struct.hash_map<rust_task *, rust_proxy<rust_task> *>::map_entry" = type opaque
47-
%"struct.lock_free_queue<rust_message *>::node_t" = type { %9*, %"struct.lock_free_queue<rust_message *>::pointer_t" }
48+
%"struct.lock_free_queue<rust_message *>::node_t" = type { %7*, %"struct.lock_free_queue<rust_message *>::pointer_t" }
4849
%"struct.lock_free_queue<rust_message *>::pointer_t" = type { %"struct.lock_free_queue<rust_message *>::node_t"*, i32 }
4950
%struct.maybe_proxy = type { %struct.rc_base, %struct.rust_task* }
5051
%struct.randctx = type { i32, [256 x i32], [256 x i32], i32, i32, i32 }
5152
%struct.rc_base = type { i32 }
5253
%struct.registers_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, i16, i32, i32 }
53-
%struct.rust_alarm = type { %struct.rust_task*, i32 }
5454
%struct.rust_cond = type { i8 }
55-
%struct.rust_dom = type { %struct.rc_base, i32, %class.rust_log, i32, %class.rust_srv*, %class.memory_region, %class.memory_region, i8*, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_task_list, %class.rust_crate_cache, %struct.randctx, %struct.rust_task*, %struct.rust_task*, i32, %class.rust_kernel*, i32, %class.hash_map, %11, %class.rust_message_queue*, %struct._opaque_pthread_attr_t }
5655
%struct.rust_ivec = type { i32, i32, %union.rust_ivec_payload }
5756
%struct.rust_ivec_heap = type { i32, [0 x i8] }
58-
%struct.rust_task = type { %struct.maybe_proxy, %struct.stk_seg*, i32, i32, %struct.gc_alloc*, %struct.rust_dom*, %class.rust_crate_cache*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32, %class.timer, i32*, %class.array_list, %struct.rust_alarm, %class.rust_handle*, %class.context }
57+
%struct.rust_scheduler = type { %struct.rc_base, 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, %struct.rust_task*, %struct.rust_task*, i32, %class.rust_kernel*, i32, %9, %10, %class.rust_message_queue*, %struct._opaque_pthread_attr_t }
58+
%struct.rust_task = type { %struct.maybe_proxy, %struct.stk_seg*, i32, i32, %struct.gc_alloc*, %struct.rust_scheduler*, %class.rust_crate_cache*, %class.rust_kernel*, i8*, %class.rust_task_list*, %struct.rust_cond*, i8*, %struct.rust_task*, i32, i32, i32, %class.timer, i32*, %class.array_list, %class.rust_handle*, %class.context, i32, i32, %class.memory_region, %"class.rust_task::wakeup_callback"*, %class.lock_and_signal }
5959
%struct.rust_vec = type { %struct.rc_base, i32, i32, i32, [0 x i8] }
6060
%struct.stk_seg = type { i32, i32, [0 x i8] }
6161
%struct.type_desc = type { %struct.type_desc**, i32, i32, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*)*, i32, void (i8*, %struct.rust_task*, i8*, %struct.type_desc**, i8*, i8*, i8)*, %struct.UT_hash_handle, i32, [0 x %struct.type_desc*] }
@@ -97,6 +97,15 @@ if.end17: ; preds = %if.else, %entry, %i
9797
ret i32 %div
9898
}
9999

100+
define linkonce_odr i8* @rust_intrinsic_ptr_offset(%struct.rust_task* nocapture %task, %struct.type_desc* nocapture %ty, i8* %ptr, i32 %count) nounwind readonly {
101+
entry:
102+
%size = getelementptr inbounds %struct.type_desc* %ty, i32 0, i32 1
103+
%tmp1 = load i32* %size, align 4, !tbaa !0
104+
%mul = mul i32 %tmp1, %count
105+
%arrayidx = getelementptr inbounds i8* %ptr, i32 %mul
106+
ret i8* %arrayidx
107+
}
108+
100109
!0 = metadata !{metadata !"long", metadata !1}
101110
!1 = metadata !{metadata !"omnipotent char", metadata !2}
102111
!2 = metadata !{metadata !"Simple C/C++ TBAA", null}

0 commit comments

Comments
 (0)