slightly optimizing assignment
This commit is contained in:
parent
3127d04e41
commit
2dff9f7244
|
@ -25,12 +25,12 @@ fn align_up(value: u64, align: u64) -> u64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
struct LinReg(Reg, Rc<RefCell<RegAlloc>>);
|
struct LinReg(Reg, Option<Rc<RefCell<RegAlloc>>>);
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
impl Drop for LinReg {
|
impl Drop for LinReg {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
self.1.borrow_mut().free(self.0);
|
self.1.take().map(|b| b.borrow_mut().free(self.0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_reg(&mut self) -> LinReg {
|
fn alloc_reg(&mut self) -> LinReg {
|
||||||
LinReg(self.gpa.borrow_mut().allocate(), self.gpa.clone()).into()
|
LinReg(self.gpa.borrow_mut().allocate(), Some(self.gpa.clone())).into()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn alloc_stack(&mut self, size: u64) -> Rc<Stack> {
|
fn alloc_stack(&mut self, size: u64) -> Rc<Stack> {
|
||||||
|
@ -1230,7 +1230,15 @@ impl<'a> Codegen<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let lsize = self.size_of(left.ty);
|
let lsize = self.size_of(left.ty);
|
||||||
let lhs = self.loc_to_reg(left.loc, lsize);
|
let ty = ctx.ty().unwrap_or(left.ty);
|
||||||
|
let lhs = match std::mem::take(&mut ctx).loc() {
|
||||||
|
Some(Loc::RegRef(reg)) if Loc::RegRef(reg) == left.loc => LinReg(reg, None),
|
||||||
|
Some(loc) => {
|
||||||
|
ctx = Ctx::Dest(Value { ty, loc });
|
||||||
|
self.loc_to_reg(left.loc, lsize)
|
||||||
|
}
|
||||||
|
None => self.loc_to_reg(left.loc, lsize),
|
||||||
|
};
|
||||||
let right = self.expr_ctx(right, Ctx::Inferred(left.ty))?;
|
let right = self.expr_ctx(right, Ctx::Inferred(left.ty))?;
|
||||||
let rsize = self.size_of(right.ty);
|
let rsize = self.size_of(right.ty);
|
||||||
let rhs = self.loc_to_reg(right.loc, rsize);
|
let rhs = self.loc_to_reg(right.loc, rsize);
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 678
|
code size: 666
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 320
|
code size: 314
|
||||||
ret: 33
|
ret: 44
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 293
|
code size: 287
|
||||||
ret: 55
|
ret: 16
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 296
|
code size: 290
|
||||||
ret: 55
|
ret: 55
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
code size: 130
|
code size: 124
|
||||||
ret: 0
|
ret: 0
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
Loading…
Reference in a new issue