1 // RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s
3 // Check that MatchRegisterName and MatchRegisterAltName are generated
4 // correctly when multiple registers are defined with the same name and
5 // AllowDuplicateRegisterNames is set.
7 include "llvm/Target/Target.td"
9 def ArchInstrInfo : InstrInfo;
11 def ArchAsmParser : AsmParser {
12 let AllowDuplicateRegisterNames = 1;
13 let ShouldEmitMatchRegisterAltName = 1;
17 let InstructionSet = ArchInstrInfo;
18 let AssemblyParsers = [ArchAsmParser];
21 let Namespace = "Arch" in {
22 class ArchReg<string n, list <string> alt, list <RegAltNameIndex> altidx>
25 let RegAltNameIndices = altidx;
28 def ABIRegAltName : RegAltNameIndex;
31 def R#i#_32 : ArchReg<"r"#i, ["x"#i], [ABIRegAltName]>;
32 def R#i#_64 : ArchReg<"r"#i, ["x"#i], [ABIRegAltName]>;
34 } // Namespace = "Arch"
36 def GPR32 : RegisterClass<"Arch", [i32], 32, (add
37 (sequence "R%u_32", 0, 3)
40 def GPR64 : RegisterClass<"Arch", [i64], 64, (add
41 (sequence "R%u_64", 0, 3)
44 // CHECK: static unsigned MatchRegisterName(StringRef Name) {
45 // CHECK: switch (Name.size()) {
46 // CHECK: default: break;
47 // CHECK: case 2: // 8 strings to match.
48 // CHECK: if (Name[0] != 'r')
50 // CHECK: switch (Name[1]) {
51 // CHECK: default: break;
52 // CHECK: case '0': // 2 strings to match.
53 // CHECK: return 1; // "r0"
54 // CHECK: case '1': // 2 strings to match.
55 // CHECK: return 3; // "r1"
56 // CHECK: case '2': // 2 strings to match.
57 // CHECK: return 5; // "r2"
58 // CHECK: case '3': // 2 strings to match.
59 // CHECK: return 7; // "r3"
66 // CHECK: static unsigned MatchRegisterAltName(StringRef Name) {
67 // CHECK: switch (Name.size()) {
68 // CHECK: default: break;
69 // CHECK: case 2: // 8 strings to match.
70 // CHECK: if (Name[0] != 'x')
72 // CHECK: switch (Name[1]) {
73 // CHECK: default: break;
74 // CHECK: case '0': // 2 strings to match.
75 // CHECK: return 1; // "x0"
76 // CHECK: case '1': // 2 strings to match.
77 // CHECK: return 3; // "x1"
78 // CHECK: case '2': // 2 strings to match.
79 // CHECK: return 5; // "x2"
80 // CHECK: case '3': // 2 strings to match.
81 // CHECK: return 7; // "x3"