Merge reloc_func and reloc_globalsym into reloc_external.

This commit is contained in:
Dan Gohman
2017-10-31 12:06:13 -07:00
parent b60b2ce135
commit 5d063eb8bc
12 changed files with 52 additions and 55 deletions

View File

@@ -477,7 +477,7 @@ fnaddr4 = TailRecipe(
'fnaddr4', FuncAddr, size=4, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_func(RelocKind::Abs4.into(), func_ref);
sink.reloc_external(RelocKind::Abs4.into(), &func.dfg.ext_funcs[func_ref].name);
sink.put4(0);
''')
@@ -486,7 +486,7 @@ fnaddr8 = TailRecipe(
'fnaddr8', FuncAddr, size=8, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_func(RelocKind::Abs8.into(), func_ref);
sink.reloc_external(RelocKind::Abs8.into(), &func.dfg.ext_funcs[func_ref].name);
sink.put8(0);
''')
@@ -495,7 +495,7 @@ allones_fnaddr4 = TailRecipe(
'allones_fnaddr4', FuncAddr, size=4, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_func(RelocKind::Abs4.into(), func_ref);
sink.reloc_external(RelocKind::Abs4.into(), &func.dfg.ext_funcs[func_ref].name);
// Write the immediate as `!0` for the benefit of BaldrMonkey.
sink.put4(!0);
''')
@@ -505,7 +505,7 @@ allones_fnaddr8 = TailRecipe(
'allones_fnaddr8', FuncAddr, size=8, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_func(RelocKind::Abs8.into(), func_ref);
sink.reloc_external(RelocKind::Abs8.into(), &func.dfg.ext_funcs[func_ref].name);
// Write the immediate as `!0` for the benefit of BaldrMonkey.
sink.put8(!0);
''')
@@ -515,7 +515,7 @@ gvaddr4 = TailRecipe(
'gvaddr4', UnaryGlobalVar, size=4, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_globalsym(RelocKind::Abs4.into(), global_var);
sink.reloc_external(RelocKind::Abs4.into(), &func.global_vars[global_var].symbol_name());
sink.put4(0);
''')
@@ -524,7 +524,7 @@ gvaddr8 = TailRecipe(
'gvaddr8', UnaryGlobalVar, size=8, ins=(), outs=GPR,
emit='''
PUT_OP(bits | (out_reg0 & 7), rex1(out_reg0), sink);
sink.reloc_globalsym(RelocKind::Abs8.into(), global_var);
sink.reloc_external(RelocKind::Abs8.into(), &func.global_vars[global_var].symbol_name());
sink.put8(0);
''')
@@ -798,7 +798,7 @@ call_id = TailRecipe(
'call_id', Call, size=4, ins=(), outs=(),
emit='''
PUT_OP(bits, BASE_REX, sink);
sink.reloc_func(RelocKind::PCRel4.into(), func_ref);
sink.reloc_external(RelocKind::PCRel4.into(), &func.dfg.ext_funcs[func_ref].name);
sink.put4(0);
''')

View File

@@ -183,7 +183,7 @@ UJ = EncRecipe(
UJcall = EncRecipe(
'UJcall', Call, size=4, ins=(), outs=(),
emit='''
sink.reloc_func(RelocKind::Call.into(), func_ref);
sink.reloc_external(RelocKind::Call.into(), &func.dfg.ext_funcs[func_ref].name);
// rd=%x1 is the standard link register.
put_uj(bits, 0, 1, sink);
''')

View File

@@ -14,7 +14,7 @@
//! relocations to a `RelocSink` trait object. Relocations are less frequent than the
//! `CodeSink::put*` methods, so the performance impact of the virtual callbacks is less severe.
use ir::{Ebb, FuncRef, GlobalVar, JumpTable};
use ir::{ExternalName, Ebb, JumpTable};
use super::{CodeSink, CodeOffset, Reloc};
use std::ptr::write_unaligned;
@@ -51,12 +51,8 @@ pub trait RelocSink {
/// Add a relocation referencing an EBB at the current offset.
fn reloc_ebb(&mut self, CodeOffset, Reloc, Ebb);
/// Add a relocation referencing an external function at the current offset.
fn reloc_func(&mut self, CodeOffset, Reloc, FuncRef);
/// Add a relocation referencing an external global variable symbol at the
/// current offset.
fn reloc_globalsym(&mut self, CodeOffset, Reloc, GlobalVar);
/// Add a relocation referencing an external symbol at the current offset.
fn reloc_external(&mut self, CodeOffset, Reloc, &ExternalName);
/// Add a relocation referencing a jump table.
fn reloc_jt(&mut self, CodeOffset, Reloc, JumpTable);
@@ -100,14 +96,9 @@ impl<'a> CodeSink for MemoryCodeSink<'a> {
self.relocs.reloc_ebb(ofs, rel, ebb);
}
fn reloc_func(&mut self, rel: Reloc, func: FuncRef) {
fn reloc_external(&mut self, rel: Reloc, name: &ExternalName) {
let ofs = self.offset();
self.relocs.reloc_func(ofs, rel, func);
}
fn reloc_globalsym(&mut self, rel: Reloc, global: GlobalVar) {
let ofs = self.offset();
self.relocs.reloc_globalsym(ofs, rel, global);
self.relocs.reloc_external(ofs, rel, name);
}
fn reloc_jt(&mut self, rel: Reloc, jt: JumpTable) {

View File

@@ -9,7 +9,7 @@ mod memorysink;
pub use self::relaxation::relax_branches;
pub use self::memorysink::{MemoryCodeSink, RelocSink};
use ir::{Ebb, FuncRef, GlobalVar, JumpTable, Function, Inst};
use ir::{ExternalName, Ebb, JumpTable, Function, Inst};
use regalloc::RegDiversions;
/// Offset in bytes from the beginning of the function.
@@ -44,12 +44,8 @@ pub trait CodeSink {
/// Add a relocation referencing an EBB at the current offset.
fn reloc_ebb(&mut self, Reloc, Ebb);
/// Add a relocation referencing an external function at the current offset.
fn reloc_func(&mut self, Reloc, FuncRef);
/// Add a relocation referencing an external global variable symbol at the
/// current offset. This is only used for `GlobalVarData::Sym` globals.
fn reloc_globalsym(&mut self, Reloc, GlobalVar);
/// Add a relocation referencing an external symbol at the current offset.
fn reloc_external(&mut self, Reloc, &ExternalName);
/// Add a relocation referencing a jump table.
fn reloc_jt(&mut self, Reloc, JumpTable);

View File

@@ -35,6 +35,16 @@ pub enum GlobalVarData {
},
}
impl GlobalVarData {
/// Assume that `self` is an `GlobalVarData::Sym` and return its name.
pub fn symbol_name(&self) -> &ExternalName {
match *self {
GlobalVarData::Sym { ref name } => name,
_ => panic!("only symbols have names"),
}
}
}
impl fmt::Display for GlobalVarData {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {