Skip to content

Commit

Permalink
Fixed dead code elimination
Browse files Browse the repository at this point in the history
  • Loading branch information
FractalFir committed Aug 4, 2024
1 parent cc861a1 commit e17b6d7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cilly/src/bin/linker/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn main() {

add_mandatory_statics(&mut final_assembly);

//tmp.eliminate_dead_code();
final_assembly.eliminate_dead_code();
final_assembly
.save_tmp(&mut std::fs::File::create(path.with_extension("cilly2")).unwrap())
.unwrap();
Expand Down
2 changes: 0 additions & 2 deletions cilly/src/v2/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ impl Assembly {
tdef.methods_mut()
.retain(|def| self.method_defs.contains_key(def));
});
// Free all the dead roots
//self.realloc_roots();
}
/*pub fn realloc_nodes(&mut self){
Expand Down
8 changes: 7 additions & 1 deletion cilly/src/v2/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ impl BasicBlock {
pub fn block_id(&self) -> u32 {
self.block_id
}

pub fn iter_roots(&self) -> impl Iterator<Item = RootIdx> + '_ {
let handler_iter: Box<dyn Iterator<Item = RootIdx>> = match self.handler() {
Some(handler) => Box::new(handler.iter().flat_map(|block| block.iter_roots())),
None => Box::new(std::iter::empty()),
};
self.roots().iter().copied().chain(handler_iter)
}
pub fn handler(&self) -> Option<&[BasicBlock]> {
self.handler.as_ref().map(|b| b.as_ref())
}
Expand Down
8 changes: 5 additions & 3 deletions cilly/src/v2/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ impl MethodDef {
MethodImpl::MethodBody { blocks, .. } => Some(
blocks
.iter()
.flat_map(|block| block.roots())
.flat_map(|root| super::CILIter::new(asm.get_root(*root).clone(), asm)),
.flat_map(|block| block.iter_roots())
.flat_map(|root| super::CILIter::new(asm.get_root(root).clone(), asm)),
),
MethodImpl::Extern { .. } => None,
MethodImpl::AliasFor(_) => panic!(),
MethodImpl::AliasFor(_) => {
panic!("Unresolved alias returned by MethodDef::resolved_implementation")
}
MethodImpl::Missing => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion setup_rustc_fork.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test -e "rust" || git clone --quiet https://github.com/rust-lang/rust.git --filt
pushd rust
git fetch
git checkout --no-progress -- .
# git checkout --no-progress "$(rustc -V | cut -d' ' -f3 | tr -d '(')"
git checkout --no-progress "$(rustc -V | cut -d' ' -f3 | tr -d '(')"

git submodule update --quiet --init src/tools/cargo library/backtrace library/stdarch

Expand Down
114 changes: 47 additions & 67 deletions test/fuzz/fail8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![allow(
unused_parens,
unused_assignments,
unused_variables,
overflowing_literals,
internal_features
)]
Expand Down Expand Up @@ -131,7 +132,7 @@ fn dump_var(
val2.printf_debug();
}
}
#[custom_mir(dialect = "runtime", phase = "initial")]

pub fn fn0(
mut _1: bool,
mut _2: char,
Expand All @@ -148,16 +149,11 @@ pub fn fn0(
mut _13: u64,
mut _14: u128,
) -> f32 {
mir! {
let _16: (bool, i16, i8);
let _18: Adt46;
{
Call(_18 = fn1(_1, _16, _12, _1, _3, _4), ReturnTo(bb9), UnwindUnreachable())
}
bb9 = {
Return()
}
}
let _16: (bool, i16, i8) = Default::default();

fn1(_1, _16, _12, _1, _3, _4);

0.0
}
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn1(
Expand All @@ -167,7 +163,7 @@ pub fn fn1(
mut _4: bool,
mut _5: isize,
mut _6: i8,
) -> Adt46 {
) -> () {
mir! {
let _8: (u64, f32);
let _11: Adt43;
Expand All @@ -179,7 +175,7 @@ pub fn fn1(
}
}
}
#[custom_mir(dialect = "runtime", phase = "initial")]

pub fn fn2(
mut _1: isize,
mut _2: i16,
Expand All @@ -189,25 +185,28 @@ pub fn fn2(
mut _6: i16,
mut _7: isize,
mut _8: (bool, i16, i8),
) -> Adt46 {
mir! {
let _9: ((u128, (i128, i8, i8, u16)),);
let _10: (bool, i16, i8);
let _12: isize;
let _14: (bool, i16, i8);
let _15: ((u128, (i128, i8, i8, u16)),);
{
Goto(bb1)
}
bb1 = {
Call(RET = fn3(_12, _9.0.1.3, _10, _8, _14.0, _15.0.1.3, _10.0, _9.0.1.3, _10, _10, _14), ReturnTo(bb13), UnwindUnreachable())
}
bb13 = {
Return()
}
}
) {
let _9: ((u128, (i128, i8, i8, u16)),) = Default::default();
let _10: (bool, i16, i8) = Default::default();
let _12: isize = Default::default();
let _14: (bool, i16, i8) = Default::default();
let _15: ((u128, (i128, i8, i8, u16)),) = Default::default();

fn3(
_12,
_9.0 .1 .3,
_10,
_8,
_14.0,
_15.0 .1 .3,
_10.0,
_9.0 .1 .3,
_10,
_10,
_14,
)
}
#[custom_mir(dialect = "runtime", phase = "initial")]

pub fn fn3(
mut _1: isize,
mut _2: u16,
Expand All @@ -220,32 +219,20 @@ pub fn fn3(
mut _9: (bool, i16, i8),
mut _10: (bool, i16, i8),
mut _11: (bool, i16, i8),
) -> Adt46 {
mir! {
let _16: (i8, i16);
{
Call(_10.1 = fn4(_11.0, _16.1, _11.0), ReturnTo(bb12), UnwindUnreachable())
}
bb12 = {
Return()
}
}
) {
let _16: (i8, i16) = Default::default();

fn4(_11.0, _16.1, _11.0);
}
#[custom_mir(dialect = "runtime", phase = "initial")]
fn fn4(mut _1: bool, mut _2: i16, mut _3: bool) -> i16 {
mir! {
let _5: f32;
let _7: Adt49;
let _8: ((u64, f32), u8, f32, [bool; 2]);
{
Call(_7 = fn6(_1, _8, _3, _3, _5, _8.3, _8), ReturnTo(bb3), UnwindUnreachable())
}
bb3 = {
Return()
}
}

fn fn4(mut _1: bool, mut _2: i16, mut _3: bool) {
let _5: f32 = Default::default();

let _8: ((u64, f32), u8, f32, [bool; 2]) = Default::default();

fn6(_1, _8, _3, _3, _5, _8.3, _8);
}
#[custom_mir(dialect = "runtime", phase = "initial")]

pub fn fn6(
mut _1: bool,
mut _2: ((u64, f32), u8, f32, [bool; 2]),
Expand All @@ -254,19 +241,12 @@ pub fn fn6(
mut _5: f32,
mut _6: [bool; 2],
mut _7: ((u64, f32), u8, f32, [bool; 2]),
) -> Adt49 {
mir! {
let _9: (u64, f32);
let _10: bool;
let _27: Adt49;
{
) {
let mut _9: (u64, f32) = Default::default();
let _10: bool = Default::default();

_9.0 = 869855573_u32 as u64;
Call(_27.fld0 = fn13(_2, _3, _9, _1, _10, _9.1, _2.3), ReturnTo(bb10), UnwindUnreachable())
}
bb10 = {
Return()
}
}
fn13(_2, _3, _9, _1, _10, _9.1, _2.3);
}
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn13(
Expand Down

0 comments on commit e17b6d7

Please sign in to comment.