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?
24 // With multiple address spaces
25 def pat_frag_b : PatFrag <(ops node:$ptr), (load node:$ptr), [{}]> {
26 let AddressSpaces = [ 123, 455 ];
27 let IsLoad = 1; // FIXME: Can this be inferred?
31 def inst_a : Instruction {
32 let OutOperandList = (outs GPR32:$dst);
33 let InOperandList = (ins GPR32:$src);
36 def inst_b : Instruction {
37 let OutOperandList = (outs GPR32:$dst);
38 let InOperandList = (ins GPR32:$src);
41 def inst_c : Instruction {
42 let OutOperandList = (outs);
43 let InOperandList = (ins GPR32:$src0, GPR32:$src1);
47 // SDAG: // Predicate_pat_frag_a
48 // SDAG-NEXT: SDNode *N = Node;
49 // SDAG-NEXT: (void)N;
50 // SDAG-NEXT: unsigned AddrSpace = cast<MemSDNode>(N)->getAddressSpace();
52 // SDAG-NEXT: if (AddrSpace != 999)
53 // SDAG-NEXT: return false;
54 // SDAG-NEXT: if (cast<MemSDNode>(N)->getMemoryVT() != MVT::i32) return false;
55 // SDAG-NEXT: return true;
57 // GISEL: GIM_Try, /*On fail goto*//*Label 0*/ 47, // Rule ID 0 //
58 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
59 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_LOAD,
60 // GISEL-NEXT: GIM_CheckMemorySizeEqualToLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
61 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/1, /*AddrSpace*/999,
62 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/4,
63 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
65 (pat_frag_a GPR32:$src),
70 // SDAG-NEXT: // Predicate_pat_frag_b
71 // SDAG-NEXT: SDNode *N = Node;
72 // SDAG-NEXT: (void)N;
73 // SDAG-NEXT: unsigned AddrSpace = cast<MemSDNode>(N)->getAddressSpace();
74 // SDAG-NEXT: if (AddrSpace != 123 && AddrSpace != 455)
75 // SDAG-NEXT: return false;
76 // SDAG-NEXT: if (cast<MemSDNode>(N)->getMemoryVT() != MVT::i32) return false;
77 // SDAG-NEXT: return true;
80 // GISEL: GIM_Try, /*On fail goto*//*Label 1*/ 95, // Rule ID 1 //
81 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
82 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_LOAD,
83 // GISEL-NEXT: GIM_CheckMemorySizeEqualToLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
84 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/2, /*AddrSpace*/123, /*AddrSpace*/455,
85 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/4,
86 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
88 (pat_frag_b GPR32:$src),
93 def truncstorei16_addrspace : PatFrag<(ops node:$val, node:$ptr),
94 (truncstore node:$val, node:$ptr)> {
97 let AddressSpaces = [ 123, 455 ];
100 // Test truncstore without a specific MemoryVT
101 // GISEL: GIM_Try, /*On fail goto*//*Label 2*/ 133, // Rule ID 2 //
102 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
103 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_STORE,
104 // GISEL-NEXT: GIM_CheckMemorySizeLessThanLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
105 // GISEL-NEXT: GIM_CheckAtomicOrdering, /*MI*/0, /*Order*/(int64_t)AtomicOrdering::NotAtomic,
106 // GISEL-NEXT: // MIs[0] src0
107 // GISEL-NEXT: GIM_CheckType, /*MI*/0, /*Op*/0, /*Type*/GILLT_s32,
109 (truncstore GPR32:$src0, GPR32:$src1),
110 (inst_c GPR32:$src0, GPR32:$src1)
113 // Test truncstore with specific MemoryVT
114 // GISEL: GIM_Try, /*On fail goto*//*Label 3*/ 181, // Rule ID 3 //
115 // GISEL-NEXT: GIM_CheckNumOperands, /*MI*/0, /*Expected*/2,
116 // GISEL-NEXT: GIM_CheckOpcode, /*MI*/0, TargetOpcode::G_STORE,
117 // GISEL-NEXT: GIM_CheckMemorySizeLessThanLLT, /*MI*/0, /*MMO*/0, /*OpIdx*/0,
118 // GISEL-NEXT: GIM_CheckMemoryAddressSpace, /*MI*/0, /*MMO*/0, /*NumAddrSpace*/2, /*AddrSpace*/123, /*AddrSpace*/455,
119 // GISEL-NEXT: GIM_CheckMemorySizeEqualTo, /*MI*/0, /*MMO*/0, /*Size*/2,
121 (truncstorei16_addrspace GPR32:$src0, GPR32:$src1),
122 (inst_c GPR32:$src0, GPR32:$src1)