| 1 | //===-- VE.h - Top-level interface for VE representation --------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the entry points for global functions defined in the LLVM |
| 10 | // VE back-end. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_LIB_TARGET_VE_VE_H |
| 15 | #define LLVM_LIB_TARGET_VE_VE_H |
| 16 | |
| 17 | #include "MCTargetDesc/VEMCTargetDesc.h" |
| 18 | #include "llvm/ADT/StringSwitch.h" |
| 19 | #include "llvm/CodeGen/MachineFunctionAnalysisManager.h" |
| 20 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 21 | #include "llvm/IR/Analysis.h" |
| 22 | #include "llvm/IR/PassManager.h" |
| 23 | #include "llvm/Support/CodeGen.h" |
| 24 | #include "llvm/Support/ErrorHandling.h" |
| 25 | #include "llvm/Target/TargetMachine.h" |
| 26 | |
| 27 | namespace llvm { |
| 28 | class AsmPrinter; |
| 29 | class FunctionPass; |
| 30 | class MCInst; |
| 31 | class MachineInstr; |
| 32 | class PassRegistry; |
| 33 | class VETargetMachine; |
| 34 | |
| 35 | class VEDAGToDAGISelPass : public SelectionDAGISelPass { |
| 36 | public: |
| 37 | VEDAGToDAGISelPass(VETargetMachine &TM); |
| 38 | }; |
| 39 | |
| 40 | FunctionPass *createVEDAGToDAGISelLegacyPass(VETargetMachine &TM); |
| 41 | |
| 42 | class VELVLGenPass : public RequiredPassInfoMixin<VELVLGenPass> { |
| 43 | public: |
| 44 | PreservedAnalyses run(MachineFunction &MF, |
| 45 | MachineFunctionAnalysisManager &MFAM); |
| 46 | }; |
| 47 | |
| 48 | FunctionPass *createVELVLGenLegacyPass(); |
| 49 | void initializeVEAsmPrinterPass(PassRegistry &); |
| 50 | void initializeVEDAGToDAGISelLegacyPass(PassRegistry &); |
| 51 | |
| 52 | void LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, |
| 53 | AsmPrinter &AP); |
| 54 | } // namespace llvm |
| 55 | |
| 56 | namespace llvm { |
| 57 | // Enums corresponding to VE condition codes, both icc's and fcc's. These |
| 58 | // values must be kept in sync with the ones in the .td file. |
| 59 | namespace VECC { |
| 60 | enum CondCode { |
| 61 | // Integer comparison |
| 62 | CC_IG = 0, // Greater |
| 63 | CC_IL = 1, // Less |
| 64 | CC_INE = 2, // Not Equal |
| 65 | CC_IEQ = 3, // Equal |
| 66 | CC_IGE = 4, // Greater or Equal |
| 67 | CC_ILE = 5, // Less or Equal |
| 68 | |
| 69 | // Floating point comparison |
| 70 | CC_AF = 0 + 6, // Never |
| 71 | CC_G = 1 + 6, // Greater |
| 72 | CC_L = 2 + 6, // Less |
| 73 | CC_NE = 3 + 6, // Not Equal |
| 74 | CC_EQ = 4 + 6, // Equal |
| 75 | CC_GE = 5 + 6, // Greater or Equal |
| 76 | CC_LE = 6 + 6, // Less or Equal |
| 77 | CC_NUM = 7 + 6, // Number |
| 78 | CC_NAN = 8 + 6, // NaN |
| 79 | CC_GNAN = 9 + 6, // Greater or NaN |
| 80 | CC_LNAN = 10 + 6, // Less or NaN |
| 81 | CC_NENAN = 11 + 6, // Not Equal or NaN |
| 82 | CC_EQNAN = 12 + 6, // Equal or NaN |
| 83 | CC_GENAN = 13 + 6, // Greater or Equal or NaN |
| 84 | CC_LENAN = 14 + 6, // Less or Equal or NaN |
| 85 | CC_AT = 15 + 6, // Always |
| 86 | UNKNOWN |
| 87 | }; |
| 88 | } |
| 89 | // Enums corresponding to VE Rounding Mode. These values must be kept in |
| 90 | // sync with the ones in the .td file. |
| 91 | namespace VERD { |
| 92 | enum RoundingMode { |
| 93 | RD_NONE = 0, // According to PSW |
| 94 | RD_RZ = 8, // Round toward Zero |
| 95 | RD_RP = 9, // Round toward Plus infinity |
| 96 | RD_RM = 10, // Round toward Minus infinity |
| 97 | RD_RN = 11, // Round to Nearest (ties to Even) |
| 98 | RD_RA = 12, // Round to Nearest (ties to Away) |
| 99 | UNKNOWN |
| 100 | }; |
| 101 | } |
| 102 | |
| 103 | inline static const char *VECondCodeToString(VECC::CondCode CC) { |
| 104 | switch (CC) { |
| 105 | case VECC::CC_IG: return "gt" ; |
| 106 | case VECC::CC_IL: return "lt" ; |
| 107 | case VECC::CC_INE: return "ne" ; |
| 108 | case VECC::CC_IEQ: return "eq" ; |
| 109 | case VECC::CC_IGE: return "ge" ; |
| 110 | case VECC::CC_ILE: return "le" ; |
| 111 | case VECC::CC_AF: return "af" ; |
| 112 | case VECC::CC_G: return "gt" ; |
| 113 | case VECC::CC_L: return "lt" ; |
| 114 | case VECC::CC_NE: return "ne" ; |
| 115 | case VECC::CC_EQ: return "eq" ; |
| 116 | case VECC::CC_GE: return "ge" ; |
| 117 | case VECC::CC_LE: return "le" ; |
| 118 | case VECC::CC_NUM: return "num" ; |
| 119 | case VECC::CC_NAN: return "nan" ; |
| 120 | case VECC::CC_GNAN: return "gtnan" ; |
| 121 | case VECC::CC_LNAN: return "ltnan" ; |
| 122 | case VECC::CC_NENAN: return "nenan" ; |
| 123 | case VECC::CC_EQNAN: return "eqnan" ; |
| 124 | case VECC::CC_GENAN: return "genan" ; |
| 125 | case VECC::CC_LENAN: return "lenan" ; |
| 126 | case VECC::CC_AT: return "at" ; |
| 127 | default: |
| 128 | llvm_unreachable("Invalid cond code" ); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | inline static VECC::CondCode stringToVEICondCode(StringRef S) { |
| 133 | return StringSwitch<VECC::CondCode>(S) |
| 134 | .Case(S: "gt" , Value: VECC::CC_IG) |
| 135 | .Case(S: "lt" , Value: VECC::CC_IL) |
| 136 | .Case(S: "ne" , Value: VECC::CC_INE) |
| 137 | .Case(S: "eq" , Value: VECC::CC_IEQ) |
| 138 | .Case(S: "ge" , Value: VECC::CC_IGE) |
| 139 | .Case(S: "le" , Value: VECC::CC_ILE) |
| 140 | .Case(S: "af" , Value: VECC::CC_AF) |
| 141 | .Case(S: "at" , Value: VECC::CC_AT) |
| 142 | .Case(S: "" , Value: VECC::CC_AT) |
| 143 | .Default(Value: VECC::UNKNOWN); |
| 144 | } |
| 145 | |
| 146 | inline static VECC::CondCode stringToVEFCondCode(StringRef S) { |
| 147 | return StringSwitch<VECC::CondCode>(S) |
| 148 | .Case(S: "gt" , Value: VECC::CC_G) |
| 149 | .Case(S: "lt" , Value: VECC::CC_L) |
| 150 | .Case(S: "ne" , Value: VECC::CC_NE) |
| 151 | .Case(S: "eq" , Value: VECC::CC_EQ) |
| 152 | .Case(S: "ge" , Value: VECC::CC_GE) |
| 153 | .Case(S: "le" , Value: VECC::CC_LE) |
| 154 | .Case(S: "num" , Value: VECC::CC_NUM) |
| 155 | .Case(S: "nan" , Value: VECC::CC_NAN) |
| 156 | .Case(S: "gtnan" , Value: VECC::CC_GNAN) |
| 157 | .Case(S: "ltnan" , Value: VECC::CC_LNAN) |
| 158 | .Case(S: "nenan" , Value: VECC::CC_NENAN) |
| 159 | .Case(S: "eqnan" , Value: VECC::CC_EQNAN) |
| 160 | .Case(S: "genan" , Value: VECC::CC_GENAN) |
| 161 | .Case(S: "lenan" , Value: VECC::CC_LENAN) |
| 162 | .Case(S: "af" , Value: VECC::CC_AF) |
| 163 | .Case(S: "at" , Value: VECC::CC_AT) |
| 164 | .Case(S: "" , Value: VECC::CC_AT) |
| 165 | .Default(Value: VECC::UNKNOWN); |
| 166 | } |
| 167 | |
| 168 | inline static bool isIntVECondCode(VECC::CondCode CC) { |
| 169 | return CC < VECC::CC_AF; |
| 170 | } |
| 171 | |
| 172 | inline static unsigned VECondCodeToVal(VECC::CondCode CC) { |
| 173 | switch (CC) { |
| 174 | case VECC::CC_IG: |
| 175 | return 1; |
| 176 | case VECC::CC_IL: |
| 177 | return 2; |
| 178 | case VECC::CC_INE: |
| 179 | return 3; |
| 180 | case VECC::CC_IEQ: |
| 181 | return 4; |
| 182 | case VECC::CC_IGE: |
| 183 | return 5; |
| 184 | case VECC::CC_ILE: |
| 185 | return 6; |
| 186 | case VECC::CC_AF: |
| 187 | return 0; |
| 188 | case VECC::CC_G: |
| 189 | return 1; |
| 190 | case VECC::CC_L: |
| 191 | return 2; |
| 192 | case VECC::CC_NE: |
| 193 | return 3; |
| 194 | case VECC::CC_EQ: |
| 195 | return 4; |
| 196 | case VECC::CC_GE: |
| 197 | return 5; |
| 198 | case VECC::CC_LE: |
| 199 | return 6; |
| 200 | case VECC::CC_NUM: |
| 201 | return 7; |
| 202 | case VECC::CC_NAN: |
| 203 | return 8; |
| 204 | case VECC::CC_GNAN: |
| 205 | return 9; |
| 206 | case VECC::CC_LNAN: |
| 207 | return 10; |
| 208 | case VECC::CC_NENAN: |
| 209 | return 11; |
| 210 | case VECC::CC_EQNAN: |
| 211 | return 12; |
| 212 | case VECC::CC_GENAN: |
| 213 | return 13; |
| 214 | case VECC::CC_LENAN: |
| 215 | return 14; |
| 216 | case VECC::CC_AT: |
| 217 | return 15; |
| 218 | default: |
| 219 | llvm_unreachable("Invalid cond code" ); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | inline static VECC::CondCode VEValToCondCode(unsigned Val, bool IsInteger) { |
| 224 | if (IsInteger) { |
| 225 | switch (Val) { |
| 226 | case 0: |
| 227 | return VECC::CC_AF; |
| 228 | case 1: |
| 229 | return VECC::CC_IG; |
| 230 | case 2: |
| 231 | return VECC::CC_IL; |
| 232 | case 3: |
| 233 | return VECC::CC_INE; |
| 234 | case 4: |
| 235 | return VECC::CC_IEQ; |
| 236 | case 5: |
| 237 | return VECC::CC_IGE; |
| 238 | case 6: |
| 239 | return VECC::CC_ILE; |
| 240 | case 15: |
| 241 | return VECC::CC_AT; |
| 242 | } |
| 243 | } else { |
| 244 | switch (Val) { |
| 245 | case 0: |
| 246 | return VECC::CC_AF; |
| 247 | case 1: |
| 248 | return VECC::CC_G; |
| 249 | case 2: |
| 250 | return VECC::CC_L; |
| 251 | case 3: |
| 252 | return VECC::CC_NE; |
| 253 | case 4: |
| 254 | return VECC::CC_EQ; |
| 255 | case 5: |
| 256 | return VECC::CC_GE; |
| 257 | case 6: |
| 258 | return VECC::CC_LE; |
| 259 | case 7: |
| 260 | return VECC::CC_NUM; |
| 261 | case 8: |
| 262 | return VECC::CC_NAN; |
| 263 | case 9: |
| 264 | return VECC::CC_GNAN; |
| 265 | case 10: |
| 266 | return VECC::CC_LNAN; |
| 267 | case 11: |
| 268 | return VECC::CC_NENAN; |
| 269 | case 12: |
| 270 | return VECC::CC_EQNAN; |
| 271 | case 13: |
| 272 | return VECC::CC_GENAN; |
| 273 | case 14: |
| 274 | return VECC::CC_LENAN; |
| 275 | case 15: |
| 276 | return VECC::CC_AT; |
| 277 | } |
| 278 | } |
| 279 | llvm_unreachable("Invalid cond code" ); |
| 280 | } |
| 281 | |
| 282 | inline static const char *VERDToString(VERD::RoundingMode R) { |
| 283 | switch (R) { |
| 284 | case VERD::RD_NONE: |
| 285 | return "" ; |
| 286 | case VERD::RD_RZ: |
| 287 | return ".rz" ; |
| 288 | case VERD::RD_RP: |
| 289 | return ".rp" ; |
| 290 | case VERD::RD_RM: |
| 291 | return ".rm" ; |
| 292 | case VERD::RD_RN: |
| 293 | return ".rn" ; |
| 294 | case VERD::RD_RA: |
| 295 | return ".ra" ; |
| 296 | default: |
| 297 | llvm_unreachable("Invalid branch predicate" ); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | inline static VERD::RoundingMode stringToVERD(StringRef S) { |
| 302 | return StringSwitch<VERD::RoundingMode>(S) |
| 303 | .Case(S: "" , Value: VERD::RD_NONE) |
| 304 | .Case(S: ".rz" , Value: VERD::RD_RZ) |
| 305 | .Case(S: ".rp" , Value: VERD::RD_RP) |
| 306 | .Case(S: ".rm" , Value: VERD::RD_RM) |
| 307 | .Case(S: ".rn" , Value: VERD::RD_RN) |
| 308 | .Case(S: ".ra" , Value: VERD::RD_RA) |
| 309 | .Default(Value: VERD::UNKNOWN); |
| 310 | } |
| 311 | |
| 312 | inline static unsigned VERDToVal(VERD::RoundingMode R) { |
| 313 | switch (R) { |
| 314 | case VERD::RD_NONE: |
| 315 | case VERD::RD_RZ: |
| 316 | case VERD::RD_RP: |
| 317 | case VERD::RD_RM: |
| 318 | case VERD::RD_RN: |
| 319 | case VERD::RD_RA: |
| 320 | return static_cast<unsigned>(R); |
| 321 | default: |
| 322 | break; |
| 323 | } |
| 324 | llvm_unreachable("Invalid branch predicates" ); |
| 325 | } |
| 326 | |
| 327 | inline static VERD::RoundingMode VEValToRD(unsigned Val) { |
| 328 | switch (Val) { |
| 329 | case static_cast<unsigned>(VERD::RD_NONE): |
| 330 | return VERD::RD_NONE; |
| 331 | case static_cast<unsigned>(VERD::RD_RZ): |
| 332 | return VERD::RD_RZ; |
| 333 | case static_cast<unsigned>(VERD::RD_RP): |
| 334 | return VERD::RD_RP; |
| 335 | case static_cast<unsigned>(VERD::RD_RM): |
| 336 | return VERD::RD_RM; |
| 337 | case static_cast<unsigned>(VERD::RD_RN): |
| 338 | return VERD::RD_RN; |
| 339 | case static_cast<unsigned>(VERD::RD_RA): |
| 340 | return VERD::RD_RA; |
| 341 | default: |
| 342 | break; |
| 343 | } |
| 344 | llvm_unreachable("Invalid branch predicates" ); |
| 345 | } |
| 346 | |
| 347 | // MImm - Special immediate value of sequential bit stream of 0 or 1. |
| 348 | // See VEInstrInfo.td for details. |
| 349 | inline static bool isMImmVal(uint64_t Val) { |
| 350 | if (Val == 0) { |
| 351 | // (0)1 is 0 |
| 352 | return true; |
| 353 | } |
| 354 | if (isMask_64(Value: Val)) { |
| 355 | // (m)0 patterns |
| 356 | return true; |
| 357 | } |
| 358 | // (m)1 patterns |
| 359 | return (Val & (UINT64_C(1) << 63)) && isShiftedMask_64(Value: Val); |
| 360 | } |
| 361 | |
| 362 | inline static bool isMImm32Val(uint32_t Val) { |
| 363 | if (Val == 0) { |
| 364 | // (0)1 is 0 |
| 365 | return true; |
| 366 | } |
| 367 | if (isMask_32(Value: Val)) { |
| 368 | // (m)0 patterns |
| 369 | return true; |
| 370 | } |
| 371 | // (m)1 patterns |
| 372 | return (Val & (UINT32_C(1) << 31)) && isShiftedMask_32(Value: Val); |
| 373 | } |
| 374 | |
| 375 | /// val2MImm - Convert an integer immediate value to target MImm immediate. |
| 376 | inline static uint64_t val2MImm(uint64_t Val) { |
| 377 | if (Val == 0) |
| 378 | return 0; // (0)1 |
| 379 | if (Val & (UINT64_C(1) << 63)) |
| 380 | return llvm::countl_one(Value: Val); // (m)1 |
| 381 | return llvm::countl_zero(Val) | 0x40; // (m)0 |
| 382 | } |
| 383 | |
| 384 | /// mimm2Val - Convert a target MImm immediate to an integer immediate value. |
| 385 | inline static uint64_t mimm2Val(uint64_t Val) { |
| 386 | if (Val == 0) |
| 387 | return 0; // (0)1 |
| 388 | if ((Val & 0x40) == 0) |
| 389 | return (uint64_t)((INT64_C(1) << 63) >> (Val & 0x3f)); // (m)1 |
| 390 | return ((uint64_t)INT64_C(-1) >> (Val & 0x3f)); // (m)0 |
| 391 | } |
| 392 | |
| 393 | inline unsigned M0(unsigned Val) { return Val + 64; } |
| 394 | inline unsigned M1(unsigned Val) { return Val; } |
| 395 | |
| 396 | static const unsigned StandardVectorWidth = 256; |
| 397 | static const unsigned PackedVectorWidth = 512; |
| 398 | |
| 399 | } // namespace llvm |
| 400 | #endif |
| 401 | |