Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
cleanup and avoid some unnecessary allocs
Browse files Browse the repository at this point in the history
  • Loading branch information
iximeow committed Oct 2, 2019
1 parent 0f4a833 commit b27354d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cranelift-codegen/src/ir/framelayout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::isa::RegUnit;
use std::boxed::Box;

#[cfg(not(feature = "std"))]
use hashmap_core::HashMap;
use crate::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;

Expand Down
23 changes: 12 additions & 11 deletions cranelift-codegen/src/isa/x86/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::regalloc::RegisterSet;
use crate::result::CodegenResult;
use crate::stack_layout::layout_stack;
use core::i32;
use std::boxed::Box;
use target_lexicon::{PointerWidth, Triple};

/// Argument registers for x86-64
Expand Down Expand Up @@ -651,13 +652,11 @@ fn insert_common_epilogues(
if let Some(inst) = pos.current_inst() {
if pos.func.dfg[inst].opcode().is_return() {
// figure out if we need to insert end-of-function-aware frame layout information
let following_inst = pos.next_ebb().and_then(|next_ebb| {
pos.goto_first_inst(next_ebb);
pos.current_inst()
});

// and rewind back to where we want to insert prologue instructions
pos.goto_last_inst(ebb);
let following_inst = pos
.func
.layout
.next_ebb(ebb)
.and_then(|next_ebb| pos.func.layout.first_inst(next_ebb));

if following_inst.is_some() {
if let Some(ref mut frame_layout) = pos.func.frame_layout {
Expand Down Expand Up @@ -748,10 +747,12 @@ fn insert_common_epilogue(
.instructions
.entry(inst)
.and_modify(|insts| {
let mut new_instructions = insts.to_vec();
new_instructions.push(new_cfa);
*insts = new_instructions.into_boxed_slice();
*insts = insts
.into_iter()
.map(|x| *x)
.chain(std::iter::once(new_cfa))
.collect::<Box<[_]>>();
})
.or_insert_with(|| vec![new_cfa].into_boxed_slice());
.or_insert_with(|| Box::new([new_cfa]));
}
}

0 comments on commit b27354d

Please sign in to comment.