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 widen!";
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) {
188 /// TypeString - for a modifier and type, generate the name of the typedef for
189 /// that type. If generic is true, emit the generic vector type rather than
190 /// the public NEON type. QUc -> uint8x8t_t / __neon_uint8x8_t.
191 static std::string TypeString(const char mod, StringRef typestr,
192 bool generic = false) {
205 // base type to get the type string for.
206 char type = ClassifyType(typestr, quad, poly, usgn);
208 // Based on the modifying character, change the type and width if necessary.
209 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
221 s += poly ? "poly8" : "int8";
224 s += quad ? "x16" : "x8";
227 s += poly ? "poly16" : "int16";
230 s += quad ? "x8" : "x4";
236 s += quad ? "x4" : "x2";
242 s += quad ? "x2" : "x1";
248 s += quad ? "x8" : "x4";
254 s += quad ? "x4" : "x2";
257 throw "unhandled type!";
268 // Append _t, finishing the type string typedef type.
280 /// TypeString - for a modifier and type, generate the clang BuiltinsARM.def
281 /// prototype code for the function. See the top of clang's Builtins.def for
282 /// a description of the type strings.
283 static std::string BuiltinTypeString(const char mod, StringRef typestr,
284 ClassKind ck, bool ret) {
297 // base type to get the type string for.
298 char type = ClassifyType(typestr, quad, poly, usgn);
300 // Based on the modifying character, change the type and width if necessary.
301 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
312 usgn = usgn | poly | ((ck == ClassI || ck == ClassW) && scal && type != 'f');
332 // Since the return value must be one type, return a vector type of the
333 // appropriate width which we will bitcast. An exception is made for
334 // returning structs of 2, 3, or 4 vectors which are returned in a sret-like
335 // fashion, storing them to a pointer arg.
337 if (mod == '2' || mod == '3' || mod == '4')
339 if (mod == 'f' || (ck != ClassB && type == 'f'))
340 return quad ? "V4f" : "V2f";
341 if (ck != ClassB && type == 's')
342 return quad ? "V8s" : "V4s";
343 if (ck != ClassB && type == 'i')
344 return quad ? "V4i" : "V2i";
345 if (ck != ClassB && type == 'l')
346 return quad ? "V2LLi" : "V1LLi";
348 return quad ? "V16c" : "V8c";
351 // Non-return array types are passed as individual vectors.
353 return quad ? "V16cV16c" : "V8cV8c";
355 return quad ? "V16cV16cV16c" : "V8cV8cV8c";
357 return quad ? "V16cV16cV16cV16c" : "V8cV8cV8cV8c";
359 if (mod == 'f' || (ck != ClassB && type == 'f'))
360 return quad ? "V4f" : "V2f";
361 if (ck != ClassB && type == 's')
362 return quad ? "V8s" : "V4s";
363 if (ck != ClassB && type == 'i')
364 return quad ? "V4i" : "V2i";
365 if (ck != ClassB && type == 'l')
366 return quad ? "V2LLi" : "V1LLi";
368 return quad ? "V16c" : "V8c";
371 /// StructTag - generate the name of the struct tag for a type.
372 /// These names are mandated by ARM's ABI.
373 static std::string StructTag(StringRef typestr) {
378 // base type to get the type string for.
379 char type = ClassifyType(typestr, quad, poly, usgn);
383 s += quad ? "128_" : "64_";
389 s += poly ? "poly8" : "int8";
392 s += poly ? "poly16" : "int16";
407 throw "unhandled type!";
411 // Append _t, finishing the struct tag name.
417 /// MangleName - Append a type or width suffix to a base neon function name,
418 /// and insert a 'q' in the appropriate location if the operation works on
419 /// 128b rather than 64b. E.g. turn "vst2_lane" into "vst2q_lane_f32", etc.
420 static std::string MangleName(const std::string &name, StringRef typestr,
422 if (name == "vcvt_f32_f16")
428 char type = ClassifyType(typestr, quad, poly, usgn);
430 std::string s = name;
435 case ClassS: s += poly ? "_p8" : usgn ? "_u8" : "_s8"; break;
436 case ClassI: s += "_i8"; break;
437 case ClassW: s += "_8"; break;
443 case ClassS: s += poly ? "_p16" : usgn ? "_u16" : "_s16"; break;
444 case ClassI: s += "_i16"; break;
445 case ClassW: s += "_16"; break;
451 case ClassS: s += usgn ? "_u32" : "_s32"; break;
452 case ClassI: s += "_i32"; break;
453 case ClassW: s += "_32"; break;
459 case ClassS: s += usgn ? "_u64" : "_s64"; break;
460 case ClassI: s += "_i64"; break;
461 case ClassW: s += "_64"; break;
468 case ClassI: s += "_f16"; break;
469 case ClassW: s += "_16"; break;
476 case ClassI: s += "_f32"; break;
477 case ClassW: s += "_32"; break;
482 throw "unhandled type!";
488 // Insert a 'q' before the first '_' character so that it ends up before
489 // _lane or _n on vector-scalar operations.
491 size_t pos = s.find('_');
492 s = s.insert(pos, "q");
497 // Generate the string "(argtype a, argtype b, ...)"
498 static std::string GenArgs(const std::string &proto, StringRef typestr) {
499 bool define = proto.find('i') != std::string::npos;
505 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
507 s += TypeString(proto[i], typestr);
519 static std::string Duplicate(unsigned nElts, StringRef typestr,
520 const std::string &a) {
523 s = "(__neon_" + TypeString('d', typestr) + "){ ";
524 for (unsigned i = 0; i != nElts; ++i) {
534 // Generate the definition for this intrinsic, e.g. "a + b" for OpAdd.
535 // If structTypes is true, the NEON types are structs of vector types rather
536 // than vector types, and the call becomes "a.val + b.val"
537 static std::string GenOpString(OpKind op, const std::string &proto,
538 StringRef typestr, bool structTypes = true) {
539 bool dummy, quad = false;
540 char type = ClassifyType(typestr, quad, dummy, dummy);
543 case 'c': nElts = 8; break;
544 case 's': nElts = 4; break;
545 case 'i': nElts = 2; break;
546 case 'l': nElts = 1; break;
547 case 'h': nElts = 4; break;
548 case 'f': nElts = 2; break;
551 std::string ts = TypeString(proto[0], typestr);
552 std::string s = ts + " r; r";
560 if (proto.size() > 1)
561 a = (structTypes && proto[1] != 'l' && proto[1] != 's') ? "a.val" : "a";
562 b = structTypes ? "b.val" : "b";
563 c = structTypes ? "c.val" : "c";
573 b = Duplicate(nElts << (int)quad, typestr, "b");
578 c = Duplicate(nElts << (int)quad, typestr, "c");
580 s += a + " + ( " + b + " * " + c + " )";
583 c = Duplicate(nElts << (int)quad, typestr, "c");
585 s += a + " - ( " + b + " * " + c + " )";
588 s += "(__neon_" + ts + ")(" + a + " == " + b + ")";
591 s += "(__neon_" + ts + ")(" + a + " >= " + b + ")";
594 s += "(__neon_" + ts + ")(" + a + " <= " + b + ")";
597 s += "(__neon_" + ts + ")(" + a + " > " + b + ")";
600 s += "(__neon_" + ts + ")(" + a + " < " + b + ")";
624 s += "(__neon_" + ts + ")" + a;
627 s += "__builtin_shufflevector((__neon_int64x1_t)" + a;
628 s += ", (__neon_int64x1_t)" + b + ", 0, 1)";
631 s += "(__neon_int64x1_t)(((__neon_int64x2_t)" + a + ")[1])";
634 s += "(__neon_int64x1_t)(((__neon_int64x2_t)" + a + ")[0])";
637 s += Duplicate(nElts << (int)quad, typestr, a);
640 // ((0 & 1) | (~0 & 2))
641 ts = TypeString(proto[1], typestr);
642 s += "( " + a + " & (__neon_" + ts + ")" + b + ") | ";
643 s += "(~" + a + " & (__neon_" + ts + ")" + c + ")";
646 s += "__builtin_shufflevector(" + a + ", " + a;
647 for (unsigned i = 2; i <= nElts << (int)quad; i += 2)
648 for (unsigned j = 0; j != 2; ++j)
649 s += ", " + utostr(i - j - 1);
654 s += "__builtin_shufflevector(" + a + ", " + a;
655 for (unsigned i = nElts; i <= nElts << (1 + (int)quad); i += nElts)
656 for (unsigned j = 0; j != nElts; ++j)
657 s += ", " + utostr(i - j - 1);
661 s += "__builtin_shufflevector(" + a + ", " + a;
662 for (unsigned i = nElts; i <= nElts << (int)quad; i += nElts)
663 for (unsigned j = 0; j != nElts; ++j)
664 s += ", " + utostr(i - j - 1);
668 throw "unknown OpKind!";
675 static unsigned GetNeonEnum(const std::string &proto, StringRef typestr) {
676 unsigned mod = proto[0];
679 if (mod == 'v' || mod == 'f')
689 // base type to get the type string for.
690 char type = ClassifyType(typestr, quad, poly, usgn);
692 // Based on the modifying character, change the type and width if necessary.
693 type = ModType(mod, type, quad, poly, usgn, scal, cnst, pntr);
720 throw "unhandled type!";
726 // Generate the definition for this intrinsic, e.g. __builtin_neon_cls(a)
727 // If structTypes is true, the NEON types are structs of vector types rather
728 // than vector types, and the call becomes __builtin_neon_cls(a.val)
729 static std::string GenBuiltin(const std::string &name, const std::string &proto,
730 StringRef typestr, ClassKind ck,
731 bool structTypes = true) {
732 bool dummy, quad = false;
733 char type = ClassifyType(typestr, quad, dummy, dummy);
736 case 'c': nElts = 8; break;
737 case 's': nElts = 4; break;
738 case 'i': nElts = 2; break;
739 case 'l': nElts = 1; break;
740 case 'h': nElts = 4; break;
741 case 'f': nElts = 2; break;
743 if (quad) nElts <<= 1;
748 // If this builtin returns a struct 2, 3, or 4 vectors, pass it as an implicit
749 // sret-like argument.
750 bool sret = (proto[0] == '2' || proto[0] == '3' || proto[0] == '4');
752 // If this builtin takes an immediate argument, we need to #define it rather
753 // than use a standard declaration, so that SemaChecking can range check
754 // the immediate passed by the user.
755 bool define = proto.find('i') != std::string::npos;
757 // If all types are the same size, bitcasting the args will take care
758 // of arg checking. The actual signedness etc. will be taken care of with
760 if (proto.find('s') == std::string::npos)
763 if (proto[0] != 'v') {
764 std::string ts = TypeString(proto[0], typestr);
768 s += "({ " + ts + " r; ";
769 else if (proto[0] != 's')
770 s += "(" + ts + "){(__neon_" + ts + ")";
775 if (structTypes && proto[0] != 's' && proto[0] != 'i' && proto[0] != 'l')
782 bool splat = proto.find('a') != std::string::npos;
784 s += "__builtin_neon_";
786 std::string vname(name, 0, name.size()-2);
787 s += MangleName(vname, typestr, ck);
789 s += MangleName(name, typestr, ck);
793 // Pass the address of the return variable as the first argument to sret-like
798 for (unsigned i = 1, e = proto.size(); i != e; ++i, ++arg) {
799 std::string args = std::string(&arg, 1);
801 args = "(" + args + ")";
803 // Handle multiple-vector values specially, emitting each subvector as an
804 // argument to the __builtin.
805 if (structTypes && (proto[i] == '2' || proto[i] == '3' || proto[i] == '4')){
806 for (unsigned vi = 0, ve = proto[i] - '0'; vi != ve; ++vi) {
807 s += args + ".val[" + utostr(vi) + "]";
817 if (splat && (i + 1) == e)
818 s += Duplicate(nElts, typestr, args);
822 if (structTypes && proto[i] != 's' && proto[i] != 'i' && proto[i] != 'l' &&
823 proto[i] != 'p' && proto[i] != 'c' && proto[i] != 'a') {
830 // Extra constant integer to hold type class enum for this function, e.g. s8
832 s += ", " + utostr(GetNeonEnum(proto, typestr));
839 if (proto[0] != 'v') {
843 else if (proto[0] != 's')
852 static std::string GenBuiltinDef(const std::string &name,
853 const std::string &proto,
854 StringRef typestr, ClassKind ck) {
855 std::string s("BUILTIN(__builtin_neon_");
857 // If all types are the same size, bitcasting the args will take care
858 // of arg checking. The actual signedness etc. will be taken care of with
860 if (proto.find('s') == std::string::npos)
863 s += MangleName(name, typestr, ck);
866 for (unsigned i = 0, e = proto.size(); i != e; ++i)
867 s += BuiltinTypeString(proto[i], typestr, ck, i == 0);
869 // Extra constant integer to hold type class enum for this function, e.g. s8
877 /// run - Read the records in arm_neon.td and output arm_neon.h. arm_neon.h
878 /// is comprised of type definitions and function declarations.
879 void NeonEmitter::run(raw_ostream &OS) {
880 EmitSourceFileHeader("ARM NEON Header", OS);
882 // FIXME: emit license into file?
884 OS << "#ifndef __ARM_NEON_H\n";
885 OS << "#define __ARM_NEON_H\n\n";
887 OS << "#ifndef __ARM_NEON__\n";
888 OS << "#error \"NEON support not enabled\"\n";
891 OS << "#include <stdint.h>\n\n";
893 // Emit NEON-specific scalar typedefs.
894 OS << "typedef float float32_t;\n";
895 OS << "typedef uint8_t poly8_t;\n";
896 OS << "typedef uint16_t poly16_t;\n";
897 OS << "typedef uint16_t float16_t;\n";
899 // Emit Neon vector typedefs.
900 std::string TypedefTypes("cQcsQsiQilQlUcQUcUsQUsUiQUiUlQUlhQhfQfPcQPcPsQPs");
901 SmallVector<StringRef, 24> TDTypeVec;
902 ParseTypes(0, TypedefTypes, TDTypeVec);
904 // Emit vector typedefs.
905 for (unsigned v = 1; v != 5; ++v) {
906 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
907 bool dummy, quad = false;
908 (void) ClassifyType(TDTypeVec[i], quad, dummy, dummy);
909 OS << "typedef __attribute__(( __vector_size__(";
911 OS << utostr(8*v*(quad ? 2 : 1)) << ") )) ";
915 OS << TypeString('s', TDTypeVec[i]);
918 char t = (v == 1) ? 'd' : '0' + v;
919 OS << TypeString(t, TDTypeVec[i]) << ";\n";
924 // Emit struct typedefs.
925 for (unsigned vi = 1; vi != 5; ++vi) {
926 for (unsigned i = 0, e = TDTypeVec.size(); i != e; ++i) {
927 std::string ts = TypeString('d', TDTypeVec[i], vi == 1);
928 std::string vs = TypeString((vi > 1) ? '0' + vi : 'd', TDTypeVec[i]);
929 std::string tag = (vi > 1) ? vs : StructTag(TDTypeVec[i]);
930 OS << "typedef struct " << tag << " {\n";
931 OS << " " << ts << " val";
933 OS << "[" << utostr(vi) << "]";
934 OS << ";\n} " << vs << ";\n\n";
938 OS << "#define __ai static __attribute__((__always_inline__))\n\n";
940 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
942 // Unique the return+pattern types, and assign them.
943 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
945 std::string name = LowercaseString(R->getName());
946 std::string Proto = R->getValueAsString("Prototype");
947 std::string Types = R->getValueAsString("Types");
949 SmallVector<StringRef, 16> TypeVec;
950 ParseTypes(R, Types, TypeVec);
952 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
954 bool define = Proto.find('i') != std::string::npos;
956 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
957 assert(!Proto.empty() && "");
959 // static always inline + return type
963 OS << "__ai " << TypeString(Proto[0], TypeVec[ti]);
965 // Function name with type suffix
966 OS << " " << MangleName(name, TypeVec[ti], ClassS);
968 // Function arguments
969 OS << GenArgs(Proto, TypeVec[ti]);
978 OS << GenOpString(k, Proto, TypeVec[ti]);
980 if (R->getSuperClasses().size() < 2)
981 throw TGError(R->getLoc(), "Builtin has no class kind");
983 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
986 throw TGError(R->getLoc(), "Builtin has no class kind");
987 OS << GenBuiltin(name, Proto, TypeVec[ti], ck);
995 OS << "#undef __ai\n\n";
996 OS << "#endif /* __ARM_NEON_H */\n";
999 static unsigned RangeFromType(StringRef typestr) {
1000 // base type to get the type string for.
1001 bool quad = false, dummy = false;
1002 char type = ClassifyType(typestr, quad, dummy, dummy);
1006 return (8 << (int)quad) - 1;
1009 return (4 << (int)quad) - 1;
1012 return (2 << (int)quad) - 1;
1014 return (1 << (int)quad) - 1;
1016 throw "unhandled type!";
1021 /// runHeader - Emit a file with sections defining:
1022 /// 1. the NEON section of BuiltinsARM.def.
1023 /// 2. the SemaChecking code for the type overload checking.
1024 /// 3. the SemaChecking code for validation of intrinsic immedate arguments.
1025 void NeonEmitter::runHeader(raw_ostream &OS) {
1026 std::vector<Record*> RV = Records.getAllDerivedDefinitions("Inst");
1028 StringMap<OpKind> EmittedMap;
1030 // Generate BuiltinsARM.def for NEON
1031 OS << "#ifdef GET_NEON_BUILTINS\n";
1032 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1034 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1038 std::string Proto = R->getValueAsString("Prototype");
1040 // Functions with 'a' (the splat code) in the type prototype should not get
1041 // their own builtin as they use the non-splat variant.
1042 if (Proto.find('a') != std::string::npos)
1045 std::string Types = R->getValueAsString("Types");
1046 SmallVector<StringRef, 16> TypeVec;
1047 ParseTypes(R, Types, TypeVec);
1049 if (R->getSuperClasses().size() < 2)
1050 throw TGError(R->getLoc(), "Builtin has no class kind");
1052 std::string name = LowercaseString(R->getName());
1053 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1055 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1056 // Generate the BuiltinsARM.def declaration for this builtin, ensuring
1057 // that each unique BUILTIN() macro appears only once in the output
1059 std::string bd = GenBuiltinDef(name, Proto, TypeVec[ti], ck);
1060 if (EmittedMap.count(bd))
1063 EmittedMap[bd] = OpNone;
1069 // Generate the overloaded type checking code for SemaChecking.cpp
1070 OS << "#ifdef GET_NEON_OVERLOAD_CHECK\n";
1071 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1073 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1077 std::string Proto = R->getValueAsString("Prototype");
1078 std::string Types = R->getValueAsString("Types");
1079 std::string name = LowercaseString(R->getName());
1081 // Functions with 'a' (the splat code) in the type prototype should not get
1082 // their own builtin as they use the non-splat variant.
1083 if (Proto.find('a') != std::string::npos)
1086 // Functions which have a scalar argument cannot be overloaded, no need to
1087 // check them if we are emitting the type checking code.
1088 if (Proto.find('s') != std::string::npos)
1091 SmallVector<StringRef, 16> TypeVec;
1092 ParseTypes(R, Types, TypeVec);
1094 if (R->getSuperClasses().size() < 2)
1095 throw TGError(R->getLoc(), "Builtin has no class kind");
1097 int si = -1, qi = -1;
1098 unsigned mask = 0, qmask = 0;
1099 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1100 // Generate the switch case(s) for this builtin for the type validation.
1101 bool quad = false, poly = false, usgn = false;
1102 (void) ClassifyType(TypeVec[ti], quad, poly, usgn);
1106 qmask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1109 mask |= 1 << GetNeonEnum(Proto, TypeVec[ti]);
1113 OS << "case ARM::BI__builtin_neon_"
1114 << MangleName(name, TypeVec[si], ClassB)
1115 << ": mask = " << "0x" << utohexstr(mask) << "; break;\n";
1117 OS << "case ARM::BI__builtin_neon_"
1118 << MangleName(name, TypeVec[qi], ClassB)
1119 << ": mask = " << "0x" << utohexstr(qmask) << "; break;\n";
1123 // Generate the intrinsic range checking code for shift/lane immediates.
1124 OS << "#ifdef GET_NEON_IMMEDIATE_CHECK\n";
1125 for (unsigned i = 0, e = RV.size(); i != e; ++i) {
1128 OpKind k = OpMap[R->getValueAsDef("Operand")->getName()];
1132 std::string name = LowercaseString(R->getName());
1133 std::string Proto = R->getValueAsString("Prototype");
1134 std::string Types = R->getValueAsString("Types");
1136 // Functions with 'a' (the splat code) in the type prototype should not get
1137 // their own builtin as they use the non-splat variant.
1138 if (Proto.find('a') != std::string::npos)
1141 // Functions which do not have an immediate do not need to have range
1142 // checking code emitted.
1143 if (Proto.find('i') == std::string::npos)
1146 SmallVector<StringRef, 16> TypeVec;
1147 ParseTypes(R, Types, TypeVec);
1149 if (R->getSuperClasses().size() < 2)
1150 throw TGError(R->getLoc(), "Builtin has no class kind");
1152 ClassKind ck = ClassMap[R->getSuperClasses()[1]];
1154 for (unsigned ti = 0, te = TypeVec.size(); ti != te; ++ti) {
1155 std::string namestr, shiftstr, rangestr;
1157 // Builtins which are overloaded by type will need to have their upper
1158 // bound computed at Sema time based on the type constant.
1159 if (Proto.find('s') == std::string::npos) {
1161 if (R->getValueAsBit("isShift")) {
1162 shiftstr = ", true";
1164 // Right shifts have an 'r' in the name, left shifts do not.
1165 if (name.find('r') != std::string::npos)
1166 rangestr = "l = 1; ";
1168 rangestr += "u = RFT(TV" + shiftstr + ")";
1170 rangestr = "u = " + utostr(RangeFromType(TypeVec[ti]));
1172 // Make sure cases appear only once by uniquing them in a string map.
1173 namestr = MangleName(name, TypeVec[ti], ck);
1174 if (EmittedMap.count(namestr))
1176 EmittedMap[namestr] = OpNone;
1178 // Calculate the index of the immediate that should be range checked.
1179 unsigned immidx = 0;
1181 // Builtins that return a struct of multiple vectors have an extra
1182 // leading arg for the struct return.
1183 if (Proto[0] == '2' || Proto[0] == '3' || Proto[0] == '4')
1186 // Add one to the index for each argument until we reach the immediate
1187 // to be checked. Structs of vectors are passed as multiple arguments.
1188 for (unsigned ii = 1, ie = Proto.size(); ii != ie; ++ii) {
1189 switch (Proto[ii]) {
1190 default: immidx += 1; break;
1191 case '2': immidx += 2; break;
1192 case '3': immidx += 3; break;
1193 case '4': immidx += 4; break;
1194 case 'i': ie = ii + 1; break;
1197 OS << "case ARM::BI__builtin_neon_" << MangleName(name, TypeVec[ti], ck)
1198 << ": i = " << immidx << "; " << rangestr << "; break;\n";