Skip to content

Commit 38fa06b

Browse files
committed
Cleanup based on review by @nagisa
* We don't have SEH-based unwinding yet. For this reason we don't need operand bundles in MIR trans. * Refactored some uses of fcx. * Refactored some calls to `with_block`.
1 parent a9ab809 commit 38fa06b

File tree

5 files changed

+36
-67
lines changed

5 files changed

+36
-67
lines changed

src/librustc_trans/trans/cleanup.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx
740740
UnwindExit(val) => {
741741
// Generate a block that will resume unwinding to the
742742
// calling function
743-
let bcx = self.new_block("resume", None, None);
743+
let bcx = self.new_block("resume", None);
744744
match val {
745745
UnwindKind::LandingPad => {
746746
let addr = self.landingpad_alloca.get()
@@ -830,7 +830,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx
830830
let name = scope.block_name("clean");
831831
debug!("generating cleanups for {}", name);
832832

833-
let bcx_in = self.new_block(&name[..], None, None);
833+
let bcx_in = self.new_block(&name[..], None);
834834
let exit_label = label.start(bcx_in);
835835
let mut bcx_out = bcx_in;
836836
let len = scope.cleanups.len();
@@ -873,7 +873,7 @@ impl<'blk, 'tcx> CleanupHelperMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx
873873
Some(llbb) => return llbb,
874874
None => {
875875
let name = last_scope.block_name("unwind");
876-
pad_bcx = self.new_block(&name[..], None, None);
876+
pad_bcx = self.new_block(&name[..], None);
877877
last_scope.cached_landing_pad = Some(pad_bcx.llbb);
878878
}
879879
}

src/librustc_trans/trans/common.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -434,33 +434,28 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
434434

435435
pub fn new_block(&'a self,
436436
name: &str,
437-
opt_node_id: Option<ast::NodeId>,
438-
landing_pad: Option<LandingPad>)
437+
opt_node_id: Option<ast::NodeId>)
439438
-> Block<'a, 'tcx> {
440439
unsafe {
441440
let name = CString::new(name).unwrap();
442441
let llbb = llvm::LLVMAppendBasicBlockInContext(self.ccx.llcx(),
443442
self.llfn,
444443
name.as_ptr());
445-
let block = BlockS::new(llbb, opt_node_id, self);
446-
if let Some(landing_pad) = landing_pad {
447-
block.lpad.set(Some(self.lpad_arena.alloc(landing_pad)));
448-
}
449-
block
444+
BlockS::new(llbb, opt_node_id, self)
450445
}
451446
}
452447

453448
pub fn new_id_block(&'a self,
454449
name: &str,
455450
node_id: ast::NodeId)
456451
-> Block<'a, 'tcx> {
457-
self.new_block(name, Some(node_id), None)
452+
self.new_block(name, Some(node_id))
458453
}
459454

460455
pub fn new_temp_block(&'a self,
461456
name: &str)
462457
-> Block<'a, 'tcx> {
463-
self.new_block(name, None, None)
458+
self.new_block(name, None)
464459
}
465460

466461
pub fn join_blocks(&'a self,
@@ -759,10 +754,6 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
759754
self.bcx.llbb
760755
}
761756

762-
pub fn lpad(&self) -> Option<&'blk LandingPad> {
763-
self.bcx.lpad()
764-
}
765-
766757
pub fn mir(&self) -> &'blk Mir<'tcx> {
767758
self.bcx.mir()
768759
}

src/librustc_trans/trans/mir/block.rs

