Skip to content

Commit 85536ae

Browse files
b-s-aadriweb
authored andcommitted
[Z80] Register definition refactoring
24-bit eZ80 registers now defined like in RISCV source code. Change eliminates register name duplication.
1 parent 03261a2 commit 85536ae

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

llvm/lib/Target/Z80/Z80RegisterInfo.td

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,32 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
let Namespace = "Z80" in {
1617
class Z80Reg<string n, bits<16> Enc = -1> : Register<n> {
17-
let Namespace = "Z80";
1818
let HWEncoding = Enc;
1919
}
20+
21+
// Subregister indices.
22+
def sub_low : SubRegIndex<8>;
23+
def sub_high : SubRegIndex<8, 8>;
24+
def sub_short : SubRegIndex<16>;
25+
2026
class Z80RegWithSubRegs<string n, list<Register> sub = [], bits<16> enc = -1>
2127
: Z80Reg<n, enc> {
2228
let SubRegs = sub;
29+
let SubRegIndices = [sub_high, sub_low];
30+
let CoveredBySubRegs = 1;
2331
}
2432

25-
// Subregister indices.
26-
let Namespace = "Z80" in {
27-
def sub_low : SubRegIndex<8>;
28-
def sub_high : SubRegIndex<8, 8>;
29-
def sub_short : SubRegIndex<16>;
33+
class EZ80RegPair<Z80Reg subreg>
34+
: Register<""> {
35+
let HWEncoding{1-0} = subreg.HWEncoding{1-0};
36+
let SubRegs = [subreg];
37+
let SubRegIndices = [sub_short];
38+
let AsmName = subreg.AsmName;
39+
//let AltNames = subreg.AltNames;
40+
}
3041
}
31-
3242
//===----------------------------------------------------------------------===//
3343
// Register definitions...
3444
//
@@ -51,33 +61,37 @@ def IYH : Z80Reg<"iyh", 4>;
5161
def IYL : Z80Reg<"iyl", 5>;
5262
}
5363

54-
let SubRegIndices = [sub_high, sub_low], CoveredBySubRegs = 1 in {
5564
// 16-bit registers
5665
def AF : Z80RegWithSubRegs<"af", [A,F], 3>, DwarfRegNum<[3]>;
5766
def BC : Z80RegWithSubRegs<"bc", [B,C], 0>, DwarfRegNum<[0]>;
5867
def DE : Z80RegWithSubRegs<"de", [D,E], 1>, DwarfRegNum<[1]>;
5968
def HL : Z80RegWithSubRegs<"hl", [H,L], 2>, DwarfRegNum<[2]>;
6069
// 16-bit index registers
61-
let CostPerUse = [1] in {
62-
def IX : Z80RegWithSubRegs<"ix", [IXH,IXL], 2>, DwarfRegNum<[4]>;
63-
def IY : Z80RegWithSubRegs<"iy", [IYH,IYL], 2>, DwarfRegNum<[5]>;
64-
}
70+
let CostPerUse = 1 in {
71+
def IX : Z80RegWithSubRegs<"ix", [IXH,IXL], 2>;
72+
def IY : Z80RegWithSubRegs<"iy", [IYH,IYL], 2>;
6573
}
66-
def SPS : Z80Reg<"sp", 3>, DwarfRegNum<[6]>;
6774

68-
let SubRegIndices = [sub_short] in {
75+
def SPS : Z80Reg<"sp", 3>;
76+
6977
// 24-bit registers
70-
def UBC : Z80RegWithSubRegs<"bc", [BC], 0>, DwarfRegAlias<BC>;
71-
def UDE : Z80RegWithSubRegs<"de", [DE], 1>, DwarfRegAlias<DE>;
72-
def UHL : Z80RegWithSubRegs<"hl", [HL], 2>, DwarfRegAlias<HL>;
78+
def UBC : EZ80RegPair<BC>;
79+
def UDE : EZ80RegPair<DE>;
80+
def UHL : EZ80RegPair<HL>;
7381
// 24-bit index registers
74-
let CostPerUse = [1] in {
75-
def UIX : Z80RegWithSubRegs<"ix", [IX], 2>, DwarfRegAlias<IX>;
76-
def UIY : Z80RegWithSubRegs<"iy", [IY], 2>, DwarfRegAlias<IY>;
82+
let CostPerUse = 1 in {
83+
def UIX : EZ80RegPair<IX>;
84+
def UIY : EZ80RegPair<IY>;
7785
}
78-
}
79-
def SPL : Z80Reg<"sp", 3>, DwarfRegNum<[7]>;
80-
def PC : Z80Reg<"pc">, DwarfRegNum<[8]>;
86+
87+
//definition of SPL register for EZ80 ADL mode.
88+
//It havn't common part with SPS register, so this definition is not 100%
89+
//correct, but SPS and SPL cannot be used within one function. Moreover, ADL=1
90+
//and ADL=0 instructions cannot be mixed within one ELF section, because no one
91+
//disassembler which may correctly disassemble result code.
92+
def SPL : EZ80RegPair<SPS>;
93+
94+
def PC : Z80Reg<"pc">;
8195

8296
//===----------------------------------------------------------------------===//
8397
// Register Class Definitions...

0 commit comments

Comments
 (0)