Skip to content

Commit 2418569

Browse files
committed
---
yaml --- r: 142832 b: refs/heads/try2 c: 9735f33 h: refs/heads/master v: v3
1 parent 22e9414 commit 2418569

File tree

24 files changed

+145
-455
lines changed

24 files changed

+145
-455
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a1f4843895d1152527f94e73fc64bf744d97d255
8+
refs/heads/try2: 9735f339fe8397bdc55495ef5875982779461cd2
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/dist.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ PKG_FILES := \
1919
$(S)LICENSE-APACHE \
2020
$(S)LICENSE-MIT \
2121
$(S)AUTHORS.txt \
22+
$(S)CONTRIBUTING.md \
2223
$(S)README.md \
24+
$(S)RELEASES.txt \
2325
$(S)configure $(S)Makefile.in \
2426
$(S)man \
2527
$(S)doc \

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 37 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,11 @@ pub fn trans_trace(bcx: block, sp_opt: Option<span>, trace_str: @str) {
11021102
Call(bcx, ccx.upcalls.trace, args);
11031103
}
11041104

1105+
pub fn build_return(bcx: block) {
1106+
let _icx = push_ctxt("build_return");
1107+
Br(bcx, bcx.fcx.llreturn);
1108+
}
1109+
11051110
pub fn ignore_lhs(_bcx: block, local: &ast::local) -> bool {
11061111
match local.node.pat.node {
11071112
ast::pat_wild => true, _ => false
@@ -1359,42 +1364,6 @@ pub fn cleanup_and_leave(bcx: block,
13591364
}
13601365
}
13611366

1362-
pub fn cleanup_block(bcx: block, upto: Option<BasicBlockRef>) -> block{
1363-
let _icx = push_ctxt("cleanup_block");
1364-
let mut cur = bcx;
1365-
let mut bcx = bcx;
1366-
loop {
1367-
debug!("cleanup_block: %s", cur.to_str());
1368-
1369-
if bcx.sess().trace() {
1370-
trans_trace(
1371-
bcx, None,
1372-
(fmt!("cleanup_block(%s)", cur.to_str())).to_managed());
1373-
}
1374-
1375-
let mut cur_scope = cur.scope;
1376-
loop {
1377-
cur_scope = match cur_scope {
1378-
Some (inf) => {
1379-
bcx = trans_block_cleanups_(bcx, inf.cleanups.to_owned(), false);
1380-
inf.parent
1381-
}
1382-
None => break
1383-
}
1384-
}
1385-
1386-
match upto {
1387-
Some(bb) => { if cur.llbb == bb { break; } }
1388-
_ => ()
1389-
}
1390-
cur = match cur.parent {
1391-
Some(next) => next,
1392-
None => { assert!(upto.is_none()); break; }
1393-
};
1394-
}
1395-
bcx
1396-
}
1397-
13981367
pub fn cleanup_and_Br(bcx: block, upto: block, target: BasicBlockRef) {
13991368
let _icx = push_ctxt("cleanup_and_Br");
14001369
cleanup_and_leave(bcx, Some(upto.llbb), Some(target));
@@ -1557,7 +1526,7 @@ pub fn alloca_maybe_zeroed(cx: block, ty: Type, name: &str, zero: bool) -> Value
15571526
return llvm::LLVMGetUndef(ty.to_ref());
15581527
}
15591528
}
1560-
let initcx = base::raw_block(cx.fcx, false, cx.fcx.get_llstaticallocas());
1529+
let initcx = base::raw_block(cx.fcx, false, cx.fcx.llstaticallocas);
15611530
let p = Alloca(initcx, ty, name);
15621531
if zero { memzero(initcx, p, ty); }
15631532
p
@@ -1570,26 +1539,24 @@ pub fn arrayalloca(cx: block, ty: Type, v: ValueRef) -> ValueRef {
15701539
return llvm::LLVMGetUndef(ty.to_ref());
15711540
}
15721541
}
1573-
return ArrayAlloca(base::raw_block(cx.fcx, false, cx.fcx.get_llstaticallocas()), ty, v);
1542+
return ArrayAlloca(base::raw_block(cx.fcx, false, cx.fcx.llstaticallocas), ty, v);
15741543
}
15751544

