From cdf70ccb7733b80579f06d8dcdcb3a38d3a27ccc Mon Sep 17 00:00:00 2001 From: Tyler McMullen Date: Wed, 22 Nov 2017 19:18:11 -0800 Subject: [PATCH] Add copy_special instruction. --- lib/cretonne/meta/base/formats.py | 1 + lib/cretonne/meta/base/instructions.py | 7 +++++++ lib/cretonne/src/ir/instructions.rs | 5 +++++ lib/cretonne/src/verifier/mod.rs | 1 + lib/cretonne/src/write.rs | 13 +++++++++++++ lib/reader/src/parser.rs | 9 +++++++++ 6 files changed, 36 insertions(+) diff --git a/lib/cretonne/meta/base/formats.py b/lib/cretonne/meta/base/formats.py index 1961d9d4a9..539d87561b 100644 --- a/lib/cretonne/meta/base/formats.py +++ b/lib/cretonne/meta/base/formats.py @@ -64,6 +64,7 @@ StackStore = InstructionFormat(VALUE, stack_slot, offset32) HeapAddr = InstructionFormat(heap, VALUE, uimm32) RegMove = InstructionFormat(VALUE, ('src', regunit), ('dst', regunit)) +CopySpecial = InstructionFormat(('src', regunit), ('dst', regunit)) RegSpill = InstructionFormat( VALUE, ('src', regunit), ('dst', entities.stack_slot)) RegFill = InstructionFormat( diff --git a/lib/cretonne/meta/base/instructions.py b/lib/cretonne/meta/base/instructions.py index 26a6f66077..195f255046 100644 --- a/lib/cretonne/meta/base/instructions.py +++ b/lib/cretonne/meta/base/instructions.py @@ -537,6 +537,13 @@ regmove = Instruction( ins=(x, src, dst), other_side_effects=True) +copy_special = Instruction( + 'copy_special', r""" + Copies a value from one special register to another. e.g. rbp -> rsp. + """, + ins=(src, dst), + other_side_effects=True) + regspill = Instruction( 'regspill', r""" Temporarily divert ``x`` from ``src`` to ``SS``. diff --git a/lib/cretonne/src/ir/instructions.rs b/lib/cretonne/src/ir/instructions.rs index c474258f37..37ca23150c 100644 --- a/lib/cretonne/src/ir/instructions.rs +++ b/lib/cretonne/src/ir/instructions.rs @@ -236,6 +236,11 @@ pub enum InstructionData { src: RegUnit, dst: RegUnit, }, + CopySpecial { + opcode: Opcode, + src: RegUnit, + dst: RegUnit, + }, RegSpill { opcode: Opcode, arg: Value, diff --git a/lib/cretonne/src/verifier/mod.rs b/lib/cretonne/src/verifier/mod.rs index 6b67ed1bed..259cf48a5e 100644 --- a/lib/cretonne/src/verifier/mod.rs +++ b/lib/cretonne/src/verifier/mod.rs @@ -358,6 +358,7 @@ impl<'a> Verifier<'a> { Load { .. } | Store { .. } | RegMove { .. } | + CopySpecial { .. } | Trap { .. } | CondTrap { .. } | NullAry { .. } => {} diff --git a/lib/cretonne/src/write.rs b/lib/cretonne/src/write.rs index 1604ca559a..8c8c280ca9 100644 --- a/lib/cretonne/src/write.rs +++ b/lib/cretonne/src/write.rs @@ -394,6 +394,19 @@ pub fn write_operands( write!(w, " {}, %{} -> %{}", arg, src, dst) } } + CopySpecial { src, dst, .. } => { + if let Some(isa) = isa { + let regs = isa.register_info(); + write!( + w, + " {} -> {}", + regs.display_regunit(src), + regs.display_regunit(dst) + ) + } else { + write!(w, " %{} -> %{}", src, dst) + } + } RegSpill { arg, src, dst, .. } => { if let Some(isa) = isa { let regs = isa.register_info(); diff --git a/lib/reader/src/parser.rs b/lib/reader/src/parser.rs index b96cba20b2..b3827de62c 100644 --- a/lib/reader/src/parser.rs +++ b/lib/reader/src/parser.rs @@ -2270,6 +2270,15 @@ impl<'a> Parser<'a> { dst, } } + InstructionFormat::CopySpecial => { + let src = self.match_regunit(ctx.unique_isa)?; + self.match_token( + Token::Arrow, + "expected '->' between register units", + )?; + let dst = self.match_regunit(ctx.unique_isa)?; + InstructionData::CopySpecial { opcode, src, dst } + } InstructionFormat::RegSpill => { let arg = self.match_value("expected SSA value operand")?; self.match_token(