+18-29
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use trans::adt;
1616
use trans::attributes;
1717
use trans::base;
1818
use trans::build;
19-
use trans::common::{self, Block, BlockAndBuilder, LandingPad};
19+
use trans::common::{self, Block, BlockAndBuilder};
2020
use trans::debuginfo::DebugLoc;
2121
use trans::Disr;
2222
use trans::foreign;
@@ -119,16 +119,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
119119
if let Some(unwind) = unwind {
120120
let uwbcx = self.bcx(unwind);
121121
let unwind = self.make_landing_pad(uwbcx);
122-
let bundle = bcx.lpad().and_then(|b| b.bundle());
123122
bcx.invoke(drop_fn,
124123
&[llvalue],
125124
self.llblock(target),
126125
unwind.llbb(),
127-
bundle,
126+
None,
128127
None);
129128
} else {
130-
let bundle = bcx.lpad().and_then(|b| b.bundle());
131-
bcx.call(drop_fn, &[llvalue], bundle, None);
129+
bcx.call(drop_fn, &[llvalue], None, None);
132130
bcx.br(self.llblock(target));
133131
}
134132
}
@@ -190,28 +188,26 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
190188
let cleanup = self.bcx(cleanup);
191189
let landingpad = self.make_landing_pad(cleanup);
192190
let unreachable_blk = self.unreachable_block();
193-
let bundle = bcx.lpad().and_then(|b| b.bundle());
194191
bcx.invoke(callee.immediate(),
195192
&llargs[..],
196193
unreachable_blk.llbb,
197194
landingpad.llbb(),
198-
bundle,
195+
None,
199196
Some(attrs));
200197
},
201198
(false, false, &Some(cleanup), &Some((_, success))) => {
202199
let cleanup = self.bcx(cleanup);
203200
let landingpad = self.make_landing_pad(cleanup);
204201
let (target, postinvoke) = if must_copy_dest {
205-
(bcx.fcx().new_block("", None, None).build(), Some(self.bcx(success)))
202+
(bcx.fcx().new_block("", None).build(), Some(self.bcx(success)))
206203
} else {
207204
(self.bcx(success), None)
208205
};
209-
let bundle = bcx.lpad().and_then(|b| b.bundle());
210206
let invokeret = bcx.invoke(callee.immediate(),
211207
&llargs[..],
212208
target.llbb(),
213209
landingpad.llbb(),
214-
bundle,
210+
None,
215211
Some(attrs));
216212
if let Some(postinvoketarget) = postinvoke {
217213
// We translate the copy into a temporary block. The temporary block is
@@ -247,15 +243,13 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
247243
}
248244
},
249245
(false, _, _, &None) => {
250-
let bundle = bcx.lpad().and_then(|b| b.bundle());
251-
bcx.call(callee.immediate(), &llargs[..], bundle, Some(attrs));
246+
bcx.call(callee.immediate(), &llargs[..], None, Some(attrs));
252247
bcx.unreachable();
253248
}
254249
(false, _, _, &Some((_, target))) => {
255-
let bundle = bcx.lpad().and_then(|b| b.bundle());
256250
let llret = bcx.call(callee.immediate(),
257251
&llargs[..],
258-
bundle,
252+
None,
259253
Some(attrs));
260254
if must_copy_dest {
261255
let (ret_dest, ret_ty) = ret_dest_ty
@@ -294,40 +288,35 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
294288
slot
295289
} else {
296290
let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false);
297-
let slot = bcx.with_block(|bcx| {
298-
base::alloca(bcx, llretty, "personalityslot")
299-
});
300-
self.llpersonalityslot = Some(slot);
301291
bcx.with_block(|bcx| {
292+
let slot = base::alloca(bcx, llretty, "personalityslot");
293+
self.llpersonalityslot = Some(slot);
302294
base::call_lifetime_start(bcx, slot);
303-
});
304-
slot
295+
slot
296+
})
305297
}
306298
}
307299

308300
fn make_landing_pad(&mut self,
309301
cleanup: BlockAndBuilder<'bcx, 'tcx>)
310302
-> BlockAndBuilder<'bcx, 'tcx>
311303
{
312-
let cleanup_llbb = cleanup.llbb();
313-
let bcx = cleanup.map_block(|cleanup| {
314-
// FIXME(#30941) this doesn't handle msvc-style exceptions
315-
cleanup.fcx.new_block("cleanup", None, Some(LandingPad::gnu()))
316-
});
304+
// FIXME(#30941) this doesn't handle msvc-style exceptions
305+
let bcx = self.fcx.new_block("cleanup", None).build();
317306
let ccx = bcx.ccx();
318-
let llpersonality = bcx.fcx().eh_personality();
307+
let llpersonality = self.fcx.eh_personality();
319308
let llretty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false);
320-
let llretval = bcx.landing_pad(llretty, llpersonality, 1, bcx.fcx().llfn);
309+
let llretval = bcx.landing_pad(llretty, llpersonality, 1, self.fcx.llfn);
321310
bcx.set_cleanup(llretval);
322311
let slot = self.get_personality_slot(&bcx);
323312
bcx.store(llretval, slot);
324-
bcx.br(cleanup_llbb);
313+
bcx.br(cleanup.llbb());
325314
bcx
326315
}
327316