15761545
pub struct BasicBlocks {
15771546
sa: BasicBlockRef,
1547+
rt: BasicBlockRef
15781548
}
15791549

1580-
pub fn mk_staticallocas_basic_block(llfn: ValueRef) -> BasicBlockRef {
1550+
// Creates the standard set of basic blocks for a function
1551+
pub fn mk_standard_basic_blocks(llfn: ValueRef) -> BasicBlocks {
15811552
unsafe {
15821553
let cx = task_llcx();
1583-
str::as_c_str("static_allocas",
1584-
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
1585-
}
1586-
}
1587-
1588-
pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
1589-
unsafe {
1590-
let cx = task_llcx();
1591-
str::as_c_str("return",
1592-
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
1554+
BasicBlocks {
1555+
sa: str::as_c_str("static_allocas",
1556+
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf)),
1557+
rt: str::as_c_str("return",
1558+
|buf| llvm::LLVMAppendBasicBlockInContext(cx, llfn, buf))
1559+
}
15931560
}
15941561
}
15951562

@@ -1601,7 +1568,7 @@ pub fn make_return_pointer(fcx: fn_ctxt, output_type: ty::t) -> ValueRef {
16011568
llvm::LLVMGetParam(fcx.llfn, 0)
16021569
} else {
16031570
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
1604-
alloca(raw_block(fcx, false, fcx.get_llstaticallocas()), lloutputtype,
1571+
alloca(raw_block(fcx, false, fcx.llstaticallocas), lloutputtype,
16051572
"__make_return_pointer")
16061573
}
16071574
}
@@ -1629,6 +1596,8 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16291596
id,
16301597
param_substs.repr(ccx.tcx));
16311598

