Merge reloc_func and reloc_globalsym into reloc_external.
This commit is contained in:
@@ -17,9 +17,9 @@ function %I32() {
|
||||
ebb0:
|
||||
|
||||
; asm: movl $-1, %ecx
|
||||
[-,%rcx] v400 = func_addr.i32 fn0 ; bin: b9 Abs4(fn0) ffffffff
|
||||
[-,%rcx] v400 = func_addr.i32 fn0 ; bin: b9 Abs4(%foo) ffffffff
|
||||
; asm: movl $-1, %esi
|
||||
[-,%rsi] v401 = func_addr.i32 fn0 ; bin: be Abs4(fn0) ffffffff
|
||||
[-,%rsi] v401 = func_addr.i32 fn0 ; bin: be Abs4(%foo) ffffffff
|
||||
|
||||
return ; bin: c3
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ function %I64() {
|
||||
ebb0:
|
||||
|
||||
; asm: movabsq $-1, %rcx
|
||||
[-,%rcx] v400 = func_addr.i64 fn0 ; bin: 48 b9 Abs8(fn0) ffffffffffffffff
|
||||
[-,%rcx] v400 = func_addr.i64 fn0 ; bin: 48 b9 Abs8(%foo) ffffffffffffffff
|
||||
; asm: movabsq $-1, %rsi
|
||||
[-,%rsi] v401 = func_addr.i64 fn0 ; bin: 48 be Abs8(fn0) ffffffffffffffff
|
||||
[-,%rsi] v401 = func_addr.i64 fn0 ; bin: 48 be Abs8(%foo) ffffffffffffffff
|
||||
; asm: movabsq $-1, %r10
|
||||
[-,%r10] v402 = func_addr.i64 fn0 ; bin: 49 ba Abs8(fn0) ffffffffffffffff
|
||||
[-,%r10] v402 = func_addr.i64 fn0 ; bin: 49 ba Abs8(%foo) ffffffffffffffff
|
||||
|
||||
return ; bin: c3
|
||||
}
|
||||
|
||||
@@ -342,12 +342,12 @@ ebb0:
|
||||
[-,%rsi] v351 = bint.i32 v301 ; bin: 0f b6 f2
|
||||
|
||||
; asm: call foo
|
||||
call fn0() ; bin: e8 PCRel4(fn0) 00000000
|
||||
call fn0() ; bin: e8 PCRel4(%foo) 00000000
|
||||
|
||||
; asm: movl $0, %ecx
|
||||
[-,%rcx] v400 = func_addr.i32 fn0 ; bin: b9 Abs4(fn0) 00000000
|
||||
[-,%rcx] v400 = func_addr.i32 fn0 ; bin: b9 Abs4(%foo) 00000000
|
||||
; asm: movl $0, %esi
|
||||
[-,%rsi] v401 = func_addr.i32 fn0 ; bin: be Abs4(fn0) 00000000
|
||||
[-,%rsi] v401 = func_addr.i32 fn0 ; bin: be Abs4(%foo) 00000000
|
||||
|
||||
; asm: call *%ecx
|
||||
call_indirect sig0, v400() ; bin: ff d1
|
||||
@@ -355,9 +355,9 @@ ebb0:
|
||||
call_indirect sig0, v401() ; bin: ff d6
|
||||
|
||||
; asm: movl $0, %ecx
|
||||
[-,%rcx] v450 = globalsym_addr.i32 gv0 ; bin: b9 Abs4(gv0) 00000000
|
||||
[-,%rcx] v450 = globalsym_addr.i32 gv0 ; bin: b9 Abs4(%some_gv) 00000000
|
||||
; asm: movl $0, %esi
|
||||
[-,%rsi] v451 = globalsym_addr.i32 gv0 ; bin: be Abs4(gv0) 00000000
|
||||
[-,%rsi] v451 = globalsym_addr.i32 gv0 ; bin: be Abs4(%some_gv) 00000000
|
||||
|
||||
; Spill / Fill.
|
||||
|
||||
|
||||
@@ -429,14 +429,14 @@ ebb0:
|
||||
[-,%rsi] v351 = bint.i64 v301 ; bin: 0f b6 f2
|
||||
|
||||
; asm: call foo
|
||||
call fn0() ; bin: e8 PCRel4(fn0) 00000000
|
||||
call fn0() ; bin: e8 PCRel4(%foo) 00000000
|
||||
|
||||
; asm: movabsq $0, %rcx
|
||||
[-,%rcx] v400 = func_addr.i64 fn0 ; bin: 48 b9 Abs8(fn0) 0000000000000000
|
||||
[-,%rcx] v400 = func_addr.i64 fn0 ; bin: 48 b9 Abs8(%foo) 0000000000000000
|
||||
; asm: movabsq $0, %rsi
|
||||
[-,%rsi] v401 = func_addr.i64 fn0 ; bin: 48 be Abs8(fn0) 0000000000000000
|
||||
[-,%rsi] v401 = func_addr.i64 fn0 ; bin: 48 be Abs8(%foo) 0000000000000000
|
||||
; asm: movabsq $0, %r10
|
||||
[-,%r10] v402 = func_addr.i64 fn0 ; bin: 49 ba Abs8(fn0) 0000000000000000
|
||||
[-,%r10] v402 = func_addr.i64 fn0 ; bin: 49 ba Abs8(%foo) 0000000000000000
|
||||
|
||||
; asm: call *%rcx
|
||||
call_indirect sig0, v400() ; bin: ff d1
|
||||
@@ -446,11 +446,11 @@ ebb0:
|
||||
call_indirect sig0, v402() ; bin: 41 ff d2
|
||||
|
||||
; asm: movabsq $-1, %rcx
|
||||
[-,%rcx] v450 = globalsym_addr.i64 gv0 ; bin: 48 b9 Abs8(gv0) 0000000000000000
|
||||
[-,%rcx] v450 = globalsym_addr.i64 gv0 ; bin: 48 b9 Abs8(%some_gv) 0000000000000000
|
||||
; asm: movabsq $-1, %rsi
|
||||
[-,%rsi] v451 = globalsym_addr.i64 gv0 ; bin: 48 be Abs8(gv0) 0000000000000000
|
||||
[-,%rsi] v451 = globalsym_addr.i64 gv0 ; bin: 48 be Abs8(%some_gv) 0000000000000000
|
||||
; asm: movabsq $-1, %r10
|
||||
[-,%r10] v452 = globalsym_addr.i64 gv0 ; bin: 49 ba Abs8(gv0) 0000000000000000
|
||||
[-,%r10] v452 = globalsym_addr.i64 gv0 ; bin: 49 ba Abs8(%some_gv) 0000000000000000
|
||||
|
||||
; Spill / Fill.
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ ebb0(v9999: i32):
|
||||
; Control Transfer Instructions
|
||||
|
||||
; jal %x1, fn0
|
||||
call fn0() ; bin: Call(fn0) 000000ef
|
||||
call fn0() ; bin: Call(%foo) 000000ef
|
||||
|
||||
; jalr %x1, %x10
|
||||
call_indirect sig0, v1() ; bin: 000500e7
|
||||
|
||||
@@ -75,12 +75,13 @@ impl binemit::CodeSink for TextSink {
|
||||
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], ebb).unwrap();
|
||||
}
|
||||
|
||||
fn reloc_func(&mut self, reloc: binemit::Reloc, fref: ir::FuncRef) {
|
||||
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], fref).unwrap();
|
||||
}
|
||||
|
||||
fn reloc_globalsym(&mut self, reloc: binemit::Reloc, global: ir::GlobalVar) {
|
||||
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], global).unwrap();
|
||||
fn reloc_external(&mut self, reloc: binemit::Reloc, name: &ir::ExternalName) {
|
||||
write!(
|
||||
self.text,
|
||||
"{}({}) ",
|
||||
self.rnames[reloc.0 as usize],
|
||||
name,
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
fn reloc_jt(&mut self, reloc: binemit::Reloc, jt: ir::JumpTable) {
|
||||
|
||||
@@ -98,7 +98,6 @@ impl binemit::CodeSink for SizeSink {
|
||||
}
|
||||
|
||||
fn reloc_ebb(&mut self, _reloc: binemit::Reloc, _ebb: ir::Ebb) {}
|
||||
fn reloc_func(&mut self, _reloc: binemit::Reloc, _fref: ir::FuncRef) {}
|
||||
fn reloc_globalsym(&mut self, _reloc: binemit::Reloc, _global: ir::GlobalVar) {}
|
||||
fn reloc_external(&mut self, _reloc: binemit::Reloc, _name: &ir::ExternalName) {}
|
||||
fn reloc_jt(&mut self, _reloc: binemit::Reloc, _jt: ir::JumpTable) {}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
''')
|
||||
|
||||
|
||||
@@ -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);
|
||||
''')
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user