Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Commit 005a5bc

Browse files
bors[bot]vext01
andcommitted
Merge #18
18: Implement more TIR lowerings. r=ltratt a=vext01 This is a whole load more TIR lowerings. The TIR graphs are starting to look more complete, although there's still a lot more to do. I only stopped here because the changes are getting large, and more edits can come in later PRs. There's one part of this code (which I will point out), which i'm likely to change. It involves a type-parameterised MIR struct, which I think ultimately we will make concrete in TIR. However, I want to see the outcome of this upstream PR first: rust-lang/rust#60441 There's a ykpack change to accompany this: ykjit/yk#3 Co-authored-by: Edd Barrett <[email protected]>
2 parents 1d3e5d8 + 5242934 commit 005a5bc

File tree

4 files changed

+166
-13
lines changed

4 files changed

+166
-13
lines changed

Cargo.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -4045,7 +4045,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
40454045
[[package]]
40464046
name = "ykpack"
40474047
version = "0.1.0"
4048-
source = "git+https://github.com/softdevteam/yk#0c7016c47bff4b149a2bc1d304cf637f6d64719e"
4048+
source = "git+https://github.com/softdevteam/yk#eac9ee05a85f5b7a2158bc5b01b63c8a34f5132f"
40494049
dependencies = [
40504050
"fallible-iterator 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
40514051
"rmp-serde 0.14.0 (git+https://github.com/3Hren/msgpack-rust?rev=40b3d480b20961e6eeceb416b32bcd0a3383846a)",

src/librustc_yk_sections/emit_tir.rs

+163-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Copyright 2018 King's College London.
21
// Created by the Software Development Team <http://soft-dev.org/>.
32
//
43
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
@@ -17,7 +16,8 @@ use rustc::ty::TyCtxt;
1716
use rustc::hir::def_id::DefId;
1817
use rustc::mir::{
1918
Mir, TerminatorKind, Operand, Constant, StatementKind, BasicBlock, BasicBlockData, Terminator,
20-
Place, Rvalue, Statement, Local, PlaceBase
19+
Place, Rvalue, Statement, Local, PlaceBase, BorrowKind, BinOp, UnOp, NullOp, Projection,
20+
AggregateKind
2121
};
2222
use rustc::ty::{TyS, TyKind, Const, LazyConst};
2323
use rustc::util::nodemap::DefIdSet;
@@ -29,6 +29,7 @@ use std::io::Write;
2929
use std::error::Error;
3030
use std::cell::{Cell, RefCell};
3131
use std::mem::size_of;
32+
use std::marker::PhantomData;
3233
use rustc_data_structures::bit_set::BitSet;
3334
use rustc_data_structures::indexed_vec::IndexVec;
3435
use ykpack;
@@ -264,6 +265,8 @@ impl<'tcx> ToPack<ykpack::Terminator> for (&ConvCx<'_, 'tcx, '_>, &Terminator<'t
264265
unwind_bb: unwind_bb.map(|bb| u32::from(bb)),
265266
},
266267
TerminatorKind::Call{ref func, cleanup: cleanup_bb, ref destination, .. } => {
268+
// In MIR, a call instruction accepts an arbitrary operand, but in TIR we special
269+
// case the call targets.
267270
let ser_oper = if let Operand::Constant(box Constant {
268271
literal: LazyConst::Evaluated(Const {
269272
ty: &TyS {
@@ -307,7 +310,7 @@ impl<'tcx> ToPack<ykpack::BasicBlock> for
307310
fn to_pack(&mut self) -> ykpack::BasicBlock {
308311
let (ccx, bb, bb_data) = self;
309312
let ser_stmts = bb_data.statements.iter().map(|stmt| (*ccx, *bb, stmt).to_pack());
310-
ykpack::BasicBlock::new(ser_stmts.collect(),
313+
ykpack::BasicBlock::new(ser_stmts.filter(|s| *s != ykpack::Statement::Nop).collect(),
311314
(*ccx, bb_data.terminator.as_ref().unwrap()).to_pack())
312315
}
313316
}
@@ -321,12 +324,23 @@ impl<'tcx> ToPack<ykpack::Statement> for (&ConvCx<'_, 'tcx, '_>, BasicBlock, &St
321324
StatementKind::Assign(ref place, ref rval) => {
322325
let lhs = (*ccx, place).to_pack();
323326
let rhs = (*ccx, &**rval).to_pack();
324-
if let ykpack::Place::Local(tvar) = lhs {
327+
if let ykpack::Place::Base(ykpack::PlaceBase::Local(tvar)) = lhs {
325328
ccx.push_def_site(*bb, tvar);
326329
}
327330
ykpack::Statement::Assign(lhs, rhs)
328331
},
329-
_ => ykpack::Statement::Unimplemented,
332+
StatementKind::SetDiscriminant{ref place, ref variant_index} =>
333+
ykpack::Statement::SetDiscriminant((*ccx, place).to_pack(), variant_index.as_u32()),
334+
// StorageLive/Dead not useful to the tracer. Ignore them.
335+
StatementKind::StorageLive(..)
336+
| StatementKind::StorageDead(..) => ykpack::Statement::Nop,
337+
StatementKind::InlineAsm{..} => ykpack::Statement::Unimplemented,
338+
// These MIR statements all codegen to nothing, and are thus nops for us too. See
339+
// codegen_statement() in librustc_codegen_ssa for proof.
340+
StatementKind::Retag(..)
341+
| StatementKind::AscribeUserType(..)
342+
| StatementKind::FakeRead(..)
343+
| StatementKind::Nop => ykpack::Statement::Nop,
330344
}
331345
}
332346
}
@@ -337,8 +351,50 @@ impl<'tcx> ToPack<ykpack::Place> for (&ConvCx<'_, 'tcx, '_>, &Place<'tcx>) {
337351
let (ccx, place) = self;
338352

339353
match place {
340-
Place::Base(PlaceBase::Local(local)) => ykpack::Place::Local(ccx.tir_var(*local)),
341-
_ => ykpack::Place::Unimplemented, // FIXME
354+
Place::Base(pb) => ykpack::Place::Base((*ccx, pb).to_pack()),
355+
Place::Projection(pj) => ykpack::Place::Projection((*ccx, pj.as_ref()).to_pack()),
356+
}
357+
}
358+
}
359+
360+
/// Projection -> Pack
361+
/// In Rust, projections are parameterised, but there is only ever one concrete instantiation, so
362+
/// we lower to a concrete `PlaceProjection`.
363+
impl<'tcx, T> ToPack<ykpack::PlaceProjection>
364+
for (&ConvCx<'_, 'tcx, '_>, &Projection<'tcx, Place<'tcx>, Local, T>)
365+
{
366+
fn to_pack(&mut self) -> ykpack::PlaceProjection {
367+
let (ccx, pj) = self;
368+
369+
ykpack::PlaceProjection {
370+
base: Box::new((*ccx, &pj.base).to_pack()),
371+
elem: ykpack::ProjectionElem::Unimplemented(PhantomData), // FIXME
372+
}
373+
}
374+
}
375+
376+
/// PlaceBase -> Pack
377+
impl<'tcx> ToPack<ykpack::PlaceBase> for (&ConvCx<'_, 'tcx, '_>, &PlaceBase<'tcx>) {
378+
fn to_pack(&mut self) -> ykpack::PlaceBase {
379+
let (ccx, pb) = self;
380+
381+
match pb {
382+
PlaceBase::Local(local) => ykpack::PlaceBase::Local(ccx.tir_var(*local)),
383+
PlaceBase::Static(s) => ykpack::PlaceBase::Static((*ccx, &s.as_ref().def_id).to_pack()),
384+
PlaceBase::Promoted(bx) => ykpack::PlaceBase::Promoted(bx.0.as_u32()),
385+
}
386+
}
387+
}
388+
389+
/// Operand -> Pack
390+
impl<'tcx> ToPack<ykpack::Operand> for (&ConvCx<'_, 'tcx, '_>, &Operand<'tcx>) {
391+
fn to_pack(&mut self) -> ykpack::Operand {
392+
let (ccx, op) = self;
393+
394+
match *op {
395+
Operand::Move(place) | Operand::Copy(place)
396+
=> ykpack::Operand::Place((*ccx, place).to_pack()),
397+
_ => ykpack::Operand::Unimplemented, // FIXME
342398
}
343399
}
344400
}
@@ -349,8 +405,106 @@ impl<'tcx> ToPack<ykpack::Rvalue> for (&ConvCx<'_, 'tcx, '_>, &Rvalue<'tcx>) {
349405
let (ccx, rval) = self;
350406

351407
match *rval {
352-
Rvalue::Use(Operand::Move(place)) => ykpack::Rvalue::Place((*ccx, place).to_pack()),
353-
_ => ykpack::Rvalue::Unimplemented, // FIXME
408+
Rvalue::Use(oper) => ykpack::Rvalue::Use((*ccx, oper).to_pack()),
409+
Rvalue::Repeat(oper, len) => ykpack::Rvalue::Repeat((*ccx, oper).to_pack(), *len),
410+
Rvalue::Ref(_region, borrow_kind, place) => ykpack::Rvalue::Ref(
411+
(*ccx, borrow_kind).to_pack(),
412+
(*ccx, place).to_pack()),
413+
Rvalue::Len(place) => ykpack::Rvalue::Len((*ccx, place).to_pack()),
414+
// Since TIR is currently untyped we consider a cast as a simple variable use.
415+
Rvalue::Cast(_, oper, _) => ykpack::Rvalue::Use((*ccx, oper).to_pack()),
416+
Rvalue::BinaryOp(bop, o1, o2) => ykpack::Rvalue::BinaryOp(
417+
(*ccx, bop).to_pack(),
418+
(*ccx, o1).to_pack(),
419+
(*ccx, o2).to_pack()),
420+
Rvalue::CheckedBinaryOp(bop, o1, o2) => ykpack::Rvalue::CheckedBinaryOp(
421+
(*ccx, bop).to_pack(),
422+
(*ccx, o1).to_pack(),
423+
(*ccx, o2).to_pack()),
424+
Rvalue::NullaryOp(null_op, _) => ykpack::Rvalue::NullaryOp((*ccx, null_op).to_pack()),
425+
Rvalue::UnaryOp(un_op, op) =>
426+
ykpack::Rvalue::UnaryOp((*ccx, un_op).to_pack(), (*ccx, op).to_pack()),
427+
Rvalue::Discriminant(place) => ykpack::Rvalue::Discriminant((*ccx, place).to_pack()),
428+
Rvalue::Aggregate(ag_kind, ops) => ykpack::Rvalue::Aggregate(
429+
(*ccx, ag_kind.as_ref()).to_pack(),
430+
ops.iter().map(|op| (*ccx, op).to_pack()).collect()),
431+
}
432+
}
433+
}
434+
435+
/// AggregateKind -> Pack
436+
impl<'tcx> ToPack<ykpack::AggregateKind> for (&ConvCx<'_, 'tcx, '_>, &AggregateKind<'tcx>) {
437+
fn to_pack(&mut self) -> ykpack::AggregateKind {
438+
let (ccx, ak) = self;
439+
match *ak {
440+
AggregateKind::Array(_) => ykpack::AggregateKind::Array,
441+
AggregateKind::Tuple => ykpack::AggregateKind::Tuple,
442+
AggregateKind::Adt{..} => ykpack::AggregateKind::Unimplemented,
443+
AggregateKind::Closure(def_id, _) =>
444+
ykpack::AggregateKind::Closure((*ccx, def_id).to_pack()),
445+
AggregateKind::Generator(def_id, ..) =>
446+
ykpack::AggregateKind::Generator((*ccx, def_id).to_pack()),
447+
}
448+
}
449+
}
450+
451+
/// BorrowKind -> Pack
452+
impl<'tcx> ToPack<ykpack::BorrowKind> for (&ConvCx<'_, 'tcx, '_>, &BorrowKind) {
453+
fn to_pack(&mut self) -> ykpack::BorrowKind {
454+
let (_ccx, bk) = self;
455+
match *bk {
456+
BorrowKind::Shared => ykpack::BorrowKind::Shared,
457+
BorrowKind::Shallow => ykpack::BorrowKind::Shallow,
458+
BorrowKind::Unique => ykpack::BorrowKind::Unique,
459+
BorrowKind::Mut{..} => ykpack::BorrowKind::Mut,
460+
}
461+
}
462+
}
463+
464+
/// BinOp -> Pack
465+
impl<'tcx> ToPack<ykpack::BinOp> for (&ConvCx<'_, 'tcx, '_>, &BinOp) {
466+
fn to_pack(&mut self) -> ykpack::BinOp {
467+
let (_ccx, op) = self;
468+
match *op {
469+
BinOp::Add => ykpack::BinOp::Add,
470+
BinOp::Sub => ykpack::BinOp::Sub,
471+
BinOp::Mul => ykpack::BinOp::Mul,
472+
BinOp::Div => ykpack::BinOp::Div,
473+
BinOp::Rem => ykpack::BinOp::Rem,
474+
BinOp::BitXor => ykpack::BinOp::BitXor,
475+
BinOp::BitAnd => ykpack::BinOp::BitAnd,
476+
BinOp::BitOr => ykpack::BinOp::BitOr,
477+
BinOp::Shl => ykpack::BinOp::Shl,
478+
BinOp::Shr => ykpack::BinOp::Shr,
479+
BinOp::Eq => ykpack::BinOp::Eq,
480+
BinOp::Lt => ykpack::BinOp::Lt,
481+
BinOp::Le => ykpack::BinOp::Le,
482+
BinOp::Ne => ykpack::BinOp::Ne,
483+
BinOp::Ge => ykpack::BinOp::Ge,
484+
BinOp::Gt => ykpack::BinOp::Gt,
485+
BinOp::Offset => ykpack::BinOp::Offset,
486+
}
487+
}
488+
}
489+
490+
/// NullOp -> Pack
491+
impl<'tcx> ToPack<ykpack::NullOp> for (&ConvCx<'_, 'tcx, '_>, &NullOp) {
492+
fn to_pack(&mut self) -> ykpack::NullOp {
493+
let (_ccx, op) = self;
494+
match *op {
495+
NullOp::SizeOf => ykpack::NullOp::SizeOf,
496+
NullOp::Box => ykpack::NullOp::Box,
497+
}
498+
}
499+
}
500+
501+
/// UnOp -> Pack
502+
impl<'tcx> ToPack<ykpack::UnOp> for (&ConvCx<'_, 'tcx, '_>, &UnOp) {
503+
fn to_pack(&mut self) -> ykpack::UnOp {
504+
let (_ccx, op) = self;
505+
match *op {
506+
UnOp::Not => ykpack::UnOp::Not,
507+
UnOp::Neg => ykpack::UnOp::Neg,
354508
}
355509
}
356510
}

src/test/yk-tir/simple_tir.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ fn main() {
1919
// ...
2020
// term: SwitchInt { target_bbs: [4, 3] }
2121
// bb3:
22-
// Assign(Local(0), Unimplemented)
22+
// Assign(Base(Local(0)), Use(Unimplemented))
2323
// term: Goto { target_bb: 4 }
2424
// bb4:
25-
// Unimplemented
2625
// ...
2726
// [End TIR for main]

src/tools/tidy/src/extdeps.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const WHITELISTED_SOURCES: &[&str] = &[
1010
// The following are needed for Yorick whilst we use an unreleased revision not on crates.io.
1111
"\"git+https://github.com/3Hren/msgpack-rust?\
1212
rev=40b3d480b20961e6eeceb416b32bcd0a3383846a#40b3d480b20961e6eeceb416b32bcd0a3383846a\"",
13-
"\"git+https://github.com/softdevteam/yk#0c7016c47bff4b149a2bc1d304cf637f6d64719e\"",
13+
"\"git+https://github.com/softdevteam/yk#eac9ee05a85f5b7a2158bc5b01b63c8a34f5132f\"",
1414
];
1515

1616
/// Checks for external package sources.

0 commit comments

Comments
 (0)