1599+
let llbbs = mk_standard_basic_blocks(llfndecl);
1600+
16321601
let substd_output_type = match param_substs {
16331602
None => output_type,
16341603
Some(substs) => {
@@ -1642,9 +1611,9 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
16421611
llvm::LLVMGetUndef(Type::i8p().to_ref())
16431612
},
16441613
llretptr: None,
1645-
llstaticallocas: None,
1614+
llstaticallocas: llbbs.sa,
16461615
llloadenv: None,
1647-
llreturn: None,
1616+
llreturn: llbbs.rt,
16481617
llself: None,
16491618
personality: None,
16501619
loop_ret: None,
@@ -1788,24 +1757,16 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
17881757

17891758
// Ties up the llstaticallocas -> llloadenv -> lltop edges,
17901759
// and builds the return block.
1791-
pub fn finish_fn(fcx: fn_ctxt, lltop: BasicBlockRef, last_bcx: block) {
1760+
pub fn finish_fn(fcx: fn_ctxt, lltop: BasicBlockRef) {
17921761
let _icx = push_ctxt("finish_fn");
17931762
tie_up_header_blocks(fcx, lltop);
1794-
1795-
let ret_cx = match fcx.llreturn {
1796-
Some(llreturn) => {
1797-
if !last_bcx.terminated {
1798-
Br(last_bcx, llreturn);
1799-
}
1800-
raw_block(fcx, false, llreturn)
1801-
}
1802-
None => last_bcx
1803-
};
1804-
build_return_block(fcx, ret_cx);
1763+
build_return_block(fcx);
18051764
}
18061765

18071766
// Builds the return block for a function.
1808-
pub fn build_return_block(fcx: fn_ctxt, ret_cx: block) {
1767+
pub fn build_return_block(fcx: fn_ctxt) {
1768+
let ret_cx = raw_block(fcx, false, fcx.llreturn);
1769+
18091770
// Return the value if this function immediate; otherwise, return void.
18101771
if fcx.llretptr.is_some() && fcx.has_immediate_return_value {
18111772
Ret(ret_cx, Load(ret_cx, fcx.llretptr.get()))
@@ -1816,24 +1777,14 @@ pub fn build_return_block(fcx: fn_ctxt, ret_cx: block) {
18161777

18171778
pub fn tie_up_header_blocks(fcx: fn_ctxt, lltop: BasicBlockRef) {
18181779
let _icx = push_ctxt("tie_up_header_blocks");
1819-
let llnext = match fcx.llloadenv {
1780+
match fcx.llloadenv {
18201781
Some(ll) => {
1821-
unsafe {
1822-
llvm::LLVMMoveBasicBlockBefore(ll, lltop);
1823-
}
1782+
Br(raw_block(fcx, false, fcx.llstaticallocas), ll);
18241783
Br(raw_block(fcx, false, ll), lltop);
1825-
ll
18261784
}
1827-
None => lltop
1828-
};
1829-
match fcx.llstaticallocas {
1830-
Some(ll) => {
1831-
unsafe {
1832-
llvm::LLVMMoveBasicBlockBefore(ll, llnext);
1833-
}
1834-
Br(raw_block(fcx, false, ll), llnext);
1785+
None => {
1786+
Br(raw_block(fcx, false, fcx.llstaticallocas), lltop);
18351787
}
1836-
None => ()
18371788
}
18381789
}
18391790

@@ -1903,21 +1854,16 @@ pub fn trans_closure(ccx: @mut CrateContext,
19031854
}
19041855

19051856
finish(bcx);
1906-
match fcx.llreturn {
1907-
Some(llreturn) => cleanup_and_Br(bcx, bcx_top, llreturn),
1908-
None => bcx = cleanup_block(bcx, Some(bcx_top.llbb))
1909-
};
1857+
cleanup_and_Br(bcx, bcx_top, fcx.llreturn);
19101858

19111859
// Put return block after all other blocks.
19121860
// This somewhat improves single-stepping experience in debugger.
19131861
unsafe {
1914-
for fcx.llreturn.iter().advance |&llreturn| {
1915-
llvm::LLVMMoveBasicBlockAfter(llreturn, bcx.llbb);
1916-
}
1862+
llvm::LLVMMoveBasicBlockAfter(fcx.llreturn, bcx.llbb);
19171863
}
19181864

19191865
// Insert the mandatory first few basic blocks before lltop.
1920-
finish_fn(fcx, lltop, bcx);
1866+
finish_fn(fcx, lltop);
19211867
}
19221868

19231869
// trans_fn: creates an LLVM function corresponding to a source language
@@ -2100,7 +2046,8 @@ pub fn trans_enum_variant_or_tuple_like_struct<A:IdAndTy>(
21002046
let arg_ty = arg_tys[i];
21012047
memcpy_ty(bcx, lldestptr, llarg, arg_ty);
21022048
}
2103-
finish_fn(fcx, lltop, bcx);
2049+
build_return(bcx);
2050+
finish_fn(fcx, lltop);
21042051
}
21052052

21062053
pub fn trans_enum_def(ccx: @mut CrateContext, enum_definition: &ast::enum_def,
@@ -2341,7 +2288,8 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
23412288
let args = ~[llenvarg];
23422289
Call(bcx, main_llfn, args);
23432290

2344-
finish_fn(fcx, lltop, bcx);
2291+
build_return(bcx);
2292+
finish_fn(fcx, lltop);
23452293
return llfdecl;
23462294
}
23472295

branches/try2/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ pub fn trans_call_inner(in_cx: block,
704704
Store(bcx, C_bool(false), bcx.fcx.llretptr.get());
705705
}
706706
}
707-
base::cleanup_and_leave(bcx, None, Some(bcx.fcx.get_llreturn()));
707+
base::cleanup_and_leave(bcx, None, Some(bcx.fcx.llreturn));
708708
Unreachable(bcx);
709709
bcx
710710
}

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ pub struct fn_ctxt_ {
178178
// the function, due to LLVM's quirks.
179179
// A block for all the function's static allocas, so that LLVM
180180
// will coalesce them into a single alloca call.
181-
llstaticallocas: Option<BasicBlockRef>,
181+
llstaticallocas: BasicBlockRef,
182182
// A block containing code that copies incoming arguments to space
183183
// already allocated by code in one of the llallocas blocks.
184184
// (LLVM requires that arguments be copied to local allocas before
185185
// allowing most any operation to be performed on them.)
186186
llloadenv: Option<BasicBlockRef>,
187-
llreturn: Option<BasicBlockRef>,
187+
llreturn: BasicBlockRef,
188188
// The 'self' value currently in use in this function, if there
189189
// is one.
190190
//
@@ -251,21 +251,6 @@ impl fn_ctxt_ {
251251
}
252252
}
253253

254-
pub fn get_llstaticallocas(&mut self) -> BasicBlockRef {
255-
if self.llstaticallocas.is_none() {
256-
self.llstaticallocas = Some(base::mk_staticallocas_basic_block(self.llfn));
257-
}
258-
259-
self.llstaticallocas.get()
260-
}
261-
262-
pub fn get_llreturn(&mut self) -> BasicBlockRef {
263-
if self.llreturn.is_none() {
264-
self.llreturn = Some(base::mk_return_basic_block(self.llfn));
265-
}
266-
267-
self.llreturn.get()
268-
}
269254
}
270255

271256
pub type fn_ctxt = @mut fn_ctxt_;

branches/try2/src/librustc/middle/trans/controlflow.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ pub fn trans_if(bcx: block,
6767
expr::trans_to_datum(bcx, cond).to_result();
6868

6969
let then_bcx_in = scope_block(bcx, thn.info(), "then");
70+
let else_bcx_in = scope_block(bcx, els.info(), "else");
7071

7172
let cond_val = bool_to_i1(bcx, cond_val);
73+
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
74+
75+
debug!("then_bcx_in=%s, else_bcx_in=%s",
76+
then_bcx_in.to_str(), else_bcx_in.to_str());
7277

7378
let then_bcx_out = trans_block(then_bcx_in, thn, dest);
7479
let then_bcx_out = trans_block_cleanups(then_bcx_out,
@@ -78,10 +83,9 @@ pub fn trans_if(bcx: block,
7883
// because trans_expr will create another scope block
7984
// context for the block, but we've already got the
8085
// 'else' context
81-
let (else_bcx_in, next_bcx) = match els {
86+
let else_bcx_out = match els {
8287
Some(elexpr) => {
83-
let else_bcx_in = scope_block(bcx, els.info(), "else");
84-
let else_bcx_out = match elexpr.node {
88+
match elexpr.node {
8589
ast::expr_if(_, _, _) => {
8690
let elseif_blk = ast_util::block_from_expr(elexpr);
8791
trans_block(else_bcx_in, &elseif_blk, dest)
@@ -91,25 +95,14 @@ pub fn trans_if(bcx: block,
9195
}
9296
// would be nice to have a constraint on ifs
9397
_ => bcx.tcx().sess.bug("strange alternative in if")
94-
};
95-
let else_bcx_out = trans_block_cleanups(else_bcx_out,
96-
block_cleanups(else_bcx_in));
97-
98-
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
99-
}
100-
_ => {
101-
let next_bcx = sub_block(bcx, "next");
102-
Br(then_bcx_out, next_bcx.llbb);
103-
104-
(next_bcx, next_bcx)
98+
}
10599
}
100+
_ => else_bcx_in
106101
};
102+
let else_bcx_out = trans_block_cleanups(else_bcx_out,
103+
block_cleanups(else_bcx_in));
104+
return join_blocks(bcx, [then_bcx_out, else_bcx_out]);
107105

108-
debug!("then_bcx_in=%s, else_bcx_in=%s",
109-
then_bcx_in.to_str(), else_bcx_in.to_str());
110-
111-
CondBr(bcx, cond_val, then_bcx_in.llbb, else_bcx_in.llbb);
112-
next_bcx
113106
}
114107

115108
pub fn join_blocks(parent_bcx: block, in_cxs: &[block]) -> block {
@@ -286,7 +279,7 @@ pub fn trans_break_cont(bcx: block,
286279
// This is a return from a loop body block
287280
None => {
288281
Store(bcx, C_bool(!to_end), bcx.fcx.llretptr.get());
289-
cleanup_and_leave(bcx, None, Some(bcx.fcx.get_llreturn()));
282+
cleanup_and_leave(bcx, None, Some(bcx.fcx.llreturn));
290283
Unreachable(bcx);
291284
return bcx;
292285
}
@@ -335,7 +328,7 @@ pub fn trans_ret(bcx: block, e: Option<@ast::expr>) -> block {
335328
}
336329
_ => ()
337330
}
338-
cleanup_and_leave(bcx, None, Some(bcx.fcx.get_llreturn()));
331+
cleanup_and_leave(bcx, None, Some(bcx.fcx.llreturn));
339332
Unreachable(bcx);
340333
return bcx;
341334
}

0 commit comments

Comments
 (0)