1 // RUN: llvm-tblgen -gen-dag-isel -I %p/../../include %s 2>&1 | FileCheck -check-prefix=SDAG %s
2 // RUN: llvm-tblgen -gen-global-isel -optimize-match-table=false -I %p/../../include %s -o - < %s | FileCheck -check-prefix=GISEL %s
4 include "llvm/Target/Target.td"
6 def TestTargetInstrInfo : InstrInfo;
9 def TestTarget : Target {
10 let InstructionSet = TestTargetInstrInfo;
13 def R0 : Register<"r0"> { let Namespace = "MyTarget"; }
14 def GPR32 : RegisterClass<"MyTarget", [i32], 32, (add R0)>;
17 // With one address space
18 def pat_frag_a : PatFrag <(ops node:$ptr), (load node:$ptr), [{}]> {
19 let AddressSpaces = [ 999 ];
20 let IsLoad = 1; // FIXME: Can this be inferred?
25 // With multiple address spaces
26 def pat_frag_b : PatFrag <(ops node:$ptr), (load node:$ptr), [{}]> {
27 let AddressSpaces = [ 123, 455 ];
28 let IsLoad = 1; // FIXME: Can this be inferred?
32 def inst_a : Instruction {
33 let OutOperandList = (outs GPR32:$dst);
34 let InOperandList = (ins GPR32:$src);
37 def inst_b : Instruction {
38 let OutOperandList = (outs GPR32:$dst);
39 let InOperandList = (ins GPR32:$src);
42 def inst_c : Instruction {
43 let OutOperandList = (outs);
44 let InOperandList = (ins GPR32:$src0, GPR32:$src1);
47 def inst_d : Instruction {
48 let OutOperandList = (outs);
49 let InOperandList = (ins GPR32:$src0, GPR32:$src1);
53 // SDAG-NEXT: // Predicate_pat_frag_b
54 // SDAG-NEXT: SDNode *N = Node;
55 // SDAG-NEXT: (void)N;
56 // SDAG-NEXT: unsigned AddrSpace = cast<MemSDNode>(N)->getAddressSpace();
57 // SDAG-NEXT: if (AddrSpace != 123 && AddrSpace != 455)
58 // SDAG-NEXT: return false;
59 // SDAG-NEXT: if (cast<MemSDNode>(N)->getMemoryVT() != MVT::i32) return false;
60 // SDAG-NEXT: return true;
63 // GISEL: GIM_Try, /*On fail goto*//*Label 0*/ {{[0-9]+}}, // Rule ID 0 //
64 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
65 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_LOAD,
66 // GISEL-NEXT: GIM_CheckMemorySizeEqualToLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
67 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/2, /*AddrSpace*/123, /*AddrSpace*/455,
68 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/4,
69 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
71 (pat_frag_b GPR32:$src),
77 // SDAG: // Predicate_pat_frag_a
78 // SDAG-NEXT: SDNode *N = Node;
79 // SDAG-NEXT: (void)N;
80 // SDAG-NEXT: unsigned AddrSpace = cast<MemSDNode>(N)->getAddressSpace();
82 // SDAG-NEXT: if (AddrSpace != 999)
83 // SDAG-NEXT: return false;
84 // SDAG-NEXT: if (cast<MemSDNode>(N)->getAlignment() < 2)
85 // SDAG-NEXT: return false;
86 // SDAG-NEXT: if (cast<MemSDNode>(N)->getMemoryVT() != MVT::i32) return false;
87 // SDAG-NEXT: return true;
89 // GISEL: GIM_Try, /*On fail goto*//*Label 1*/ {{[0-9]+}}, // Rule ID 1 //
90 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
91 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_LOAD,
92 // GISEL-NEXT: GIM_CheckMemorySizeEqualToLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
93 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/1, /*AddrSpace*/999,
94 // GISEL-NEXT: GIM_CheckMemoryAlignment, /*MI*/0, /*MMO*/0, /*MinAlign*/2,
95 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/4,
96 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
98 (pat_frag_a GPR32:$src),
103 def truncstorei16_addrspace : PatFrag<(ops node:$val, node:$ptr),
104 (truncstore node:$val, node:$ptr)> {
107 let AddressSpaces = [ 123, 455 ];
110 // Test truncstore without a specific MemoryVT
111 // GISEL: GIM_Try, /*On fail goto*//*Label 2*/ {{[0-9]+}}, // Rule ID 2 //
112 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
113 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_STORE,
114 // GISEL-NEXT: GIM_CheckMemorySizeLessThanLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
115 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
116 // GISEL-NEXT: // MIs[0] src0
117 // GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/0, /*Type*/GILLT_s32,
119 (truncstore GPR32:$src0, GPR32:$src1),
120 (inst_c GPR32:$src0, GPR32:$src1)
123 // Test non-truncstore has a size equal to LLT check.
124 // GISEL: GIM_Try, /*On fail goto*//*Label 3*/ {{[0-9]+}}, // Rule ID 3 //
125 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
126 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_STORE,
127 // GISEL-NEXT: GIM_CheckMemorySizeEqualToLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
129 (store GPR32:$src0, GPR32:$src1),
130 (inst_d GPR32:$src0, GPR32:$src1)
133 // Test truncstore with specific MemoryVT
134 // GISEL: GIM_Try, /*On fail goto*//*Label 4*/ {{[0-9]+}}, // Rule ID 4 //
135 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
136 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_STORE,
137 // GISEL-NEXT: GIM_CheckMemorySizeLessThanLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
138 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/2, /*AddrSpace*/123, /*AddrSpace*/455,
139 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/2,
141 (truncstorei16_addrspace GPR32:$src0, GPR32:$src1),
142 (inst_c GPR32:$src0, GPR32:$src1)