1 //===- SveEmitter.cpp - Generate arm_sve.h for use with clang -*- 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 tablegen backend is responsible for emitting arm_sve.h, which includes 10 // a declaration and definition of each function specified by the ARM C/C++ 11 // Language Extensions (ACLE). 12 // 13 // For details, visit: 14 // https://developer.arm.com/architectures/system-architectures/software-standards/acle 15 // 16 // Each SVE instruction is implemented in terms of 1 or more functions which 17 // are suffixed with the element type of the input vectors. Functions may be 18 // implemented in terms of generic vector operations such as +, *, -, etc. or 19 // by calling a __builtin_-prefixed function which will be handled by clang's 20 // CodeGen library. 21 // 22 // See also the documentation in include/clang/Basic/arm_sve.td. 23 // 24 //===----------------------------------------------------------------------===// 25 26 #include "llvm/ADT/STLExtras.h" 27 #include "llvm/ADT/StringMap.h" 28 #include "llvm/ADT/ArrayRef.h" 29 #include "llvm/ADT/StringExtras.h" 30 #include "llvm/TableGen/Record.h" 31 #include "llvm/TableGen/Error.h" 32 #include <string> 33 #include <sstream> 34 #include <set> 35 #include <cctype> 36 #include <tuple> 37 38 using namespace llvm; 39 40 enum ClassKind { 41 ClassNone, 42 ClassS, // signed/unsigned, e.g., "_s8", "_u8" suffix 43 ClassG, // Overloaded name without type suffix 44 }; 45 46 using TypeSpec = std::string; 47 48 namespace { 49 50 class ImmCheck { 51 unsigned Arg; 52 unsigned Kind; 53 unsigned ElementSizeInBits; 54 55 public: 56 ImmCheck(unsigned Arg, unsigned Kind, unsigned ElementSizeInBits = 0) 57 : Arg(Arg), Kind(Kind), ElementSizeInBits(ElementSizeInBits) {} 58 ImmCheck(const ImmCheck &Other) = default; 59 ~ImmCheck() = default; 60 61 unsigned getArg() const { return Arg; } 62 unsigned getKind() const { return Kind; } 63 unsigned getElementSizeInBits() const { return ElementSizeInBits; } 64 }; 65 66 class SVEType { 67 TypeSpec TS; 68 bool Float, Signed, Immediate, Void, Constant, Pointer; 69 bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp; 70 unsigned Bitwidth, ElementBitwidth, NumVectors; 71 72 public: 73 SVEType() : SVEType(TypeSpec(), 'v') {} 74 75 SVEType(TypeSpec TS, char CharMod) 76 : TS(TS), Float(false), Signed(true), Immediate(false), Void(false), 77 Constant(false), Pointer(false), DefaultType(false), IsScalable(true), 78 Predicate(false), PredicatePattern(false), PrefetchOp(false), 79 Bitwidth(128), ElementBitwidth(~0U), NumVectors(1) { 80 if (!TS.empty()) 81 applyTypespec(); 82 applyModifier(CharMod); 83 } 84 85 bool isPointer() const { return Pointer; } 86 bool isVoidPointer() const { return Pointer && Void; } 87 bool isSigned() const { return Signed; } 88 bool isImmediate() const { return Immediate; } 89 bool isScalar() const { return NumVectors == 0; } 90 bool isVector() const { return NumVectors > 0; } 91 bool isScalableVector() const { return isVector() && IsScalable; } 92 bool isChar() const { return ElementBitwidth == 8; } 93 bool isVoid() const { return Void & !Pointer; } 94 bool isDefault() const { return DefaultType; } 95 bool isFloat() const { return Float; } 96 bool isInteger() const { return !Float && !Predicate; } 97 bool isScalarPredicate() const { 98 return !Float && Predicate && NumVectors == 0; 99 } 100 bool isPredicateVector() const { return Predicate; } 101 bool isPredicatePattern() const { return PredicatePattern; } 102 bool isPrefetchOp() const { return PrefetchOp; } 103 bool isConstant() const { return Constant; } 104 unsigned getElementSizeInBits() const { return ElementBitwidth; } 105 unsigned getNumVectors() const { return NumVectors; } 106 107 unsigned getNumElements() const { 108 assert(ElementBitwidth != ~0U); 109 return Bitwidth / ElementBitwidth; 110 } 111 unsigned getSizeInBits() const { 112 return Bitwidth; 113 } 114 115 /// Return the string representation of a type, which is an encoded 116 /// string for passing to the BUILTIN() macro in Builtins.def. 117 std::string builtin_str() const; 118 119 /// Return the C/C++ string representation of a type for use in the 120 /// arm_sve.h header file. 121 std::string str() const; 122 123 private: 124 /// Creates the type based on the typespec string in TS. 125 void applyTypespec(); 126 127 /// Applies a prototype modifier to the type. 128 void applyModifier(char Mod); 129 }; 130 131 132 class SVEEmitter; 133 134 /// The main grunt class. This represents an instantiation of an intrinsic with 135 /// a particular typespec and prototype. 136 class Intrinsic { 137 /// The unmangled name. 138 std::string Name; 139 140 /// The name of the corresponding LLVM IR intrinsic. 141 std::string LLVMName; 142 143 /// Intrinsic prototype. 144 std::string Proto; 145 146 /// The base type spec for this intrinsic. 147 TypeSpec BaseTypeSpec; 148 149 /// The base class kind. Most intrinsics use ClassS, which has full type 150 /// info for integers (_s32/_u32), or ClassG which is used for overloaded 151 /// intrinsics. 152 ClassKind Class; 153 154 /// The architectural #ifdef guard. 155 std::string Guard; 156 157 // The merge suffix such as _m, _x or _z. 158 std::string MergeSuffix; 159 160 /// The types of return value [0] and parameters [1..]. 161 std::vector<SVEType> Types; 162 163 /// The "base type", which is VarType('d', BaseTypeSpec). 164 SVEType BaseType; 165 166 uint64_t Flags; 167 168 SmallVector<ImmCheck, 2> ImmChecks; 169 170 public: 171 Intrinsic(StringRef Name, StringRef Proto, uint64_t MergeTy, 172 StringRef MergeSuffix, uint64_t MemoryElementTy, StringRef LLVMName, 173 uint64_t Flags, ArrayRef<ImmCheck> ImmChecks, TypeSpec BT, 174 ClassKind Class, SVEEmitter &Emitter, StringRef Guard); 175 176 ~Intrinsic()=default; 177 178 std::string getName() const { return Name; } 179 std::string getLLVMName() const { return LLVMName; } 180 std::string getProto() const { return Proto; } 181 TypeSpec getBaseTypeSpec() const { return BaseTypeSpec; } 182 SVEType getBaseType() const { return BaseType; } 183 184 StringRef getGuard() const { return Guard; } 185 ClassKind getClassKind() const { return Class; } 186 187 SVEType getReturnType() const { return Types[0]; } 188 ArrayRef<SVEType> getTypes() const { return Types; } 189 SVEType getParamType(unsigned I) const { return Types[I + 1]; } 190 unsigned getNumParams() const { return Proto.size() - 1; } 191 192 uint64_t getFlags() const { return Flags; } 193 bool isFlagSet(uint64_t Flag) const { return Flags & Flag;} 194 195 ArrayRef<ImmCheck> getImmChecks() const { return ImmChecks; } 196 197 /// Return the type string for a BUILTIN() macro in Builtins.def. 198 std::string getBuiltinTypeStr(); 199 200 /// Return the name, mangled with type information. The name is mangled for 201 /// ClassS, so will add type suffixes such as _u32/_s32. 202 std::string getMangledName() const { return mangleName(ClassS); } 203 204 /// Returns true if the intrinsic is overloaded, in that it should also generate 205 /// a short form without the type-specifiers, e.g. 'svld1(..)' instead of 206 /// 'svld1_u32(..)'. 207 static bool isOverloadedIntrinsic(StringRef Name) { 208 auto BrOpen = Name.find("["); 209 auto BrClose = Name.find(']'); 210 return BrOpen != std::string::npos && BrClose != std::string::npos; 211 } 212 213 /// Return true if the intrinsic takes a splat operand. 214 bool hasSplat() const { 215 // These prototype modifiers are described in arm_sve.td. 216 return Proto.find_first_of("ajfrKLR@") != std::string::npos; 217 } 218 219 /// Return the parameter index of the splat operand. 220 unsigned getSplatIdx() const { 221 // These prototype modifiers are described in arm_sve.td. 222 auto Idx = Proto.find_first_of("ajfrKLR@"); 223 assert(Idx != std::string::npos && Idx > 0 && 224 "Prototype has no splat operand"); 225 return Idx - 1; 226 } 227 228 /// Emits the intrinsic declaration to the ostream. 229 void emitIntrinsic(raw_ostream &OS) const; 230 231 private: 232 std::string getMergeSuffix() const { return MergeSuffix; } 233 std::string mangleName(ClassKind LocalCK) const; 234 std::string replaceTemplatedArgs(std::string Name, TypeSpec TS, 235 std::string Proto) const; 236 }; 237 238 class SVEEmitter { 239 private: 240 // The reinterpret builtins are generated separately because they 241 // need the cross product of all types (121 functions in total), 242 // which is inconvenient to specify in the arm_sve.td file or 243 // generate in CGBuiltin.cpp. 244 struct ReinterpretTypeInfo { 245 const char *Suffix; 246 const char *Type; 247 const char *BuiltinType; 248 }; 249 SmallVector<ReinterpretTypeInfo, 11> Reinterprets = { 250 {"s8", "svint8_t", "q16Sc"}, {"s16", "svint16_t", "q8Ss"}, 251 {"s32", "svint32_t", "q4Si"}, {"s64", "svint64_t", "q2SWi"}, 252 {"u8", "svuint8_t", "q16Uc"}, {"u16", "svuint16_t", "q8Us"}, 253 {"u32", "svuint32_t", "q4Ui"}, {"u64", "svuint64_t", "q2UWi"}, 254 {"f16", "svfloat16_t", "q8h"}, {"f32", "svfloat32_t", "q4f"}, 255 {"f64", "svfloat64_t", "q2d"}}; 256 257 RecordKeeper &Records; 258 llvm::StringMap<uint64_t> EltTypes; 259 llvm::StringMap<uint64_t> MemEltTypes; 260 llvm::StringMap<uint64_t> FlagTypes; 261 llvm::StringMap<uint64_t> MergeTypes; 262 llvm::StringMap<uint64_t> ImmCheckTypes; 263 264 public: 265 SVEEmitter(RecordKeeper &R) : Records(R) { 266 for (auto *RV : Records.getAllDerivedDefinitions("EltType")) 267 EltTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value"); 268 for (auto *RV : Records.getAllDerivedDefinitions("MemEltType")) 269 MemEltTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value"); 270 for (auto *RV : Records.getAllDerivedDefinitions("FlagType")) 271 FlagTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value"); 272 for (auto *RV : Records.getAllDerivedDefinitions("MergeType")) 273 MergeTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value"); 274 for (auto *RV : Records.getAllDerivedDefinitions("ImmCheckType")) 275 ImmCheckTypes[RV->getNameInitAsString()] = RV->getValueAsInt("Value"); 276 } 277 278 /// Returns the enum value for the immcheck type 279 unsigned getEnumValueForImmCheck(StringRef C) const { 280 auto It = ImmCheckTypes.find(C); 281 if (It != ImmCheckTypes.end()) 282 return It->getValue(); 283 llvm_unreachable("Unsupported imm check"); 284 } 285 286 /// Returns the enum value for the flag type 287 uint64_t getEnumValueForFlag(StringRef C) const { 288 auto Res = FlagTypes.find(C); 289 if (Res != FlagTypes.end()) 290 return Res->getValue(); 291 llvm_unreachable("Unsupported flag"); 292 } 293 294 // Returns the SVETypeFlags for a given value and mask. 295 uint64_t encodeFlag(uint64_t V, StringRef MaskName) const { 296 auto It = FlagTypes.find(MaskName); 297 if (It != FlagTypes.end()) { 298 uint64_t Mask = It->getValue(); 299 unsigned Shift = llvm::countTrailingZeros(Mask); 300 return (V << Shift) & Mask; 301 } 302 llvm_unreachable("Unsupported flag"); 303 } 304 305 // Returns the SVETypeFlags for the given element type. 306 uint64_t encodeEltType(StringRef EltName) { 307 auto It = EltTypes.find(EltName); 308 if (It != EltTypes.end()) 309 return encodeFlag(It->getValue(), "EltTypeMask"); 310 llvm_unreachable("Unsupported EltType"); 311 } 312 313 // Returns the SVETypeFlags for the given memory element type. 314 uint64_t encodeMemoryElementType(uint64_t MT) { 315 return encodeFlag(MT, "MemEltTypeMask"); 316 } 317 318 // Returns the SVETypeFlags for the given merge type. 319 uint64_t encodeMergeType(uint64_t MT) { 320 return encodeFlag(MT, "MergeTypeMask"); 321 } 322 323 // Returns the SVETypeFlags for the given splat operand. 324 unsigned encodeSplatOperand(unsigned SplatIdx) { 325 assert(SplatIdx < 7 && "SplatIdx out of encodable range"); 326 return encodeFlag(SplatIdx + 1, "SplatOperandMask"); 327 } 328 329 // Returns the SVETypeFlags value for the given SVEType. 330 uint64_t encodeTypeFlags(const SVEType &T); 331 332 /// Emit arm_sve.h. 333 void createHeader(raw_ostream &o); 334 335 /// Emit all the __builtin prototypes and code needed by Sema. 336 void createBuiltins(raw_ostream &o); 337 338 /// Emit all the information needed to map builtin -> LLVM IR intrinsic. 339 void createCodeGenMap(raw_ostream &o); 340 341 /// Emit all the range checks for the immediates. 342 void createRangeChecks(raw_ostream &o); 343 344 /// Create the SVETypeFlags used in CGBuiltins 345 void createTypeFlags(raw_ostream &o); 346 347 /// Create intrinsic and add it to \p Out 348 void createIntrinsic(Record *R, SmallVectorImpl<std::unique_ptr<Intrinsic>> &Out); 349 }; 350 351 } // end anonymous namespace 352 353 354 //===----------------------------------------------------------------------===// 355 // Type implementation 356 //===----------------------------------------------------------------------===// 357 358 std::string SVEType::builtin_str() const { 359 std::string S; 360 if (isVoid()) 361 return "v"; 362 363 if (isVoidPointer()) 364 S += "v"; 365 else if (!Float) 366 switch (ElementBitwidth) { 367 case 1: S += "b"; break; 368 case 8: S += "c"; break; 369 case 16: S += "s"; break; 370 case 32: S += "i"; break; 371 case 64: S += "Wi"; break; 372 case 128: S += "LLLi"; break; 373 default: llvm_unreachable("Unhandled case!"); 374 } 375 else 376 switch (ElementBitwidth) { 377 case 16: S += "h"; break; 378 case 32: S += "f"; break; 379 case 64: S += "d"; break; 380 default: llvm_unreachable("Unhandled case!"); 381 } 382 383 if (!isFloat()) { 384 if ((isChar() || isPointer()) && !isVoidPointer()) { 385 // Make chars and typed pointers explicitly signed. 386 if (Signed) 387 S = "S" + S; 388 else if (!Signed) 389 S = "U" + S; 390 } else if (!isVoidPointer() && !Signed) { 391 S = "U" + S; 392 } 393 } 394 395 // Constant indices are "int", but have the "constant expression" modifier. 396 if (isImmediate()) { 397 assert(!isFloat() && "fp immediates are not supported"); 398 S = "I" + S; 399 } 400 401 if (isScalar()) { 402 if (Constant) S += "C"; 403 if (Pointer) S += "*"; 404 return S; 405 } 406 407 assert(isScalableVector() && "Unsupported type"); 408 return "q" + utostr(getNumElements() * NumVectors) + S; 409 } 410 411 std::string SVEType::str() const { 412 if (isPredicatePattern()) 413 return "sv_pattern"; 414 415 if (isPrefetchOp()) 416 return "sv_prfop"; 417 418 std::string S; 419 if (Void) 420 S += "void"; 421 else { 422 if (isScalableVector()) 423 S += "sv"; 424 if (!Signed && !Float) 425 S += "u"; 426 427 if (Float) 428 S += "float"; 429 else if (isScalarPredicate() || isPredicateVector()) 430 S += "bool"; 431 else 432 S += "int"; 433 434 if (!isScalarPredicate() && !isPredicateVector()) 435 S += utostr(ElementBitwidth); 436 if (!isScalableVector() && isVector()) 437 S += "x" + utostr(getNumElements()); 438 if (NumVectors > 1) 439 S += "x" + utostr(NumVectors); 440 if (!isScalarPredicate()) 441 S += "_t"; 442 } 443 444 if (Constant) 445 S += " const"; 446 if (Pointer) 447 S += " *"; 448 449 return S; 450 } 451 void SVEType::applyTypespec() { 452 for (char I : TS) { 453 switch (I) { 454 case 'P': 455 Predicate = true; 456 break; 457 case 'U': 458 Signed = false; 459 break; 460 case 'c': 461 ElementBitwidth = 8; 462 break; 463 case 's': 464 ElementBitwidth = 16; 465 break; 466 case 'i': 467 ElementBitwidth = 32; 468 break; 469 case 'l': 470 ElementBitwidth = 64; 471 break; 472 case 'h': 473 Float = true; 474 ElementBitwidth = 16; 475 break; 476 case 'f': 477 Float = true; 478 ElementBitwidth = 32; 479 break; 480 case 'd': 481 Float = true; 482 ElementBitwidth = 64; 483 break; 484 default: 485 llvm_unreachable("Unhandled type code!"); 486 } 487 } 488 assert(ElementBitwidth != ~0U && "Bad element bitwidth!"); 489 } 490 491 void SVEType::applyModifier(char Mod) { 492 switch (Mod) { 493 case 'v': 494 Void = true; 495 break; 496 case 'd': 497 DefaultType = true; 498 break; 499 case 'c': 500 Constant = true; 501 LLVM_FALLTHROUGH; 502 case 'p': 503 Pointer = true; 504 Bitwidth = ElementBitwidth; 505 NumVectors = 0; 506 break; 507 case 'e': 508 Signed = false; 509 ElementBitwidth /= 2; 510 break; 511 case 'h': 512 ElementBitwidth /= 2; 513 break; 514 case 'q': 515 ElementBitwidth /= 4; 516 break; 517 case 'b': 518 Signed = false; 519 Float = false; 520 ElementBitwidth /= 4; 521 break; 522 case 'o': 523 ElementBitwidth *= 4; 524 break; 525 case 'P': 526 Signed = true; 527 Float = false; 528 Predicate = true; 529 Bitwidth = 16; 530 ElementBitwidth = 1; 531 break; 532 case 's': 533 case 'a': 534 Bitwidth = ElementBitwidth; 535 NumVectors = 0; 536 break; 537 case 'R': 538 ElementBitwidth /= 2; 539 NumVectors = 0; 540 break; 541 case 'r': 542 ElementBitwidth /= 4; 543 NumVectors = 0; 544 break; 545 case '@': 546 Signed = false; 547 Float = false; 548 ElementBitwidth /= 4; 549 NumVectors = 0; 550 break; 551 case 'K': 552 Signed = true; 553 Float = false; 554 Bitwidth = ElementBitwidth; 555 NumVectors = 0; 556 break; 557 case 'L': 558 Signed = false; 559 Float = false; 560 Bitwidth = ElementBitwidth; 561 NumVectors = 0; 562 break; 563 case 'u': 564 Predicate = false; 565 Signed = false; 566 Float = false; 567 break; 568 case 'x': 569 Predicate = false; 570 Signed = true; 571 Float = false; 572 break; 573 case 'i': 574 Predicate = false; 575 Float = false; 576 ElementBitwidth = Bitwidth = 64; 577 NumVectors = 0; 578 Signed = false; 579 Immediate = true; 580 break; 581 case 'I': 582 Predicate = false; 583 Float = false; 584 ElementBitwidth = Bitwidth = 32; 585 NumVectors = 0; 586 Signed = true; 587 Immediate = true; 588 PredicatePattern = true; 589 break; 590 case 'J': 591 Predicate = false; 592 Float = false; 593 ElementBitwidth = Bitwidth = 32; 594 NumVectors = 0; 595 Signed = true; 596 Immediate = true; 597 PrefetchOp = true; 598 break; 599 case 'k': 600 Predicate = false; 601 Signed = true; 602 Float = false; 603 ElementBitwidth = Bitwidth = 32; 604 NumVectors = 0; 605 break; 606 case 'l': 607 Predicate = false; 608 Signed = true; 609 Float = false; 610 ElementBitwidth = Bitwidth = 64; 611 NumVectors = 0; 612 break; 613 case 'm': 614 Predicate = false; 615 Signed = false; 616 Float = false; 617 ElementBitwidth = Bitwidth = 32; 618 NumVectors = 0; 619 break; 620 case 'n': 621 Predicate = false; 622 Signed = false; 623 Float = false; 624 ElementBitwidth = Bitwidth = 64; 625 NumVectors = 0; 626 break; 627 case 'w': 628 ElementBitwidth = 64; 629 break; 630 case 'j': 631 ElementBitwidth = Bitwidth = 64; 632 NumVectors = 0; 633 break; 634 case 'f': 635 Signed = false; 636 ElementBitwidth = Bitwidth = 64; 637 NumVectors = 0; 638 break; 639 case 'g': 640 Signed = false; 641 Float = false; 642 ElementBitwidth = 64; 643 break; 644 case 't': 645 Signed = true; 646 Float = false; 647 ElementBitwidth = 32; 648 break; 649 case 'z': 650 Signed = false; 651 Float = false; 652 ElementBitwidth = 32; 653 break; 654 case 'O': 655 Predicate = false; 656 Float = true; 657 ElementBitwidth = 16; 658 break; 659 case 'M': 660 Predicate = false; 661 Float = true; 662 ElementBitwidth = 32; 663 break; 664 case 'N': 665 Predicate = false; 666 Float = true; 667 ElementBitwidth = 64; 668 break; 669 case 'Q': 670 Constant = true; 671 Pointer = true; 672 Void = true; 673 NumVectors = 0; 674 break; 675 case 'S': 676 Constant = true; 677 Pointer = true; 678 ElementBitwidth = Bitwidth = 8; 679 NumVectors = 0; 680 Signed = true; 681 break; 682 case 'W': 683 Constant = true; 684 Pointer = true; 685 ElementBitwidth = Bitwidth = 8; 686 NumVectors = 0; 687 Signed = false; 688 break; 689 case 'T': 690 Constant = true; 691 Pointer = true; 692 ElementBitwidth = Bitwidth = 16; 693 NumVectors = 0; 694 Signed = true; 695 break; 696 case 'X': 697 Constant = true; 698 Pointer = true; 699 ElementBitwidth = Bitwidth = 16; 700 NumVectors = 0; 701 Signed = false; 702 break; 703 case 'Y': 704 Constant = true; 705 Pointer = true; 706 ElementBitwidth = Bitwidth = 32; 707 NumVectors = 0; 708 Signed = false; 709 break; 710 case 'U': 711 Constant = true; 712 Pointer = true; 713 ElementBitwidth = Bitwidth = 32; 714 NumVectors = 0; 715 Signed = true; 716 break; 717 case 'A': 718 Pointer = true; 719 ElementBitwidth = Bitwidth = 8; 720 NumVectors = 0; 721 Signed = true; 722 break; 723 case 'B': 724 Pointer = true; 725 ElementBitwidth = Bitwidth = 16; 726 NumVectors = 0; 727 Signed = true; 728 break; 729 case 'C': 730 Pointer = true; 731 ElementBitwidth = Bitwidth = 32; 732 NumVectors = 0; 733 Signed = true; 734 break; 735 case 'D': 736 Pointer = true; 737 ElementBitwidth = Bitwidth = 64; 738 NumVectors = 0; 739 Signed = true; 740 break; 741 case 'E': 742 Pointer = true; 743 ElementBitwidth = Bitwidth = 8; 744 NumVectors = 0; 745 Signed = false; 746 break; 747 case 'F': 748 Pointer = true; 749 ElementBitwidth = Bitwidth = 16; 750 NumVectors = 0; 751 Signed = false; 752 break; 753 case 'G': 754 Pointer = true; 755 ElementBitwidth = Bitwidth = 32; 756 NumVectors = 0; 757 Signed = false; 758 break; 759 default: 760 llvm_unreachable("Unhandled character!"); 761 } 762 } 763 764 765 //===----------------------------------------------------------------------===// 766 // Intrinsic implementation 767 //===----------------------------------------------------------------------===// 768 769 Intrinsic::Intrinsic(StringRef Name, StringRef Proto, uint64_t MergeTy, 770 StringRef MergeSuffix, uint64_t MemoryElementTy, 771 StringRef LLVMName, uint64_t Flags, 772 ArrayRef<ImmCheck> Checks, TypeSpec BT, ClassKind Class, 773 SVEEmitter &Emitter, StringRef Guard) 774 : Name(Name.str()), LLVMName(LLVMName), Proto(Proto.str()), 775 BaseTypeSpec(BT), Class(Class), Guard(Guard.str()), 776 MergeSuffix(MergeSuffix.str()), BaseType(BT, 'd'), Flags(Flags), 777 ImmChecks(Checks.begin(), Checks.end()) { 778 779 // Types[0] is the return value. 780 for (unsigned I = 0; I < Proto.size(); ++I) { 781 SVEType T(BaseTypeSpec, Proto[I]); 782 Types.push_back(T); 783 784 // Add range checks for immediates 785 if (I > 0) { 786 if (T.isPredicatePattern()) 787 ImmChecks.emplace_back( 788 I - 1, Emitter.getEnumValueForImmCheck("ImmCheck0_31")); 789 else if (T.isPrefetchOp()) 790 ImmChecks.emplace_back( 791 I - 1, Emitter.getEnumValueForImmCheck("ImmCheck0_13")); 792 } 793 } 794 795 // Set flags based on properties 796 this->Flags |= Emitter.encodeTypeFlags(BaseType); 797 this->Flags |= Emitter.encodeMemoryElementType(MemoryElementTy); 798 this->Flags |= Emitter.encodeMergeType(MergeTy); 799 if (hasSplat()) 800 this->Flags |= Emitter.encodeSplatOperand(getSplatIdx()); 801 } 802 803 std::string Intrinsic::getBuiltinTypeStr() { 804 std::string S; 805 806 SVEType RetT = getReturnType(); 807 // Since the return value must be one type, return a vector type of the 808 // appropriate width which we will bitcast. An exception is made for 809 // returning structs of 2, 3, or 4 vectors which are returned in a sret-like 810 // fashion, storing them to a pointer arg. 811 if (RetT.getNumVectors() > 1) { 812 S += "vv*"; // void result with void* first argument 813 } else 814 S += RetT.builtin_str(); 815 816 for (unsigned I = 0; I < getNumParams(); ++I) 817 S += getParamType(I).builtin_str(); 818 819 return S; 820 } 821 822 std::string Intrinsic::replaceTemplatedArgs(std::string Name, TypeSpec TS, 823 std::string Proto) const { 824 std::string Ret = Name; 825 while (Ret.find('{') != std::string::npos) { 826 size_t Pos = Ret.find('{'); 827 size_t End = Ret.find('}'); 828 unsigned NumChars = End - Pos + 1; 829 assert(NumChars == 3 && "Unexpected template argument"); 830 831 SVEType T; 832 char C = Ret[Pos+1]; 833 switch(C) { 834 default: 835 llvm_unreachable("Unknown predication specifier"); 836 case 'd': 837 T = SVEType(TS, 'd'); 838 break; 839 case '0': 840 case '1': 841 case '2': 842 case '3': 843 T = SVEType(TS, Proto[C - '0']); 844 break; 845 } 846 847 // Replace templated arg with the right suffix (e.g. u32) 848 std::string TypeCode; 849 if (T.isInteger()) 850 TypeCode = T.isSigned() ? 's' : 'u'; 851 else if (T.isPredicateVector()) 852 TypeCode = 'b'; 853 else 854 TypeCode = 'f'; 855 Ret.replace(Pos, NumChars, TypeCode + utostr(T.getElementSizeInBits())); 856 } 857 858 return Ret; 859 } 860 861 std::string Intrinsic::mangleName(ClassKind LocalCK) const { 862 std::string S = getName(); 863 864 if (LocalCK == ClassG) { 865 // Remove the square brackets and everything in between. 866 while (S.find("[") != std::string::npos) { 867 auto Start = S.find("["); 868 auto End = S.find(']'); 869 S.erase(Start, (End-Start)+1); 870 } 871 } else { 872 // Remove the square brackets. 873 while (S.find("[") != std::string::npos) { 874 auto BrPos = S.find('['); 875 if (BrPos != std::string::npos) 876 S.erase(BrPos, 1); 877 BrPos = S.find(']'); 878 if (BrPos != std::string::npos) 879 S.erase(BrPos, 1); 880 } 881 } 882 883 // Replace all {d} like expressions with e.g. 'u32' 884 return replaceTemplatedArgs(S, getBaseTypeSpec(), getProto()) + 885 getMergeSuffix(); 886 } 887 888 void Intrinsic::emitIntrinsic(raw_ostream &OS) const { 889 // Use the preprocessor to 890 if (getClassKind() != ClassG || getProto().size() <= 1) { 891 OS << "#define " << mangleName(getClassKind()) 892 << "(...) __builtin_sve_" << mangleName(ClassS) 893 << "(__VA_ARGS__)\n"; 894 } else { 895 std::string FullName = mangleName(ClassS); 896 std::string ProtoName = mangleName(ClassG); 897 898 OS << "__aio __attribute__((__clang_arm_builtin_alias(" 899 << "__builtin_sve_" << FullName << ")))\n"; 900 901 OS << getTypes()[0].str() << " " << ProtoName << "("; 902 for (unsigned I = 0; I < getTypes().size() - 1; ++I) { 903 if (I != 0) 904 OS << ", "; 905 OS << getTypes()[I + 1].str(); 906 } 907 OS << ");\n"; 908 } 909 } 910 911 //===----------------------------------------------------------------------===// 912 // SVEEmitter implementation 913 //===----------------------------------------------------------------------===// 914 uint64_t SVEEmitter::encodeTypeFlags(const SVEType &T) { 915 if (T.isFloat()) { 916 switch (T.getElementSizeInBits()) { 917 case 16: 918 return encodeEltType("EltTyFloat16"); 919 case 32: 920 return encodeEltType("EltTyFloat32"); 921 case 64: 922 return encodeEltType("EltTyFloat64"); 923 default: 924 llvm_unreachable("Unhandled float element bitwidth!"); 925 } 926 } 927 928 if (T.isPredicateVector()) { 929 switch (T.getElementSizeInBits()) { 930 case 8: 931 return encodeEltType("EltTyBool8"); 932 case 16: 933 return encodeEltType("EltTyBool16"); 934 case 32: 935 return encodeEltType("EltTyBool32"); 936 case 64: 937 return encodeEltType("EltTyBool64"); 938 default: 939 llvm_unreachable("Unhandled predicate element bitwidth!"); 940 } 941 } 942 943 switch (T.getElementSizeInBits()) { 944 case 8: 945 return encodeEltType("EltTyInt8"); 946 case 16: 947 return encodeEltType("EltTyInt16"); 948 case 32: 949 return encodeEltType("EltTyInt32"); 950 case 64: 951 return encodeEltType("EltTyInt64"); 952 default: 953 llvm_unreachable("Unhandled integer element bitwidth!"); 954 } 955 } 956 957 void SVEEmitter::createIntrinsic( 958 Record *R, SmallVectorImpl<std::unique_ptr<Intrinsic>> &Out) { 959 StringRef Name = R->getValueAsString("Name"); 960 StringRef Proto = R->getValueAsString("Prototype"); 961 StringRef Types = R->getValueAsString("Types"); 962 StringRef Guard = R->getValueAsString("ArchGuard"); 963 StringRef LLVMName = R->getValueAsString("LLVMIntrinsic"); 964 uint64_t Merge = R->getValueAsInt("Merge"); 965 StringRef MergeSuffix = R->getValueAsString("MergeSuffix"); 966 uint64_t MemEltType = R->getValueAsInt("MemEltType"); 967 std::vector<Record*> FlagsList = R->getValueAsListOfDefs("Flags"); 968 std::vector<Record*> ImmCheckList = R->getValueAsListOfDefs("ImmChecks"); 969 970 int64_t Flags = 0; 971 for (auto FlagRec : FlagsList) 972 Flags |= FlagRec->getValueAsInt("Value"); 973 974 // Create a dummy TypeSpec for non-overloaded builtins. 975 if (Types.empty()) { 976 assert((Flags & getEnumValueForFlag("IsOverloadNone")) && 977 "Expect TypeSpec for overloaded builtin!"); 978 Types = "i"; 979 } 980 981 // Extract type specs from string 982 SmallVector<TypeSpec, 8> TypeSpecs; 983 TypeSpec Acc; 984 for (char I : Types) { 985 Acc.push_back(I); 986 if (islower(I)) { 987 TypeSpecs.push_back(TypeSpec(Acc)); 988 Acc.clear(); 989 } 990 } 991 992 // Remove duplicate type specs. 993 llvm::sort(TypeSpecs); 994 TypeSpecs.erase(std::unique(TypeSpecs.begin(), TypeSpecs.end()), 995 TypeSpecs.end()); 996 997 // Create an Intrinsic for each type spec. 998 for (auto TS : TypeSpecs) { 999 // Collate a list of range/option checks for the immediates. 1000 SmallVector<ImmCheck, 2> ImmChecks; 1001 for (auto *R : ImmCheckList) { 1002 int64_t Arg = R->getValueAsInt("Arg"); 1003 int64_t EltSizeArg = R->getValueAsInt("EltSizeArg"); 1004 int64_t Kind = R->getValueAsDef("Kind")->getValueAsInt("Value"); 1005 assert(Arg >= 0 && Kind >= 0 && "Arg and Kind must be nonnegative"); 1006 1007 unsigned ElementSizeInBits = 0; 1008 if (EltSizeArg >= 0) 1009 ElementSizeInBits = 1010 SVEType(TS, Proto[EltSizeArg + /* offset by return arg */ 1]) 1011 .getElementSizeInBits(); 1012 ImmChecks.push_back(ImmCheck(Arg, Kind, ElementSizeInBits)); 1013 } 1014 1015 Out.push_back(std::make_unique<Intrinsic>( 1016 Name, Proto, Merge, MergeSuffix, MemEltType, LLVMName, Flags, ImmChecks, 1017 TS, ClassS, *this, Guard)); 1018 1019 // Also generate the short-form (e.g. svadd_m) for the given type-spec. 1020 if (Intrinsic::isOverloadedIntrinsic(Name)) 1021 Out.push_back(std::make_unique<Intrinsic>( 1022 Name, Proto, Merge, MergeSuffix, MemEltType, LLVMName, Flags, 1023 ImmChecks, TS, ClassG, *this, Guard)); 1024 } 1025 } 1026 1027 void SVEEmitter::createHeader(raw_ostream &OS) { 1028 OS << "/*===---- arm_sve.h - ARM SVE intrinsics " 1029 "-----------------------------------===\n" 1030 " *\n" 1031 " *\n" 1032 " * Part of the LLVM Project, under the Apache License v2.0 with LLVM " 1033 "Exceptions.\n" 1034 " * See https://llvm.org/LICENSE.txt for license information.\n" 1035 " * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n" 1036 " *\n" 1037 " *===-----------------------------------------------------------------" 1038 "------===\n" 1039 " */\n\n"; 1040 1041 OS << "#ifndef __ARM_SVE_H\n"; 1042 OS << "#define __ARM_SVE_H\n\n"; 1043 1044 OS << "#if !defined(__ARM_FEATURE_SVE)\n"; 1045 OS << "#error \"SVE support not enabled\"\n"; 1046 OS << "#else\n\n"; 1047 1048 OS << "#if !defined(__LITTLE_ENDIAN__)\n"; 1049 OS << "#error \"Big endian is currently not supported for arm_sve.h\"\n"; 1050 OS << "#endif\n"; 1051 1052 OS << "#include <stdint.h>\n\n"; 1053 OS << "#ifdef __cplusplus\n"; 1054 OS << "extern \"C\" {\n"; 1055 OS << "#else\n"; 1056 OS << "#include <stdbool.h>\n"; 1057 OS << "#endif\n\n"; 1058 1059 OS << "typedef __fp16 float16_t;\n"; 1060 OS << "typedef float float32_t;\n"; 1061 OS << "typedef double float64_t;\n"; 1062 1063 OS << "typedef __SVInt8_t svint8_t;\n"; 1064 OS << "typedef __SVInt16_t svint16_t;\n"; 1065 OS << "typedef __SVInt32_t svint32_t;\n"; 1066 OS << "typedef __SVInt64_t svint64_t;\n"; 1067 OS << "typedef __SVUint8_t svuint8_t;\n"; 1068 OS << "typedef __SVUint16_t svuint16_t;\n"; 1069 OS << "typedef __SVUint32_t svuint32_t;\n"; 1070 OS << "typedef __SVUint64_t svuint64_t;\n"; 1071 OS << "typedef __SVFloat16_t svfloat16_t;\n"; 1072 OS << "typedef __SVFloat32_t svfloat32_t;\n"; 1073 OS << "typedef __SVFloat64_t svfloat64_t;\n"; 1074 OS << "typedef __SVBool_t svbool_t;\n\n"; 1075 1076 OS << "typedef enum\n"; 1077 OS << "{\n"; 1078 OS << " SV_POW2 = 0,\n"; 1079 OS << " SV_VL1 = 1,\n"; 1080 OS << " SV_VL2 = 2,\n"; 1081 OS << " SV_VL3 = 3,\n"; 1082 OS << " SV_VL4 = 4,\n"; 1083 OS << " SV_VL5 = 5,\n"; 1084 OS << " SV_VL6 = 6,\n"; 1085 OS << " SV_VL7 = 7,\n"; 1086 OS << " SV_VL8 = 8,\n"; 1087 OS << " SV_VL16 = 9,\n"; 1088 OS << " SV_VL32 = 10,\n"; 1089 OS << " SV_VL64 = 11,\n"; 1090 OS << " SV_VL128 = 12,\n"; 1091 OS << " SV_VL256 = 13,\n"; 1092 OS << " SV_MUL4 = 29,\n"; 1093 OS << " SV_MUL3 = 30,\n"; 1094 OS << " SV_ALL = 31\n"; 1095 OS << "} sv_pattern;\n\n"; 1096 1097 OS << "typedef enum\n"; 1098 OS << "{\n"; 1099 OS << " SV_PLDL1KEEP = 0,\n"; 1100 OS << " SV_PLDL1STRM = 1,\n"; 1101 OS << " SV_PLDL2KEEP = 2,\n"; 1102 OS << " SV_PLDL2STRM = 3,\n"; 1103 OS << " SV_PLDL3KEEP = 4,\n"; 1104 OS << " SV_PLDL3STRM = 5,\n"; 1105 OS << " SV_PSTL1KEEP = 8,\n"; 1106 OS << " SV_PSTL1STRM = 9,\n"; 1107 OS << " SV_PSTL2KEEP = 10,\n"; 1108 OS << " SV_PSTL2STRM = 11,\n"; 1109 OS << " SV_PSTL3KEEP = 12,\n"; 1110 OS << " SV_PSTL3STRM = 13\n"; 1111 OS << "} sv_prfop;\n\n"; 1112 1113 OS << "/* Function attributes */\n"; 1114 OS << "#define __aio static inline __attribute__((__always_inline__, " 1115 "__nodebug__, __overloadable__))\n\n"; 1116 1117 // Add reinterpret functions. 1118 for (auto ShortForm : { false, true } ) 1119 for (const ReinterpretTypeInfo &From : Reinterprets) 1120 for (const ReinterpretTypeInfo &To : Reinterprets) { 1121 if (ShortForm) { 1122 OS << "__aio " << From.Type << " svreinterpret_" << From.Suffix; 1123 OS << "(" << To.Type << " op) {\n"; 1124 OS << " return __builtin_sve_reinterpret_" << From.Suffix << "_" 1125 << To.Suffix << "(op);\n"; 1126 OS << "}\n\n"; 1127 } else 1128 OS << "#define svreinterpret_" << From.Suffix << "_" << To.Suffix 1129 << "(...) __builtin_sve_reinterpret_" << From.Suffix << "_" 1130 << To.Suffix << "(__VA_ARGS__)\n"; 1131 } 1132 1133 SmallVector<std::unique_ptr<Intrinsic>, 128> Defs; 1134 std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst"); 1135 for (auto *R : RV) 1136 createIntrinsic(R, Defs); 1137 1138 // Sort intrinsics in header file by following order/priority: 1139 // - Architectural guard (i.e. does it require SVE2 or SVE2_AES) 1140 // - Class (is intrinsic overloaded or not) 1141 // - Intrinsic name 1142 std::stable_sort( 1143 Defs.begin(), Defs.end(), [](const std::unique_ptr<Intrinsic> &A, 1144 const std::unique_ptr<Intrinsic> &B) { 1145 auto ToTuple = [](const std::unique_ptr<Intrinsic> &I) { 1146 return std::make_tuple(I->getGuard(), (unsigned)I->getClassKind(), I->getName()); 1147 }; 1148 return ToTuple(A) < ToTuple(B); 1149 }); 1150 1151 StringRef InGuard = ""; 1152 for (auto &I : Defs) { 1153 // Emit #endif/#if pair if needed. 1154 if (I->getGuard() != InGuard) { 1155 if (!InGuard.empty()) 1156 OS << "#endif //" << InGuard << "\n"; 1157 InGuard = I->getGuard(); 1158 if (!InGuard.empty()) 1159 OS << "\n#if " << InGuard << "\n"; 1160 } 1161 1162 // Actually emit the intrinsic declaration. 1163 I->emitIntrinsic(OS); 1164 } 1165 1166 if (!InGuard.empty()) 1167 OS << "#endif //" << InGuard << "\n"; 1168 1169 OS << "#if defined(__ARM_FEATURE_SVE2)\n"; 1170 OS << "#define svcvtnt_f16_x svcvtnt_f16_m\n"; 1171 OS << "#define svcvtnt_f16_f32_x svcvtnt_f16_f32_m\n"; 1172 OS << "#define svcvtnt_f32_x svcvtnt_f32_m\n"; 1173 OS << "#define svcvtnt_f32_f64_x svcvtnt_f32_f64_m\n\n"; 1174 1175 OS << "#define svcvtxnt_f32_x svcvtxnt_f32_m\n"; 1176 OS << "#define svcvtxnt_f32_f64_x svcvtxnt_f32_f64_m\n\n"; 1177 1178 OS << "#endif /*__ARM_FEATURE_SVE2 */\n\n"; 1179 1180 OS << "#ifdef __cplusplus\n"; 1181 OS << "} // extern \"C\"\n"; 1182 OS << "#endif\n\n"; 1183 OS << "#endif /*__ARM_FEATURE_SVE */\n\n"; 1184 OS << "#endif /* __ARM_SVE_H */\n"; 1185 } 1186 1187 void SVEEmitter::createBuiltins(raw_ostream &OS) { 1188 std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst"); 1189 SmallVector<std::unique_ptr<Intrinsic>, 128> Defs; 1190 for (auto *R : RV) 1191 createIntrinsic(R, Defs); 1192 1193 // The mappings must be sorted based on BuiltinID. 1194 llvm::sort(Defs, [](const std::unique_ptr<Intrinsic> &A, 1195 const std::unique_ptr<Intrinsic> &B) { 1196 return A->getMangledName() < B->getMangledName(); 1197 }); 1198 1199 OS << "#ifdef GET_SVE_BUILTINS\n"; 1200 for (auto &Def : Defs) { 1201 // Only create BUILTINs for non-overloaded intrinsics, as overloaded 1202 // declarations only live in the header file. 1203 if (Def->getClassKind() != ClassG) 1204 OS << "BUILTIN(__builtin_sve_" << Def->getMangledName() << ", \"" 1205 << Def->getBuiltinTypeStr() << "\", \"n\")\n"; 1206 } 1207 1208 // Add reinterpret builtins 1209 for (const ReinterpretTypeInfo &From : Reinterprets) 1210 for (const ReinterpretTypeInfo &To : Reinterprets) 1211 OS << "BUILTIN(__builtin_sve_reinterpret_" << From.Suffix << "_" 1212 << To.Suffix << +", \"" << From.BuiltinType << To.BuiltinType 1213 << "\", \"n\")\n"; 1214 1215 OS << "#endif\n\n"; 1216 } 1217 1218 void SVEEmitter::createCodeGenMap(raw_ostream &OS) { 1219 std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst"); 1220 SmallVector<std::unique_ptr<Intrinsic>, 128> Defs; 1221 for (auto *R : RV) 1222 createIntrinsic(R, Defs); 1223 1224 // The mappings must be sorted based on BuiltinID. 1225 llvm::sort(Defs, [](const std::unique_ptr<Intrinsic> &A, 1226 const std::unique_ptr<Intrinsic> &B) { 1227 return A->getMangledName() < B->getMangledName(); 1228 }); 1229 1230 OS << "#ifdef GET_SVE_LLVM_INTRINSIC_MAP\n"; 1231 for (auto &Def : Defs) { 1232 // Builtins only exist for non-overloaded intrinsics, overloaded 1233 // declarations only live in the header file. 1234 if (Def->getClassKind() == ClassG) 1235 continue; 1236 1237 uint64_t Flags = Def->getFlags(); 1238 auto FlagString = std::to_string(Flags); 1239 1240 std::string LLVMName = Def->getLLVMName(); 1241 std::string Builtin = Def->getMangledName(); 1242 if (!LLVMName.empty()) 1243 OS << "SVEMAP1(" << Builtin << ", " << LLVMName << ", " << FlagString 1244 << "),\n"; 1245 else 1246 OS << "SVEMAP2(" << Builtin << ", " << FlagString << "),\n"; 1247 } 1248 OS << "#endif\n\n"; 1249 } 1250 1251 void SVEEmitter::createRangeChecks(raw_ostream &OS) { 1252 std::vector<Record *> RV = Records.getAllDerivedDefinitions("Inst"); 1253 SmallVector<std::unique_ptr<Intrinsic>, 128> Defs; 1254 for (auto *R : RV) 1255 createIntrinsic(R, Defs); 1256 1257 // The mappings must be sorted based on BuiltinID. 1258 llvm::sort(Defs, [](const std::unique_ptr<Intrinsic> &A, 1259 const std::unique_ptr<Intrinsic> &B) { 1260 return A->getMangledName() < B->getMangledName(); 1261 }); 1262 1263 1264 OS << "#ifdef GET_SVE_IMMEDIATE_CHECK\n"; 1265 1266 // Ensure these are only emitted once. 1267 std::set<std::string> Emitted; 1268 1269 for (auto &Def : Defs) { 1270 if (Emitted.find(Def->getMangledName()) != Emitted.end() || 1271 Def->getImmChecks().empty()) 1272 continue; 1273 1274 OS << "case SVE::BI__builtin_sve_" << Def->getMangledName() << ":\n"; 1275 for (auto &Check : Def->getImmChecks()) 1276 OS << "ImmChecks.push_back(std::make_tuple(" << Check.getArg() << ", " 1277 << Check.getKind() << ", " << Check.getElementSizeInBits() << "));\n"; 1278 OS << " break;\n"; 1279 1280 Emitted.insert(Def->getMangledName()); 1281 } 1282 1283 OS << "#endif\n\n"; 1284 } 1285 1286 /// Create the SVETypeFlags used in CGBuiltins 1287 void SVEEmitter::createTypeFlags(raw_ostream &OS) { 1288 OS << "#ifdef LLVM_GET_SVE_TYPEFLAGS\n"; 1289 for (auto &KV : FlagTypes) 1290 OS << "const uint64_t " << KV.getKey() << " = " << KV.getValue() << ";\n"; 1291 OS << "#endif\n\n"; 1292 1293 OS << "#ifdef LLVM_GET_SVE_ELTTYPES\n"; 1294 for (auto &KV : EltTypes) 1295 OS << " " << KV.getKey() << " = " << KV.getValue() << ",\n"; 1296 OS << "#endif\n\n"; 1297 1298 OS << "#ifdef LLVM_GET_SVE_MEMELTTYPES\n"; 1299 for (auto &KV : MemEltTypes) 1300 OS << " " << KV.getKey() << " = " << KV.getValue() << ",\n"; 1301 OS << "#endif\n\n"; 1302 1303 OS << "#ifdef LLVM_GET_SVE_MERGETYPES\n"; 1304 for (auto &KV : MergeTypes) 1305 OS << " " << KV.getKey() << " = " << KV.getValue() << ",\n"; 1306 OS << "#endif\n\n"; 1307 1308 OS << "#ifdef LLVM_GET_SVE_IMMCHECKTYPES\n"; 1309 for (auto &KV : ImmCheckTypes) 1310 OS << " " << KV.getKey() << " = " << KV.getValue() << ",\n"; 1311 OS << "#endif\n\n"; 1312 } 1313 1314 namespace clang { 1315 void EmitSveHeader(RecordKeeper &Records, raw_ostream &OS) { 1316 SVEEmitter(Records).createHeader(OS); 1317 } 1318 1319 void EmitSveBuiltins(RecordKeeper &Records, raw_ostream &OS) { 1320 SVEEmitter(Records).createBuiltins(OS); 1321 } 1322 1323 void EmitSveBuiltinCG(RecordKeeper &Records, raw_ostream &OS) { 1324 SVEEmitter(Records).createCodeGenMap(OS); 1325 } 1326 1327 void EmitSveRangeChecks(RecordKeeper &Records, raw_ostream &OS) { 1328 SVEEmitter(Records).createRangeChecks(OS); 1329 } 1330 1331 void EmitSveTypeFlags(RecordKeeper &Records, raw_ostream &OS) { 1332 SVEEmitter(Records).createTypeFlags(OS); 1333 } 1334 1335 } // End namespace clang 1336