1//===- HexagonOperands.td - Hexagon immediate processing -*- tablegen -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illnois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10def s4_0ImmOperand : AsmOperandClass { let Name = "s4_0Imm"; } 11def s4_1ImmOperand : AsmOperandClass { let Name = "s4_1Imm"; } 12def s4_2ImmOperand : AsmOperandClass { let Name = "s4_2Imm"; } 13def s4_3ImmOperand : AsmOperandClass { let Name = "s4_3Imm"; } 14 15// Immediate operands. 16 17let PrintMethod = "printImmOperand" in { 18 def s32Imm : Operand<i32>; 19 def s8Imm : Operand<i32>; 20 def s8Imm64 : Operand<i64>; 21 def s6Imm : Operand<i32>; 22 def s6_3Imm : Operand<i32>; 23 def s4Imm : Operand<i32>; 24 def s4_0Imm : Operand<i32> { let DecoderMethod = "s4_0ImmDecoder"; } 25 def s4_1Imm : Operand<i32> { let DecoderMethod = "s4_1ImmDecoder"; } 26 def s4_2Imm : Operand<i32> { let DecoderMethod = "s4_2ImmDecoder"; } 27 def s4_3Imm : Operand<i32> { let DecoderMethod = "s4_3ImmDecoder"; } 28 def u64Imm : Operand<i64>; 29 def u32Imm : Operand<i32>; 30 def u26_6Imm : Operand<i32>; 31 def u16Imm : Operand<i32>; 32 def u16_0Imm : Operand<i32>; 33 def u16_1Imm : Operand<i32>; 34 def u16_2Imm : Operand<i32>; 35 def u16_3Imm : Operand<i32>; 36 def u11_3Imm : Operand<i32>; 37 def u10Imm : Operand<i32>; 38 def u9Imm : Operand<i32>; 39 def u8Imm : Operand<i32>; 40 def u7Imm : Operand<i32>; 41 def u6Imm : Operand<i32>; 42 def u6_0Imm : Operand<i32>; 43 def u6_1Imm : Operand<i32>; 44 def u6_2Imm : Operand<i32>; 45 def u6_3Imm : Operand<i32>; 46 def u5Imm : Operand<i32>; 47 def u5_2Imm : Operand<i32>; 48 def u5_3Imm : Operand<i32>; 49 def u4Imm : Operand<i32>; 50 def u4_0Imm : Operand<i32>; 51 def u4_2Imm : Operand<i32>; 52 def u3Imm : Operand<i32>; 53 def u3_0Imm : Operand<i32>; 54 def u3_1Imm : Operand<i32>; 55 def u2Imm : Operand<i32>; 56 def u1Imm : Operand<i32>; 57 def n8Imm : Operand<i32>; 58 def m6Imm : Operand<i32>; 59} 60 61let PrintMethod = "printNOneImmOperand" in 62def nOneImm : Operand<i32>; 63 64// 65// Immediate predicates 66// 67def s32ImmPred : PatLeaf<(i32 imm), [{ 68 int64_t v = (int64_t)N->getSExtValue(); 69 return isInt<32>(v); 70}]>; 71 72def s32_0ImmPred : PatLeaf<(i32 imm), [{ 73 int64_t v = (int64_t)N->getSExtValue(); 74 return isInt<32>(v); 75}]>; 76 77def s31_1ImmPred : PatLeaf<(i32 imm), [{ 78 int64_t v = (int64_t)N->getSExtValue(); 79 return isShiftedInt<31,1>(v); 80}]>; 81 82def s30_2ImmPred : PatLeaf<(i32 imm), [{ 83 int64_t v = (int64_t)N->getSExtValue(); 84 return isShiftedInt<31,1>(v); 85}]>; 86 87def s29_3ImmPred : PatLeaf<(i32 imm), [{ 88 int64_t v = (int64_t)N->getSExtValue(); 89 return isShiftedInt<31,1>(v); 90}]>; 91 92def s22_10ImmPred : PatLeaf<(i32 imm), [{ 93 int64_t v = (int64_t)N->getSExtValue(); 94 return isShiftedInt<22,10>(v); 95}]>; 96 97def s8_24ImmPred : PatLeaf<(i32 imm), [{ 98 int64_t v = (int64_t)N->getSExtValue(); 99 return isShiftedInt<8,24>(v); 100}]>; 101 102def s16_16ImmPred : PatLeaf<(i32 imm), [{ 103 int64_t v = (int64_t)N->getSExtValue(); 104 return isShiftedInt<16,16>(v); 105}]>; 106 107def s26_6ImmPred : PatLeaf<(i32 imm), [{ 108 int64_t v = (int64_t)N->getSExtValue(); 109 return isShiftedInt<26,6>(v); 110}]>; 111 112def s16ImmPred : PatLeaf<(i32 imm), [{ 113 int64_t v = (int64_t)N->getSExtValue(); 114 return isInt<16>(v); 115}]>; 116 117def s13ImmPred : PatLeaf<(i32 imm), [{ 118 int64_t v = (int64_t)N->getSExtValue(); 119 return isInt<13>(v); 120}]>; 121 122def s12ImmPred : PatLeaf<(i32 imm), [{ 123 int64_t v = (int64_t)N->getSExtValue(); 124 return isInt<12>(v); 125}]>; 126 127def s11_0ImmPred : PatLeaf<(i32 imm), [{ 128 int64_t v = (int64_t)N->getSExtValue(); 129 return isInt<11>(v); 130}]>; 131 132def s11_1ImmPred : PatLeaf<(i32 imm), [{ 133 int64_t v = (int64_t)N->getSExtValue(); 134 return isShiftedInt<11,1>(v); 135}]>; 136 137def s11_2ImmPred : PatLeaf<(i32 imm), [{ 138 int64_t v = (int64_t)N->getSExtValue(); 139 return isShiftedInt<11,2>(v); 140}]>; 141 142def s11_3ImmPred : PatLeaf<(i32 imm), [{ 143 int64_t v = (int64_t)N->getSExtValue(); 144 return isShiftedInt<11,3>(v); 145}]>; 146 147def s10ImmPred : PatLeaf<(i32 imm), [{ 148 int64_t v = (int64_t)N->getSExtValue(); 149 return isInt<10>(v); 150}]>; 151 152def s9ImmPred : PatLeaf<(i32 imm), [{ 153 int64_t v = (int64_t)N->getSExtValue(); 154 return isInt<9>(v); 155}]>; 156 157def m9ImmPred : PatLeaf<(i32 imm), [{ 158 int64_t v = (int64_t)N->getSExtValue(); 159 return isInt<9>(v) && (v != -256); 160}]>; 161 162def s8ImmPred : PatLeaf<(i32 imm), [{ 163 int64_t v = (int64_t)N->getSExtValue(); 164 return isInt<8>(v); 165}]>; 166 167def s8Imm64Pred : PatLeaf<(i64 imm), [{ 168 int64_t v = (int64_t)N->getSExtValue(); 169 return isInt<8>(v); 170}]>; 171 172def s6ImmPred : PatLeaf<(i32 imm), [{ 173 int64_t v = (int64_t)N->getSExtValue(); 174 return isInt<6>(v); 175}]>; 176 177def s4_0ImmPred : PatLeaf<(i32 imm), [{ 178 int64_t v = (int64_t)N->getSExtValue(); 179 return isInt<4>(v); 180}]>; 181 182def s4_1ImmPred : PatLeaf<(i32 imm), [{ 183 int64_t v = (int64_t)N->getSExtValue(); 184 return isShiftedInt<4,1>(v); 185}]>; 186 187def s4_2ImmPred : PatLeaf<(i32 imm), [{ 188 int64_t v = (int64_t)N->getSExtValue(); 189 return isShiftedInt<4,2>(v); 190}]>; 191 192def s4_3ImmPred : PatLeaf<(i32 imm), [{ 193 int64_t v = (int64_t)N->getSExtValue(); 194 return isShiftedInt<4,3>(v); 195}]>; 196 197 198def u64ImmPred : PatLeaf<(i64 imm), [{ 199 // Adding "N ||" to suppress gcc unused warning. 200 return (N || true); 201}]>; 202 203def u32ImmPred : PatLeaf<(i32 imm), [{ 204 int64_t v = (int64_t)N->getSExtValue(); 205 return isUInt<32>(v); 206}]>; 207 208def u32_0ImmPred : PatLeaf<(i32 imm), [{ 209 int64_t v = (int64_t)N->getSExtValue(); 210 return isUInt<32>(v); 211}]>; 212 213def u31_1ImmPred : PatLeaf<(i32 imm), [{ 214 int64_t v = (int64_t)N->getSExtValue(); 215 return isShiftedUInt<31,1>(v); 216}]>; 217 218def u30_2ImmPred : PatLeaf<(i32 imm), [{ 219 int64_t v = (int64_t)N->getSExtValue(); 220 return isShiftedUInt<30,2>(v); 221}]>; 222 223def u29_3ImmPred : PatLeaf<(i32 imm), [{ 224 int64_t v = (int64_t)N->getSExtValue(); 225 return isShiftedUInt<29,3>(v); 226}]>; 227 228def u26_6ImmPred : PatLeaf<(i32 imm), [{ 229 int64_t v = (int64_t)N->getSExtValue(); 230 return isShiftedUInt<26,6>(v); 231}]>; 232 233def u16ImmPred : PatLeaf<(i32 imm), [{ 234 int64_t v = (int64_t)N->getSExtValue(); 235 return isUInt<16>(v); 236}]>; 237 238def u16_s8ImmPred : PatLeaf<(i32 imm), [{ 239 int64_t v = (int64_t)N->getSExtValue(); 240 return isShiftedUInt<16,8>(v); 241}]>; 242 243def u16_0ImmPred : PatLeaf<(i32 imm), [{ 244 int64_t v = (int64_t)N->getSExtValue(); 245 return isUInt<16>(v); 246}]>; 247 248def u11_3ImmPred : PatLeaf<(i32 imm), [{ 249 int64_t v = (int64_t)N->getSExtValue(); 250 return isShiftedUInt<11,3>(v); 251}]>; 252 253def u9ImmPred : PatLeaf<(i32 imm), [{ 254 int64_t v = (int64_t)N->getSExtValue(); 255 return isUInt<9>(v); 256}]>; 257 258def u8ImmPred : PatLeaf<(i32 imm), [{ 259 int64_t v = (int64_t)N->getSExtValue(); 260 return isUInt<8>(v); 261}]>; 262 263def u7StrictPosImmPred : ImmLeaf<i32, [{ 264 // u7StrictPosImmPred predicate - True if the immediate fits in an 7-bit 265 // unsigned field and is strictly greater than 0. 266 return isUInt<7>(Imm) && Imm > 0; 267}]>; 268 269def u7ImmPred : PatLeaf<(i32 imm), [{ 270 int64_t v = (int64_t)N->getSExtValue(); 271 return isUInt<7>(v); 272}]>; 273 274def u6ImmPred : PatLeaf<(i32 imm), [{ 275 int64_t v = (int64_t)N->getSExtValue(); 276 return isUInt<6>(v); 277}]>; 278 279def u6_0ImmPred : PatLeaf<(i32 imm), [{ 280 int64_t v = (int64_t)N->getSExtValue(); 281 return isUInt<6>(v); 282}]>; 283 284def u6_1ImmPred : PatLeaf<(i32 imm), [{ 285 int64_t v = (int64_t)N->getSExtValue(); 286 return isShiftedUInt<6,1>(v); 287}]>; 288 289def u6_2ImmPred : PatLeaf<(i32 imm), [{ 290 int64_t v = (int64_t)N->getSExtValue(); 291 return isShiftedUInt<6,2>(v); 292}]>; 293 294def u6_3ImmPred : PatLeaf<(i32 imm), [{ 295 int64_t v = (int64_t)N->getSExtValue(); 296 return isShiftedUInt<6,3>(v); 297}]>; 298 299def u5ImmPred : PatLeaf<(i32 imm), [{ 300 int64_t v = (int64_t)N->getSExtValue(); 301 return isUInt<5>(v); 302}]>; 303 304def u4ImmPred : PatLeaf<(i32 imm), [{ 305 int64_t v = (int64_t)N->getSExtValue(); 306 return isUInt<4>(v); 307}]>; 308 309def u3ImmPred : PatLeaf<(i32 imm), [{ 310 int64_t v = (int64_t)N->getSExtValue(); 311 return isUInt<3>(v); 312}]>; 313 314def u2ImmPred : PatLeaf<(i32 imm), [{ 315 int64_t v = (int64_t)N->getSExtValue(); 316 return isUInt<2>(v); 317}]>; 318 319def u1ImmPred : PatLeaf<(i1 imm), [{ 320 int64_t v = (int64_t)N->getSExtValue(); 321 return isUInt<1>(v); 322}]>; 323 324def m5BImmPred : PatLeaf<(i32 imm), [{ 325 // m5BImmPred predicate - True if the (char) number is in range -1 .. -31 326 // and will fit in a 5 bit field when made positive, for use in memops. 327 // this is specific to the zero extending of a negative by CombineInstr 328 int8_t v = (int8_t)N->getSExtValue(); 329 return (-31 <= v && v <= -1); 330}]>; 331 332def m5HImmPred : PatLeaf<(i32 imm), [{ 333 // m5HImmPred predicate - True if the (short) number is in range -1 .. -31 334 // and will fit in a 5 bit field when made positive, for use in memops. 335 // this is specific to the zero extending of a negative by CombineInstr 336 int16_t v = (int16_t)N->getSExtValue(); 337 return (-31 <= v && v <= -1); 338}]>; 339 340def m5ImmPred : PatLeaf<(i32 imm), [{ 341 // m5ImmPred predicate - True if the number is in range -1 .. -31 342 // and will fit in a 5 bit field when made positive, for use in memops. 343 int64_t v = (int64_t)N->getSExtValue(); 344 return (-31 <= v && v <= -1); 345}]>; 346 347//InN means negative integers in [-(2^N - 1), 0] 348def n8ImmPred : PatLeaf<(i32 imm), [{ 349 // n8ImmPred predicate - True if the immediate fits in a 8-bit signed 350 // field. 351 int64_t v = (int64_t)N->getSExtValue(); 352 return (-255 <= v && v <= 0); 353}]>; 354 355def nOneImmPred : PatLeaf<(i32 imm), [{ 356 // nOneImmPred predicate - True if the immediate is -1. 357 int64_t v = (int64_t)N->getSExtValue(); 358 return (-1 == v); 359}]>; 360 361def Set5ImmPred : PatLeaf<(i32 imm), [{ 362 // Set5ImmPred predicate - True if the number is in the series of values. 363 // [ 2^0, 2^1, ... 2^31 ] 364 // For use in setbit immediate. 365 uint32_t v = (int32_t)N->getSExtValue(); 366 // Constrain to 32 bits, and then check for single bit. 367 return ImmIsSingleBit(v); 368}]>; 369 370def Clr5ImmPred : PatLeaf<(i32 imm), [{ 371 // Clr5ImmPred predicate - True if the number is in the series of 372 // bit negated values. 373 // [ 2^0, 2^1, ... 2^31 ] 374 // For use in clrbit immediate. 375 // Note: we are bit NOTing the value. 376 uint32_t v = ~ (int32_t)N->getSExtValue(); 377 // Constrain to 32 bits, and then check for single bit. 378 return ImmIsSingleBit(v); 379}]>; 380 381def SetClr5ImmPred : PatLeaf<(i32 imm), [{ 382 // SetClr5ImmPred predicate - True if the immediate is in range 0..31. 383 int32_t v = (int32_t)N->getSExtValue(); 384 return (v >= 0 && v <= 31); 385}]>; 386 387def Set4ImmPred : PatLeaf<(i32 imm), [{ 388 // Set4ImmPred predicate - True if the number is in the series of values: 389 // [ 2^0, 2^1, ... 2^15 ]. 390 // For use in setbit immediate. 391 uint16_t v = (int16_t)N->getSExtValue(); 392 // Constrain to 16 bits, and then check for single bit. 393 return ImmIsSingleBit(v); 394}]>; 395 396def Clr4ImmPred : PatLeaf<(i32 imm), [{ 397 // Clr4ImmPred predicate - True if the number is in the series of 398 // bit negated values: 399 // [ 2^0, 2^1, ... 2^15 ]. 400 // For use in setbit and clrbit immediate. 401 uint16_t v = ~ (int16_t)N->getSExtValue(); 402 // Constrain to 16 bits, and then check for single bit. 403 return ImmIsSingleBit(v); 404}]>; 405 406def SetClr4ImmPred : PatLeaf<(i32 imm), [{ 407 // SetClr4ImmPred predicate - True if the immediate is in the range 0..15. 408 int16_t v = (int16_t)N->getSExtValue(); 409 return (v >= 0 && v <= 15); 410}]>; 411 412def Set3ImmPred : PatLeaf<(i32 imm), [{ 413 // Set3ImmPred predicate - True if the number is in the series of values: 414 // [ 2^0, 2^1, ... 2^7 ]. 415 // For use in setbit immediate. 416 uint8_t v = (int8_t)N->getSExtValue(); 417 // Constrain to 8 bits, and then check for single bit. 418 return ImmIsSingleBit(v); 419}]>; 420 421def Clr3ImmPred : PatLeaf<(i32 imm), [{ 422 // Clr3ImmPred predicate - True if the number is in the series of 423 // bit negated values: 424 // [ 2^0, 2^1, ... 2^7 ]. 425 // For use in setbit and clrbit immediate. 426 uint8_t v = ~ (int8_t)N->getSExtValue(); 427 // Constrain to 8 bits, and then check for single bit. 428 return ImmIsSingleBit(v); 429}]>; 430 431def SetClr3ImmPred : PatLeaf<(i32 imm), [{ 432 // SetClr3ImmPred predicate - True if the immediate is in the range 0..7. 433 int8_t v = (int8_t)N->getSExtValue(); 434 return (v >= 0 && v <= 7); 435}]>; 436 437 438// Extendable immediate operands. 439 440let PrintMethod = "printExtOperand" in { 441 def f32Ext : Operand<f32>; 442 def s16Ext : Operand<i32> { let DecoderMethod = "s16ImmDecoder"; } 443 def s12Ext : Operand<i32> { let DecoderMethod = "s12ImmDecoder"; } 444 def s11_0Ext : Operand<i32> { let DecoderMethod = "s11_0ImmDecoder"; } 445 def s11_1Ext : Operand<i32> { let DecoderMethod = "s11_1ImmDecoder"; } 446 def s11_2Ext : Operand<i32> { let DecoderMethod = "s11_2ImmDecoder"; } 447 def s11_3Ext : Operand<i32> { let DecoderMethod = "s11_3ImmDecoder"; } 448 def s10Ext : Operand<i32> { let DecoderMethod = "s10ImmDecoder"; } 449 def s9Ext : Operand<i32> { let DecoderMethod = "s90ImmDecoder"; } 450 def s8Ext : Operand<i32> { let DecoderMethod = "s8ImmDecoder"; } 451 def s7Ext : Operand<i32>; 452 def s6Ext : Operand<i32> { let DecoderMethod = "s6_0ImmDecoder"; } 453 def u6Ext : Operand<i32>; 454 def u7Ext : Operand<i32>; 455 def u8Ext : Operand<i32>; 456 def u9Ext : Operand<i32>; 457 def u10Ext : Operand<i32>; 458 def u6_0Ext : Operand<i32>; 459 def u6_1Ext : Operand<i32>; 460 def u6_2Ext : Operand<i32>; 461 def u6_3Ext : Operand<i32>; 462} 463 464def s10ExtPred : PatLeaf<(i32 imm), [{ 465 int64_t v = (int64_t)N->getSExtValue(); 466 if (isInt<10>(v)) 467 return true; 468 469 // Return true if extending this immediate is profitable and the value 470 // can fit in a 32-bit signed field. 471 return isConstExtProfitable(Node) && isInt<32>(v); 472}]>; 473 474def s8ExtPred : PatLeaf<(i32 imm), [{ 475 int64_t v = (int64_t)N->getSExtValue(); 476 if (isInt<8>(v)) 477 return true; 478 479 // Return true if extending this immediate is profitable and the value 480 // can fit in a 32-bit signed field. 481 return isConstExtProfitable(Node) && isInt<32>(v); 482}]>; 483 484def u8ExtPred : PatLeaf<(i32 imm), [{ 485 int64_t v = (int64_t)N->getSExtValue(); 486 if (isUInt<8>(v)) 487 return true; 488 489 // Return true if extending this immediate is profitable and the value 490 // can fit in a 32-bit unsigned field. 491 return isConstExtProfitable(Node) && isUInt<32>(v); 492}]>; 493 494def u9ExtPred : PatLeaf<(i32 imm), [{ 495 int64_t v = (int64_t)N->getSExtValue(); 496 if (isUInt<9>(v)) 497 return true; 498 499 // Return true if extending this immediate is profitable and the value 500 // can fit in a 32-bit unsigned field. 501 return isConstExtProfitable(Node) && isUInt<32>(v); 502}]>; 503 504 505// This complex pattern exists only to create a machine instruction operand 506// of type "frame index". There doesn't seem to be a way to do that directly 507// in the patterns. 508def AddrFI : ComplexPattern<i32, 1, "SelectAddrFI", [frameindex], []>; 509 510// These complex patterns are not strictly necessary, since global address 511// folding will happen during DAG combining. For distinguishing between GA 512// and GP, pat frags with HexagonCONST32 and HexagonCONST32_GP can be used. 513def AddrGA : ComplexPattern<i32, 1, "SelectAddrGA", [], []>; 514def AddrGP : ComplexPattern<i32, 1, "SelectAddrGP", [], []>; 515 516// Address operands. 517 518let PrintMethod = "printGlobalOperand" in { 519 def globaladdress : Operand<i32>; 520 def globaladdressExt : Operand<i32>; 521} 522 523let PrintMethod = "printJumpTable" in 524def jumptablebase : Operand<i32>; 525 526def brtarget : Operand<OtherVT>; 527def brtargetExt : Operand<OtherVT> { 528 let PrintMethod = "printExtBrtarget"; 529} 530def calltarget : Operand<i32>; 531 532def bblabel : Operand<i32>; 533def bbl : SDNode<"ISD::BasicBlock", SDTPtrLeaf , [], "BasicBlockSDNode">; 534 535def symbolHi32 : Operand<i32> { 536 let PrintMethod = "printSymbolHi"; 537} 538def symbolLo32 : Operand<i32> { 539 let PrintMethod = "printSymbolLo"; 540} 541 542// Return true if for a 32 to 64-bit sign-extended load. 543def is_sext_i32 : PatLeaf<(i64 DoubleRegs:$src1), [{ 544 LoadSDNode *LD = dyn_cast<LoadSDNode>(N); 545 if (!LD) 546 return false; 547 return LD->getExtensionType() == ISD::SEXTLOAD && 548 LD->getMemoryVT().getScalarType() == MVT::i32; 549}]>; 550