Add conditional branch encodings for RISC-V.

Not all br_icmp opcodes are present in the ISA. The missing ones can be
reached by commuting operands.

Don't attempt to encode EBB offsets yet. For now just emit an EBB
relocation for the branch instruction.
This commit is contained in:
Jakob Stoklund Olesen
2017-04-03 15:07:08 -07:00
parent 1b6a6f4e48
commit 479ff156c1
9 changed files with 124 additions and 12 deletions

View File

@@ -75,5 +75,21 @@ ebb0:
[-,%x7] v140 = iconst.i32 0x12345000 ; bin: 123453b7
[-,%x16] v141 = iconst.i32 0xffffffff_fedcb000 ; bin: fedcb837
; Control Transfer Instructions
; beq
br_icmp eq, v1, v2, ebb0 ; bin: Branch(ebb0) 01550063
; bne
br_icmp ne, v1, v2, ebb0 ; bin: Branch(ebb0) 01551063
; blt
br_icmp slt, v1, v2, ebb0 ; bin: Branch(ebb0) 01554063
; bge
br_icmp sge, v1, v2, ebb0 ; bin: Branch(ebb0) 01555063
; bltu
br_icmp ult, v1, v2, ebb0 ; bin: Branch(ebb0) 01556063
; bgeu
br_icmp uge, v1, v2, ebb0 ; bin: Branch(ebb0) 01557063
return
}

View File

@@ -25,6 +25,7 @@ pub fn subtest(parsed: &TestCommand) -> Result<Box<SubTest>> {
// Code sink that generates text.
struct TextSink {
rnames: &'static [&'static str],
text: String,
}
@@ -45,12 +46,16 @@ impl binemit::CodeSink for TextSink {
write!(self.text, "{:016x} ", x).unwrap();
}
fn reloc_func(&mut self, _: binemit::Reloc, _: ir::FuncRef) {
unimplemented!()
fn reloc_ebb(&mut self, reloc: binemit::Reloc, ebb: ir::Ebb) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], ebb).unwrap();
}
fn reloc_jt(&mut self, _: binemit::Reloc, _: ir::JumpTable) {
unimplemented!()
fn reloc_func(&mut self, reloc: binemit::Reloc, fref: ir::FuncRef) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], fref).unwrap();
}
fn reloc_jt(&mut self, reloc: binemit::Reloc, jt: ir::JumpTable) {
write!(self.text, "{}({}) ", self.rnames[reloc.0 as usize], jt).unwrap();
}
}
@@ -73,7 +78,10 @@ impl SubTest for TestBinEmit {
// value locations. The current error reporting is just crashing...
let mut func = func.into_owned();
let mut sink = TextSink { text: String::new() };
let mut sink = TextSink {
rnames: isa.reloc_names(),
text: String::new(),
};
for comment in &context.details.comments {
if let Some(want) = match_directive(comment.text, "bin:") {

View File

@@ -56,7 +56,7 @@ fi
if [ -n "$needcheck" ]; then
banner $(python --version 2>&1)
$topdir/lib/cretonne/meta/check.sh
touch $tsfile
touch $tsfile || echo no target directory
fi
PKGS="cretonne cretonne-reader cretonne-tools filecheck"