about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-07-07 15:18:07 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-07-07 15:18:07 -0700
commitdeca79f37256b359139822f0f8706ac7c3cce26f (patch)
treed56fcc4b2585d445ae1a1e1eabc3639de41fecec /src/comp
parent5547e5dd216f2b062809b52abff01b5baca0d6a0 (diff)
parentf6117173c9f26efdcf50cb664d006ea2bdf0d0cb (diff)
downloadrust-deca79f37256b359139822f0f8706ac7c3cce26f.tar.gz
rust-deca79f37256b359139822f0f8706ac7c3cce26f.zip
Merge pull request #634 from robarnold/upstream-stable
Allocate ivecs out of the kernel pool
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/back/upcall.rs15
-rw-r--r--src/comp/middle/trans.rs32
2 files changed, 39 insertions, 8 deletions
diff --git a/src/comp/back/upcall.rs b/src/comp/back/upcall.rs
index 5fad90ce031..db750fe7a6d 100644
--- a/src/comp/back/upcall.rs
+++ b/src/comp/back/upcall.rs
@@ -47,6 +47,8 @@ type upcalls =
         ValueRef exit,
         ValueRef malloc,
         ValueRef free,
+        ValueRef shared_malloc,
+        ValueRef shared_free,
         ValueRef mark,
         ValueRef new_str,
         ValueRef dup_str,
@@ -56,7 +58,9 @@ type upcalls =
         ValueRef new_task,
         ValueRef start_task,
         ValueRef ivec_resize,
-        ValueRef ivec_spill);
+        ValueRef ivec_spill,
+        ValueRef ivec_resize_shared,
+        ValueRef ivec_spill_shared);
 
 fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
     fn decl(type_names tn, ModuleRef llmod, str name, vec[TypeRef] tys,
@@ -97,6 +101,9 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
              malloc=d("malloc", [T_size_t(), T_ptr(T_tydesc(tn))],
                       T_ptr(T_i8())),
              free=dv("free", [T_ptr(T_i8()), T_int()]),
+             shared_malloc=d("shared_malloc",
+                      [T_size_t(), T_ptr(T_tydesc(tn))], T_ptr(T_i8())),
+             shared_free=dv("shared_free", [T_ptr(T_i8())]),
              mark=d("mark", [T_ptr(T_i8())], T_int()),
              new_str=d("new_str", [T_ptr(T_i8()), T_size_t()],
                        T_ptr(T_str())),
@@ -119,7 +126,11 @@ fn declare_upcalls(type_names tn, ModuleRef llmod) -> @upcalls {
              ivec_resize=d("ivec_resize", [T_ptr(T_opaque_ivec()), T_int()],
                            T_void()),
              ivec_spill=d("ivec_spill", [T_ptr(T_opaque_ivec()), T_int()],
-                          T_void()));
+                          T_void()),
+             ivec_resize_shared=d("ivec_resize_shared",
+                           [T_ptr(T_opaque_ivec()), T_int()], T_void()),
+             ivec_spill_shared=d("ivec_spill_shared",
+                          [T_ptr(T_opaque_ivec()), T_int()], T_void()));
 }
 //
 // Local Variables:
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 8f7f26e1693..61b677f058f 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -1186,6 +1186,12 @@ fn trans_non_gc_free(&@block_ctxt cx, ValueRef v) -> result {
     ret rslt(cx, C_int(0));
 }
 
+fn trans_shared_free(&@block_ctxt cx, ValueRef v) -> result {
+    cx.build.Call(cx.fcx.lcx.ccx.upcalls.shared_free,
+                  [cx.fcx.lltaskptr, cx.build.PointerCast(v, T_ptr(T_i8()))]);
+    ret rslt(cx, C_int(0));
+}
+
 fn find_scope_cx(&@block_ctxt cx) -> @block_ctxt {
     if (cx.kind != NON_SCOPE_BLOCK) { ret cx; }
     alt (cx.parent) {
@@ -1614,6 +1620,18 @@ fn trans_raw_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize) ->
     ret rslt(cx, cx.build.PointerCast(rval, llptr_ty));
 }
 
