Add a fold_redundant_jumps() pass to the branch relaxation phase. (#887)

This commit is contained in:
Sean Stangl
2019-08-09 15:30:11 -06:00
committed by GitHub
parent e6e274a3aa
commit c7b4b98cac
8 changed files with 178 additions and 41 deletions

View File

@@ -8,7 +8,7 @@ use crate::entity::{PrimaryMap, SecondaryMap};
use crate::ir;
use crate::ir::{DataFlowGraph, ExternalName, Layout, Signature};
use crate::ir::{
Ebb, ExtFuncData, FuncRef, GlobalValue, GlobalValueData, Heap, HeapData, JumpTable,
Ebb, ExtFuncData, FuncRef, GlobalValue, GlobalValueData, Heap, HeapData, Inst, JumpTable,
JumpTableData, SigRef, StackSlot, StackSlotData, Table, TableData,
};
use crate::ir::{EbbOffsets, InstEncodings, SourceLocs, StackSlots, ValueLocations};
@@ -20,7 +20,7 @@ use crate::write::write_function;
use core::fmt;
#[cfg(feature = "basic-blocks")]
use crate::ir::{Inst, Opcode};
use crate::ir::Opcode;
/// A function.
///
@@ -223,6 +223,15 @@ impl Function {
self.dfg.collect_debug_info();
}
/// Changes the destination of a jump or branch instruction.
/// Does nothing if called with a non-jump or non-branch instruction.
pub fn change_branch_destination(&mut self, inst: Inst, new_dest: Ebb) {
match self.dfg[inst].branch_destination_mut() {
None => (),
Some(inst_dest) => *inst_dest = new_dest,
}
}
/// Checks that the specified EBB can be encoded as a basic block.
///
/// On error, returns the first invalid instruction and an error message.