fix one bug + refactor Option handling in some func
This commit is contained in:
@@ -3215,13 +3215,13 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
ty: impl Into<Option<GPRType>>,
|
ty: impl Into<Option<GPRType>>,
|
||||||
val: &mut ValueLocation,
|
val: &mut ValueLocation,
|
||||||
) -> Result<Option<GPR>, Error> {
|
) -> Result<Option<GPR>, Error> {
|
||||||
let out = match self.to_reg(ty, *val) {
|
if let Some(out) = self.to_reg(ty, *val)? {
|
||||||
Err(e) => return Err(e),
|
self.free_value(*val)?;
|
||||||
Ok(o) => o.unwrap(),
|
*val = ValueLocation::Reg(out);
|
||||||
};
|
Ok(Some(out))
|
||||||
self.free_value(*val)?;
|
} else {
|
||||||
*val = ValueLocation::Reg(out);
|
Ok(None)
|
||||||
Ok(Some(out))
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clones this value into a register so that it can be efficiently read
|
/// Clones this value into a register so that it can be efficiently read
|
||||||
@@ -3236,13 +3236,13 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
self.block_state.regs.mark_used(r);
|
self.block_state.regs.mark_used(r);
|
||||||
Ok(Some(r))
|
Ok(Some(r))
|
||||||
}
|
}
|
||||||
val => {
|
val => match self.take_reg(ty.unwrap_or(GPRType::Rq)) {
|
||||||
let scratch = self.take_reg(ty.unwrap_or(GPRType::Rq)).unwrap();
|
Some(scratch) => {
|
||||||
|
self.copy_value(val, CCLoc::Reg(scratch))?;
|
||||||
self.copy_value(val, CCLoc::Reg(scratch))?;
|
Ok(Some(scratch))
|
||||||
|
}
|
||||||
Ok(Some(scratch))
|
None => Ok(None),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3253,13 +3253,14 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
ty: impl Into<Option<GPRType>>,
|
ty: impl Into<Option<GPRType>>,
|
||||||
val: &mut ValueLocation,
|
val: &mut ValueLocation,
|
||||||
) -> Result<Option<GPR>, Error> {
|
) -> Result<Option<GPR>, Error> {
|
||||||
let out = match self.to_temp_reg(ty, *val) {
|
let out = self.to_temp_reg(ty, *val)?;
|
||||||
Err(e) => return Err(e),
|
if let Some(o) = out {
|
||||||
Ok(o) => o.unwrap(),
|
self.free_value(*val)?;
|
||||||
};
|
*val = ValueLocation::Reg(o);
|
||||||
self.free_value(*val)?;
|
Ok(Some(o))
|
||||||
*val = ValueLocation::Reg(out);
|
} else {
|
||||||
Ok(Some(out))
|
return Ok(None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn into_temp_loc(
|
fn into_temp_loc(
|
||||||
@@ -3288,25 +3289,25 @@ impl<'this, M: ModuleContext> Context<'this, M> {
|
|||||||
val: ValueLocation,
|
val: ValueLocation,
|
||||||
) -> Result<Option<GPR>, Error> {
|
) -> Result<Option<GPR>, Error> {
|
||||||
// If we have `None` as the type then it always matches (`.unwrap_or(true)`)
|
// If we have `None` as the type then it always matches (`.unwrap_or(true)`)
|
||||||
let res = match val {
|
match val {
|
||||||
ValueLocation::Reg(r) => {
|
ValueLocation::Reg(r) => {
|
||||||
let ty = ty.into();
|
let ty = ty.into();
|
||||||
let type_matches = ty.map(|t| t == r.type_()).unwrap_or(true);
|
let type_matches = ty.map(|t| t == r.type_()).unwrap_or(true);
|
||||||
|
|
||||||
if self.block_state.regs.num_usages(r) <= 1 && type_matches {
|
if self.block_state.regs.num_usages(r) <= 1 && type_matches {
|
||||||
self.block_state.regs.mark_used(r);
|
self.block_state.regs.mark_used(r);
|
||||||
Some(r)
|
Ok(Some(r))
|
||||||
} else {
|
} else {
|
||||||
let scratch = self.take_reg(ty.unwrap_or(GPRType::Rq)).unwrap();
|
if let Some(scratch) = self.take_reg(ty.unwrap_or(GPRType::Rq)) {
|
||||||
|
self.copy_value(val, CCLoc::Reg(scratch))?;
|
||||||
self.copy_value(val, CCLoc::Reg(scratch))?;
|
Ok(Some(scratch))
|
||||||
|
} else {
|
||||||
Some(scratch)
|
Ok(None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val => self.to_reg(ty, val)?,
|
val => self.to_reg(ty, val),
|
||||||
};
|
}
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn f32_neg(&mut self) -> Result<(), Error> {
|
pub fn f32_neg(&mut self) -> Result<(), Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user