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 intrinsic alias analysis mod/ref behavior.
52 EmitModRefBehavior(Ints, OS);
54 // Emit a list of intrinsics with corresponding GCC builtins.
55 EmitGCCBuiltinList(Ints, OS);
57 // Emit code to translate GCC builtins into LLVM intrinsics.
58 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
61 void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
63 OS << "// Enum values for Intrinsics.h\n";
64 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
65 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
66 OS << " " << Ints[i].EnumName;
67 OS << ((i != e-1) ? ", " : " ");
68 OS << std::string(40-Ints[i].EnumName.size(), ' ')
69 << "// " << Ints[i].Name << "\n";
74 void IntrinsicEmitter::
75 EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
77 // Build a function name -> intrinsic name mapping.
78 std::map<std::string, unsigned> IntMapping;
79 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
80 IntMapping[Ints[i].Name] = i;
82 OS << "// Function name -> enum value recognizer code.\n";
83 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
84 OS << " switch (Name[5]) {\n";
86 // Emit the intrinsics in sorted order.
88 for (std::map<std::string, unsigned>::iterator I = IntMapping.begin(),
89 E = IntMapping.end(); I != E; ++I) {
90 if (I->first[5] != LastChar) {
91 LastChar = I->first[5];
93 OS << " case '" << LastChar << "':\n";
96 // For overloaded intrinsics, only the prefix needs to match
97 if (Ints[I->second].isOverloaded)
98 OS << " if (Len > " << I->first.size()
99 << " && !memcmp(Name, \"" << I->first << ".\", "
100 << (I->first.size() + 1) << ")) return " << TargetPrefix << "Intrinsic::"
101 << Ints[I->second].EnumName << ";\n";
103 OS << " if (Len == " << I->first.size()
104 << " && !memcmp(Name, \"" << I->first << "\", "
105 << I->first.size() << ")) return " << TargetPrefix << "Intrinsic::"
106 << Ints[I->second].EnumName << ";\n";
112 void IntrinsicEmitter::
113 EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
115 OS << "// Intrinsic ID to name table\n";
116 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
117 OS << " // Note that entry #0 is the invalid intrinsic!\n";
118 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
119 OS << " \"" << Ints[i].Name << "\",\n";
123 static void EmitTypeForValueType(std::ostream &OS, MVT::SimpleValueType VT) {
124 if (MVT(VT).isInteger()) {
125 unsigned BitWidth = MVT(VT).getSizeInBits();
126 OS << "IntegerType::get(" << BitWidth << ")";
127 } else if (VT == MVT::Other) {
128 // MVT::OtherVT is used to mean the empty struct type here.
129 OS << "StructType::get(std::vector<const Type *>())";
130 } else if (VT == MVT::f32) {
131 OS << "Type::FloatTy";
132 } else if (VT == MVT::f64) {
133 OS << "Type::DoubleTy";
134 } else if (VT == MVT::f80) {
135 OS << "Type::X86_FP80Ty";
136 } else if (VT == MVT::f128) {
137 OS << "Type::FP128Ty";
138 } else if (VT == MVT::ppcf128) {
139 OS << "Type::PPC_FP128Ty";
140 } else if (VT == MVT::isVoid) {
141 OS << "Type::VoidTy";
143 assert(false && "Unsupported ValueType!");
147 static void EmitTypeGenerate(std::ostream &OS, const Record *ArgType,
150 static void EmitTypeGenerate(std::ostream &OS,
151 const std::vector<Record*> &ArgTypes,
153 if (ArgTypes.size() == 1) {
154 EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
158 OS << "StructType::get(";
160 for (std::vector<Record*>::const_iterator
161 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
162 EmitTypeGenerate(OS, *I, ArgNo);
169 static void EmitTypeGenerate(std::ostream &OS, const Record *ArgType,
171 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
173 if (ArgType->isSubClassOf("LLVMMatchType")) {
174 unsigned Number = ArgType->getValueAsInt("Number");
175 assert(Number < ArgNo && "Invalid matching number!");
176 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
177 OS << "VectorType::getExtendedElementVectorType"
178 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
179 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
180 OS << "VectorType::getTruncatedElementVectorType"
181 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
183 OS << "Tys[" << Number << "]";
184 } else if (VT == MVT::iAny || VT == MVT::fAny) {
185 // NOTE: The ArgNo variable here is not the absolute argument number, it is
186 // the index of the "arbitrary" type in the Tys array passed to the
187 // Intrinsic::getDeclaration function. Consequently, we only want to
188 // increment it when we actually hit an overloaded type. Getting this wrong
189 // leads to very subtle bugs!
190 OS << "Tys[" << ArgNo++ << "]";
191 } else if (MVT(VT).isVector()) {
193 OS << "VectorType::get(";
194 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT());
195 OS << ", " << VVT.getVectorNumElements() << ")";
196 } else if (VT == MVT::iPTR) {
197 OS << "PointerType::getUnqual(";
198 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
200 } else if (VT == MVT::iPTRAny) {
201 // Make sure the user has passed us an argument type to overload. If not,
202 // treat it as an ordinary (not overloaded) intrinsic.
203 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
204 << "] : PointerType::getUnqual(";
205 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
208 } else if (VT == MVT::isVoid) {
210 OS << "Type::VoidTy";
212 // MVT::isVoid is used to mean varargs here.
215 EmitTypeForValueType(OS, VT);
219 /// RecordListComparator - Provide a determinstic comparator for lists of
222 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
223 struct RecordListComparator {
224 bool operator()(const RecPair &LHS,
225 const RecPair &RHS) const {
227 const std::vector<Record*> *LHSVec = &LHS.first;
228 const std::vector<Record*> *RHSVec = &RHS.first;
229 unsigned RHSSize = RHSVec->size();
230 unsigned LHSSize = LHSVec->size();
233 if (i == RHSSize) return false; // RHS is shorter than LHS.
234 if ((*LHSVec)[i] != (*RHSVec)[i])
235 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
236 } while (++i != LHSSize);
238 if (i != RHSSize) return true;
241 LHSVec = &LHS.second;
242 RHSVec = &RHS.second;
243 RHSSize = RHSVec->size();
244 LHSSize = LHSVec->size();
246 for (i = 0; i != LHSSize; ++i) {
247 if (i == RHSSize) return false; // RHS is shorter than LHS.
248 if ((*LHSVec)[i] != (*RHSVec)[i])
249 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
257 void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
259 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
260 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
261 OS << " switch (ID) {\n";
262 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
264 // This checking can emit a lot of very common code. To reduce the amount of
265 // code that we emit, batch up cases that have identical types. This avoids
266 // problems where GCC can run out of memory compiling Verifier.cpp.
267 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
268 MapTy UniqueArgInfos;
270 // Compute the unique argument type info.
271 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
272 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
273 Ints[i].IS.ParamTypeDefs)].push_back(i);
275 // Loop through the array, emitting one comparison for each batch.
276 for (MapTy::iterator I = UniqueArgInfos.begin(),
277 E = UniqueArgInfos.end(); I != E; ++I) {
278 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
279 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
280 << Ints[I->second[i]].Name << "\n";
282 const RecPair &ArgTypes = I->first;
283 const std::vector<Record*> &RetTys = ArgTypes.first;
284 const std::vector<Record*> &ParamTys = ArgTypes.second;
286 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
289 // Emit return types.
290 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
291 Record *ArgType = RetTys[j];
294 if (ArgType->isSubClassOf("LLVMMatchType")) {
295 unsigned Number = ArgType->getValueAsInt("Number");
296 assert(Number < j && "Invalid matching number!");
297 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
298 OS << "~(ExtendedElementVectorType | " << Number << ")";
299 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
300 OS << "~(TruncatedElementVectorType | " << Number << ")";
304 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
305 OS << getEnumName(VT);
307 if (VT == MVT::isVoid && j != 0 && j != je - 1)
308 throw "Var arg type not last argument";
312 // Emit the parameter types.
313 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
314 Record *ArgType = ParamTys[j];
317 if (ArgType->isSubClassOf("LLVMMatchType")) {
318 unsigned Number = ArgType->getValueAsInt("Number");
319 assert(Number < j + RetTys.size() && "Invalid matching number!");
320 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
321 OS << "~(ExtendedElementVectorType | " << Number << ")";
322 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
323 OS << "~(TruncatedElementVectorType | " << Number << ")";
327 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
328 OS << getEnumName(VT);
330 if (VT == MVT::isVoid && j != 0 && j != je - 1)
331 throw "Var arg type not last argument";
342 void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
344 OS << "// Code for generating Intrinsic function declarations.\n";
345 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
346 OS << " switch (id) {\n";
347 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
349 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
351 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
352 MapTy UniqueArgInfos;
354 // Compute the unique argument type info.
355 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
356 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
357 Ints[i].IS.ParamTypeDefs)].push_back(i);
359 // Loop through the array, emitting one generator for each batch.
360 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
362 for (MapTy::iterator I = UniqueArgInfos.begin(),
363 E = UniqueArgInfos.end(); I != E; ++I) {
364 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
365 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
366 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
368 const RecPair &ArgTypes = I->first;
369 const std::vector<Record*> &RetTys = ArgTypes.first;
370 const std::vector<Record*> &ParamTys = ArgTypes.second;
372 unsigned N = ParamTys.size();
375 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
376 OS << " IsVarArg = true;\n";
381 OS << " ResultTy = ";
382 EmitTypeGenerate(OS, RetTys, ArgNo);
385 for (unsigned j = 0; j != N; ++j) {
386 OS << " ArgTys.push_back(";
387 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
398 /// EmitAttributes - This emits the Intrinsic::getAttributes method.
399 void IntrinsicEmitter::
400 EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS) {
401 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
402 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
404 OS << "static AttrListPtr getAttributes(" << TargetPrefix
405 << "Intrinsic::ID id) {";
407 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
408 OS << " // No intrinsic can throw exceptions.\n";
409 OS << " Attributes Attr = Attribute::NoUnwind;\n";
410 OS << " switch (id) {\n";
411 OS << " default: break;\n";
412 unsigned MaxArgAttrs = 0;
413 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
415 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
416 switch (Ints[i].ModRef) {
418 case CodeGenIntrinsic::NoMem:
419 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
424 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
426 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
427 switch (Ints[i].ModRef) {
429 case CodeGenIntrinsic::ReadArgMem:
430 case CodeGenIntrinsic::ReadMem:
431 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
436 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
439 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
440 OS << " unsigned NumAttrs = 0;\n";
441 OS << " switch (id) {\n";
442 OS << " default: break;\n";
444 // Add argument attributes for any intrinsics that have them.
445 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
446 if (Ints[i].ArgumentAttributes.empty()) continue;
448 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
451 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
452 Ints[i].ArgumentAttributes;
453 // Sort by argument index.
454 std::sort(ArgAttrs.begin(), ArgAttrs.end());
456 unsigned NumArgsWithAttrs = 0;
458 while (!ArgAttrs.empty()) {
459 unsigned ArgNo = ArgAttrs[0].first;
461 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
464 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
465 switch (ArgAttrs[0].second) {
466 default: assert(0 && "Unknown arg attribute");
467 case CodeGenIntrinsic::NoCapture:
468 OS << "|Attribute::NoCapture";
471 ArgAttrs.erase(ArgAttrs.begin());
476 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
481 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
482 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
484 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
487 /// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
488 void IntrinsicEmitter::
489 EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS){
490 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
491 OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
492 OS << "switch (id) {\n";
493 OS << "default:\n return UnknownModRefBehavior;\n";
494 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
495 if (Ints[i].ModRef == CodeGenIntrinsic::WriteMem)
497 OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
499 switch (Ints[i].ModRef) {
501 assert(false && "Unknown Mod/Ref type!");
502 case CodeGenIntrinsic::NoMem:
503 OS << " return DoesNotAccessMemory;\n";
505 case CodeGenIntrinsic::ReadArgMem:
506 case CodeGenIntrinsic::ReadMem:
507 OS << " return OnlyReadsMemory;\n";
509 case CodeGenIntrinsic::WriteArgMem:
510 OS << " return AccessesArguments;\n";
515 OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
518 void IntrinsicEmitter::
519 EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, std::ostream &OS){
520 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
521 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
522 OS << " switch (F->getIntrinsicID()) {\n";
523 OS << " default: BuiltinName = \"\"; break;\n";
524 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
525 if (!Ints[i].GCCBuiltinName.empty()) {
526 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
527 << Ints[i].GCCBuiltinName << "\"; break;\n";
534 /// EmitBuiltinComparisons - Emit comparisons to determine whether the specified
535 /// sorted range of builtin names is equal to the current builtin. This breaks
536 /// it down into a simple tree.
538 /// At this point, we know that all the builtins in the range have the same name
539 /// for the first 'CharStart' characters. Only the end of the name needs to be
541 typedef std::map<std::string, std::string>::const_iterator StrMapIterator;
542 static void EmitBuiltinComparisons(StrMapIterator Start, StrMapIterator End,
543 unsigned CharStart, unsigned Indent,
544 std::string TargetPrefix, std::ostream &OS) {
545 if (Start == End) return; // empty range.
547 // Determine what, if anything, is the same about all these strings.
548 std::string CommonString = Start->first;
549 unsigned NumInRange = 0;
550 for (StrMapIterator I = Start; I != End; ++I, ++NumInRange) {
551 // Find the first character that doesn't match.
552 const std::string &ThisStr = I->first;
553 unsigned NonMatchChar = CharStart;
554 while (NonMatchChar < CommonString.size() &&
555 NonMatchChar < ThisStr.size() &&
556 CommonString[NonMatchChar] == ThisStr[NonMatchChar])
558 // Truncate off pieces that don't match.
559 CommonString.resize(NonMatchChar);
562 // Just compare the rest of the string.
563 if (NumInRange == 1) {
564 if (CharStart != CommonString.size()) {
565 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
566 if (CharStart) OS << "+" << CharStart;
567 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
568 OS << CommonString.size() - CharStart << "))\n";
571 OS << std::string(Indent*2, ' ') << "IntrinsicID = " << TargetPrefix
573 OS << Start->second << ";\n";
577 // At this point, we potentially have a common prefix for these builtins, emit
578 // a check for this common prefix.
579 if (CommonString.size() != CharStart) {
580 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
581 if (CharStart) OS << "+" << CharStart;
582 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
583 OS << CommonString.size()-CharStart << ")) {\n";
585 EmitBuiltinComparisons(Start, End, CommonString.size(), Indent+1,
587 OS << std::string(Indent*2, ' ') << "}\n";
591 // Output a switch on the character that differs across the set.
592 OS << std::string(Indent*2, ' ') << "switch (BuiltinName[" << CharStart
595 OS << " // \"" << std::string(Start->first.begin(),
596 Start->first.begin()+CharStart) << "\"";
599 for (StrMapIterator I = Start; I != End; ) {
600 char ThisChar = I->first[CharStart];
601 OS << std::string(Indent*2, ' ') << "case '" << ThisChar << "':\n";
602 // Figure out the range that has this common character.
603 StrMapIterator NextChar = I;
604 for (++NextChar; NextChar != End && NextChar->first[CharStart] == ThisChar;
607 EmitBuiltinComparisons(I, NextChar, CharStart+1, Indent+1, TargetPrefix,OS);
608 OS << std::string(Indent*2, ' ') << " break;\n";
611 OS << std::string(Indent*2, ' ') << "}\n";
614 /// EmitTargetBuiltins - All of the builtins in the specified map are for the
615 /// same target, and we already checked it.
616 static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
617 const std::string &TargetPrefix,
619 // Rearrange the builtins by length.
620 std::vector<std::map<std::string, std::string> > BuiltinsByLen;
621 BuiltinsByLen.reserve(100);
623 for (StrMapIterator I = BIM.begin(), E = BIM.end(); I != E; ++I) {
624 if (I->first.size() >= BuiltinsByLen.size())
625 BuiltinsByLen.resize(I->first.size()+1);
626 BuiltinsByLen[I->first.size()].insert(*I);
629 // Now that we have all the builtins by their length, emit a switch stmt.
630 OS << " switch (strlen(BuiltinName)) {\n";
631 OS << " default: break;\n";
632 for (unsigned i = 0, e = BuiltinsByLen.size(); i != e; ++i) {
633 if (BuiltinsByLen[i].empty()) continue;
634 OS << " case " << i << ":\n";
635 EmitBuiltinComparisons(BuiltinsByLen[i].begin(), BuiltinsByLen[i].end(),
636 0, 3, TargetPrefix, OS);
643 void IntrinsicEmitter::
644 EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
646 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
648 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
649 if (!Ints[i].GCCBuiltinName.empty()) {
650 // Get the map for this target prefix.
651 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
653 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
654 Ints[i].EnumName)).second)
655 throw "Intrinsic '" + Ints[i].TheDef->getName() +
656 "': duplicate GCC builtin name!";
660 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
661 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
662 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
663 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
664 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
667 OS << "static " << TargetPrefix << "Intrinsic::ID "
668 << "getIntrinsicForGCCBuiltin(const char "
669 << "*TargetPrefix, const char *BuiltinName) {\n";
670 OS << " " << TargetPrefix << "Intrinsic::ID IntrinsicID = ";
672 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
673 << "*TargetPrefix, const char *BuiltinName) {\n";
674 OS << " Intrinsic::ID IntrinsicID = ";
678 OS << "(" << TargetPrefix<< "Intrinsic::ID)";
680 OS << "Intrinsic::not_intrinsic;\n";
682 // Note: this could emit significantly better code if we cared.
683 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
685 if (!I->first.empty())
686 OS << "if (!strcmp(TargetPrefix, \"" << I->first << "\")) ";
688 OS << "/* Target Independent Builtins */ ";
691 // Emit the comparisons for this target prefix.
692 EmitTargetBuiltins(I->second, TargetPrefix, OS);
695 OS << " return IntrinsicID;\n";