1//===- XtensaOperands.td - Xtensa instruction operands -------*- tblgen-*--===// 2// 3// The LLVM Compiler Infrastructure 4// 5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 6// See https://llvm.org/LICENSE.txt for license information. 7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 8// 9//===----------------------------------------------------------------------===// 10 11// Immediate operands with a shared generic render method. 12class ImmAsmOperand<string name> : AsmOperandClass { 13 let Name = name; 14 let RenderMethod = "addImmOperands"; 15 let DiagnosticType = !strconcat("Invalid", name); 16} 17 18class Immediate<ValueType vt, code pred, string asmop> 19 : Operand<vt>, ImmLeaf<vt, pred> { 20 let PrintMethod = "print"#asmop; 21 let ParserMatchClass = !cast<AsmOperandClass>(asmop); 22} 23 24// imm8 predicate - Immediate in the range [-128,127] 25def Imm8_AsmOperand : ImmAsmOperand<"Imm8">; 26def imm8 : Immediate<i32, [{ return Imm >= -128 && Imm <= 127; }], "Imm8_AsmOperand"> { 27 let EncoderMethod = "getImm8OpValue"; 28 let DecoderMethod = "decodeImm8Operand"; 29} 30 31// imm8_sh8 predicate - Immediate in the range [-32768,32512] with (bits[7-0] == 0) 32// imm8 value left shifted by 8 bits 33def Imm8_sh8_AsmOperand : ImmAsmOperand<"Imm8_sh8">; 34def imm8_sh8 : Immediate<i32, [{ return Imm >= -32768 && Imm <= 32512 && ((Imm & 0xFF) == 0); }], 35 "Imm8_sh8_AsmOperand"> { 36 let EncoderMethod = "getImm8_sh8OpValue"; 37 let DecoderMethod = "decodeImm8_sh8Operand"; 38} 39 40// imm12 predicate - Immediate in the range [-2048,2047] 41def Imm12_AsmOperand : ImmAsmOperand<"Imm12">; 42def imm12 : Immediate<i32, [{ return Imm >= -2048 && Imm <= 2047; }], "Imm12_AsmOperand"> { 43 let EncoderMethod = "getImm12OpValue"; 44 let DecoderMethod = "decodeImm12Operand"; 45} 46 47// imm12m predicate - Immediate for MOV operation 48def Imm12m_AsmOperand : ImmAsmOperand<"Imm12m">; 49def imm12m : Immediate<i32, [{ return Imm >= -2048 && Imm <= 2047; }], "Imm12m_AsmOperand"> { 50 let EncoderMethod = "getImm12OpValue"; 51 let DecoderMethod = "decodeImm12Operand"; 52} 53 54// uimm4 predicate - Immediate in the range [0,15] 55def Uimm4_AsmOperand : ImmAsmOperand<"Uimm4">; 56def uimm4 : Immediate<i32, [{ return Imm >= 0 && Imm <= 15; }], "Uimm4_AsmOperand"> { 57 let EncoderMethod = "getUimm4OpValue"; 58 let DecoderMethod = "decodeUimm4Operand"; 59} 60 61// uimm5 predicate - Immediate in the range [0,31] 62def Uimm5_AsmOperand : ImmAsmOperand<"Uimm5">; 63def uimm5 : Immediate<i32, [{ return Imm >= 0 && Imm <= 31; }], "Uimm5_AsmOperand"> { 64 let EncoderMethod = "getUimm5OpValue"; 65 let DecoderMethod = "decodeUimm5Operand"; 66} 67 68// imm1_16 predicate - Immediate in the range [1,16] 69def Imm1_16_AsmOperand : ImmAsmOperand<"Imm1_16">; 70def imm1_16 : Immediate<i32, [{ return Imm >= 1 && Imm <= 16; }], "Imm1_16_AsmOperand"> { 71 let EncoderMethod = "getImm1_16OpValue"; 72 let DecoderMethod = "decodeImm1_16Operand"; 73} 74 75// imm1n_15 predicate - Immediate in the range [-1,15], except 0 76def Imm1n_15_AsmOperand: ImmAsmOperand<"Imm1n_15">; 77def imm1n_15: Immediate<i32, [{ return Imm >= -1 && Imm <= 15 && Imm != 0; }], "Imm1n_15_AsmOperand"> { 78 let EncoderMethod = "getImm1n_15OpValue"; 79 let DecoderMethod = "decodeImm1n_15Operand"; 80} 81 82// imm32n_95 predicate - Immediate in the range [-32,95] 83def Imm32n_95_AsmOperand: ImmAsmOperand<"Imm32n_95">; 84def imm32n_95: Immediate<i32, [{ return Imm >= -32 && Imm <= 95; }], "Imm32n_95_AsmOperand"> { 85 let EncoderMethod = "getImm32n_95OpValue"; 86 let DecoderMethod = "decodeImm32n_95Operand"; 87} 88 89// shimm1_31 predicate - Immediate in the range [1,31] 90def Shimm1_31_AsmOperand : ImmAsmOperand<"Shimm1_31">; 91def shimm1_31 : Immediate<i32, [{ return Imm >= 1 && Imm <= 31; }], "Shimm1_31_AsmOperand"> { 92 let EncoderMethod = "getShimm1_31OpValue"; 93 let DecoderMethod = "decodeShimm1_31Operand"; 94} 95 96// Memory offset 0..255 for 8-bit memory accesses 97def Offset8m8_AsmOperand : ImmAsmOperand<"Offset8m8">; 98def offset8m8 : Immediate<i32, 99 [{ return Imm >= 0 && Imm <= 255; }], 100 "Offset8m8_AsmOperand">; 101 102// Memory offset 0..510 for 16-bit memory accesses 103def Offset8m16_AsmOperand : ImmAsmOperand<"Offset8m16">; 104def offset8m16 : Immediate<i32, 105 [{ return Imm >= 0 && Imm <= 510 && (Imm & 0x1 == 0); }], 106 "Offset8m16_AsmOperand">; 107 108// Memory offset 0..1020 for 32-bit memory accesses 109def Offset8m32_AsmOperand : ImmAsmOperand<"Offset8m32">; 110def offset8m32 : Immediate<i32, 111 [{ return Imm >= 0 && Imm <= 1020 && (Imm & 0x3 == 0); }], 112 "Offset8m32_AsmOperand">; 113 114// Memory offset 0..60 for 32-bit memory accesses 115def Offset4m32_AsmOperand : ImmAsmOperand<"Offset4m32">; 116def offset4m32 : Immediate<i32, 117 [{ return Imm >= 0 && Imm <= 60 && (Imm & 0x3 == 0); }], 118 "Offset4m32_AsmOperand">; 119 120// b4const predicate - Branch Immediate 4-bit signed operand 121def B4const_AsmOperand: ImmAsmOperand<"B4const">; 122def b4const: Immediate<i32, 123 [{ switch (Imm) { 124 case -1: case 1: case 2: case 3: case 4: 125 case 5: case 6: case 7: case 8: case 10: case 12: 126 case 16: case 32: case 64: case 128: case 256: return 1; 127 default: return 0; 128 } 129 }], 130 "B4const_AsmOperand"> { 131 let EncoderMethod = "getB4constOpValue"; 132 let DecoderMethod = "decodeB4constOperand"; 133} 134 135// b4constu predicate - Branch Immediate 4-bit unsigned operand 136def B4constu_AsmOperand: ImmAsmOperand<"B4constu">; 137def b4constu: Immediate<i32, 138 [{ switch (Imm) { 139 case 32768: case 65536: case 2: case 3: case 4: 140 case 5: case 6: case 7: case 8: case 10: case 12: 141 case 16: case 32: case 64: case 128: case 256: return 1; 142 default: return 0; 143 } 144 }], 145 "B4constu_AsmOperand"> { 146 let EncoderMethod = "getB4constuOpValue"; 147 let DecoderMethod = "decodeB4constuOperand"; 148} 149//===----------------------------------------------------------------------===// 150// Memory address operands 151//===----------------------------------------------------------------------===// 152 153class mem<Operand offset> : Operand<i32> { 154 let MIOperandInfo = (ops AR, offset); 155 let EncoderMethod = "getMemRegEncoding"; 156 let OperandType = "OPERAND_MEMORY"; 157 let PrintMethod = "printMemOperand"; 158} 159 160def mem8 : mem<offset8m8> { 161 let DecoderMethod = "decodeMem8Operand"; 162} 163 164def mem16 : mem<offset8m16> { 165 let DecoderMethod = "decodeMem16Operand"; 166} 167 168def mem32 : mem<offset8m32> { 169 let DecoderMethod = "decodeMem32Operand"; 170} 171 172def mem32n : mem<offset4m32> { 173 let DecoderMethod = "decodeMem32nOperand"; 174} 175 176//Add patterns for future use in stack addressing mode 177def addr_ish1 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH1", [frameindex]>; 178def addr_ish2 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH2", [frameindex]>; 179def addr_ish4 : ComplexPattern<iPTR, 2, "selectMemRegAddrISH4", [frameindex]>; 180 181//===----------------------------------------------------------------------===// 182// Symbolic address operands 183//===----------------------------------------------------------------------===// 184def XtensaPCRelTargetAsmOperand : AsmOperandClass { 185 let Name = "PCRelTarget"; 186 let ParserMethod = "parsePCRelTarget"; 187 let PredicateMethod = "isImm"; 188 let RenderMethod = "addImmOperands"; 189} 190 191def pcrel32call : Operand<iPTR> { 192 let PrintMethod = "printCallOperand"; 193 let EncoderMethod = "getCallEncoding"; 194 let DecoderMethod = "decodeCallOperand"; 195 let ParserMatchClass = XtensaPCRelTargetAsmOperand; 196} 197 198def brtarget : Operand<OtherVT> { 199 let PrintMethod = "printBranchTarget"; 200 let EncoderMethod = "getBranchTargetEncoding"; 201 let DecoderMethod = "decodeBranchOperand"; 202 let ParserMatchClass = XtensaPCRelTargetAsmOperand; 203} 204 205def jumptarget : Operand<OtherVT> { 206 let PrintMethod = "printJumpTarget"; 207 let EncoderMethod = "getJumpTargetEncoding"; 208 let DecoderMethod = "decodeJumpOperand"; 209 let ParserMatchClass = XtensaPCRelTargetAsmOperand; 210} 211 212def L32Rtarget : Operand<i32> { 213 let PrintMethod = "printL32RTarget"; 214 let EncoderMethod = "getL32RTargetEncoding"; 215 let DecoderMethod = "decodeL32ROperand"; 216 let ParserMatchClass = XtensaPCRelTargetAsmOperand; 217} 218