Rework br_table to use BlockCall (#5731)
Rework br_table to use BlockCall, allowing us to avoid adding new nodes during ssa construction to hold block arguments. Additionally, many places where we previously matched on InstructionData to extract branch destinations can be replaced with a use of branch_destination or branch_destination_mut.
This commit is contained in:
@@ -1783,9 +1783,13 @@ impl<'a> Parser<'a> {
|
||||
|
||||
// Parse a jump table literal.
|
||||
//
|
||||
// jump-table-lit ::= "[" block {"," block } "]"
|
||||
// jump-table-lit ::= "[" block(args) {"," block(args) } "]"
|
||||
// | "[]"
|
||||
fn parse_jump_table(&mut self, def: Block) -> ParseResult<JumpTableData> {
|
||||
fn parse_jump_table(
|
||||
&mut self,
|
||||
ctx: &mut Context,
|
||||
def: ir::BlockCall,
|
||||
) -> ParseResult<ir::JumpTable> {
|
||||
self.match_token(Token::LBracket, "expected '[' before jump table contents")?;
|
||||
|
||||
let mut data = Vec::new();
|
||||
@@ -1793,7 +1797,8 @@ impl<'a> Parser<'a> {
|
||||
match self.token() {
|
||||
Some(Token::Block(dest)) => {
|
||||
self.consume();
|
||||
data.push(dest);
|
||||
let args = self.parse_opt_value_list()?;
|
||||
data.push(ctx.function.dfg.block_call(dest, &args));
|
||||
|
||||
loop {
|
||||
match self.token() {
|
||||
@@ -1801,7 +1806,8 @@ impl<'a> Parser<'a> {
|
||||
self.consume();
|
||||
if let Some(Token::Block(dest)) = self.token() {
|
||||
self.consume();
|
||||
data.push(dest);
|
||||
let args = self.parse_opt_value_list()?;
|
||||
data.push(ctx.function.dfg.block_call(dest, &args));
|
||||
} else {
|
||||
return err!(self.loc, "expected jump_table entry");
|
||||
}
|
||||
@@ -1817,7 +1823,11 @@ impl<'a> Parser<'a> {
|
||||
|
||||
self.consume();
|
||||
|
||||
Ok(JumpTableData::new(def, &data))
|
||||
Ok(ctx
|
||||
.function
|
||||
.dfg
|
||||
.jump_tables
|
||||
.push(JumpTableData::new(def, &data)))
|
||||
}
|
||||
|
||||
// Parse a constant decl.
|
||||
@@ -2588,9 +2598,10 @@ impl<'a> Parser<'a> {
|
||||
let arg = self.match_value("expected SSA value operand")?;
|
||||
self.match_token(Token::Comma, "expected ',' between operands")?;
|
||||
let block_num = self.match_block("expected branch destination block")?;
|
||||
let args = self.parse_opt_value_list()?;
|
||||
let destination = ctx.function.dfg.block_call(block_num, &args);
|
||||
self.match_token(Token::Comma, "expected ',' between operands")?;
|
||||
let table_data = self.parse_jump_table(block_num)?;
|
||||
let table = ctx.function.dfg.jump_tables.push(table_data);
|
||||
let table = self.parse_jump_table(ctx, destination)?;
|
||||
InstructionData::BranchTable { opcode, arg, table }
|
||||
}
|
||||
InstructionFormat::TernaryImm8 => {
|
||||
|
||||
Reference in New Issue
Block a user