1 //===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
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 emits information about intrinsic functions.
12 //===----------------------------------------------------------------------===//
14 #include "CodeGenTarget.h"
15 #include "IntrinsicEmitter.h"
17 #include "llvm/ADT/StringExtras.h"
21 //===----------------------------------------------------------------------===//
22 // IntrinsicEmitter Implementation
23 //===----------------------------------------------------------------------===//
25 void IntrinsicEmitter::run(std::ostream &OS) {
26 EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
28 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
30 if (TargetOnly && !Ints.empty())
31 TargetPrefix = Ints[0].TargetPrefix;
33 // Emit the enum information.
34 EmitEnumInfo(Ints, OS);
36 // Emit the intrinsic ID -> name table.
37 EmitIntrinsicToNameTable(Ints, OS);
39 // Emit the function name recognizer.
40 EmitFnNameRecognizer(Ints, OS);
42 // Emit the intrinsic verifier.
43 EmitVerifier(Ints, OS);
45 // Emit the intrinsic declaration generator.
46 EmitGenerator(Ints, OS);
48 // Emit the intrinsic parameter attributes.
49 EmitAttributes(Ints, OS);
51 // Emit a list of intrinsics with corresponding GCC builtins.
52 EmitGCCBuiltinList(Ints, OS);
54 // Emit code to translate GCC builtins into LLVM intrinsics.
55 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
58 void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
60 OS << "// Enum values for Intrinsics.h\n";
61 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
62 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
63 OS << " " << Ints[i].EnumName;
64 OS << ((i != e-1) ? ", " : " ");
65 OS << std::string(40-Ints[i].EnumName.size(), ' ')
66 << "// " << Ints[i].Name << "\n";
71 void IntrinsicEmitter::
72 EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
74 // Build a function name -> intrinsic name mapping.
75 std::map<std::string, unsigned> IntMapping;
76 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
77 IntMapping[Ints[i].Name] = i;
79 OS << "// Function name -> enum value recognizer code.\n";
80 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
81 OS << " switch (Name[5]) {\n";
83 // Emit the intrinsics in sorted order.
85 for (std::map<std::string, unsigned>::iterator I = IntMapping.begin(),
86 E = IntMapping.end(); I != E; ++I) {
87 if (I->first[5] != LastChar) {
88 LastChar = I->first[5];
90 OS << " case '" << LastChar << "':\n";
93 // For overloaded intrinsics, only the prefix needs to match
94 if (Ints[I->second].isOverloaded)
95 OS << " if (Len > " << I->first.size()
96 << " && !memcmp(Name, \"" << I->first << ".\", "
97 << (I->first.size() + 1) << ")) return " << TargetPrefix << "Intrinsic::"
98 << Ints[I->second].EnumName << ";\n";
100 OS << " if (Len == " << I->first.size()
101 << " && !memcmp(Name, \"" << I->first << "\", "
102 << I->first.size() << ")) return " << TargetPrefix << "Intrinsic::"
103 << Ints[I->second].EnumName << ";\n";
109 void IntrinsicEmitter::
110 EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
112 OS << "// Intrinsic ID to name table\n";
113 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
114 OS << " // Note that entry #0 is the invalid intrinsic!\n";
115 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
116 OS << " \"" << Ints[i].Name << "\",\n";
120 static void EmitTypeForValueType(std::ostream &OS, MVT::SimpleValueType VT) {
121 if (MVT(VT).isInteger()) {
122 unsigned BitWidth = MVT(VT).getSizeInBits();
123 OS << "IntegerType::get(" << BitWidth << ")";
124 } else if (VT == MVT::Other) {
125 // MVT::OtherVT is used to mean the empty struct type here.
126 OS << "StructType::get(std::vector<const Type *>())";
127 } else if (VT == MVT::f32) {
128 OS << "Type::FloatTy";
129 } else if (VT == MVT::f64) {
130 OS << "Type::DoubleTy";
131 } else if (VT == MVT::f80) {
132 OS << "Type::X86_FP80Ty";
133 } else if (VT == MVT::f128) {
134 OS << "Type::FP128Ty";
135 } else if (VT == MVT::ppcf128) {
136 OS << "Type::PPC_FP128Ty";
137 } else if (VT == MVT::isVoid) {
138 OS << "Type::VoidTy";
140 assert(false && "Unsupported ValueType!");
144 static void EmitTypeGenerate(std::ostream &OS, const Record *ArgType,
147 static void EmitTypeGenerate(std::ostream &OS,
148 const std::vector<Record*> &ArgTypes,
150 if (ArgTypes.size() == 1) {
151 EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
155 OS << "StructType::get(";
157 for (std::vector<Record*>::const_iterator
158 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
159 EmitTypeGenerate(OS, *I, ArgNo);
166 static void EmitTypeGenerate(std::ostream &OS, const Record *ArgType,
168 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
170 if (ArgType->isSubClassOf("LLVMMatchType")) {
171 unsigned Number = ArgType->getValueAsInt("Number");
172 assert(Number < ArgNo && "Invalid matching number!");
173 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
174 OS << "VectorType::getExtendedElementVectorType"
175 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
176 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
177 OS << "VectorType::getTruncatedElementVectorType"
178 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
180 OS << "Tys[" << Number << "]";
181 } else if (VT == MVT::iAny || VT == MVT::fAny) {
182 // NOTE: The ArgNo variable here is not the absolute argument number, it is
183 // the index of the "arbitrary" type in the Tys array passed to the
184 // Intrinsic::getDeclaration function. Consequently, we only want to
185 // increment it when we actually hit an overloaded type. Getting this wrong
186 // leads to very subtle bugs!
187 OS << "Tys[" << ArgNo++ << "]";
188 } else if (MVT(VT).isVector()) {
190 OS << "VectorType::get(";
191 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT());
192 OS << ", " << VVT.getVectorNumElements() << ")";
193 } else if (VT == MVT::iPTR) {
194 OS << "PointerType::getUnqual(";
195 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
197 } else if (VT == MVT::iPTRAny) {
198 // Make sure the user has passed us an argument type to overload. If not,
199 // treat it as an ordinary (not overloaded) intrinsic.
200 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
201 << "] : PointerType::getUnqual(";
202 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
205 } else if (VT == MVT::isVoid) {
207 OS << "Type::VoidTy";
209 // MVT::isVoid is used to mean varargs here.
212 EmitTypeForValueType(OS, VT);
216 /// RecordListComparator - Provide a determinstic comparator for lists of
219 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
220 struct RecordListComparator {
221 bool operator()(const RecPair &LHS,
222 const RecPair &RHS) const {
224 const std::vector<Record*> *LHSVec = &LHS.first;
225 const std::vector<Record*> *RHSVec = &RHS.first;
226 unsigned RHSSize = RHSVec->size();
227 unsigned LHSSize = LHSVec->size();
230 if (i == RHSSize) return false; // RHS is shorter than LHS.
231 if ((*LHSVec)[i] != (*RHSVec)[i])
232 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
233 } while (++i != LHSSize);
235 if (i != RHSSize) return true;
238 LHSVec = &LHS.second;
239 RHSVec = &RHS.second;
240 RHSSize = RHSVec->size();
241 LHSSize = LHSVec->size();
243 for (i = 0; i != LHSSize; ++i) {
244 if (i == RHSSize) return false; // RHS is shorter than LHS.
245 if ((*LHSVec)[i] != (*RHSVec)[i])
246 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
254 void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
256 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
257 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
258 OS << " switch (ID) {\n";
259 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
261 // This checking can emit a lot of very common code. To reduce the amount of
262 // code that we emit, batch up cases that have identical types. This avoids
263 // problems where GCC can run out of memory compiling Verifier.cpp.
264 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
265 MapTy UniqueArgInfos;
267 // Compute the unique argument type info.
268 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
269 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
270 Ints[i].IS.ParamTypeDefs)].push_back(i);
272 // Loop through the array, emitting one comparison for each batch.
273 for (MapTy::iterator I = UniqueArgInfos.begin(),
274 E = UniqueArgInfos.end(); I != E; ++I) {
275 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
276 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
277 << Ints[I->second[i]].Name << "\n";
279 const RecPair &ArgTypes = I->first;
280 const std::vector<Record*> &RetTys = ArgTypes.first;
281 const std::vector<Record*> &ParamTys = ArgTypes.second;
283 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
286 // Emit return types.
287 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
288 Record *ArgType = RetTys[j];
291 if (ArgType->isSubClassOf("LLVMMatchType")) {
292 unsigned Number = ArgType->getValueAsInt("Number");
293 assert(Number < j && "Invalid matching number!");
294 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
295 OS << "~(ExtendedElementVectorType | " << Number << ")";
296 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
297 OS << "~(TruncatedElementVectorType | " << Number << ")";
301 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
302 OS << getEnumName(VT);
304 if (VT == MVT::isVoid && j != 0 && j != je - 1)
305 throw "Var arg type not last argument";
309 // Emit the parameter types.
310 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
311 Record *ArgType = ParamTys[j];
314 if (ArgType->isSubClassOf("LLVMMatchType")) {
315 unsigned Number = ArgType->getValueAsInt("Number");
316 assert(Number < j + RetTys.size() && "Invalid matching number!");
317 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
318 OS << "~(ExtendedElementVectorType | " << Number << ")";
319 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
320 OS << "~(TruncatedElementVectorType | " << Number << ")";
324 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
325 OS << getEnumName(VT);
327 if (VT == MVT::isVoid && j != 0 && j != je - 1)
328 throw "Var arg type not last argument";
339 void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
341 OS << "// Code for generating Intrinsic function declarations.\n";
342 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
343 OS << " switch (id) {\n";
344 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
346 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
348 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
349 MapTy UniqueArgInfos;
351 // Compute the unique argument type info.
352 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
353 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
354 Ints[i].IS.ParamTypeDefs)].push_back(i);
356 // Loop through the array, emitting one generator for each batch.
357 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
359 for (MapTy::iterator I = UniqueArgInfos.begin(),
360 E = UniqueArgInfos.end(); I != E; ++I) {
361 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
362 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
363 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
365 const RecPair &ArgTypes = I->first;
366 const std::vector<Record*> &RetTys = ArgTypes.first;
367 const std::vector<Record*> &ParamTys = ArgTypes.second;
369 unsigned N = ParamTys.size();
372 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
373 OS << " IsVarArg = true;\n";
378 OS << " ResultTy = ";
379 EmitTypeGenerate(OS, RetTys, ArgNo);
382 for (unsigned j = 0; j != N; ++j) {
383 OS << " ArgTys.push_back(";
384 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
395 /// EmitAttributes - This emits the Intrinsic::getAttributes method.
396 void IntrinsicEmitter::
397 EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS) {
398 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
399 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
401 OS << "static AttrListPtr getAttributes(" << TargetPrefix
402 << "Intrinsic::ID id) {";
404 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
405 OS << " // No intrinsic can throw exceptions.\n";
406 OS << " Attributes Attr = Attribute::NoUnwind;\n";
407 OS << " switch (id) {\n";
408 OS << " default: break;\n";
409 unsigned MaxArgAttrs = 0;
410 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
412 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
413 switch (Ints[i].ModRef) {
415 case CodeGenIntrinsic::NoMem:
416 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
421 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
423 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
424 switch (Ints[i].ModRef) {
426 case CodeGenIntrinsic::ReadArgMem:
427 case CodeGenIntrinsic::ReadMem:
428 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
433 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
436 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
437 OS << " unsigned NumAttrs = 0;\n";
438 OS << " switch (id) {\n";
439 OS << " default: break;\n";
441 // Add argument attributes for any intrinsics that have them.
442 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
443 if (Ints[i].ArgumentAttributes.empty()) continue;
445 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
448 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
449 Ints[i].ArgumentAttributes;
450 // Sort by argument index.
451 std::sort(ArgAttrs.begin(), ArgAttrs.end());
453 unsigned NumArgsWithAttrs = 0;
455 while (!ArgAttrs.empty()) {
456 unsigned ArgNo = ArgAttrs[0].first;
458 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
461 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
462 switch (ArgAttrs[0].second) {
463 default: assert(0 && "Unknown arg attribute");
464 case CodeGenIntrinsic::NoCapture:
465 OS << "|Attribute::NoCapture";
468 ArgAttrs.erase(ArgAttrs.begin());
473 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
478 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
479 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
481 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
484 void IntrinsicEmitter::
485 EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS){
486 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
487 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
488 OS << " switch (F->getIntrinsicID()) {\n";
489 OS << " default: BuiltinName = \"\"; break;\n";
490 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
491 if (!Ints[i].GCCBuiltinName.empty()) {
492 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
493 << Ints[i].GCCBuiltinName << "\"; break;\n";
500 /// EmitBuiltinComparisons - Emit comparisons to determine whether the specified
501 /// sorted range of builtin names is equal to the current builtin. This breaks
502 /// it down into a simple tree.
504 /// At this point, we know that all the builtins in the range have the same name
505 /// for the first 'CharStart' characters. Only the end of the name needs to be
507 typedef std::map<std::string, std::string>::const_iterator StrMapIterator;
508 static void EmitBuiltinComparisons(StrMapIterator Start, StrMapIterator End,
509 unsigned CharStart, unsigned Indent,
510 std::string TargetPrefix, std::ostream &OS) {
511 if (Start == End) return; // empty range.
513 // Determine what, if anything, is the same about all these strings.
514 std::string CommonString = Start->first;
515 unsigned NumInRange = 0;
516 for (StrMapIterator I = Start; I != End; ++I, ++NumInRange) {
517 // Find the first character that doesn't match.
518 const std::string &ThisStr = I->first;
519 unsigned NonMatchChar = CharStart;
520 while (NonMatchChar < CommonString.size() &&
521 NonMatchChar < ThisStr.size() &&
522 CommonString[NonMatchChar] == ThisStr[NonMatchChar])
524 // Truncate off pieces that don't match.
525 CommonString.resize(NonMatchChar);
528 // Just compare the rest of the string.
529 if (NumInRange == 1) {
530 if (CharStart != CommonString.size()) {
531 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
532 if (CharStart) OS << "+" << CharStart;
533 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
534 OS << CommonString.size() - CharStart << "))\n";
537 OS << std::string(Indent*2, ' ') << "IntrinsicID = " << TargetPrefix
539 OS << Start->second << ";\n";
543 // At this point, we potentially have a common prefix for these builtins, emit
544 // a check for this common prefix.
545 if (CommonString.size() != CharStart) {
546 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
547 if (CharStart) OS << "+" << CharStart;
548 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
549 OS << CommonString.size()-CharStart << ")) {\n";
551 EmitBuiltinComparisons(Start, End, CommonString.size(), Indent+1,
553 OS << std::string(Indent*2, ' ') << "}\n";
557 // Output a switch on the character that differs across the set.
558 OS << std::string(Indent*2, ' ') << "switch (BuiltinName[" << CharStart
561 OS << " // \"" << std::string(Start->first.begin(),
562 Start->first.begin()+CharStart) << "\"";
565 for (StrMapIterator I = Start; I != End; ) {
566 char ThisChar = I->first[CharStart];
567 OS << std::string(Indent*2, ' ') << "case '" << ThisChar << "':\n";
568 // Figure out the range that has this common character.
569 StrMapIterator NextChar = I;
570 for (++NextChar; NextChar != End && NextChar->first[CharStart] == ThisChar;
573 EmitBuiltinComparisons(I, NextChar, CharStart+1, Indent+1, TargetPrefix,OS);
574 OS << std::string(Indent*2, ' ') << " break;\n";
577 OS << std::string(Indent*2, ' ') << "}\n";
580 /// EmitTargetBuiltins - All of the builtins in the specified map are for the
581 /// same target, and we already checked it.
582 static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
583 const std::string &TargetPrefix,
585 // Rearrange the builtins by length.
586 std::vector<std::map<std::string, std::string> > BuiltinsByLen;
587 BuiltinsByLen.reserve(100);
589 for (StrMapIterator I = BIM.begin(), E = BIM.end(); I != E; ++I) {
590 if (I->first.size() >= BuiltinsByLen.size())
591 BuiltinsByLen.resize(I->first.size()+1);
592 BuiltinsByLen[I->first.size()].insert(*I);
595 // Now that we have all the builtins by their length, emit a switch stmt.
596 OS << " switch (strlen(BuiltinName)) {\n";
597 OS << " default: break;\n";
598 for (unsigned i = 0, e = BuiltinsByLen.size(); i != e; ++i) {
599 if (BuiltinsByLen[i].empty()) continue;
600 OS << " case " << i << ":\n";
601 EmitBuiltinComparisons(BuiltinsByLen[i].begin(), BuiltinsByLen[i].end(),
602 0, 3, TargetPrefix, OS);
609 void IntrinsicEmitter::
610 EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
612 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
614 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
615 if (!Ints[i].GCCBuiltinName.empty()) {
616 // Get the map for this target prefix.
617 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
619 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
620 Ints[i].EnumName)).second)
621 throw "Intrinsic '" + Ints[i].TheDef->getName() +
622 "': duplicate GCC builtin name!";
626 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
627 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
628 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
629 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
630 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
633 OS << "static " << TargetPrefix << "Intrinsic::ID "
634 << "getIntrinsicForGCCBuiltin(const char "
635 << "*TargetPrefix, const char *BuiltinName) {\n";
636 OS << " " << TargetPrefix << "Intrinsic::ID IntrinsicID = ";
638 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
639 << "*TargetPrefix, const char *BuiltinName) {\n";
640 OS << " Intrinsic::ID IntrinsicID = ";
644 OS << "(" << TargetPrefix<< "Intrinsic::ID)";
646 OS << "Intrinsic::not_intrinsic;\n";
648 // Note: this could emit significantly better code if we cared.
649 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
651 if (!I->first.empty())
652 OS << "if (!strcmp(TargetPrefix, \"" << I->first << "\")) ";
654 OS << "/* Target Independent Builtins */ ";
657 // Emit the comparisons for this target prefix.
658 EmitTargetBuiltins(I->second, TargetPrefix, OS);
661 OS << " return IntrinsicID;\n";