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 "StringMatcher.h"
18 #include "llvm/ADT/StringExtras.h"
22 //===----------------------------------------------------------------------===//
23 // IntrinsicEmitter Implementation
24 //===----------------------------------------------------------------------===//
26 void IntrinsicEmitter::run(raw_ostream &OS) {
27 EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
29 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
31 if (TargetOnly && !Ints.empty())
32 TargetPrefix = Ints[0].TargetPrefix;
36 // Emit the enum information.
37 EmitEnumInfo(Ints, OS);
39 // Emit the intrinsic ID -> name table.
40 EmitIntrinsicToNameTable(Ints, OS);
42 // Emit the intrinsic ID -> overload table.
43 EmitIntrinsicToOverloadTable(Ints, OS);
45 // Emit the function name recognizer.
46 EmitFnNameRecognizer(Ints, OS);
48 // Emit the intrinsic verifier.
49 EmitVerifier(Ints, OS);
51 // Emit the intrinsic declaration generator.
52 EmitGenerator(Ints, OS);
54 // Emit the intrinsic parameter attributes.
55 EmitAttributes(Ints, OS);
57 // Emit intrinsic alias analysis mod/ref behavior.
58 EmitModRefBehavior(Ints, OS);
60 // Emit a list of intrinsics with corresponding GCC builtins.
61 EmitGCCBuiltinList(Ints, OS);
63 // Emit code to translate GCC builtins into LLVM intrinsics.
64 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
69 void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
70 OS << "// VisualStudio defines setjmp as _setjmp\n"
71 "#if defined(_MSC_VER) && defined(setjmp)\n"
72 "# pragma push_macro(\"setjmp\")\n"
77 void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
78 OS << "#if defined(_MSC_VER)\n"
79 "// let's return it to _setjmp state\n"
80 "# pragma pop_macro(\"setjmp\")\n"
84 void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
86 OS << "// Enum values for Intrinsics.h\n";
87 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
88 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
89 OS << " " << Ints[i].EnumName;
90 OS << ((i != e-1) ? ", " : " ");
91 OS << std::string(40-Ints[i].EnumName.size(), ' ')
92 << "// " << Ints[i].Name << "\n";
97 void IntrinsicEmitter::
98 EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
100 // Build a 'first character of function name' -> intrinsic # mapping.
101 std::map<char, std::vector<unsigned> > IntMapping;
102 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
103 IntMapping[Ints[i].Name[5]].push_back(i);
105 OS << "// Function name -> enum value recognizer code.\n";
106 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
107 OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
108 OS << " switch (Name[5]) { // Dispatch on first letter.\n";
109 OS << " default: break;\n";
110 // Emit the intrinsic matching stuff by first letter.
111 for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
112 E = IntMapping.end(); I != E; ++I) {
113 OS << " case '" << I->first << "':\n";
114 std::vector<unsigned> &IntList = I->second;
116 // Emit all the overloaded intrinsics first, build a table of the
117 // non-overloaded ones.
118 std::vector<StringMatcher::StringPair> MatchTable;
120 for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
121 unsigned IntNo = IntList[i];
122 std::string Result = "return " + TargetPrefix + "Intrinsic::" +
123 Ints[IntNo].EnumName + ";";
125 if (!Ints[IntNo].isOverloaded) {
126 MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
130 // For overloaded intrinsics, only the prefix needs to match
131 std::string TheStr = Ints[IntNo].Name.substr(6);
132 TheStr += '.'; // Require "bswap." instead of bswap.
133 OS << " if (NameR.startswith(\"" << TheStr << "\")) "
137 // Emit the matcher logic for the fixed length strings.
138 StringMatcher("NameR", MatchTable, OS).Emit(1);
139 OS << " break; // end of '" << I->first << "' case.\n";
146 void IntrinsicEmitter::
147 EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
149 OS << "// Intrinsic ID to name table\n";
150 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
151 OS << " // Note that entry #0 is the invalid intrinsic!\n";
152 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
153 OS << " \"" << Ints[i].Name << "\",\n";
157 void IntrinsicEmitter::
158 EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
160 OS << "// Intrinsic ID to overload table\n";
161 OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
162 OS << " // Note that entry #0 is the invalid intrinsic!\n";
163 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
165 if (Ints[i].isOverloaded)
174 static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) {
175 if (EVT(VT).isInteger()) {
176 unsigned BitWidth = EVT(VT).getSizeInBits();
177 OS << "IntegerType::get(Context, " << BitWidth << ")";
178 } else if (VT == MVT::Other) {
179 // MVT::OtherVT is used to mean the empty struct type here.
180 OS << "StructType::get(Context)";
181 } else if (VT == MVT::f32) {
182 OS << "Type::getFloatTy(Context)";
183 } else if (VT == MVT::f64) {
184 OS << "Type::getDoubleTy(Context)";
185 } else if (VT == MVT::f80) {
186 OS << "Type::getX86_FP80Ty(Context)";
187 } else if (VT == MVT::f128) {
188 OS << "Type::getFP128Ty(Context)";
189 } else if (VT == MVT::ppcf128) {
190 OS << "Type::getPPC_FP128Ty(Context)";
191 } else if (VT == MVT::isVoid) {
192 OS << "Type::getVoidTy(Context)";
193 } else if (VT == MVT::Metadata) {
194 OS << "Type::getMetadataTy(Context)";
195 } else if (VT == MVT::x86mmx) {
196 OS << "Type::getX86_MMXTy(Context)";
198 assert(false && "Unsupported ValueType!");
202 static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
205 static void EmitTypeGenerate(raw_ostream &OS,
206 const std::vector<Record*> &ArgTypes,
208 if (ArgTypes.empty())
209 return EmitTypeForValueType(OS, MVT::isVoid);
211 if (ArgTypes.size() == 1)
212 return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
214 OS << "StructType::get(Context, ";
216 for (std::vector<Record*>::const_iterator
217 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
218 EmitTypeGenerate(OS, *I, ArgNo);
225 static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
227 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
229 if (ArgType->isSubClassOf("LLVMMatchType")) {
230 unsigned Number = ArgType->getValueAsInt("Number");
231 assert(Number < ArgNo && "Invalid matching number!");
232 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
233 OS << "VectorType::getExtendedElementVectorType"
234 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
235 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
236 OS << "VectorType::getTruncatedElementVectorType"
237 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
239 OS << "Tys[" << Number << "]";
240 } else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny) {
241 // NOTE: The ArgNo variable here is not the absolute argument number, it is
242 // the index of the "arbitrary" type in the Tys array passed to the
243 // Intrinsic::getDeclaration function. Consequently, we only want to
244 // increment it when we actually hit an overloaded type. Getting this wrong
245 // leads to very subtle bugs!
246 OS << "Tys[" << ArgNo++ << "]";
247 } else if (EVT(VT).isVector()) {
249 OS << "VectorType::get(";
250 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy);
251 OS << ", " << VVT.getVectorNumElements() << ")";
252 } else if (VT == MVT::iPTR) {
253 OS << "PointerType::getUnqual(";
254 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
256 } else if (VT == MVT::iPTRAny) {
257 // Make sure the user has passed us an argument type to overload. If not,
258 // treat it as an ordinary (not overloaded) intrinsic.
259 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
260 << "] : PointerType::getUnqual(";
261 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
264 } else if (VT == MVT::isVoid) {
266 OS << "Type::getVoidTy(Context)";
268 // MVT::isVoid is used to mean varargs here.
271 EmitTypeForValueType(OS, VT);
275 /// RecordListComparator - Provide a deterministic comparator for lists of
278 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
279 struct RecordListComparator {
280 bool operator()(const RecPair &LHS,
281 const RecPair &RHS) const {
283 const std::vector<Record*> *LHSVec = &LHS.first;
284 const std::vector<Record*> *RHSVec = &RHS.first;
285 unsigned RHSSize = RHSVec->size();
286 unsigned LHSSize = LHSVec->size();
288 for (; i != LHSSize; ++i) {
289 if (i == RHSSize) return false; // RHS is shorter than LHS.
290 if ((*LHSVec)[i] != (*RHSVec)[i])
291 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
294 if (i != RHSSize) return true;
297 LHSVec = &LHS.second;
298 RHSVec = &RHS.second;
299 RHSSize = RHSVec->size();
300 LHSSize = LHSVec->size();
302 for (i = 0; i != LHSSize; ++i) {
303 if (i == RHSSize) return false; // RHS is shorter than LHS.
304 if ((*LHSVec)[i] != (*RHSVec)[i])
305 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
313 void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
315 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
316 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
317 OS << " switch (ID) {\n";
318 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
320 // This checking can emit a lot of very common code. To reduce the amount of
321 // code that we emit, batch up cases that have identical types. This avoids
322 // problems where GCC can run out of memory compiling Verifier.cpp.
323 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
324 MapTy UniqueArgInfos;
326 // Compute the unique argument type info.
327 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
328 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
329 Ints[i].IS.ParamTypeDefs)].push_back(i);
331 // Loop through the array, emitting one comparison for each batch.
332 for (MapTy::iterator I = UniqueArgInfos.begin(),
333 E = UniqueArgInfos.end(); I != E; ++I) {
334 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
335 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
336 << Ints[I->second[i]].Name << "\n";
338 const RecPair &ArgTypes = I->first;
339 const std::vector<Record*> &RetTys = ArgTypes.first;
340 const std::vector<Record*> &ParamTys = ArgTypes.second;
341 std::vector<unsigned> OverloadedTypeIndices;
343 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
346 // Emit return types.
347 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
348 Record *ArgType = RetTys[j];
351 if (ArgType->isSubClassOf("LLVMMatchType")) {
352 unsigned Number = ArgType->getValueAsInt("Number");
353 assert(Number < OverloadedTypeIndices.size() &&
354 "Invalid matching number!");
355 Number = OverloadedTypeIndices[Number];
356 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
357 OS << "~(ExtendedElementVectorType | " << Number << ")";
358 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
359 OS << "~(TruncatedElementVectorType | " << Number << ")";
363 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
364 OS << getEnumName(VT);
366 if (EVT(VT).isOverloaded())
367 OverloadedTypeIndices.push_back(j);
369 if (VT == MVT::isVoid && j != 0 && j != je - 1)
370 throw "Var arg type not last argument";
374 // Emit the parameter types.
375 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
376 Record *ArgType = ParamTys[j];
379 if (ArgType->isSubClassOf("LLVMMatchType")) {
380 unsigned Number = ArgType->getValueAsInt("Number");
381 assert(Number < OverloadedTypeIndices.size() &&
382 "Invalid matching number!");
383 Number = OverloadedTypeIndices[Number];
384 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
385 OS << "~(ExtendedElementVectorType | " << Number << ")";
386 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
387 OS << "~(TruncatedElementVectorType | " << Number << ")";
391 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
392 OS << getEnumName(VT);
394 if (EVT(VT).isOverloaded())
395 OverloadedTypeIndices.push_back(j + RetTys.size());
397 if (VT == MVT::isVoid && j != 0 && j != je - 1)
398 throw "Var arg type not last argument";
409 void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
411 OS << "// Code for generating Intrinsic function declarations.\n";
412 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
413 OS << " switch (id) {\n";
414 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
416 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
418 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
419 MapTy UniqueArgInfos;
421 // Compute the unique argument type info.
422 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
423 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
424 Ints[i].IS.ParamTypeDefs)].push_back(i);
426 // Loop through the array, emitting one generator for each batch.
427 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
429 for (MapTy::iterator I = UniqueArgInfos.begin(),
430 E = UniqueArgInfos.end(); I != E; ++I) {
431 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
432 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
433 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
435 const RecPair &ArgTypes = I->first;
436 const std::vector<Record*> &RetTys = ArgTypes.first;
437 const std::vector<Record*> &ParamTys = ArgTypes.second;
439 unsigned N = ParamTys.size();
442 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
443 OS << " IsVarArg = true;\n";
448 OS << " ResultTy = ";
449 EmitTypeGenerate(OS, RetTys, ArgNo);
452 for (unsigned j = 0; j != N; ++j) {
453 OS << " ArgTys.push_back(";
454 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
465 /// EmitAttributes - This emits the Intrinsic::getAttributes method.
466 void IntrinsicEmitter::
467 EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
468 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
469 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
471 OS << "static AttrListPtr getAttributes(" << TargetPrefix
472 << "Intrinsic::ID id) {";
474 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
475 OS << " // No intrinsic can throw exceptions.\n";
476 OS << " Attributes Attr = Attribute::NoUnwind;\n";
477 OS << " switch (id) {\n";
478 OS << " default: break;\n";
479 unsigned MaxArgAttrs = 0;
480 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
482 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
483 switch (Ints[i].ModRef) {
485 case CodeGenIntrinsic::NoMem:
486 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
491 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
493 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
494 switch (Ints[i].ModRef) {
496 case CodeGenIntrinsic::ReadArgMem:
497 case CodeGenIntrinsic::ReadMem:
498 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
503 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
506 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
507 OS << " unsigned NumAttrs = 0;\n";
508 OS << " switch (id) {\n";
509 OS << " default: break;\n";
511 // Add argument attributes for any intrinsics that have them.
512 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
513 if (Ints[i].ArgumentAttributes.empty()) continue;
515 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
518 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
519 Ints[i].ArgumentAttributes;
520 // Sort by argument index.
521 std::sort(ArgAttrs.begin(), ArgAttrs.end());
523 unsigned NumArgsWithAttrs = 0;
525 while (!ArgAttrs.empty()) {
526 unsigned ArgNo = ArgAttrs[0].first;
528 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
531 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
532 switch (ArgAttrs[0].second) {
533 default: assert(0 && "Unknown arg attribute");
534 case CodeGenIntrinsic::NoCapture:
535 OS << "|Attribute::NoCapture";
538 ArgAttrs.erase(ArgAttrs.begin());
543 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
548 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
549 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
551 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
554 /// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
555 void IntrinsicEmitter::
556 EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
557 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
558 OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
559 OS << "switch (iid) {\n";
560 OS << "default:\n return UnknownModRefBehavior;\n";
561 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
562 if (Ints[i].ModRef == CodeGenIntrinsic::ReadWriteMem)
564 OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
566 switch (Ints[i].ModRef) {
568 assert(false && "Unknown Mod/Ref type!");
569 case CodeGenIntrinsic::NoMem:
570 OS << " return DoesNotAccessMemory;\n";
572 case CodeGenIntrinsic::ReadArgMem:
573 case CodeGenIntrinsic::ReadMem:
574 OS << " return OnlyReadsMemory;\n";
576 case CodeGenIntrinsic::ReadWriteArgMem:
577 OS << " return AccessesArguments;\n";
582 OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
585 void IntrinsicEmitter::
586 EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
587 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
588 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
589 OS << " switch (F->getIntrinsicID()) {\n";
590 OS << " default: BuiltinName = \"\"; break;\n";
591 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
592 if (!Ints[i].GCCBuiltinName.empty()) {
593 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
594 << Ints[i].GCCBuiltinName << "\"; break;\n";
601 /// EmitTargetBuiltins - All of the builtins in the specified map are for the
602 /// same target, and we already checked it.
603 static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
604 const std::string &TargetPrefix,
607 std::vector<StringMatcher::StringPair> Results;
609 for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
610 E = BIM.end(); I != E; ++I) {
611 std::string ResultCode =
612 "return " + TargetPrefix + "Intrinsic::" + I->second + ";";
613 Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
616 StringMatcher("BuiltinName", Results, OS).Emit();
620 void IntrinsicEmitter::
621 EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
623 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
625 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
626 if (!Ints[i].GCCBuiltinName.empty()) {
627 // Get the map for this target prefix.
628 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
630 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
631 Ints[i].EnumName)).second)
632 throw "Intrinsic '" + Ints[i].TheDef->getName() +
633 "': duplicate GCC builtin name!";
637 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
638 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
639 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
640 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
641 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
644 OS << "static " << TargetPrefix << "Intrinsic::ID "
645 << "getIntrinsicForGCCBuiltin(const char "
646 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
648 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
649 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
652 OS << " StringRef BuiltinName(BuiltinNameStr);\n";
653 OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
655 // Note: this could emit significantly better code if we cared.
656 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
658 if (!I->first.empty())
659 OS << "if (TargetPrefix == \"" << I->first << "\") ";
661 OS << "/* Target Independent Builtins */ ";
664 // Emit the comparisons for this target prefix.
665 EmitTargetBuiltins(I->second, TargetPrefix, OS);
669 if (!TargetPrefix.empty())
670 OS << "(" << TargetPrefix << "Intrinsic::ID)";
671 OS << "Intrinsic::not_intrinsic;\n";