Make Test More Thorough
[oota-llvm.git] / test / TableGen / MultiPat.td
1 // RUN: llvm-tblgen %s | FileCheck %s
2
3 class ValueType<int size, int value> {
4   int Size = size;
5   int Value = value;
6 }
7
8 def v2i64  : ValueType<128, 22>;   //  2 x i64 vector value
9 def v2f64  : ValueType<128, 28>;   //  2 x f64 vector value
10
11 class Intrinsic<string name> {
12   string Name = name;
13 }
14
15 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
16   dag             PatternToMatch  = patternToMatch;
17   list<dag>       ResultInstrs    = resultInstrs;
18 }
19
20 // Pat - A simple (but common) form of a pattern, which produces a simple result
21 // not needing a full list.
22 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
23
24 class Inst<bits<8> opcode, dag oopnds, dag iopnds, string asmstr, 
25            list<dag> pattern> {
26   bits<8> Opcode = opcode;
27   dag OutOperands = oopnds;
28   dag InOperands = iopnds;
29   string AssemblyString = asmstr;
30   list<dag> Pattern = pattern;
31 }
32
33 def ops;
34 def outs;
35 def ins;
36
37 def set;
38
39 // Define registers
40 class Register<string n> {
41   string Name = n;
42 }
43
44 class RegisterClass<list<ValueType> regTypes, list<Register> regList> {
45   list<ValueType> RegTypes = regTypes;
46   list<Register> MemberList = regList;
47 }
48
49 def XMM0: Register<"xmm0">;
50 def XMM1: Register<"xmm1">;
51 def XMM2: Register<"xmm2">;
52 def XMM3: Register<"xmm3">;
53 def XMM4: Register<"xmm4">;
54 def XMM5: Register<"xmm5">;
55 def XMM6: Register<"xmm6">;
56 def XMM7: Register<"xmm7">;
57 def XMM8:  Register<"xmm8">;
58 def XMM9:  Register<"xmm9">;
59 def XMM10: Register<"xmm10">;
60 def XMM11: Register<"xmm11">;
61 def XMM12: Register<"xmm12">;
62 def XMM13: Register<"xmm13">;
63 def XMM14: Register<"xmm14">;
64 def XMM15: Register<"xmm15">;
65
66 def VR128 : RegisterClass<[v2i64, v2f64],
67                           [XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6, XMM7,
68                            XMM8, XMM9, XMM10, XMM11,
69                            XMM12, XMM13, XMM14, XMM15]>;
70
71 // Dummy for subst
72 def REGCLASS : RegisterClass<[], []>;
73 def MNEMONIC;
74
75 class decls {
76   // Dummy for foreach
77   dag pattern;
78   int operand;
79 }
80
81 def Decls : decls;
82
83 // Define intrinsics
84 def int_x86_sse2_add_ps : Intrinsic<"addps">;
85 def int_x86_sse2_add_pd : Intrinsic<"addpd">;
86 def int_x86_sse2_sub_ps : Intrinsic<"subps">;
87 def int_x86_sse2_sub_pd : Intrinsic<"subpd">;
88 def INTRINSIC : Intrinsic<"Dummy">;
89 def bitconvert;
90 def add;
91 def sub;
92
93 class MakePatImpl<list<dag> patterns> : Pat<patterns[0], patterns[1]>;
94 class MakePat<list<dag> patterns,
95               string suffix,
96               string intr> : MakePatImpl<!foreach(Decls.pattern, patterns,
97                                                          !foreach(Decls.operand, Decls.pattern, 
98                                                                  !subst(INTRINSIC, !cast<Intrinsic>(!subst("SUFFIX", suffix, intr)),
99                                                                  !subst(REGCLASS, VR128, 
100                                                                  !subst(MNEMONIC, set, Decls.operand)))))>;
101
102 class Base<bits<8> opcode, dag opnds, dag iopnds, string asmstr, Intrinsic intr, 
103            list<list<dag>> patterns>
104       : Inst<opcode, opnds, iopnds, asmstr, 
105              !foreach(Decls.pattern, patterns[0], 
106                       !foreach(Decls.operand, Decls.pattern, 
107                                !subst(INTRINSIC, intr, 
108                                !subst(REGCLASS, VR128, 
109                                !subst(MNEMONIC, set, Decls.operand)))))>;
110
111 multiclass arith<bits<8> opcode, string asmstr, string intr, list<list<dag>> patterns> {
112   def PS : Base<opcode, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
113                  !strconcat(asmstr, "\t$dst, $src1, $src2"), !cast<Intrinsic>(!subst("SUFFIX", "_ps", intr)), patterns>;
114
115   def PD : Base<opcode, (outs VR128:$dst), (ins VR128:$src1, VR128:$src2),
116                  !strconcat(asmstr, "\t$dst, $src1, $src2"), !cast<Intrinsic>(!subst("SUFFIX", "_pd", intr)), patterns>;
117
118   multidef <patterns, list<dag> pats, 1> : MakePat<pats, "_ps", intr>;
119   multidef <patterns, list<dag> pats, 1> : MakePat<pats, "_pd", intr>;
120 }
121
122 defm ADD : arith<0x58, "add", "int_x86_sse2_addSUFFIX",
123                   // rr Patterns
124                  [[(set REGCLASS:$dst, (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))],
125                    [(set REGCLASS:$dst, (bitconvert (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))),
126                     (MNEMONIC REGCLASS:$dst, REGCLASS:$src)],
127                    [(set REGCLASS:$dst, (add (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))),
128                     (MNEMONIC (add REGCLASS:$dst, REGCLASS:$src))]]>;
129
130 // CHECK: [(set VR128:$dst, (int_x86_sse2_add_pd VR128:$src1, VR128:$src2))]
131 // CHECK: [(set VR128:$dst, (int_x86_sse2_add_ps VR128:$src1, VR128:$src2))]
132 // CHECK: (set VR128:$dst, (add (int_x86_sse2_add_ps VR128:$src1, VR128:$src2)))
133 // CHECK: (set VR128:$dst, (add (int_x86_sse2_add_pd VR128:$src1, VR128:$src2)))
134
135 defm SUB : arith<0x59, "sub", "int_x86_sse2_subSUFFIX",
136                   // rr Patterns
137                  [[(set REGCLASS:$dst, (INTRINSIC REGCLASS:$src1, REGCLASS:$src2))]]>;
138
139 // CHECK: [(set VR128:$dst, (int_x86_sse2_sub_pd VR128:$src1, VR128:$src2))]
140 // CHECK: [(set VR128:$dst, (int_x86_sse2_sub_ps VR128:$src1, VR128:$src2))]