• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// RUN: llvm-tblgen -gen-asm-matcher -I %p/../../include %s | FileCheck %s
2
3// Check that MatchRegisterName and MatchRegisterAltName are generated
4// correctly when multiple registers are defined with the same name and
5// AllowDuplicateRegisterNames is set.
6
7include "llvm/Target/Target.td"
8
9def ArchInstrInfo : InstrInfo;
10
11def ArchAsmParser : AsmParser {
12  let AllowDuplicateRegisterNames = 1;
13  let ShouldEmitMatchRegisterAltName = 1;
14}
15
16def Arch : Target {
17  let InstructionSet = ArchInstrInfo;
18  let AssemblyParsers = [ArchAsmParser];
19}
20
21let Namespace = "Arch" in {
22class ArchReg<string n, list <string> alt, list <RegAltNameIndex> altidx>
23    : Register<n> {
24  let AltNames = alt;
25  let RegAltNameIndices = altidx;
26}
27
28def ABIRegAltName : RegAltNameIndex;
29
30foreach i = 0...3 in {
31  def R#i#_32 : ArchReg<"r"#i, ["x"#i], [ABIRegAltName]>;
32  def R#i#_64 : ArchReg<"r"#i, ["x"#i], [ABIRegAltName]>;
33}
34} // Namespace = "Arch"
35
36def GPR32 : RegisterClass<"Arch", [i32], 32, (add
37    (sequence "R%u_32", 0, 3)
38)>;
39
40def GPR64 : RegisterClass<"Arch", [i64], 64, (add
41    (sequence "R%u_64", 0, 3)
42)>;
43
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')
49// CHECK:       break;
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"
60// CHECK:     }
61// CHECK:     break;
62// CHECK:   }
63// CHECK:   return 0;
64// CHECK: }
65
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')
71// CHECK:       break;
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"
82// CHECK:     }
83// CHECK:     break;
84// CHECK:   }
85// CHECK:   return 0;
86// CHECK: }
87