Make not a no-op for condition codes, only emit constants once

This commit is contained in:
Jef
2019-06-09 14:55:09 +02:00
parent dc3a4d7f4a
commit 353e6e737b
2 changed files with 28 additions and 16 deletions

View File

@@ -565,7 +565,22 @@ impl<'module, M> CodeGenSession<'module, M> {
}
}
pub fn into_translated_code_section(self) -> Result<TranslatedCodeSection, Error> {
fn finalize(&mut self) {
let mut values = self.labels.values_mut().collect::<Vec<_>>();
values.sort_unstable_by_key(|(_, align, _)| *align);
for (label, align, func) in values {
if let Some(mut func) = func.take() {
dynasm!(self.assembler
; .align *align as usize
);
self.assembler.dynamic_label(label.0);
func(&mut self.assembler);
}
}
}
pub fn into_translated_code_section(mut self) -> Result<TranslatedCodeSection, Error> {
self.finalize();
let exec_buf = self
.assembler
.finalize()
@@ -2150,6 +2165,11 @@ impl<'this, M: ModuleContext> Context<'this, M> {
return;
}
if let ValueLocation::Cond(loc) = val {
self.push(ValueLocation::Cond(!loc));
return;
}
let reg = self.into_reg(I32, val).unwrap();
let out = self.take_reg(I32).unwrap();
@@ -2174,6 +2194,11 @@ impl<'this, M: ModuleContext> Context<'this, M> {
return;
}
if let ValueLocation::Cond(loc) = val {
self.push(ValueLocation::Cond(!loc));
return;
}
let reg = self.into_reg(I64, val).unwrap();
let out = self.take_reg(I64).unwrap();
@@ -5352,20 +5377,7 @@ impl<'this, M: ModuleContext> Context<'this, M> {
);
}
/// Writes the function epilogue (right now all this does is add the trap label that the
/// conditional traps in `call_indirect` use)
pub fn epilogue(&mut self) {
let mut values = self.labels.values_mut().collect::<Vec<_>>();
values.sort_unstable_by_key(|(_, align, _)| *align);
for (label, align, func) in values {
if let Some(mut func) = func.take() {
dynasm!(self.asm
; .align *align as usize
);
self.asm.dynamic_label(label.0);
func(&mut self.asm);
}
}
}
pub fn trap(&mut self) {

View File

@@ -458,8 +458,8 @@ pub enum Operator<Label> {
/// Returning from the function is just calling the "return" block
target: BrTarget<Label>,
},
/// Pop a value off the top of the stack, jump to the `then` label if this value is `true`
/// and the `else_` label otherwise. The `then` and `else_` blocks must have the same parameters.
/// Pop a value off the top of the stack, jump to the `else_` label if this value is `true`
/// and the `then` label otherwise. The `then` and `else_` blocks must have the same parameters.
BrIf {
/// Label to jump to if the value at the top of the stack is true
then: BrTargetDrop<Label>,