+// trans_shared_malloc: expects a type indicating which pointer type we want
+// and a size indicating how much space we want malloc'd.
+fn trans_shared_malloc(&@block_ctxt cx, TypeRef llptr_ty, ValueRef llsize) ->
+   result {
+    // FIXME: need a table to collect tydesc globals.
+
+    auto tydesc = C_null(T_ptr(T_tydesc(cx.fcx.lcx.ccx.tn)));
+    auto rval =
+        cx.build.Call(cx.fcx.lcx.ccx.upcalls.shared_malloc,
+                      [cx.fcx.lltaskptr, llsize, tydesc]);
+    ret rslt(cx, cx.build.PointerCast(rval, llptr_ty));
+}
 
 // trans_malloc_boxed: expects an unboxed type and returns a pointer to enough
 // space for something of that type, along with space for a reference count;
@@ -2133,7 +2151,7 @@ fn maybe_free_ivec_heap_part(&@block_ctxt cx, ValueRef v0, ty::t unit_ty) ->
             auto m = maybe_on_heap_cx.build.InBoundsGEP(stub_ptr, v);
             maybe_on_heap_cx.build.Load(m)
         };
-    auto after_free_cx = trans_non_gc_free(maybe_on_heap_cx, heap_ptr).bcx;
+    auto after_free_cx = trans_shared_free(maybe_on_heap_cx, heap_ptr).bcx;
     after_free_cx.build.Br(next_cx.llbb);
     ret rslt(next_cx, C_nil());
 }
@@ -3673,7 +3691,8 @@ mod ivec {
         {
             auto p =
                 heap_resize_cx.build.PointerCast(v, T_ptr(T_opaque_ivec()));
-            heap_resize_cx.build.Call(cx.fcx.lcx.ccx.upcalls.ivec_resize,
+            auto upcall = cx.fcx.lcx.ccx.upcalls.ivec_resize_shared;
+            heap_resize_cx.build.Call(upcall,
                                       [cx.fcx.lltaskptr, p, new_heap_len]);
         }
         auto heap_ptr_resize =
@@ -3713,7 +3732,8 @@ mod ivec {
         {
             auto p =
                 stack_spill_cx.build.PointerCast(v, T_ptr(T_opaque_ivec()));
-            stack_spill_cx.build.Call(cx.fcx.lcx.ccx.upcalls.ivec_spill,
+            auto upcall = cx.fcx.lcx.ccx.upcalls.ivec_spill_shared;
+            stack_spill_cx.build.Call(upcall,
                                       [cx.fcx.lltaskptr, p, new_stack_len]);
         }
         auto spill_stub =
@@ -3963,7 +3983,7 @@ mod ivec {
                             heap_cx.build.InBoundsGEP(stub_ptr_heap,
                                                       stub_a));
         auto heap_sz = heap_cx.build.Add(llsize_of(llheappartty), lllen);
-        auto rs = trans_raw_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
+        auto rs = trans_shared_malloc(heap_cx, T_ptr(llheappartty), heap_sz);
         auto heap_part = rs.val;
         heap_cx = rs.bcx;
         heap_cx.build.Store(heap_part,
@@ -4100,7 +4120,7 @@ mod ivec {
 
         auto heap_part_sz = on_heap_cx.build.Add(alen,
             llsize_of(T_opaque_ivec_heap_part()));
-        auto rs = trans_raw_malloc(on_heap_cx, T_ptr(llheappartty),
+        auto rs = trans_shared_malloc(on_heap_cx, T_ptr(llheappartty),
                                    heap_part_sz);
         on_heap_cx = rs.bcx;
         auto new_heap_ptr = rs.val;
@@ -6038,7 +6058,7 @@ fn trans_ivec(@block_ctxt bcx, &(@ast::expr)[] args, ast::node_id id) ->
             bcx.build.Store(lllen, bcx.build.InBoundsGEP(llstubptr, stub_a));
 
             auto llheapsz = bcx.build.Add(llsize_of(llheapty), lllen);
-            auto rslt = trans_raw_malloc(bcx, T_ptr(llheapty), llheapsz);
+            auto rslt = trans_shared_malloc(bcx, T_ptr(llheapty), llheapsz);
             bcx = rslt.bcx;
             auto llheapptr = rslt.val;
             bcx.build.Store(llheapptr,