From c6ff29713d69b4a41c225cbde9c82e4a350dbfac Mon Sep 17 00:00:00 2001 From: Richard Osborne Date: Thu, 4 Apr 2013 19:57:46 +0000 Subject: [PATCH] [XCore] The RRegs register class is a superset of GRRegs. At the time when the XCore backend was added there were some issues with with overlapping register classes but these all seem to be fixed now. Describing the register classes correctly allow us to get rid of a codegen only instruction (LDAWSP_lru6_RRegs) and it means we can disassemble ru6 instructions that use registers above r11. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178782 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../XCore/Disassembler/XCoreDisassembler.cpp | 17 ++++++ lib/Target/XCore/XCoreFrameLowering.cpp | 4 +- lib/Target/XCore/XCoreInstrInfo.td | 54 ++++++++----------- lib/Target/XCore/XCoreRegisterInfo.td | 5 +- test/MC/Disassembler/XCore/xcore.txt | 48 +++++++++++++++++ 5 files changed, 94 insertions(+), 34 deletions(-) diff --git a/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp b/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp index 7e7d3962a72..7b99967c4f3 100644 --- a/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp +++ b/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp @@ -89,6 +89,11 @@ static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst, uint64_t Address, const void *Decoder); +static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst, + unsigned RegNo, + uint64_t Address, + const void *Decoder); + static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val, uint64_t Address, const void *Decoder); @@ -214,6 +219,18 @@ static DecodeStatus DecodeGRRegsRegisterClass(MCInst &Inst, return MCDisassembler::Success; } +static DecodeStatus DecodeRRegsRegisterClass(MCInst &Inst, + unsigned RegNo, + uint64_t Address, + const void *Decoder) +{ + if (RegNo > 15) + return MCDisassembler::Fail; + unsigned Reg = getReg(Decoder, XCore::RRegsRegClassID, RegNo); + Inst.addOperand(MCOperand::CreateReg(Reg)); + return MCDisassembler::Success; +} + static DecodeStatus DecodeBitpOperand(MCInst &Inst, unsigned Val, uint64_t Address, const void *Decoder) { if (Val > 11) diff --git a/lib/Target/XCore/XCoreFrameLowering.cpp b/lib/Target/XCore/XCoreFrameLowering.cpp index 6b6480e4b46..beeb07f831c 100644 --- a/lib/Target/XCore/XCoreFrameLowering.cpp +++ b/lib/Target/XCore/XCoreFrameLowering.cpp @@ -261,7 +261,7 @@ void XCoreFrameLowering::emitEpilogue(MachineFunction &MF, BuildMI(MBB, MBBI, dl, TII.get(Opcode)).addImm(FrameSize); MBB.erase(MBBI); } else { - int Opcode = (isU6) ? XCore::LDAWSP_ru6_RRegs : XCore::LDAWSP_lru6_RRegs; + int Opcode = (isU6) ? XCore::LDAWSP_ru6 : XCore::LDAWSP_lru6; BuildMI(MBB, MBBI, dl, TII.get(Opcode), XCore::SP).addImm(FrameSize); } } @@ -371,7 +371,7 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, .addImm(Amount); } else { assert(Old->getOpcode() == XCore::ADJCALLSTACKUP); - int Opcode = isU6 ? XCore::LDAWSP_ru6_RRegs : XCore::LDAWSP_lru6_RRegs; + int Opcode = isU6 ? XCore::LDAWSP_ru6 : XCore::LDAWSP_lru6; New=BuildMI(MF, Old->getDebugLoc(), TII.get(Opcode), XCore::SP) .addImm(Amount); } diff --git a/lib/Target/XCore/XCoreInstrInfo.td b/lib/Target/XCore/XCoreInstrInfo.td index e140ef26b46..472bff11b25 100644 --- a/lib/Target/XCore/XCoreInstrInfo.td +++ b/lib/Target/XCore/XCoreInstrInfo.td @@ -281,9 +281,9 @@ multiclass FRU6_LRU6_backwards_branch opc, string OpcStr> { } multiclass FRU6_LRU6_cp opc, string OpcStr> { - def _ru6: _FRU6; - def _lru6: _FLRU6; } @@ -515,29 +515,29 @@ def LMUL_l6r : _FL6R< //let Uses = [DP] in ... let neverHasSideEffects = 1, isReMaterializable = 1 in -def LDAWDP_ru6: _FRU6<0b011000, (outs GRRegs:$a), (ins MEMii:$b), +def LDAWDP_ru6: _FRU6<0b011000, (outs RRegs:$a), (ins MEMii:$b), "ldaw $a, dp[$b]", []>; let isReMaterializable = 1 in -def LDAWDP_lru6: _FLRU6<0b011000, (outs GRRegs:$a), (ins MEMii:$b), +def LDAWDP_lru6: _FLRU6<0b011000, (outs RRegs:$a), (ins MEMii:$b), "ldaw $a, dp[$b]", - [(set GRRegs:$a, ADDRdpii:$b)]>; + [(set RRegs:$a, ADDRdpii:$b)]>; let mayLoad=1 in -def LDWDP_ru6: _FRU6<0b010110, (outs GRRegs:$a), (ins MEMii:$b), +def LDWDP_ru6: _FRU6<0b010110, (outs RRegs:$a), (ins MEMii:$b), "ldw $a, dp[$b]", []>; -def LDWDP_lru6: _FLRU6<0b010110, (outs GRRegs:$a), (ins MEMii:$b), +def LDWDP_lru6: _FLRU6<0b010110, (outs RRegs:$a), (ins MEMii:$b), "ldw $a, dp[$b]", - [(set GRRegs:$a, (load ADDRdpii:$b))]>; + [(set RRegs:$a, (load ADDRdpii:$b))]>; let mayStore=1 in -def STWDP_ru6 : _FRU6<0b010100, (outs), (ins GRRegs:$a, MEMii:$b), +def STWDP_ru6 : _FRU6<0b010100, (outs), (ins RRegs:$a, MEMii:$b), "stw $a, dp[$b]", []>; -def STWDP_lru6 : _FLRU6<0b010100, (outs), (ins GRRegs:$a, MEMii:$b), +def STWDP_lru6 : _FLRU6<0b010100, (outs), (ins RRegs:$a, MEMii:$b), "stw $a, dp[$b]", - [(store GRRegs:$a, ADDRdpii:$b)]>; + [(store RRegs:$a, ADDRdpii:$b)]>; //let Uses = [CP] in .. let mayLoad = 1, isReMaterializable = 1, neverHasSideEffects = 1 in @@ -545,46 +545,38 @@ defm LDWCP : FRU6_LRU6_cp<0b011011, "ldw">; let Uses = [SP] in { let mayStore=1 in { -def STWSP_ru6 : _FRU6<0b010101, (outs), (ins GRRegs:$a, i32imm:$b), +def STWSP_ru6 : _FRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b), "stw $a, sp[$b]", - [(XCoreStwsp GRRegs:$a, immU6:$b)]>; + [(XCoreStwsp RRegs:$a, immU6:$b)]>; -def STWSP_lru6 : _FLRU6<0b010101, (outs), (ins GRRegs:$a, i32imm:$b), +def STWSP_lru6 : _FLRU6<0b010101, (outs), (ins RRegs:$a, i32imm:$b), "stw $a, sp[$b]", - [(XCoreStwsp GRRegs:$a, immU16:$b)]>; + [(XCoreStwsp RRegs:$a, immU16:$b)]>; } let mayLoad=1 in { -def LDWSP_ru6 : _FRU6<0b010111, (outs GRRegs:$a), (ins i32imm:$b), +def LDWSP_ru6 : _FRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b), "ldw $a, sp[$b]", []>; -def LDWSP_lru6 : _FLRU6<0b010111, (outs GRRegs:$a), (ins i32imm:$b), +def LDWSP_lru6 : _FLRU6<0b010111, (outs RRegs:$a), (ins i32imm:$b), "ldw $a, sp[$b]", []>; } let neverHasSideEffects = 1 in { -def LDAWSP_ru6 : _FRU6<0b011001, (outs GRRegs:$a), (ins i32imm:$b), +def LDAWSP_ru6 : _FRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b), "ldaw $a, sp[$b]", []>; -def LDAWSP_lru6 : _FLRU6<0b011001, (outs GRRegs:$a), (ins i32imm:$b), +def LDAWSP_lru6 : _FLRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b), "ldaw $a, sp[$b]", []>; - -let isCodeGenOnly = 1 in -def LDAWSP_ru6_RRegs : _FRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b), - "ldaw $a, sp[$b]", []>; - -let isCodeGenOnly = 1 in -def LDAWSP_lru6_RRegs : _FLRU6<0b011001, (outs RRegs:$a), (ins i32imm:$b), - "ldaw $a, sp[$b]", []>; } } let isReMaterializable = 1 in { -def LDC_ru6 : _FRU6<0b011010, (outs GRRegs:$a), (ins i32imm:$b), - "ldc $a, $b", [(set GRRegs:$a, immU6:$b)]>; +def LDC_ru6 : _FRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b), + "ldc $a, $b", [(set RRegs:$a, immU6:$b)]>; -def LDC_lru6 : _FLRU6<0b011010, (outs GRRegs:$a), (ins i32imm:$b), - "ldc $a, $b", [(set GRRegs:$a, immU16:$b)]>; +def LDC_lru6 : _FLRU6<0b011010, (outs RRegs:$a), (ins i32imm:$b), + "ldc $a, $b", [(set RRegs:$a, immU16:$b)]>; } def SETC_ru6 : _FRU6<0b111010, (outs), (ins GRRegs:$a, i32imm:$b), diff --git a/lib/Target/XCore/XCoreRegisterInfo.td b/lib/Target/XCore/XCoreRegisterInfo.td index 4c771e97006..6694b2882ac 100644 --- a/lib/Target/XCore/XCoreRegisterInfo.td +++ b/lib/Target/XCore/XCoreRegisterInfo.td @@ -51,6 +51,9 @@ def GRRegs : RegisterClass<"XCore", [i32], 32, R11)>; // Reserved -def RRegs : RegisterClass<"XCore", [i32], 32, (add CP, DP, SP, LR)> { +def RRegs : RegisterClass<"XCore", [i32], 32, + (add R0, R1, R2, R3, + R4, R5, R6, R7, R8, R9, R10, + R11, CP, DP, SP, LR)> { let isAllocatable = 0; } diff --git a/test/MC/Disassembler/XCore/xcore.txt b/test/MC/Disassembler/XCore/xcore.txt index 882d73a0e26..930bd0338d8 100644 --- a/test/MC/Disassembler/XCore/xcore.txt +++ b/test/MC/Disassembler/XCore/xcore.txt @@ -456,36 +456,72 @@ # CHECK: ldaw r1, dp[456] 0x07 0xf0 0x48 0x60 +# CHECK: ldaw cp, dp[5] +0x05 0x63 + +# CHECK: ldaw sp, dp[9929] +0x9b 0xf0 0x89 0x63 + # CHECK: ldaw r3, sp[2] 0xc2 0x64 # CHECK: ldaw r8, sp[65535] 0xff 0xf3 0x3f 0x66 +# CHECK: ldaw sp, sp[41] +0xa9 0x67 + +# CHECK: ldaw sp, sp[13121] +0xcd 0xf0 0x81 0x67 + # CHECK: ldc r3, 30 0xde 0x68 # CHECK: ldc r11, 1000 0x0f 0xf0 0xe8 0x6a +# CHECK: ldc sp, 0 +0x80 0x6b + +# CHECK: ldc lr, 81 +0x01 0xf0 0xd1 0x6b + # CHECK: ldw r0, cp[4] 0x04 0x6c # CHECK: ldw r1, cp[32345] 0xf9 0xf1 0x59 0x6c +# CHECK: ldw cp, cp[8] +0x08 0x6f + +# CHECK: ldw sp, cp[10222] +0x9f 0xf0 0xae 0x6f + # CHECK: ldw r10, dp[16] 0x90 0x5a # CHECK: ldw r10, dp[76] 0x01 0xf0 0x8c 0x5a +# CHECK: ldw lr, dp[8] +0xc8 0x5b + +# CHECK: ldw dp, dp[33221] +0x07 0xf2 0x45 0x5b + # CHECK: ldw r8, sp[51] 0x33 0x5e # CHECK: ldw r8, sp[1225] 0x13 0xf0 0x09 0x5e +# CHECK: ldw cp, sp[31] +0x1f 0x5f + +# CHECK: ldw sp, sp[1000] +0x0f 0xf0 0xa8 0x5f + # CHECK: setc res[r5], 36 0x64 0xe9 @@ -498,12 +534,24 @@ # CHECK: stw r9, dp[654] 0x0a 0xf0 0x4e 0x52 +# CHECK: stw lr, dp[23] +0xd7 0x53 + +# CHECK: stw sp, dp[44442] +0xb6 0xf2 0x9a 0x53 + # CHECK: stw r1, sp[32] 0x60 0x54 # CHECK: stw r0, sp[8761] 0x88 0xf0 0x39 0x54 +# CHECK: stw cp, sp[63] +0x3f 0x57 + +# CHECK: stw lr, sp[4391] +0x44 0xf0 0xe7 0x57 + # u6 / lu6 instructions # CHECK: bu -20 -- 2.34.1