annotate llvm/test/TableGen/TargetInstrInfo.td @ 266:00f31e85ec16 default tip

Added tag current for changeset 31d058e83c98
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 14 Oct 2023 10:13:55 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // This test describes how we eventually want to describe instructions in
anatofuz
parents:
diff changeset
2 // the target independent code generators.
anatofuz
parents:
diff changeset
3 // RUN: llvm-tblgen %s
anatofuz
parents:
diff changeset
4 // XFAIL: vg_leak
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 // Target indep stuff.
anatofuz
parents:
diff changeset
7 class Instruction { // Would have other stuff eventually
anatofuz
parents:
diff changeset
8 bit isTwoAddress = 0;
anatofuz
parents:
diff changeset
9 string AssemblyString;
anatofuz
parents:
diff changeset
10 }
anatofuz
parents:
diff changeset
11 class RegisterClass;
anatofuz
parents:
diff changeset
12
anatofuz
parents:
diff changeset
13 class RTLNode;
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 def ops; // Marker for operand list.
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 // Various expressions used in RTL descriptions.
anatofuz
parents:
diff changeset
18 def imm8 : RTLNode;
anatofuz
parents:
diff changeset
19 def imm32 : RTLNode;
anatofuz
parents:
diff changeset
20 def addr : RTLNode;
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 def set : RTLNode;
anatofuz
parents:
diff changeset
23 def signext : RTLNode;
anatofuz
parents:
diff changeset
24 def zeroext : RTLNode;
anatofuz
parents:
diff changeset
25 def plus : RTLNode;
anatofuz
parents:
diff changeset
26 def and : RTLNode;
anatofuz
parents:
diff changeset
27 def xor : RTLNode;
anatofuz
parents:
diff changeset
28 def shl : RTLNode;
anatofuz
parents:
diff changeset
29 def load : RTLNode;
anatofuz
parents:
diff changeset
30 def store : RTLNode;
anatofuz
parents:
diff changeset
31 def unspec : RTLNode;
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 // Start of X86 specific stuff.
anatofuz
parents:
diff changeset
34
anatofuz
parents:
diff changeset
35 def R8 : RegisterClass;
anatofuz
parents:
diff changeset
36 def R16 : RegisterClass;
anatofuz
parents:
diff changeset
37 def R32 : RegisterClass;
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 def CL; // As are currently defined
anatofuz
parents:
diff changeset
40 def AL;
anatofuz
parents:
diff changeset
41 def AX;
anatofuz
parents:
diff changeset
42 def EDX;
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 class Format<bits<5> val> {
anatofuz
parents:
diff changeset
45 bits<5> Value = val;
anatofuz
parents:
diff changeset
46 }
anatofuz
parents:
diff changeset
47
anatofuz
parents:
diff changeset
48 def Pseudo : Format<0>; def RawFrm : Format<1>;
anatofuz
parents:
diff changeset
49 def AddRegFrm : Format<2>; def MRMDestReg : Format<3>;
anatofuz
parents:
diff changeset
50 def MRMDestMem : Format<4>; def MRMSrcReg : Format<5>;
anatofuz
parents:
diff changeset
51 def MRMSrcMem : Format<6>;
anatofuz
parents:
diff changeset
52 def MRM0r : Format<16>; def MRM1r : Format<17>; def MRM2r : Format<18>;
anatofuz
parents:
diff changeset
53 def MRM3r : Format<19>; def MRM4r : Format<20>; def MRM5r : Format<21>;
anatofuz
parents:
diff changeset
54 def MRM6r : Format<22>; def MRM7r : Format<23>;
anatofuz
parents:
diff changeset
55 def MRM0m : Format<24>; def MRM1m : Format<25>; def MRM2m : Format<26>;
anatofuz
parents:
diff changeset
56 def MRM3m : Format<27>; def MRM4m : Format<28>; def MRM5m : Format<29>;
anatofuz
parents:
diff changeset
57 def MRM6m : Format<30>; def MRM7m : Format<31>;
anatofuz
parents:
diff changeset
58
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 class Inst<dag opnds, string asmstr, bits<8> opcode,
anatofuz
parents:
diff changeset
61 Format f, list<dag> rtl> : Instruction {
anatofuz
parents:
diff changeset
62 dag Operands = opnds;
anatofuz
parents:
diff changeset
63 string AssemblyString = asmstr;
anatofuz
parents:
diff changeset
64 bits<8> Opcode = opcode;
anatofuz
parents:
diff changeset
65 Format Format = f;
anatofuz
parents:
diff changeset
66 list<dag> RTL = rtl;
anatofuz
parents:
diff changeset
67 }
anatofuz
parents:
diff changeset
68
anatofuz
parents:
diff changeset
69
anatofuz
parents:
diff changeset
70 // Start of instruction definitions, the real point of this file.
anatofuz
parents:
diff changeset
71 //
anatofuz
parents:
diff changeset
72 // Note that these patterns show a couple of important things:
anatofuz
parents:
diff changeset
73 // 1. The order and contents of the operands of the MachineInstr are
anatofuz
parents:
diff changeset
74 // described here. Eventually we can do away with this when everything
anatofuz
parents:
diff changeset
75 // is generated from the description.
anatofuz
parents:
diff changeset
76 // 2. The asm string is captured here, which makes it possible to get rid of
anatofuz
parents:
diff changeset
77 // a ton of hacks in the various printers and a bunch of flags.
anatofuz
parents:
diff changeset
78 // 3. Target specific properties (e.g. Format) can still be captured as
anatofuz
parents:
diff changeset
79 // needed.
anatofuz
parents:
diff changeset
80 // 4. We capture the behavior of the instruction with a simplified RTL-like
anatofuz
parents:
diff changeset
81 // expression.
anatofuz
parents:
diff changeset
82 // 5. The use/def properties for each operand are automatically inferred from
anatofuz
parents:
diff changeset
83 // the pattern.
anatofuz
parents:
diff changeset
84 // 6. Address expressions should become first-class entities.
anatofuz
parents:
diff changeset
85
anatofuz
parents:
diff changeset
86 // Simple copy instruction.
anatofuz
parents:
diff changeset
87 def MOV8rr : Inst<(ops R8:$dst, R8:$src),
anatofuz
parents:
diff changeset
88 "mov $dst, $src", 0x88, MRMDestReg,
anatofuz
parents:
diff changeset
89 [(set R8:$dst, R8:$src)]>;
anatofuz
parents:
diff changeset
90
anatofuz
parents:
diff changeset
91 // Simple immediate initialization.
anatofuz
parents:
diff changeset
92 def MOV8ri : Inst<(ops R8:$dst, imm8:$src),
anatofuz
parents:
diff changeset
93 "mov $dst, $src", 0xB0, AddRegFrm,
anatofuz
parents:
diff changeset
94 [(set R8:$dst, imm8:$src)]>;
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 // Two address instructions are described as three-addr instructions, with
anatofuz
parents:
diff changeset
97 // the special target-independent isTwoAddress flag set. The asm pattern
anatofuz
parents:
diff changeset
98 // should not refer to the $src1, this would be enforced by the
anatofuz
parents:
diff changeset
99 // TargetInstrInfo tablegen backend.
anatofuz
parents:
diff changeset
100 let isTwoAddress = 1 in
anatofuz
parents:
diff changeset
101 def AND8rr : Inst<(ops R8:$dst, R8:$src1, R8:$src2),
anatofuz
parents:
diff changeset
102 "and $dst, $src2", 0x20, MRMDestReg,
anatofuz
parents:
diff changeset
103 [(set R8:$dst, (and R8:$src1, R8:$src2))]>;
anatofuz
parents:
diff changeset
104
anatofuz
parents:
diff changeset
105 // Instructions that have explicit uses/defs make them explicit in the RTL.
anatofuz
parents:
diff changeset
106 // Instructions that need extra stuff emitted in the assembly can, trivially.
anatofuz
parents:
diff changeset
107 let isTwoAddress = 1 in
anatofuz
parents:
diff changeset
108 def SHL32rCL : Inst<(ops R32:$dst, R32:$src),
anatofuz
parents:
diff changeset
109 "shl $dst, CL", 0xD2, MRM4r,
anatofuz
parents:
diff changeset
110 [(set R32:$dst, (shl R32:$src, CL))]>;
anatofuz
parents:
diff changeset
111
anatofuz
parents:
diff changeset
112 // The RTL list is a list, allowing complex instructions to be defined easily.
anatofuz
parents:
diff changeset
113 // Temporary 'internal' registers can be used to break instructions apart.
anatofuz
parents:
diff changeset
114 let isTwoAddress = 1 in
anatofuz
parents:
diff changeset
115 def XOR32mi : Inst<(ops addr:$addr, imm32:$imm),
anatofuz
parents:
diff changeset
116 "xor $dst, $src2", 0x81, MRM6m,
anatofuz
parents:
diff changeset
117 [(set R32:$tmp1, (load addr:$addr)),
anatofuz
parents:
diff changeset
118 (set R32:$tmp2, (xor R32:$tmp1, imm32:$imm)),
anatofuz
parents:
diff changeset
119 (store addr:$addr, R32:$tmp2)]>;
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 // Alternatively, if each tmporary register is only used once, the instruction
anatofuz
parents:
diff changeset
122 // can just be described in nested form. This would be the canonical
anatofuz
parents:
diff changeset
123 // representation the target generator would convert the above into. Pick your
anatofuz
parents:
diff changeset
124 // favorite indentation scheme.
anatofuz
parents:
diff changeset
125 let isTwoAddress = 1 in
anatofuz
parents:
diff changeset
126 def AND32mr : Inst<(ops addr:$addr, R32:$src),
anatofuz
parents:
diff changeset
127 "xor $dst, $src2", 0x81, MRM6m,
anatofuz
parents:
diff changeset
128 [(store addr:$addr,
anatofuz
parents:
diff changeset
129 (and
anatofuz
parents:
diff changeset
130 (load addr:$addr),
anatofuz
parents:
diff changeset
131 R32:$src)
anatofuz
parents:
diff changeset
132 )
anatofuz
parents:
diff changeset
133 ]>;
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 // Describing complex instructions is not too hard! Note how implicit uses/defs
anatofuz
parents:
diff changeset
136 // become explicit here.
anatofuz
parents:
diff changeset
137 def CBW : Inst<(ops),
anatofuz
parents:
diff changeset
138 "cbw", 0x98, RawFrm,
anatofuz
parents:
diff changeset
139 [(set AX, (signext AL))]>;
anatofuz
parents:
diff changeset
140
anatofuz
parents:
diff changeset
141 // Noop, does nothing.
anatofuz
parents:
diff changeset
142 def NOOP : Inst<(ops), "nop", 0x90, RawFrm, []>;
anatofuz
parents:
diff changeset
143
anatofuz
parents:
diff changeset
144
anatofuz
parents:
diff changeset
145 // Instructions that don't expect optimization can use unspec.
anatofuz
parents:
diff changeset
146 def IN8rr : Inst<(ops), "in AL, EDX", 0xEC, RawFrm,
anatofuz
parents:
diff changeset
147 [(set AL, (unspec EDX))]>;
anatofuz
parents:
diff changeset
148