328317
fn unreachable_block(&mut self) -> Block<'bcx, 'tcx> {
329318
self.unreachable_block.unwrap_or_else(|| {
330-
let bl = self.fcx.new_block("unreachable", None, None);
319+
let bl = self.fcx.new_block("unreachable", None);
331320
bl.build().unreachable();
332321
self.unreachable_block = Some(bl);
333322
bl

src/librustc_trans/trans/mir/mod.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use llvm::{self, ValueRef};
1313
use rustc::mir::repr as mir;
1414
use rustc::mir::tcx::LvalueTy;
1515
use trans::base;
16-
use trans::common::{self, Block, BlockAndBuilder, LandingPad};
16+
use trans::common::{self, Block, BlockAndBuilder};
1717
use trans::expr;
1818
use trans::type_of;
1919

@@ -115,12 +115,7 @@ pub fn trans_mir<'bcx, 'tcx>(bcx: BlockAndBuilder<'bcx, 'tcx>) {
115115
mir_blocks.iter()
116116
.map(|&bb|{
117117
// FIXME(#30941) this doesn't handle msvc-style exceptions
118-
let lpad = if mir.basic_block_data(bb).is_cleanup {
119-
Some(LandingPad::gnu())
120-
} else {
121-
None
122-
};
123-
fcx.new_block(&format!("{:?}", bb), None, lpad)
118+
fcx.new_block(&format!("{:?}", bb), None)
124119
})
125120
.collect();
126121

@@ -175,11 +170,9 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
175170
let lldata = llvm::get_param(fcx.llfn, idx);
176171
let llextra = llvm::get_param(fcx.llfn, idx + 1);
177172
idx += 2;
178-
let lltemp = bcx.with_block(|bcx| {
179-
base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
180-
});
181-
let (dataptr, meta) = bcx.with_block(|bcx| {
182-
(expr::get_dataptr(bcx, lltemp), expr::get_meta(bcx, lltemp))
173+
let (lltemp, dataptr, meta) = bcx.with_block(|bcx| {
174+
let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index));
175+
(lltemp, expr::get_dataptr(bcx, lltemp), expr::get_meta(bcx, lltemp))
183176
});
184177
bcx.store(lldata, dataptr);
185178
bcx.store(llextra, meta);
@@ -189,13 +182,11 @@ fn arg_value_refs<'bcx, 'tcx>(bcx: &BlockAndBuilder<'bcx, 'tcx>,
189182
// temporary and store it there
190183
let llarg = llvm::get_param(fcx.llfn, idx);
191184
idx += 1;
192-
let lltemp = bcx.with_block(|bcx| {
193-
base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index))
194-
});
195185
bcx.with_block(|bcx| {
196-
base::store_ty(bcx, llarg, lltemp, arg_ty)
197-
});
198-
lltemp
186+
let lltemp = base::alloc_ty(bcx, arg_ty, &format!("arg{}", arg_index));
187+
base::store_ty(bcx, llarg, lltemp, arg_ty);
188+
lltemp
189+
})
199190
};
200191
LvalueRef::new_sized(llval, LvalueTy::from_ty(arg_ty))
201192
})

src/librustc_trans/trans/mir/rvalue.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,10 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
497497
if input_ty == tcx.types.f32 {
498498
let lllhs = bcx.fpext(lhs, f64t);
499499
let llrhs = bcx.fpext(rhs, f64t);
500-
let bundle = bcx.lpad().and_then(|b| b.bundle());
501-
let llres = bcx.call(llfn, &[lllhs, llrhs], bundle, None);
500+
let llres = bcx.call(llfn, &[lllhs, llrhs], None, None);
502501
bcx.fptrunc(llres, Type::f32(bcx.ccx()))
503502
} else {
504-
let bundle = bcx.lpad().and_then(|b| b.bundle());
505-
bcx.call(llfn, &[lhs, rhs], bundle, None)
503+
bcx.call(llfn, &[lhs, rhs], None, None)
506504
}
507505
} else {
508506
bcx.frem(lhs, rhs)

0 commit comments

Comments
 (0)