1 //===- NeonEmitter.cpp - Generate arm_neon.h for use with clang -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tablegen backend is responsible for emitting arm_neon.h, which includes
11 // a declaration and definition of each function specified by the ARM NEON
12 // compiler interface. See ARM document DUI0348B.
14 // Each NEON instruction is implemented in terms of 1 or more functions which
15 // are suffixed with the element type of the input vectors. Functions may be
16 // implemented in terms of generic vector operations such as +, *, -, etc. or
17 // by calling a __builtin_-prefixed function which will be handled by clang's
20 // Additional validation code can be generated by this file when runHeader() is
21 // called, rather than the normal run() entry point.
23 //===----------------------------------------------------------------------===//
25 #include "NeonEmitter.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/SmallVector.h"
28 #include "llvm/ADT/StringExtras.h"
33 /// ParseTypes - break down a string such as "fQf" into a vector of StringRefs,
34 /// which each StringRef representing a single type declared in the string.
35 /// for "fQf" we would end up with 2 StringRefs, "f", and "Qf", representing
36 /// 2xfloat and 4xfloat respectively.
37 static void ParseTypes(Record *r, std::string &s,
38 SmallVectorImpl<StringRef> &TV) {
39 const char *data = s.data();
42 for (unsigned i = 0, e = s.size(); i != e; ++i, ++len) {
43 if (data[len] == 'P' || data[len] == 'Q' || data[len] == 'U')
55 throw TGError(r->getLoc(),
56 "Unexpected letter: " + std::string(data + len, 1));
59 TV.push_back(StringRef(data, len + 1));
65 /// Widen - Convert a type code into the next wider type. char -> short,
66 /// short -> int, etc.
67 static char Widen(const char t) {
75 default: throw "unhandled type in widen!";
80 /// Narrow - Convert a type code into the next smaller type. short -> char,
81 /// float -> half float, etc.
82 static char Narrow(const char t) {
92 default: throw "unhandled type in narrow!";
97 /// For a particular StringRef, return the base type code, and whether it has
98 /// the quad-vector, polynomial, or unsigned modifiers set.
99 static char ClassifyType(StringRef ty, bool &quad, bool &poly, bool &usgn) {
103 if (ty[off] == 'Q') {
109 if (ty[off] == 'P') {
114 // remember unsigned.
115 if (ty[off] == 'U') {
120 // base type to get the type string for.
124 /// ModType - Transform a type code and its modifiers based on a mod code. The
125 /// mod code definitions may be found at the top of arm_neon.td.
126 static char ModType(const char mod, char type, bool &quad, bool &poly,
127 bool &usgn, bool &scal, bool &cnst, bool &pntr) {
200 /// TypeString - for a modifier and type, generate the name of the typedef for
201 /// that type. QUc -> uint8x8_t.
202 static std::string TypeString(const char mod, StringRef typestr) {
215 // base type to get the type string for.
216 char type = ClassifyType(typestr, quad, poly, usgn);
218 // Based on the modifying character, change the type and width if necessary.
219 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
228 s += poly ? "poly8" : "int8";
231 s += quad ? "x16" : "x8";
234 s += poly ? "poly16" : "int16";
237 s += quad ? "x8" : "x4";
243 s += quad ? "x4" : "x2";
249 s += quad ? "x2" : "x1";
255 s += quad ? "x8" : "x4";
261 s += quad ? "x4" : "x2";
264 throw "unhandled type!";
275 // Append _t, finishing the type string typedef type.
287 /// BuiltinTypeString - for a modifier and type, generate the clang
288 /// BuiltinsARM.def prototype code for the function. See the top of clang's
289 /// Builtins.def for a description of the type strings.
290 static std::string BuiltinTypeString(const char mod, StringRef typestr,
291 ClassKind ck, bool ret) {
304 // base type to get the type string for.
305 char type = ClassifyType(typestr, quad, poly, usgn);
307 // Based on the modifying character, change the type and width if necessary.
308 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
310 // All pointers are void* pointers. Change type to 'v' now.
316 // Treat half-float ('h') types as unsigned short ('s') types.
321 usgn = usgn | poly | ((ck == ClassI || ck == ClassW) && scal && type != 'f');
328 else if (type == 'c')
329 s.push_back('S'); // make chars explicitly signed
331 if (type == 'l') // 64-bit long
343 // Since the return value must be one type, return a vector type of the
344 // appropriate width which we will bitcast. An exception is made for
345 // returning structs of 2, 3, or 4 vectors which are returned in a sret-like
346 // fashion, storing them to a pointer arg.
348 if (mod >= '2' && mod <= '4')
349 return "vv*"; // void result with void* first argument
350 if (mod == 'f' || (ck != ClassB && type == 'f'))
351 return quad ? "V4f" : "V2f";
352 if (ck != ClassB && type == 's')
353 return quad ? "V8s" : "V4s";
354 if (ck != ClassB && type == 'i')
355 return quad ? "V4i" : "V2i";
356 if (ck != ClassB && type == 'l')
357 return quad ? "V2LLi" : "V1LLi";
359 return quad ? "V16Sc" : "V8Sc";
362 // Non-return array types are passed as individual vectors.
364 return quad ? "V16ScV16Sc" : "V8ScV8Sc";
366 return quad ? "V16ScV16ScV16Sc" : "V8ScV8ScV8Sc";
368 return quad ? "V16ScV16ScV16ScV16Sc" : "V8ScV8ScV8ScV8Sc";
370 if (mod == 'f' || (ck != ClassB && type == 'f'))
371 return quad ? "V4f" : "V2f";
372 if (ck != ClassB && type == 's')
373 return quad ? "V8s" : "V4s";
374 if (ck != ClassB && type == 'i')
375 return quad ? "V4i" : "V2i";
376 if (ck != ClassB && type == 'l')
377 return quad ? "V2LLi" : "V1LLi";
379 return quad ? "V16Sc" : "V8Sc";
382 /// MangleName - Append a type or width suffix to a base neon function name,
383 /// and insert a 'q' in the appropriate location if the operation works on
384 /// 128b rather than 64b. E.g. turn "vst2_lane" into "vst2q_lane_f32", etc.
385 static std::string MangleName(const std::string &name, StringRef typestr,
387 if (name == "vcvt_f32_f16")
393 char type = ClassifyType(typestr, quad, poly, usgn);
395 std::string s = name;
400 case ClassS: s += poly ? "_p8" : usgn ? "_u8" : "_s8"; break;
401 case ClassI: s += "_i8"; break;
402 case ClassW: s += "_8"; break;
408 case ClassS: s += poly ? "_p16" : usgn ? "_u16" : "_s16"; break;
409 case ClassI: s += "_i16"; break;
410 case ClassW: s += "_16"; break;
416 case ClassS: s += usgn ? "_u32" : "_s32"; break;
417 case ClassI: s += "_i32"; break;
418 case ClassW: s += "_32"; break;
424 case ClassS: s += usgn ? "_u64" : "_s64"; break;
425 case ClassI: s += "_i64"; break;
426 case ClassW: s += "_64"; break;
433 case ClassI: s += "_f16"; break;
434 case ClassW: s += "_16"; break;
441 case ClassI: s += "_f32"; break;
442 case ClassW: s += "_32"; break;
447 throw "unhandled type!";
453 // Insert a 'q' before the first '_' character so that it ends up before
454 // _lane or _n on vector-scalar operations.
456 size_t pos = s.find('_');
457 s = s.insert(pos, "q");
462 // Generate the string "(argtype a, argtype b, ...)"
463 static std::string GenArgs(const std::string &proto, StringRef typestr) {
464 bool define = proto.find('i') != std::string::npos;
470 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
472 s += TypeString(proto[i], typestr);
484 // Generate the local temporaries used to provide type checking for macro
486 static std::string GenMacroLocals(const std::string &proto, StringRef typestr) {
490 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
491 // Do not create a temporary for an immediate argument.
492 // That would defeat the whole point of using a macro!
493 if (proto[i] == 'i') continue;
495 s += TypeString(proto[i], typestr) + " __";
506 static std::string Duplicate(unsigned nElts, StringRef typestr,
507 const std::string &a) {
510 s = "(" + TypeString('d', typestr) + "){ ";
511 for (unsigned i = 0; i != nElts; ++i) {
521 static unsigned GetNumElements(StringRef typestr, bool &quad) {
524 char type = ClassifyType(typestr, quad, dummy, dummy);
527 case 'c': nElts = 8; break;
528 case 's': nElts = 4; break;
529 case 'i': nElts = 2; break;
530 case 'l': nElts = 1; break;
531 case 'h': nElts = 4; break;
532 case 'f': nElts = 2; break;
534 throw "unhandled type!";
537 if (quad) nElts <<= 1;
541 // Generate the definition for this intrinsic, e.g. "a + b" for OpAdd.
542 static std::string GenOpString(OpKind op, const std::string &proto,
545 unsigned nElts = GetNumElements(typestr, quad);
547 std::string ts = TypeString(proto[0], typestr);
549 if (op == OpHi || op == OpLo) {
550 s = "union { " + ts + " r; double d; } u; u.d";
565 s += "a * " + Duplicate(nElts, typestr, "b");
571 s += "a + (b * " + Duplicate(nElts, typestr, "c") + ")";
577 s += "a - (b * " + Duplicate(nElts, typestr, "c") + ")";
583 s += "(" + ts + ")(a == b)";
586 s += "(" + ts + ")(a >= b)";
589 s += "(" + ts + ")(a <= b)";
592 s += "(" + ts + ")(a > b)";
595 s += "(" + ts + ")(a < b)";
619 s += "(" + ts + ")a";
622 s += "(" + ts + ")__builtin_shufflevector((int64x1_t)a";
623 s += ", (int64x1_t)b, 0, 1)";
626 s += "(((float64x2_t)a)[1])";
629 s += "(((float64x2_t)a)[0])";
632 s += Duplicate(nElts, typestr, "a");
635 // ((0 & 1) | (~0 & 2))
637 ts = TypeString(proto[1], typestr);
638 s += "((a & (" + ts + ")b) | ";
639 s += "(~a & (" + ts + ")c))";
642 s += "__builtin_shufflevector(a, a";
643 for (unsigned i = 2; i <= nElts; i += 2)
644 for (unsigned j = 0; j != 2; ++j)
645 s += ", " + utostr(i - j - 1);
649 unsigned WordElts = nElts >> (1 + (int)quad);
650 s += "__builtin_shufflevector(a, a";
651 for (unsigned i = WordElts; i <= nElts; i += WordElts)
652 for (unsigned j = 0; j != WordElts; ++j)
653 s += ", " + utostr(i - j - 1);
658 unsigned DblWordElts = nElts >> (int)quad;
659 s += "__builtin_shufflevector(a, a";
660 for (unsigned i = DblWordElts; i <= nElts; i += DblWordElts)
661 for (unsigned j = 0; j != DblWordElts; ++j)
662 s += ", " + utostr(i - j - 1);
667 throw "unknown OpKind!";
670 if (op == OpHi || op == OpLo)
671 s += "; return u.r;";
677 static unsigned GetNeonEnum(const std::string &proto, StringRef typestr) {
678 unsigned mod = proto[0];
681 if (mod == 'v' || mod == 'f')
691 // Base type to get the type string for.
692 char type = ClassifyType(typestr, quad, poly, usgn);
694 // Based on the modifying character, change the type and width if necessary.
695 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
699 if (quad && proto[1] != 'g')
722 throw "unhandled type!";
728 // Generate the definition for this intrinsic, e.g. __builtin_neon_cls(a)
729 static std::string GenBuiltin(const std::string &name, const std::string &proto,
730 StringRef typestr, ClassKind ck) {
733 // If this builtin returns a struct 2, 3, or 4 vectors, pass it as an implicit
734 // sret-like argument.
735 bool sret = (proto[0] >= '2' && proto[0] <= '4');
737 // If this builtin takes an immediate argument, we need to #define it rather
738 // than use a standard declaration, so that SemaChecking can range check
739 // the immediate passed by the user.
740 bool define = proto.find('i') != std::string::npos;
742 // Check if the prototype has a scalar operand with the type of the vector
743 // elements. If not, bitcasting the args will take care of arg checking.
744 // The actual signedness etc. will be taken care of with special enums.
745 if (proto.find('s') == std::string::npos)
748 // Macro arguments are not type-checked like inline function arguments, so
749 // assign them to local temporaries to get the right type checking.
751 s += GenMacroLocals(proto, typestr);
753 if (proto[0] != 'v') {
754 std::string ts = TypeString(proto[0], typestr);
764 s += ts + " r; r = (" + ts + ")";
768 bool splat = proto.find('a') != std::string::npos;
770 s += "__builtin_neon_";
772 // Call the non-splat builtin: chop off the "_n" suffix from the name.
773 std::string vname(name, 0, name.size()-2);
774 s += MangleName(vname, typestr, ck);
776 s += MangleName(name, typestr, ck);
780 // Pass the address of the return variable as the first argument to sret-like
786 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
787 std::string args = std::string(&arg, 1);
789 // For macros, use the local temporaries instead of the macro arguments.
790 if (define && proto[i] != 'i')
793 bool argQuad = false;
794 bool argPoly = false;
795 bool argUsgn = false;
796 bool argScalar = false;
798 char argType = ClassifyType(typestr, argQuad, argPoly, argUsgn);
799 argType = ModType(proto[i], argType, argQuad, argPoly, argUsgn, argScalar,
802 // Handle multiple-vector values specially, emitting each subvector as an
803 // argument to the __builtin.
804 if (proto[i] >= '2' && proto[i] <= '4') {
805 // Check if an explicit cast is needed.
806 if (argType != 'c' || argPoly || argUsgn)
807 args = (argQuad ? "(int8x16_t)" : "(int8x8_t)") + args;
809 for (unsigned vi = 0, ve = proto[i] - '0'; vi != ve; ++vi) {
810 s += args + ".val[" + utostr(vi) + "]";
820 if (splat && (i + 1) == e)
821 args = Duplicate(GetNumElements(typestr, argQuad), typestr, args);
823 // Check if an explicit cast is needed.
824 if ((splat || !argScalar) &&
825 ((ck == ClassB && argType != 'c') || argPoly || argUsgn)) {
826 std::string argTypeStr = "c";
828 argTypeStr = argType;
830 argTypeStr = "Q" + argTypeStr;
831 args = "(" + TypeString('d', argTypeStr) + ")" + args;
839 // Extra constant integer to hold type class enum for this function, e.g. s8
841 s += ", " + utostr(GetNeonEnum(proto, typestr));
845 if (proto[0] != 'v') {
856 static std::string GenBuiltinDef(const std::string &name,
857 const std::string &proto,
858 StringRef typestr, ClassKind ck) {
859 std::string s("BUILTIN(__builtin_neon_");
861 // If all types are the same size, bitcasting the args will take care
862 // of arg checking. The actual signedness etc. will be taken care of with
864 if (proto.find('s') == std::string::npos)
867 s += MangleName(name, typestr, ck);
870 for (unsigned i = 0, e = proto.size(); i != e; ++i)
871 s += BuiltinTypeString(proto[i], typestr, ck, i == 0);
873 // Extra constant integer to hold type class enum for this function, e.g. s8
881 /// run - Read the records in arm_neon.td and output arm_neon.h. arm_neon.h
882 /// is comprised of type definitions and function declarations.
883 void NeonEmitter::run(raw_ostream &OS) {
884 EmitSourceFileHeader("ARM NEON Header", OS);
886 // FIXME: emit license into file?
888 OS << "#ifndef __ARM_NEON_H\n";
889 OS << "#define __ARM_NEON_H\n\n";
891 OS << "#ifndef __ARM_NEON__\n";
892 OS << "#error \"NEON support not enabled\"\n";
895 OS << "#include <stdint.h>\n\n";
897 // Emit NEON-specific scalar typedefs.
898 OS << "typedef float float32_t;\n";
899 OS << "typedef int8_t poly8_t;\n";
900 OS << "typedef int16_t poly16_t;\n";
901 OS << "typedef uint16_t float16_t;\n";
903 // Emit Neon vector typedefs.
904 std::string TypedefTypes("cQcsQsiQilQlUcQUcUsQUsUiQUiUlQUlhQhfQfPcQPcPsQPs");
905 SmallVector<StringRef, 24> TDTypeVec;
906 ParseTypes(0, TypedefTypes, TDTypeVec);
908 // Emit vector typedefs.
909 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
910 bool dummy, quad = false, poly = false;
911 (void) ClassifyType(TDTypeVec[i], quad, poly, dummy);
913 OS << "typedef __attribute__((neon_polyvector_type(";
915 OS << "typedef __attribute__((neon_vector_type(";
917 unsigned nElts = GetNumElements(TDTypeVec[i], quad);
918 OS << utostr(nElts) << "))) ";
922 OS << TypeString('s', TDTypeVec[i]);
923 OS << " " << TypeString('d', TDTypeVec[i]) << ";\n";
926 OS << "typedef __attribute__((__vector_size__(8))) "
927 "double float64x1_t;\n";
928 OS << "typedef __attribute__((__vector_size__(16))) "
929 "double float64x2_t;\n";
932 // Emit struct typedefs.
933 for (unsigned vi = 2; vi != 5; ++vi) {
934 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
935 std::string ts = TypeString('d', TDTypeVec[i]);
936 std::string vs = TypeString('0' + vi, TDTypeVec[i]);
937 OS << "typedef struct " << vs << " {\n";
938 OS << " " << ts << " val";
939 OS << "[" << utostr(vi) << "]";
945 OS << "#define __ai static __attribute__((__always_inline__))\n\n";
947 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
949 // Unique the return+pattern types, and assign them.
950 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
952 std::string name = LowercaseString(R->getName());
953 std::string Proto = R->getValueAsString("Prototype");
954 std::string Types = R->getValueAsString("Types");
956 SmallVector<StringRef, 16> TypeVec;
957 ParseTypes(R, Types, TypeVec);
959 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
961 bool define = Proto.find('i') != std::string::npos;
963 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
964 assert(!Proto.empty() && "");
966 // static always inline + return type
970 OS << "__ai " << TypeString(Proto[0], TypeVec[ti]);
972 // Function name with type suffix
973 OS << " " << MangleName(name, TypeVec[ti], ClassS);
975 // Function arguments
976 OS << GenArgs(Proto, TypeVec[ti]);
980 OS << " __extension__ ({ \\\n ";
985 OS << GenOpString(k, Proto, TypeVec[ti]);
987 if (R->getSuperClasses().size() < 2)
988 throw TGError(R->getLoc(), "Builtin has no class kind");
990 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
993 throw TGError(R->getLoc(), "Builtin has no class kind");
994 OS << GenBuiltin(name, Proto, TypeVec[ti], ck);
1004 OS << "#undef __ai\n\n";
1005 OS << "#endif /* __ARM_NEON_H */\n";
1008 static unsigned RangeFromType(StringRef typestr) {
1009 // base type to get the type string for.
1010 bool quad = false, dummy = false;
1011 char type = ClassifyType(typestr, quad, dummy, dummy);
1015 return (8 << (int)quad) - 1;
1018 return (4 << (int)quad) - 1;
1021 return (2 << (int)quad) - 1;
1023 return (1 << (int)quad) - 1;
1025 throw "unhandled type!";
1028 assert(0 && "unreachable");
1032 /// runHeader - Emit a file with sections defining:
1033 /// 1. the NEON section of BuiltinsARM.def.
1034 /// 2. the SemaChecking code for the type overload checking.
1035 /// 3. the SemaChecking code for validation of intrinsic immedate arguments.
1036 void NeonEmitter::runHeader(raw_ostream &OS) {
1037 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
1039 StringMap<OpKind> EmittedMap;
1041 // Generate BuiltinsARM.def for NEON
1042 OS << "#ifdef GET_NEON_BUILTINS\n";
1043 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1045 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1049 std::string Proto = R->getValueAsString("Prototype");
1051 // Functions with 'a' (the splat code) in the type prototype should not get
1052 // their own builtin as they use the non-splat variant.
1053 if (Proto.find('a') != std::string::npos)
1056 std::string Types = R->getValueAsString("Types");
1057 SmallVector<StringRef, 16> TypeVec;
1058 ParseTypes(R, Types, TypeVec);
1060 if (R->getSuperClasses().size() < 2)
1061 throw TGError(R->getLoc(), "Builtin has no class kind");
1063 std::string name = LowercaseString(R->getName());
1064 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1066 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1067 // Generate the BuiltinsARM.def declaration for this builtin, ensuring
1068 // that each unique BUILTIN() macro appears only once in the output
1070 std::string bd = GenBuiltinDef(name, Proto, TypeVec[ti], ck);
1071 if (EmittedMap.count(bd))
1074 EmittedMap[bd] = OpNone;
1080 // Generate the overloaded type checking code for SemaChecking.cpp
1081 OS << "#ifdef GET_NEON_OVERLOAD_CHECK\n";
1082 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1084 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1088 std::string Proto = R->getValueAsString("Prototype");
1089 std::string Types = R->getValueAsString("Types");
1090 std::string name = LowercaseString(R->getName());
1092 // Functions with 'a' (the splat code) in the type prototype should not get
1093 // their own builtin as they use the non-splat variant.
1094 if (Proto.find('a') != std::string::npos)
1097 // Functions which have a scalar argument cannot be overloaded, no need to
1098 // check them if we are emitting the type checking code.
1099 if (Proto.find('s') != std::string::npos)
1102 SmallVector<StringRef, 16> TypeVec;
1103 ParseTypes(R, Types, TypeVec);
1105 if (R->getSuperClasses().size() < 2)
1106 throw TGError(R->getLoc(), "Builtin has no class kind");
1108 int si = -1, qi = -1;
1109 unsigned mask = 0, qmask = 0;
1110 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1111 // Generate the switch case(s) for this builtin for the type validation.
1112 bool quad = false, poly = false, usgn = false;
1113 (void) ClassifyType(TypeVec[ti], quad, poly, usgn);
1117 qmask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1120 mask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1124 OS << "case ARM::BI__builtin_neon_"
1125 << MangleName(name, TypeVec[si], ClassB)
1126 << ": mask = " << "0x" << utohexstr(mask) << "; break;\n";
1128 OS << "case ARM::BI__builtin_neon_"
1129 << MangleName(name, TypeVec[qi], ClassB)
1130 << ": mask = " << "0x" << utohexstr(qmask) << "; break;\n";
1134 // Generate the intrinsic range checking code for shift/lane immediates.
1135 OS << "#ifdef GET_NEON_IMMEDIATE_CHECK\n";
1136 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1139 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1143 std::string name = LowercaseString(R->getName());
1144 std::string Proto = R->getValueAsString("Prototype");
1145 std::string Types = R->getValueAsString("Types");
1147 // Functions with 'a' (the splat code) in the type prototype should not get
1148 // their own builtin as they use the non-splat variant.
1149 if (Proto.find('a') != std::string::npos)
1152 // Functions which do not have an immediate do not need to have range
1153 // checking code emitted.
1154 if (Proto.find('i') == std::string::npos)
1157 SmallVector<StringRef, 16> TypeVec;
1158 ParseTypes(R, Types, TypeVec);
1160 if (R->getSuperClasses().size() < 2)
1161 throw TGError(R->getLoc(), "Builtin has no class kind");
1163 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1165 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1166 std::string namestr, shiftstr, rangestr;
1168 // Builtins which are overloaded by type will need to have their upper
1169 // bound computed at Sema time based on the type constant.
1170 if (Proto.find('s') == std::string::npos) {
1172 if (R->getValueAsBit("isShift")) {
1173 shiftstr = ", true";
1175 // Right shifts have an 'r' in the name, left shifts do not.
1176 if (name.find('r') != std::string::npos)
1177 rangestr = "l = 1; ";
1179 rangestr += "u = RFT(TV" + shiftstr + ")";
1181 rangestr = "u = " + utostr(RangeFromType(TypeVec[ti]));
1183 // Make sure cases appear only once by uniquing them in a string map.
1184 namestr = MangleName(name, TypeVec[ti], ck);
1185 if (EmittedMap.count(namestr))
1187 EmittedMap[namestr] = OpNone;
1189 // Calculate the index of the immediate that should be range checked.
1190 unsigned immidx = 0;
1192 // Builtins that return a struct of multiple vectors have an extra
1193 // leading arg for the struct return.
1194 if (Proto[0] >= '2' && Proto[0] <= '4')
1197 // Add one to the index for each argument until we reach the immediate
1198 // to be checked. Structs of vectors are passed as multiple arguments.
1199 for (unsigned ii = 1, ie = Proto.size(); ii != ie; ++ii) {
1200 switch (Proto[ii]) {
1201 default: immidx += 1; break;
1202 case '2': immidx += 2; break;
1203 case '3': immidx += 3; break;
1204 case '4': immidx += 4; break;
1205 case 'i': ie = ii + 1; break;
1208 OS << "case ARM::BI__builtin_neon_" << MangleName(name, TypeVec[ti], ck)
1209 << ": i = " << immidx << "; " << rangestr << "; break;\n";