From f2b9f62f248995380e894d1e5b347ef2ad4b0198 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Thu, 19 Jan 2017 14:49:55 -0800 Subject: [PATCH] Avoid using NO_INST in the parser. This was only used for the comment rewrite mechanism, and we can just predict the next allocated instruction number instead. See the other uses of next_key() for gather_comments(). --- lib/cretonne/src/ir/dfg.rs | 8 ++++++++ lib/reader/src/parser.rs | 22 +++------------------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/lib/cretonne/src/ir/dfg.rs b/lib/cretonne/src/ir/dfg.rs index 7e843d0c87..7ab9ee24d8 100644 --- a/lib/cretonne/src/ir/dfg.rs +++ b/lib/cretonne/src/ir/dfg.rs @@ -301,6 +301,14 @@ impl DataFlowGraph { self.insts.push(data) } + /// Get the instruction reference that will be assigned to the next instruction created by + /// `make_inst`. + /// + /// This is only really useful to the parser. + pub fn next_inst(&self) -> Inst { + self.insts.next_key() + } + /// Create result values for an instruction that produces multiple results. /// /// Instructions that produce 0 or 1 result values only need to be created with `make_inst`. If diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index f73bfc7a3c..2d1d85f93d 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -13,7 +13,7 @@ use cretonne::ir::{Function, Ebb, Opcode, Value, Type, FunctionName, StackSlotDa FuncRef}; use cretonne::ir::types::VOID; use cretonne::ir::immediates::{Imm64, Ieee32, Ieee64}; -use cretonne::ir::entities::{AnyEntity, NO_INST, NO_VALUE}; +use cretonne::ir::entities::{AnyEntity, NO_VALUE}; use cretonne::ir::instructions::{InstructionFormat, InstructionData, VariableArgs, TernaryOverflowData, JumpData, BranchData, CallData, IndirectCallData, ReturnData}; @@ -283,17 +283,6 @@ impl<'a> Parser<'a> { mem::replace(&mut self.comments, Vec::new()) } - // Rewrite the entity of the last added comments from `old` to `new`. - // Also switch to collecting future comments for `new`. - fn rewrite_last_comment_entities>(&mut self, old: E, new: E) { - let old = old.into(); - let new = new.into(); - for comment in (&mut self.comments).into_iter().rev().take_while(|c| c.entity == old) { - comment.entity = new; - } - self.comment_entity = Some(new); - } - // Match and consume a token without payload. fn match_token(&mut self, want: Token<'a>, err_msg: &str) -> Result> { if self.token() == Some(want) { @@ -906,9 +895,8 @@ impl<'a> Parser<'a> { // inst-results ::= Value(v) { "," Value(vx) } // fn parse_instruction(&mut self, ctx: &mut Context, ebb: Ebb) -> Result<()> { - // Collect comments for `NO_INST` while parsing the instruction, then rewrite after we - // allocate an instruction number. - self.gather_comments(NO_INST); + // Collect comments for the next instruction to be allocated. + self.gather_comments(ctx.function.dfg.next_inst()); // Result value numbers. let mut results = Vec::new(); @@ -969,10 +957,6 @@ impl<'a> Parser<'a> { results.len()); } - // If we saw any comments while parsing the instruction, they will have been recorded as - // belonging to `NO_INST`. - self.rewrite_last_comment_entities(NO_INST, inst); - // Now map the source result values to the just created instruction results. // Pass a reference to `ctx.values` instead of `ctx` itself since the `Values` iterator // holds a reference to `ctx.function`.