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 "#define setjmp_undefined_for_visual_studio\n"
77 void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
78 OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_visual_studio)\n"
79 "// let's return it to _setjmp state\n"
80 "#define setjmp _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)";
196 assert(false && "Unsupported ValueType!");
200 static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
203 static void EmitTypeGenerate(raw_ostream &OS,
204 const std::vector<Record*> &ArgTypes,
206 if (ArgTypes.empty())
207 return EmitTypeForValueType(OS, MVT::isVoid);
209 if (ArgTypes.size() == 1)
210 return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
212 OS << "StructType::get(Context, ";
214 for (std::vector<Record*>::const_iterator
215 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
216 EmitTypeGenerate(OS, *I, ArgNo);
223 static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
225 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
227 if (ArgType->isSubClassOf("LLVMMatchType")) {
228 unsigned Number = ArgType->getValueAsInt("Number");
229 assert(Number < ArgNo && "Invalid matching number!");
230 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
231 OS << "VectorType::getExtendedElementVectorType"
232 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
233 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
234 OS << "VectorType::getTruncatedElementVectorType"
235 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
237 OS << "Tys[" << Number << "]";
238 } else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny) {
239 // NOTE: The ArgNo variable here is not the absolute argument number, it is
240 // the index of the "arbitrary" type in the Tys array passed to the
241 // Intrinsic::getDeclaration function. Consequently, we only want to
242 // increment it when we actually hit an overloaded type. Getting this wrong
243 // leads to very subtle bugs!
244 OS << "Tys[" << ArgNo++ << "]";
245 } else if (EVT(VT).isVector()) {
247 OS << "VectorType::get(";
248 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy);
249 OS << ", " << VVT.getVectorNumElements() << ")";
250 } else if (VT == MVT::iPTR) {
251 OS << "PointerType::getUnqual(";
252 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
254 } else if (VT == MVT::iPTRAny) {
255 // Make sure the user has passed us an argument type to overload. If not,
256 // treat it as an ordinary (not overloaded) intrinsic.
257 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
258 << "] : PointerType::getUnqual(";
259 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
262 } else if (VT == MVT::isVoid) {
264 OS << "Type::getVoidTy(Context)";
266 // MVT::isVoid is used to mean varargs here.
269 EmitTypeForValueType(OS, VT);
273 /// RecordListComparator - Provide a deterministic comparator for lists of
276 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
277 struct RecordListComparator {
278 bool operator()(const RecPair &LHS,
279 const RecPair &RHS) const {
281 const std::vector<Record*> *LHSVec = &LHS.first;
282 const std::vector<Record*> *RHSVec = &RHS.first;
283 unsigned RHSSize = RHSVec->size();
284 unsigned LHSSize = LHSVec->size();
286 for (; i != LHSSize; ++i) {
287 if (i == RHSSize) return false; // RHS is shorter than LHS.
288 if ((*LHSVec)[i] != (*RHSVec)[i])
289 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
292 if (i != RHSSize) return true;
295 LHSVec = &LHS.second;
296 RHSVec = &RHS.second;
297 RHSSize = RHSVec->size();
298 LHSSize = LHSVec->size();
300 for (i = 0; i != LHSSize; ++i) {
301 if (i == RHSSize) return false; // RHS is shorter than LHS.
302 if ((*LHSVec)[i] != (*RHSVec)[i])
303 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
311 void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
313 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
314 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
315 OS << " switch (ID) {\n";
316 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
318 // This checking can emit a lot of very common code. To reduce the amount of
319 // code that we emit, batch up cases that have identical types. This avoids
320 // problems where GCC can run out of memory compiling Verifier.cpp.
321 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
322 MapTy UniqueArgInfos;
324 // Compute the unique argument type info.
325 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
326 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
327 Ints[i].IS.ParamTypeDefs)].push_back(i);
329 // Loop through the array, emitting one comparison for each batch.
330 for (MapTy::iterator I = UniqueArgInfos.begin(),
331 E = UniqueArgInfos.end(); I != E; ++I) {
332 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
333 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
334 << Ints[I->second[i]].Name << "\n";
336 const RecPair &ArgTypes = I->first;
337 const std::vector<Record*> &RetTys = ArgTypes.first;
338 const std::vector<Record*> &ParamTys = ArgTypes.second;
339 std::vector<unsigned> OverloadedTypeIndices;
341 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
344 // Emit return types.
345 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
346 Record *ArgType = RetTys[j];
349 if (ArgType->isSubClassOf("LLVMMatchType")) {
350 unsigned Number = ArgType->getValueAsInt("Number");
351 assert(Number < OverloadedTypeIndices.size() &&
352 "Invalid matching number!");
353 Number = OverloadedTypeIndices[Number];
354 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
355 OS << "~(ExtendedElementVectorType | " << Number << ")";
356 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
357 OS << "~(TruncatedElementVectorType | " << Number << ")";
361 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
362 OS << getEnumName(VT);
364 if (EVT(VT).isOverloaded())
365 OverloadedTypeIndices.push_back(j);
367 if (VT == MVT::isVoid && j != 0 && j != je - 1)
368 throw "Var arg type not last argument";
372 // Emit the parameter types.
373 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
374 Record *ArgType = ParamTys[j];
377 if (ArgType->isSubClassOf("LLVMMatchType")) {
378 unsigned Number = ArgType->getValueAsInt("Number");
379 assert(Number < OverloadedTypeIndices.size() &&
380 "Invalid matching number!");
381 Number = OverloadedTypeIndices[Number];
382 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
383 OS << "~(ExtendedElementVectorType | " << Number << ")";
384 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
385 OS << "~(TruncatedElementVectorType | " << Number << ")";
389 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
390 OS << getEnumName(VT);
392 if (EVT(VT).isOverloaded())
393 OverloadedTypeIndices.push_back(j + RetTys.size());
395 if (VT == MVT::isVoid && j != 0 && j != je - 1)
396 throw "Var arg type not last argument";
407 void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
409 OS << "// Code for generating Intrinsic function declarations.\n";
410 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
411 OS << " switch (id) {\n";
412 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
414 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
416 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
417 MapTy UniqueArgInfos;
419 // Compute the unique argument type info.
420 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
421 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
422 Ints[i].IS.ParamTypeDefs)].push_back(i);
424 // Loop through the array, emitting one generator for each batch.
425 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
427 for (MapTy::iterator I = UniqueArgInfos.begin(),
428 E = UniqueArgInfos.end(); I != E; ++I) {
429 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
430 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
431 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
433 const RecPair &ArgTypes = I->first;
434 const std::vector<Record*> &RetTys = ArgTypes.first;
435 const std::vector<Record*> &ParamTys = ArgTypes.second;
437 unsigned N = ParamTys.size();
440 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
441 OS << " IsVarArg = true;\n";
446 OS << " ResultTy = ";
447 EmitTypeGenerate(OS, RetTys, ArgNo);
450 for (unsigned j = 0; j != N; ++j) {
451 OS << " ArgTys.push_back(";
452 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
463 /// EmitAttributes - This emits the Intrinsic::getAttributes method.
464 void IntrinsicEmitter::
465 EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
466 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
467 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
469 OS << "static AttrListPtr getAttributes(" << TargetPrefix
470 << "Intrinsic::ID id) {";
472 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
473 OS << " // No intrinsic can throw exceptions.\n";
474 OS << " Attributes Attr = Attribute::NoUnwind;\n";
475 OS << " switch (id) {\n";
476 OS << " default: break;\n";
477 unsigned MaxArgAttrs = 0;
478 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
480 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
481 switch (Ints[i].ModRef) {
483 case CodeGenIntrinsic::NoMem:
484 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
489 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
491 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
492 switch (Ints[i].ModRef) {
494 case CodeGenIntrinsic::ReadArgMem:
495 case CodeGenIntrinsic::ReadMem:
496 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
501 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
504 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
505 OS << " unsigned NumAttrs = 0;\n";
506 OS << " switch (id) {\n";
507 OS << " default: break;\n";
509 // Add argument attributes for any intrinsics that have them.
510 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
511 if (Ints[i].ArgumentAttributes.empty()) continue;
513 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
516 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
517 Ints[i].ArgumentAttributes;
518 // Sort by argument index.
519 std::sort(ArgAttrs.begin(), ArgAttrs.end());
521 unsigned NumArgsWithAttrs = 0;
523 while (!ArgAttrs.empty()) {
524 unsigned ArgNo = ArgAttrs[0].first;
526 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
529 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
530 switch (ArgAttrs[0].second) {
531 default: assert(0 && "Unknown arg attribute");
532 case CodeGenIntrinsic::NoCapture:
533 OS << "|Attribute::NoCapture";
536 ArgAttrs.erase(ArgAttrs.begin());
541 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
546 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
547 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
549 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
552 /// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
553 void IntrinsicEmitter::
554 EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
555 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
556 OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
557 OS << "switch (iid) {\n";
558 OS << "default:\n return UnknownModRefBehavior;\n";
559 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
560 if (Ints[i].ModRef == CodeGenIntrinsic::ReadWriteMem)
562 OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
564 switch (Ints[i].ModRef) {
566 assert(false && "Unknown Mod/Ref type!");
567 case CodeGenIntrinsic::NoMem:
568 OS << " return DoesNotAccessMemory;\n";
570 case CodeGenIntrinsic::ReadArgMem:
571 case CodeGenIntrinsic::ReadMem:
572 OS << " return OnlyReadsMemory;\n";
574 case CodeGenIntrinsic::ReadWriteArgMem:
575 OS << " return AccessesArguments;\n";
580 OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
583 void IntrinsicEmitter::
584 EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
585 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
586 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
587 OS << " switch (F->getIntrinsicID()) {\n";
588 OS << " default: BuiltinName = \"\"; break;\n";
589 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
590 if (!Ints[i].GCCBuiltinName.empty()) {
591 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
592 << Ints[i].GCCBuiltinName << "\"; break;\n";
599 /// EmitTargetBuiltins - All of the builtins in the specified map are for the
600 /// same target, and we already checked it.
601 static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
602 const std::string &TargetPrefix,
605 std::vector<StringMatcher::StringPair> Results;
607 for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
608 E = BIM.end(); I != E; ++I) {
609 std::string ResultCode =
610 "return " + TargetPrefix + "Intrinsic::" + I->second + ";";
611 Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
614 StringMatcher("BuiltinName", Results, OS).Emit();
618 void IntrinsicEmitter::
619 EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
621 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
623 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
624 if (!Ints[i].GCCBuiltinName.empty()) {
625 // Get the map for this target prefix.
626 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
628 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
629 Ints[i].EnumName)).second)
630 throw "Intrinsic '" + Ints[i].TheDef->getName() +
631 "': duplicate GCC builtin name!";
635 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
636 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
637 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
638 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
639 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
642 OS << "static " << TargetPrefix << "Intrinsic::ID "
643 << "getIntrinsicForGCCBuiltin(const char "
644 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
646 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
647 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
650 OS << " StringRef BuiltinName(BuiltinNameStr);\n";
651 OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
653 // Note: this could emit significantly better code if we cared.
654 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
656 if (!I->first.empty())
657 OS << "if (TargetPrefix == \"" << I->first << "\") ";
659 OS << "/* Target Independent Builtins */ ";
662 // Emit the comparisons for this target prefix.
663 EmitTargetBuiltins(I->second, TargetPrefix, OS);
667 if (!TargetPrefix.empty())
668 OS << "(" << TargetPrefix << "Intrinsic::ID)";
669 OS << "Intrinsic::not_intrinsic;\n";