Track regmove instruction during binemit.
Register locations can change throughout an EBB. Make sure the emit_inst() function considers this when encoding instructions and update the register diversion tracker.
This commit is contained in:
15
cranelift/filetests/isa/riscv/regmove.cton
Normal file
15
cranelift/filetests/isa/riscv/regmove.cton
Normal file
@@ -0,0 +1,15 @@
|
||||
; Test tracking of register moves.
|
||||
test binemit
|
||||
isa riscv
|
||||
|
||||
function %regmoves(i32 link [%x1]) -> i32 link [%x1] {
|
||||
ebb0(v9999: i32):
|
||||
[-,%x10] v1 = iconst.i32 1
|
||||
[-,%x7] v2 = iadd_imm v1, 1000 ; bin: 3e850393
|
||||
regmove v1, %x10 -> %x11 ; bin: 00050593
|
||||
[-,%x7] v3 = iadd_imm v1, 1000 ; bin: 3e858393
|
||||
regmove v1, %x11 -> %x10 ; bin: 00058513
|
||||
[-,%x7] v4 = iadd_imm v1, 1000 ; bin: 3e850393
|
||||
|
||||
return v9999
|
||||
}
|
||||
@@ -10,6 +10,7 @@ use cretonne::binemit;
|
||||
use cretonne::ir;
|
||||
use cretonne::ir::entities::AnyEntity;
|
||||
use cretonne::isa::TargetIsa;
|
||||
use cretonne::regalloc::RegDiversions;
|
||||
use cton_reader::TestCommand;
|
||||
use filetest::subtest::{SubTest, Context, Result};
|
||||
use utils::{match_directive, pretty_error};
|
||||
@@ -147,7 +148,9 @@ impl SubTest for TestBinEmit {
|
||||
|
||||
// Now emit all instructions.
|
||||
let mut sink = TextSink::new(isa);
|
||||
let mut divert = RegDiversions::new();
|
||||
for ebb in func.layout.ebbs() {
|
||||
divert.clear();
|
||||
// Correct header offsets should have been computed by `relax_branches()`.
|
||||
assert_eq!(sink.offset,
|
||||
func.offsets[ebb],
|
||||
@@ -160,7 +163,7 @@ impl SubTest for TestBinEmit {
|
||||
// Send legal encodings into the emitter.
|
||||
if enc.is_legal() {
|
||||
let before = sink.offset;
|
||||
isa.emit_inst(&func, inst, &mut sink);
|
||||
isa.emit_inst(&func, inst, &mut divert, &mut sink);
|
||||
let emitted = sink.offset - before;
|
||||
// Verify the encoding recipe sizes against the ISAs emit_inst implementation.
|
||||
assert_eq!(emitted,
|
||||
|
||||
@@ -52,7 +52,7 @@ impl SubTest for TestCompile {
|
||||
// Finally verify that the returned code size matches the emitted bytes.
|
||||
let mut sink = SizeSink { offset: 0 };
|
||||
binemit::emit_function(&comp_ctx.func,
|
||||
|func, inst, sink| isa.emit_inst(func, inst, sink),
|
||||
|func, inst, div, sink| isa.emit_inst(func, inst, div, sink),
|
||||
&mut sink);
|
||||
|
||||
if sink.offset != code_size {
|
||||
|
||||
Reference in New Issue
Block a user