From 338e3f151938c3b5ac247fabb7e2db746e646ec1 Mon Sep 17 00:00:00 2001 From: mlokr Date: Sat, 21 Sep 2024 14:46:12 +0200 Subject: [PATCH] fixing compiler errors --- Cargo.lock | 10 +++++++++- fooll-orig.txt | 47 ++++++++++++++++++++++++++++++++++++++++++++++ fooll.txt | 48 +++++++++++++++++++++++++++++++++++++++++++++++ hblang/Cargo.toml | 2 +- hblang/README.md | 2 +- hblang/src/son.rs | 23 +++++++++++------------ 6 files changed, 117 insertions(+), 15 deletions(-) create mode 100644 fooll-orig.txt create mode 100644 fooll.txt diff --git a/Cargo.lock b/Cargo.lock index 78d3433..8a30767 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,10 +170,12 @@ dependencies = [ [[package]] name = "regalloc2" version = "0.10.2" -source = "git+https://github.com/jakubDoka/regalloc2#52b2bbe908e78af1715de88f562f62a83e36ca96" +source = "git+https://github.com/jakubDoka/regalloc2?branch=reuse-allocations#c1c7614b3a06d38113feaac11b4e4c9ab9e8f0c8" dependencies = [ "hashbrown", + "log", "rustc-hash", + "slice-group-by", "smallvec", ] @@ -212,6 +214,12 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" +[[package]] +name = "slice-group-by" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" + [[package]] name = "smallvec" version = "1.13.2" diff --git a/fooll-orig.txt b/fooll-orig.txt new file mode 100644 index 0000000..53d5539 --- /dev/null +++ b/fooll-orig.txt @@ -0,0 +1,47 @@ +sb0[]-[]: +0: iCall { func: 1 }:[Def: v3i fixed(p1i)] +1: iCInt { value: 0 }:[Def: v6i reg] +2: iCInt { value: 30 }:[Def: v5i reg] +3: iCInt { value: 100 }:[Def: v4i reg] +4: iLoop:[] +eb0[VReg(vreg = 6, class = Int), VReg(vreg = 6, class = Int), VReg(vreg = 6, class = Int)]-[Block(1)]: +sb1[VReg(vreg = 18, class = Int), VReg(vreg = 8, class = Int), VReg(vreg = 15, class = Int)]-[Block(0), Block(11)]: +5: iIf:[Use: v8i reg, Use: v5i reg] +eb1[]-[Block(2), Block(10)]: +sb2[]-[Block(1)]: +6: iBinOp { op: Add }:[Def: v19i reg, Use: v18i reg] +7: iCall { func: 2 }:[Def: v20i fixed(p1i), Use: v6i fixed(p2i), Use: v19i fixed(p3i), Use: v5i fixed(p4i)] +8: iIf:[Use: v20i reg, Use: v15i reg] +eb2[]-[Block(3), Block(4)]: +sb3[]-[Block(2)]: +9: iReturn:[Use: v6i fixed(p1i)] +eb3[]-[]: +sb4[]-[Block(2)]: +10: iIf:[Use: v19i reg, Use: v4i reg] +eb4[]-[Block(5), Block(9)]: +sb5[]-[Block(4)]: +11: iLoop:[] +eb5[VReg(vreg = 19, class = Int)]-[Block(6)]: +sb6[VReg(vreg = 36, class = Int)]-[Block(5), Block(7)]: +12: iIf:[Use: v4i reg, Use: v36i reg] +eb6[]-[Block(7), Block(8)]: +sb7[]-[Block(6)]: +13: iBinOp { op: Add }:[Def: v41i reg, Use: v36i reg] +14: iLoop:[] +eb7[VReg(vreg = 41, class = Int)]-[Block(6)]: +sb8[]-[Block(6)]: +15: iReturn:[Use: v15i fixed(p1i)] +eb8[]-[]: +sb9[]-[Block(4)]: +16: iRegion:[] +eb9[VReg(vreg = 6, class = Int), VReg(vreg = 19, class = Int), VReg(vreg = 15, class = Int)]-[Block(11)]: +sb10[]-[Block(1)]: +17: iBinOp { op: Add }:[Def: v16i reg, Use: v15i reg] +18: iBinOp { op: Add }:[Def: v14i reg, Use: v8i reg] +19: iRegion:[] +eb10[VReg(vreg = 14, class = Int), VReg(vreg = 18, class = Int), VReg(vreg = 16, class = Int)]-[Block(11)]: +sb11[VReg(vreg = 32, class = Int), VReg(vreg = 33, class = Int), VReg(vreg = 34, class = Int)]-[Block(10), Block(9)]: +20: iLoop:[] +eb11[VReg(vreg = 33, class = Int), VReg(vreg = 32, class = Int), VReg(vreg = 34, class = Int)]-[Block(1)]: + + diff --git a/fooll.txt b/fooll.txt new file mode 100644 index 0000000..4a27e0f --- /dev/null +++ b/fooll.txt @@ -0,0 +1,48 @@ +sb0[]-[]: +0: iCall { func: 1 }:[Def: v3i fixed(p1i)] +1: iCInt { value: 0 }:[Def: v6i reg] +2: iCInt { value: 30 }:[Def: v5i reg] +3: iCInt { value: 100 }:[Def: v4i reg] +4: iLoop:[] +eb0[VReg(vreg = 4, class = Int), VReg(vreg = 6, class = Int), VReg(vreg = 6, class = Int), VReg(vreg = 6, class = Int)]-[Block(1)]: +sb1[VReg(vreg = 26, class = Int), VReg(vreg = 8, class = Int), VReg(vreg = 15, class = Int), VReg(vreg = 18, class = Int)]-[Block(0), Block(11)]: +5: iIf:[Use: v8i reg, Use: v5i reg] +eb1[]-[Block(2), Block(10)]: +sb2[]-[Block(1)]: +6: iBinOp { op: Add }:[Def: v19i reg, Use: v18i reg] +7: iCall { func: 2 }:[Def: v20i fixed(p1i), Use: v6i fixed(p2i), Use: v19i fixed(p3i), Use: v5i fixed(p4i)] +8: iIf:[Use: v20i reg, Use: v15i reg] +eb2[]-[Block(3), Block(4)]: +sb3[]-[Block(2)]: +9: iReturn:[Use: v6i fixed(p1i)] +eb3[]-[]: +sb4[]-[Block(2)]: +10: iIf:[Use: v19i reg, Use: v4i reg] +eb4[]-[Block(5), Block(9)]: +sb5[]-[Block(4)]: +11: iBinOp { op: Add }:[Def: v35i reg, Use: v26i reg] +12: iLoop:[] +eb5[VReg(vreg = 19, class = Int)]-[Block(6)]: +sb6[VReg(vreg = 38, class = Int)]-[Block(5), Block(7)]: +13: iIf:[Use: v35i reg, Use: v38i reg] +eb6[]-[Block(7), Block(8)]: +sb7[]-[Block(6)]: +14: iBinOp { op: Add }:[Def: v43i reg, Use: v38i reg] +15: iLoop:[] +eb7[VReg(vreg = 43, class = Int)]-[Block(6)]: +sb8[]-[Block(6)]: +16: iReturn:[Use: v15i fixed(p1i)] +eb8[]-[]: +sb9[]-[Block(4)]: +17: iRegion:[] +eb9[VReg(vreg = 6, class = Int), VReg(vreg = 19, class = Int), VReg(vreg = 15, class = Int)]-[Block(11)]: +sb10[]-[Block(1)]: +18: iBinOp { op: Add }:[Def: v16i reg, Use: v15i reg] +19: iBinOp { op: Add }:[Def: v14i reg, Use: v8i reg] +20: iRegion:[] +eb10[VReg(vreg = 14, class = Int), VReg(vreg = 18, class = Int), VReg(vreg = 16, class = Int)]-[Block(11)]: +sb11[VReg(vreg = 32, class = Int), VReg(vreg = 33, class = Int), VReg(vreg = 34, class = Int)]-[Block(10), Block(9)]: +21: iLoop:[] +eb11[VReg(vreg = 0, class = Int), VReg(vreg = 32, class = Int), VReg(vreg = 34, class = Int), VReg(vreg = 33, class = Int)]-[Block(1)]: + + diff --git a/hblang/Cargo.toml b/hblang/Cargo.toml index 2570c22..5ca1cf1 100644 --- a/hblang/Cargo.toml +++ b/hblang/Cargo.toml @@ -10,7 +10,7 @@ path = "src/main.rs" [dependencies] hbbytecode = { version = "0.1.0", path = "../hbbytecode" } hbvm = { path = "../hbvm", features = ["nightly"] } -regalloc2 = { git = "https://github.com/jakubDoka/regalloc2", features = [] } +regalloc2 = { git = "https://github.com/jakubDoka/regalloc2", branch = "reuse-allocations", features = ["trace-log"] } [dev-dependencies] env_logger = "0.11.5" diff --git a/hblang/README.md b/hblang/README.md index 9e50fa7..ece38f1 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -505,7 +505,7 @@ main := fn(): int { } } - width += 1 + //width += 1 loop { if width < y break diff --git a/hblang/src/son.rs b/hblang/src/son.rs index 33cca84..692af13 100644 --- a/hblang/src/son.rs +++ b/hblang/src/son.rs @@ -25,7 +25,6 @@ use { mem::{self, MaybeUninit}, ops::{self, Deref, DerefMut, Not}, ptr::Unique, - u32, }, }; @@ -1800,6 +1799,7 @@ impl Codegen { let mut nodes = std::mem::take(&mut self.ci.nodes); let func = Function::new(&mut nodes, &self.tys, sig); + dbg!(&func); let mut env = regalloc2::MachineEnv { preferred_regs_by_class: [ (1..12).map(|i| regalloc2::PReg::new(i, regalloc2::RegClass::Int)).collect(), @@ -2349,7 +2349,6 @@ impl<'a> Function<'a> { } Kind::Ctrl { index: u32::MAX } => { self.nodes[nid].ralloc_backref = self.add_block(nid); - self.bridge(prev, nid); let mut parama = self.tys.parama(self.sig.ret); for (arg, ti) in @@ -2475,16 +2474,16 @@ impl<'a> regalloc2::Function for Function<'a> { self.blocks[block.index()].instrs } - fn block_succs(&self, block: regalloc2::Block) -> impl Iterator { - self.blocks[block.index()].succs.iter().copied() + fn block_succs(&self, block: regalloc2::Block) -> &[regalloc2::Block] { + &self.blocks[block.index()].succs } - fn block_preds(&self, block: regalloc2::Block) -> impl Iterator { - self.blocks[block.index()].preds.iter().copied() + fn block_preds(&self, block: regalloc2::Block) -> &[regalloc2::Block] { + &self.blocks[block.index()].preds } - fn block_params(&self, block: regalloc2::Block) -> impl Iterator { - self.blocks[block.index()].params.iter().copied() + fn block_params(&self, block: regalloc2::Block) -> &[regalloc2::VReg] { + &self.blocks[block.index()].params } fn is_ret(&self, insn: regalloc2::Inst) -> bool { @@ -2503,17 +2502,17 @@ impl<'a> regalloc2::Function for Function<'a> { block: regalloc2::Block, _insn: regalloc2::Inst, _succ_idx: usize, - ) -> impl Iterator { + ) -> &[regalloc2::VReg] { debug_assert!( self.blocks[block.index()].succs.len() == 1 || self.blocks[block.index()].branch_blockparams.is_empty() ); - self.blocks[block.index()].branch_blockparams.iter().copied() + &self.blocks[block.index()].branch_blockparams } - fn inst_operands(&self, insn: regalloc2::Inst) -> impl Iterator { - self.instrs[insn.index()].ops.iter().copied() + fn inst_operands(&self, insn: regalloc2::Inst) -> &[regalloc2::Operand] { + &self.instrs[insn.index()].ops } fn inst_clobbers(&self, insn: regalloc2::Inst) -> regalloc2::PRegSet {