Add a trapif instruction.

This is a conditional trap controlled by integer CPU flags.
Compare to brif.
This commit is contained in:
Jakob Stoklund Olesen
2018-02-08 14:39:06 -08:00
parent 3eeef1c752
commit 11c721934c
8 changed files with 49 additions and 0 deletions

View File

@@ -380,6 +380,7 @@ is zero.
.. autoinst:: trap
.. autoinst:: trapz
.. autoinst:: trapnz
.. autoinst:: trapif
Function calls

View File

@@ -210,3 +210,18 @@ ebb0:
; nextln: copy_special %20 -> %10
; nextln: return
; nextln: }
function %cond_traps(i32) {
ebb0(v0: i32):
trapz v0, stk_ovf
v1 = ifcmp_imm v0, 5
trapif ugt v1, oob
return
}
; sameln: function %cond_traps(i32)
; nextln: ebb0($v0: i32):
; nextln: trapz $v0, stk_ovf
; nextln: $v1 = ifcmp_imm v0, 5
; nextln: trapif ugt $v1, oob
; nextln: return
; nextln: }

View File

@@ -74,6 +74,7 @@ RegFill = InstructionFormat(
Trap = InstructionFormat(trapcode)
CondTrap = InstructionFormat(VALUE, trapcode)
IntCondTrap = InstructionFormat(intcc, VALUE, trapcode)
# Finally extract the names of global variables in this module.
InstructionFormat.extract_names(globals())

View File

@@ -167,6 +167,15 @@ trapnz = Instruction(
""",
ins=(c, code), can_trap=True)
Cond = Operand('Cond', intcc)
f = Operand('f', iflags)
trapif = Instruction(
'trapif', r"""
Trap when condition is true in integer CPU flags.
""",
ins=(Cond, f, code), can_trap=True)
rvals = Operand('rvals', VARIABLE_ARGS, doc='return values')
x_return = Instruction(

View File

@@ -264,6 +264,12 @@ pub enum InstructionData {
arg: Value,
code: ir::TrapCode,
},
IntCondTrap {
opcode: Opcode,
cond: IntCC,
arg: Value,
code: ir::TrapCode,
},
}
/// A variable list of `Value` operands used for function call arguments and passing arguments to

View File

@@ -365,6 +365,7 @@ impl<'a> Verifier<'a> {
CopySpecial { .. } |
Trap { .. } |
CondTrap { .. } |
IntCondTrap { .. } |
NullAry { .. } => {}
}

View File

@@ -428,6 +428,7 @@ pub fn write_operands(
}
Trap { code, .. } => write!(w, " {}", code),
CondTrap { arg, code, .. } => write!(w, " {}, {}", arg, code),
IntCondTrap { cond, arg, code, .. } => write!(w, " {} {}, {}", cond, arg, code),
}
}

View File

@@ -2348,6 +2348,21 @@ impl<'a> Parser<'a> {
let code = self.match_enum("expected trap code")?;
InstructionData::CondTrap { opcode, arg, code }
}
InstructionFormat::IntCondTrap => {
let cond = self.match_enum("expected intcc condition code")?;
let arg = self.match_value("expected SSA value operand")?;
self.match_token(
Token::Comma,
"expected ',' between operands",
)?;
let code = self.match_enum("expected trap code")?;
InstructionData::IntCondTrap {
opcode,
cond,
arg,
code,
}
}
};
Ok(idata)
}