From eac9301cdbf529202da98c58faadf84b55655731 Mon Sep 17 00:00:00 2001 From: Simon Dardis Date: Wed, 25 Apr 2018 10:19:22 +0000 Subject: [PATCH] [mips] Fix the definition of sync, synci Also, fix the disassembly of synci for microMIPS. Reviewers: abeserminji, smaksimovic, atanasyan Differential Revision: https://reviews.llvm.org/D45870 llvm-svn: 330810 --- llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp | 18 ++++++++++++++++++ llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td | 2 +- llvm/lib/Target/Mips/MicroMipsInstrFormats.td | 5 +++-- llvm/lib/Target/Mips/MicroMipsInstrInfo.td | 11 ++++++++--- llvm/lib/Target/Mips/MipsInstrInfo.td | 11 ++++++----- .../MC/Disassembler/Mips/micromips32r3/valid-el.txt | 2 ++ llvm/test/MC/Mips/micromips/valid.s | 13 +++++++++---- llvm/test/MC/Mips/mips32r2/valid.s | 5 ++++- llvm/test/MC/Mips/mips32r3/valid.s | 5 ++++- llvm/test/MC/Mips/mips32r5/valid.s | 3 +++ llvm/test/MC/Mips/mips32r6/valid.s | 4 ++++ llvm/test/MC/Mips/mips64r2/valid.s | 4 ++++ llvm/test/MC/Mips/mips64r3/valid.s | 4 ++++ llvm/test/MC/Mips/mips64r5/valid.s | 4 ++++ llvm/test/MC/Mips/mips64r6/valid.s | 5 ++++- 15 files changed, 78 insertions(+), 18 deletions(-) diff --git a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp index 2f9c286..f7d80b4 100644 --- a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp +++ b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp @@ -305,6 +305,11 @@ static DecodeStatus DecodeSyncI(MCInst &Inst, uint64_t Address, const void *Decoder); +static DecodeStatus DecodeSyncI_MM(MCInst &Inst, + unsigned Insn, + uint64_t Address, + const void *Decoder); + static DecodeStatus DecodeSynciR6(MCInst &Inst, unsigned Insn, uint64_t Address, @@ -1649,6 +1654,19 @@ static DecodeStatus DecodeSyncI(MCInst &Inst, return MCDisassembler::Success; } +static DecodeStatus DecodeSyncI_MM(MCInst &Inst, unsigned Insn, + uint64_t Address, const void *Decoder) { + int Offset = SignExtend32<16>(Insn & 0xffff); + unsigned Base = fieldFromInstruction(Insn, 16, 5); + + Base = getReg(Decoder, Mips::GPR32RegClassID, Base); + + Inst.addOperand(MCOperand::createReg(Base)); + Inst.addOperand(MCOperand::createImm(Offset)); + + return MCDisassembler::Success; +} + static DecodeStatus DecodeSynciR6(MCInst &Inst, unsigned Insn, uint64_t Address, diff --git a/llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td b/llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td index 63356f9..1b6ee46 100644 --- a/llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td +++ b/llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td @@ -1127,7 +1127,7 @@ class SYNC_MMR6_DESC : MMR6Arch<"sync">, MipsR6Inst { bit HasSideEffects = 1; } -class SYNCI_MMR6_DESC : SYNCI_FT<"synci"> { +class SYNCI_MMR6_DESC : SYNCI_FT<"synci", mem_mm_16> { let DecoderMethod = "DecodeSynciR6"; } diff --git a/llvm/lib/Target/Mips/MicroMipsInstrFormats.td b/llvm/lib/Target/Mips/MicroMipsInstrFormats.td index d948176..4e84ee3 100644 --- a/llvm/lib/Target/Mips/MicroMipsInstrFormats.td +++ b/llvm/lib/Target/Mips/MicroMipsInstrFormats.td @@ -600,8 +600,9 @@ class SYNC_FM_MM : MMArch { } class SYNCI_FM_MM : MMArch { - bits<5> rs; - bits<16> offset; + bits<21> addr; + bits<5> rs = addr{20-16}; + bits<16> offset = addr{15-0}; bits<32> Inst; let Inst{31-26} = 0b010000; diff --git a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td index 29bc658d..d2768cd 100644 --- a/llvm/lib/Target/Mips/MicroMipsInstrInfo.td +++ b/llvm/lib/Target/Mips/MicroMipsInstrInfo.td @@ -128,6 +128,7 @@ def mem_mm_16 : Operand { let PrintMethod = "printMemOperand"; let MIOperandInfo = (ops ptr_rc, simm16); let EncoderMethod = "getMemEncodingMMImm16"; + let DecoderMethod = "DecodeMemMMImm16"; let ParserMatchClass = MipsMemSimm16AsmOperand; let OperandType = "OPERAND_MEMORY"; } @@ -960,11 +961,13 @@ let DecoderNamespace = "MicroMips", Predicates = [InMicroMips] in { } def B_MM : UncondBranch, IsBranch, ISA_MICROMIPS; let DecoderNamespace = "MicroMips" in { - let Predicates = [InMicroMips] in { /// Control Instructions - def SYNC_MM : MMRel, SYNC_FT<"sync">, SYNC_FM_MM; - def SYNCI_MM : MMRel, SYNCI_FT<"synci">, SYNCI_FM_MM; + def SYNC_MM : MMRel, SYNC_FT<"sync">, SYNC_FM_MM, ISA_MICROMIPS; + let DecoderMethod = "DecodeSyncI_MM" in + def SYNCI_MM : MMRel, SYNCI_FT<"synci", mem_mm_16>, SYNCI_FM_MM, + ISA_MICROMIPS32_NOT_MIPS32R6; + let Predicates = [InMicroMips] in { def BREAK_MM : MMRel, BRK_FT<"break">, BRK_FM_MM; def SYSCALL_MM : MMRel, SYS_FT<"syscall", uimm10, II_SYSCALL>, SYS_FM_MM; def WAIT_MM : WaitMM<"wait">, WAIT_FM_MM; @@ -1222,6 +1225,8 @@ let Predicates = [InMicroMips] in { (ROTR_MM GPR32Opnd:$rt, GPR32Opnd:$rt, uimm5:$imm), 0>; def : MipsInstAlias<"syscall", (SYSCALL_MM 0), 1>; + def : MipsInstAlias<"sync", (SYNC_MM 0), 1>, ISA_MICROMIPS; + defm : OneOrTwoOperandMacroImmediateAlias<"add", ADDi_MM>, ISA_MICROMIPS; defm : OneOrTwoOperandMacroImmediateAlias<"addu", ADDiu_MM>, ISA_MICROMIPS; diff --git a/llvm/lib/Target/Mips/MipsInstrInfo.td b/llvm/lib/Target/Mips/MipsInstrInfo.td index 265ed4d..2529972 100644 --- a/llvm/lib/Target/Mips/MipsInstrInfo.td +++ b/llvm/lib/Target/Mips/MipsInstrInfo.td @@ -1657,8 +1657,8 @@ class SYNC_FT : InstSE<(outs), (ins uimm5:$stype), "sync $stype", [(MipsSync immZExt5:$stype)], II_SYNC, FrmOther, opstr>; -class SYNCI_FT : - InstSE<(outs), (ins mem_simm16:$addr), !strconcat(opstr, "\t$addr"), [], +class SYNCI_FT : + InstSE<(outs), (ins MO:$addr), !strconcat(opstr, "\t$addr"), [], II_SYNCI, FrmOther, opstr> { let hasSideEffects = 1; let DecoderMethod = "DecodeSyncI"; @@ -2050,7 +2050,8 @@ let DecoderNamespace = "COP3_" in { } def SYNC : MMRel, StdMMR6Rel, SYNC_FT<"sync">, SYNC_FM, ISA_MIPS2; - def SYNCI : MMRel, StdMMR6Rel, SYNCI_FT<"synci">, SYNCI_FM, ISA_MIPS32R2; + def SYNCI : MMRel, StdMMR6Rel, SYNCI_FT<"synci", mem_simm16>, SYNCI_FM, + ISA_MIPS32R2; } let AdditionalPredicates = [NotInMicroMips] in { @@ -2641,8 +2642,8 @@ let AdditionalPredicates = [NotInMicroMips] in { ISA_MIPS32R2; } def : MipsInstAlias<"sdbbp", (SDBBP 0)>, ISA_MIPS32_NOT_32R6_64R6; -def : MipsInstAlias<"sync", - (SYNC 0), 1>, ISA_MIPS2; +let AdditionalPredicates = [NotInMicroMips] in + def : MipsInstAlias<"sync", (SYNC 0), 1>, ISA_MIPS2; def : MipsInstAlias<"mulo $rs, $rt", (MULOMacro GPR32Opnd:$rs, GPR32Opnd:$rs, GPR32Opnd:$rt), 0>, diff --git a/llvm/test/MC/Disassembler/Mips/micromips32r3/valid-el.txt b/llvm/test/MC/Disassembler/Mips/micromips32r3/valid-el.txt index dd31a89..1ceaa7d 100644 --- a/llvm/test/MC/Disassembler/Mips/micromips32r3/valid-el.txt +++ b/llvm/test/MC/Disassembler/Mips/micromips32r3/valid-el.txt @@ -224,3 +224,5 @@ 0x02 0x54 0x7b 0x13 # CHECK: cvt.d.s $f0, $f2 0x02 0x54 0x7b 0x33 # CHECK: cvt.d.w $f0, $f2 0x02 0x54 0x7b 0x1b # CHECK: cvt.s.d $f0, $f2 +0x07 0x00 0x7c 0x6b # CHECK: sync 7 +0x03 0x42 0x00 0x04 # CHECK: synci 1024($3) diff --git a/llvm/test/MC/Mips/micromips/valid.s b/llvm/test/MC/Mips/micromips/valid.s index 97db233..974229d 100644 --- a/llvm/test/MC/Mips/micromips/valid.s +++ b/llvm/test/MC/Mips/micromips/valid.s @@ -282,7 +282,12 @@ bc1t $fcc1, 4 # CHECK: bc1t $fcc1, 4 # encoding: [0x4 # CHECK-NEXT: #