Skip to content

Commit 66279d1

Browse files
committed
Revert back to using FunctionCx's Body
1 parent 16952cc commit 66279d1

File tree

7 files changed

+118
-147
lines changed

7 files changed

+118
-147
lines changed

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
245245
if let Some(index) = place.as_local() {
246246
self.assign(index, location);
247247
let decl_span = self.fx.mir.local_decls[index].source_info.span;
248-
if !self.fx.rvalue_creates_operand(rvalue, decl_span, self.fx.mir) {
248+
if !self.fx.rvalue_creates_operand(rvalue, decl_span) {
249249
self.not_ssa(index);
250250
}
251251
} else {

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 67 additions & 86 deletions
Large diffs are not rendered by default.

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
178178

179179
// Allocate variable and temp allocas
180180
fx.locals = {
181-
let args = arg_local_refs(&mut bx, &fx, &mir, &memory_locals);
181+
let args = arg_local_refs(&mut bx, &fx, &memory_locals);
182182

183183
let mut allocate_local = |local| {
184184
let decl = &mir.local_decls[local];
@@ -232,7 +232,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
232232
// Codegen the body of each block using reverse postorder
233233
for (bb, _) in rpo {
234234
visited.insert(bb.index());
235-
fx.codegen_block(bb, &mir);
235+
fx.codegen_block(bb);
236236
}
237237

238238
// Remove blocks that haven't been visited, or have no
@@ -321,16 +321,15 @@ fn create_funclets<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
321321
fn arg_local_refs<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
322322
bx: &mut Bx,
323323
fx: &FunctionCx<'a, 'b, 'tcx, Bx>,
324-
mir: &Body<'tcx>,
325324
memory_locals: &BitSet<mir::Local>,
326325
) -> Vec<LocalRef<'tcx, Bx::Value>> {
327326
let mut idx = 0;
328327
let mut llarg_idx = fx.fn_abi.ret.is_indirect() as usize;
329328

330-
mir.args_iter().enumerate().map(|(arg_index, local)| {
331-
let arg_decl = &mir.local_decls[local];
329+
fx.mir.args_iter().enumerate().map(|(arg_index, local)| {
330+
let arg_decl = &fx.mir.local_decls[local];
332331

333-
if Some(local) == mir.spread_arg {
332+
if Some(local) == fx.mir.spread_arg {
334333
// This argument (e.g., the last argument in the "rust-call" ABI)
335334
// is a tuple that was spread at the ABI level and now we have
336335
// to reconstruct it into a tuple local variable, from multiple

src/librustc_codegen_ssa/mir/operand.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::glue;
77
use crate::traits::*;
88

99
use rustc::mir::interpret::{ConstValue, ErrorHandled, Pointer, Scalar};
10-
use rustc::mir::{self, Body};
10+
use rustc::mir;
1111
use rustc::ty;
1212
use rustc::ty::layout::{self, Align, LayoutOf, TyLayout, Size};
1313

@@ -428,13 +428,12 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
428428

429429
pub fn codegen_consume(
430430
&mut self,
431-
mir: &Body<'tcx>,
432431
bx: &mut Bx,
433432
place_ref: &mir::PlaceRef<'_, 'tcx>
434433
) -> OperandRef<'tcx, Bx::Value> {
435434
debug!("codegen_consume(place_ref={:?})", place_ref);
436435

437-
let ty = self.monomorphized_place_ty(place_ref, mir);
436+
let ty = self.monomorphized_place_ty(place_ref);
438437
let layout = bx.cx().layout_of(ty);
439438

440439
// ZSTs don't require any actual memory access.
@@ -448,13 +447,12 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
448447

449448
// for most places, to consume them we just load them
450449
// out from their home
451-
let place = self.codegen_place(mir, bx, place_ref);
450+
let place = self.codegen_place(bx, place_ref);
452451
bx.load_operand(place)
453452
}
454453

455454
pub fn codegen_operand(
456455
&mut self,
457-
mir: &Body<'tcx>,
458456
bx: &mut Bx,
459457
operand: &mir::Operand<'tcx>
460458
) -> OperandRef<'tcx, Bx::Value> {
@@ -463,7 +461,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
463461
match *operand {
464462
mir::Operand::Copy(ref place) |
465463
mir::Operand::Move(ref place) => {
466-
self.codegen_consume(mir, bx, &place.as_ref())
464+
self.codegen_consume(bx, &place.as_ref())
467465
}
468466

469467
mir::Operand::Constant(ref constant) => {

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::traits::*;
88

99
use rustc::ty::{self, Instance, Ty};
1010
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
11-
use rustc::mir::{self, Body};
11+
use rustc::mir;
1212
use rustc::mir::tcx::PlaceTy;
1313

1414
#[derive(Copy, Clone, Debug)]
@@ -438,7 +438,6 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
438438
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
439439
pub fn codegen_place(
440440
&mut self,
441-
mir: &Body<'tcx>,
442441
bx: &mut Bx,
443442
place_ref: &mir::PlaceRef<'_, 'tcx>
444443
) -> PlaceRef<'tcx, Bx::Value> {
@@ -519,7 +518,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
519518
projection: [proj_base @ .., mir::ProjectionElem::Deref],
520519
} => {
521520
// Load the pointer from its location.
522-
self.codegen_consume(mir, bx, &mir::PlaceRef {
521+
self.codegen_consume(bx, &mir::PlaceRef {
523522
base,
524523
projection: proj_base,
525524
}).deref(bx.cx())
@@ -529,7 +528,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
529528
projection: [proj_base @ .., elem],
530529
} => {
531530
// FIXME turn this recursion into iteration
532-
let cg_base = self.codegen_place(mir, bx, &mir::PlaceRef {
531+
let cg_base = self.codegen_place(bx, &mir::PlaceRef {
533532
base,
534533
projection: proj_base,
535534
});
@@ -543,7 +542,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
543542
let index = &mir::Operand::Copy(
544543
mir::Place::from(*index)
545544
);
546-
let index = self.codegen_operand(mir, bx, index);
545+
let index = self.codegen_operand(bx, index);
547546
let llindex = index.immediate();
548547
cg_base.project_index(bx, llindex)
549548
}
@@ -590,9 +589,9 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
590589
result
591590
}
592591

593-
pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>, mir: &Body<'tcx>) -> Ty<'tcx> {
592+
pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
594593
let tcx = self.cx.tcx();
595-
let place_ty = mir::Place::ty_from(place_ref.base, place_ref.projection, mir, tcx);
594+
let place_ty = mir::Place::ty_from(place_ref.base, place_ref.projection, self.mir, tcx);
596595
self.monomorphize(&place_ty.ty)
597596
}
598597
}

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::traits::*;
1010
use rustc::ty::{self, Ty, adjustment::{PointerCast}, Instance};
1111
use rustc::ty::cast::{CastTy, IntTy};
1212
use rustc::ty::layout::{self, LayoutOf, HasTyCtxt};
13-
use rustc::mir::{self, Body};
13+
use rustc::mir;
1414
use rustc::middle::lang_items::ExchangeMallocFnLangItem;
1515
use rustc_apfloat::{ieee, Float, Status, Round};
1616
use syntax::symbol::sym;
@@ -21,7 +21,6 @@ use std::{u128, i128};
2121
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
2222
pub fn codegen_rvalue(
2323
&mut self,
24-
mir: &Body<'tcx>,
2524
mut bx: Bx,
2625
dest: PlaceRef<'tcx, Bx::Value>,
2726
rvalue: &mir::Rvalue<'tcx>
@@ -31,7 +30,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
3130

3231
match *rvalue {
3332
mir::Rvalue::Use(ref operand) => {
34-
let cg_operand = self.codegen_operand(mir, &mut bx, operand);
33+
let cg_operand = self.codegen_operand(&mut bx, operand);
3534
// FIXME: consider not copying constants through stack. (Fixable by codegen'ing
3635
// constants into `OperandValue::Ref`; why don’t we do that yet if we don’t?)
3736
cg_operand.val.store(&mut bx, dest);
@@ -44,7 +43,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
4443
if bx.cx().is_backend_scalar_pair(dest.layout) {
4544
// Into-coerce of a thin pointer to a fat pointer -- just
4645
// use the operand path.
47-
let (mut bx, temp) = self.codegen_rvalue_operand(mir, bx, rvalue);
46+
let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue);
4847
temp.val.store(&mut bx, dest);
4948
return bx;
5049
}
@@ -53,7 +52,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
5352
// this to be eliminated by MIR building, but
5453
// `CoerceUnsized` can be passed by a where-clause,
5554
// so the (generic) MIR may not be able to expand it.
56-
let operand = self.codegen_operand(mir, &mut bx, source);
55+
let operand = self.codegen_operand(&mut bx, source);
5756
match operand.val {
5857
OperandValue::Pair(..) |
5958
OperandValue::Immediate(_) => {
@@ -82,7 +81,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
8281
}
8382

8483
mir::Rvalue::Repeat(ref elem, count) => {
85-
let cg_elem = self.codegen_operand(mir, &mut bx, elem);
84+
let cg_elem = self.codegen_operand(&mut bx, elem);
8685

8786
// Do not generate the loop for zero-sized elements or empty arrays.
8887
if dest.layout.is_zst() {
@@ -125,7 +124,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
125124
_ => (dest, None)
126125
};
127126
for (i, operand) in operands.iter().enumerate() {
128-
let op = self.codegen_operand(mir, &mut bx, operand);
127+
let op = self.codegen_operand(&mut bx, operand);
129128
// Do not generate stores and GEPis for zero-sized fields.
130129
if !op.layout.is_zst() {
131130
let field_index = active_field_index.unwrap_or(i);
@@ -137,8 +136,8 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
137136
}
138137

139138
_ => {
140-
assert!(self.rvalue_creates_operand(rvalue, DUMMY_SP, mir));
141-
let (mut bx, temp) = self.codegen_rvalue_operand(mir, bx, rvalue);
139+
assert!(self.rvalue_creates_operand(rvalue, DUMMY_SP));
140+
let (mut bx, temp) = self.codegen_rvalue_operand(bx, rvalue);
142141
temp.val.store(&mut bx, dest);
143142
bx
144143
}
@@ -147,7 +146,6 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
147146

148147
pub fn codegen_rvalue_unsized(
149148
&mut self,
150-
mir: &Body<'tcx>,
151149
mut bx: Bx,
152150
indirect_dest: PlaceRef<'tcx, Bx::Value>,
153151
rvalue: &mir::Rvalue<'tcx>,
@@ -157,7 +155,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
157155

158156
match *rvalue {
159157
mir::Rvalue::Use(ref operand) => {
160-
let cg_operand = self.codegen_operand(mir, &mut bx, operand);
158+
let cg_operand = self.codegen_operand(&mut bx, operand);
161159
cg_operand.val.store_unsized(&mut bx, indirect_dest);
162160
bx
163161
}
@@ -168,19 +166,18 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
168166

169167
pub fn codegen_rvalue_operand(
170168
&mut self,
171-
mir: &Body<'tcx>,
172169
mut bx: Bx,
173170
rvalue: &mir::Rvalue<'tcx>
174171
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
175172
assert!(
176-
self.rvalue_creates_operand(rvalue, DUMMY_SP, mir),
173+
self.rvalue_creates_operand(rvalue, DUMMY_SP),
177174
"cannot codegen {:?} to operand",
178175
rvalue,
179176
);
180177

181178
match *rvalue {
182179
mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => {
183-
let operand = self.codegen_operand(mir, &mut bx, source);
180+
let operand = self.codegen_operand(&mut bx, source);
184181
debug!("cast operand is {:?}", operand);
185182
let cast = bx.cx().layout_of(self.monomorphize(&mir_cast_ty));
186183

@@ -373,7 +370,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
373370
}
374371

375372
mir::Rvalue::Ref(_, bk, ref place) => {
376-
let cg_place = self.codegen_place(mir, &mut bx, &place.as_ref());
373+
let cg_place = self.codegen_place(&mut bx, &place.as_ref());
377374

378375
let ty = cg_place.layout.ty;
379376

@@ -394,7 +391,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
394391
}
395392

396393
mir::Rvalue::Len(ref place) => {
397-
let size = self.evaluate_array_len(mir, &mut bx, place);
394+
let size = self.evaluate_array_len(&mut bx, place);
398395
let operand = OperandRef {
399396
val: OperandValue::Immediate(size),
400397
layout: bx.cx().layout_of(bx.tcx().types.usize),
@@ -403,8 +400,8 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
403400
}
404401

405402
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
406-
let lhs = self.codegen_operand(mir, &mut bx, lhs);
407-
let rhs = self.codegen_operand(mir, &mut bx, rhs);
403+
let lhs = self.codegen_operand(&mut bx, lhs);
404+
let rhs = self.codegen_operand(&mut bx, rhs);
408405
let llresult = match (lhs.val, rhs.val) {
409406
(OperandValue::Pair(lhs_addr, lhs_extra),
410407
OperandValue::Pair(rhs_addr, rhs_extra)) => {
@@ -429,8 +426,8 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
429426
(bx, operand)
430427
}
431428
mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
432-
let lhs = self.codegen_operand(mir, &mut bx, lhs);
433-
let rhs = self.codegen_operand(mir, &mut bx, rhs);
429+
let lhs = self.codegen_operand(&mut bx, lhs);
430+
let rhs = self.codegen_operand(&mut bx, rhs);
434431
let result = self.codegen_scalar_checked_binop(&mut bx, op,
435432
lhs.immediate(), rhs.immediate(),
436433
lhs.layout.ty);
@@ -445,7 +442,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
445442
}
446443

447444
mir::Rvalue::UnaryOp(op, ref operand) => {
448-
let operand = self.codegen_operand(mir, &mut bx, operand);
445+
let operand = self.codegen_operand(&mut bx, operand);
449446
let lloperand = operand.immediate();
450447
let is_float = operand.layout.ty.is_floating_point();
451448
let llval = match op {
@@ -463,8 +460,8 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
463460
}
464461

465462
mir::Rvalue::Discriminant(ref place) => {
466-
let discr_ty = rvalue.ty(mir, bx.tcx());
467-
let discr = self.codegen_place(mir, &mut bx, &place.as_ref())
463+
let discr_ty = rvalue.ty(self.mir, bx.tcx());
464+
let discr = self.codegen_place(&mut bx, &place.as_ref())
468465
.codegen_get_discr(&mut bx, discr_ty);
469466
(bx, OperandRef {
470467
val: OperandValue::Immediate(discr),
@@ -509,14 +506,14 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
509506
(bx, operand)
510507
}
511508
mir::Rvalue::Use(ref operand) => {
512-
let operand = self.codegen_operand(mir, &mut bx, operand);
509+
let operand = self.codegen_operand(&mut bx, operand);
513510
(bx, operand)
514511
}
515512
mir::Rvalue::Repeat(..) |
516513
mir::Rvalue::Aggregate(..) => {
517514
// According to `rvalue_creates_operand`, only ZST
518515
// aggregate rvalues are allowed to be operands.
519-
let ty = rvalue.ty(mir, self.cx.tcx());
516+
let ty = rvalue.ty(self.mir, self.cx.tcx());
520517
let operand = OperandRef::new_zst(
521518
&mut bx,
522519
self.cx.layout_of(self.monomorphize(&ty)),
@@ -528,7 +525,6 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
528525

529526
fn evaluate_array_len(
530527
&mut self,
531-
mir: &Body<'tcx>,
532528
bx: &mut Bx,
533529
place: &mir::Place<'tcx>,
534530
) -> Bx::Value {
@@ -543,7 +539,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
543539
}
544540
}
545541
// use common size calculation for non zero-sized types
546-
let cg_value = self.codegen_place(mir, bx, &place.as_ref());
542+
let cg_value = self.codegen_place(bx, &place.as_ref());
547543
cg_value.len(bx.cx())
548544
}
549545

@@ -704,7 +700,6 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
704700
&self,
705701
rvalue: &mir::Rvalue<'tcx>,
706702
span: Span,
707-
mir: &Body<'tcx>
708703
) -> bool {
709704
match *rvalue {
710705
mir::Rvalue::Ref(..) |
@@ -719,7 +714,7 @@ impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
719714
true,
720715
mir::Rvalue::Repeat(..) |
721716
mir::Rvalue::Aggregate(..) => {
722-
let ty = rvalue.ty(mir, self.cx.tcx());
717+
let ty = rvalue.ty(self.mir, self.cx.tcx());
723718
let ty = self.monomorphize(&ty);
724719
self.cx.spanned_layout_of(ty, span).is_zst()
725720
}

0 commit comments

Comments
 (0)