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 "CodeGenIntrinsics.h"
15 #include "CodeGenTarget.h"
16 #include "SequenceToOffsetTable.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/TableGen/Error.h"
19 #include "llvm/TableGen/Record.h"
20 #include "llvm/TableGen/StringMatcher.h"
21 #include "llvm/TableGen/TableGenBackend.h"
26 class IntrinsicEmitter {
27 RecordKeeper &Records;
29 std::string TargetPrefix;
32 IntrinsicEmitter(RecordKeeper &R, bool T)
33 : Records(R), TargetOnly(T) {}
35 void run(raw_ostream &OS);
37 void EmitPrefix(raw_ostream &OS);
39 void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
42 void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
44 void EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
46 void EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
48 void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
50 void EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
52 void EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints,
54 void EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints,
56 void EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
58 void EmitSuffix(raw_ostream &OS);
60 } // End anonymous namespace
62 //===----------------------------------------------------------------------===//
63 // IntrinsicEmitter Implementation
64 //===----------------------------------------------------------------------===//
66 void IntrinsicEmitter::run(raw_ostream &OS) {
67 emitSourceFileHeader("Intrinsic Function Source Fragment", OS);
69 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
71 if (TargetOnly && !Ints.empty())
72 TargetPrefix = Ints[0].TargetPrefix;
76 // Emit the enum information.
77 EmitEnumInfo(Ints, OS);
79 // Emit the intrinsic ID -> name table.
80 EmitIntrinsicToNameTable(Ints, OS);
82 // Emit the intrinsic ID -> overload table.
83 EmitIntrinsicToOverloadTable(Ints, OS);
85 // Emit the function name recognizer.
86 EmitFnNameRecognizer(Ints, OS);
88 // Emit the intrinsic declaration generator.
89 EmitGenerator(Ints, OS);
91 // Emit the intrinsic parameter attributes.
92 EmitAttributes(Ints, OS);
94 // Emit intrinsic alias analysis mod/ref behavior.
95 EmitModRefBehavior(Ints, OS);
97 // Emit code to translate GCC builtins into LLVM intrinsics.
98 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
103 void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
104 OS << "// VisualStudio defines setjmp as _setjmp\n"
105 "#if defined(_MSC_VER) && defined(setjmp) && \\\n"
106 " !defined(setjmp_undefined_for_msvc)\n"
107 "# pragma push_macro(\"setjmp\")\n"
109 "# define setjmp_undefined_for_msvc\n"
113 void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
114 OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
115 "// let's return it to _setjmp state\n"
116 "# pragma pop_macro(\"setjmp\")\n"
117 "# undef setjmp_undefined_for_msvc\n"
121 void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
123 OS << "// Enum values for Intrinsics.h\n";
124 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
125 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
126 OS << " " << Ints[i].EnumName;
127 OS << ((i != e-1) ? ", " : " ");
128 OS << std::string(40-Ints[i].EnumName.size(), ' ')
129 << "// " << Ints[i].Name << "\n";
134 void IntrinsicEmitter::
135 EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
137 // Build a 'first character of function name' -> intrinsic # mapping.
138 std::map<char, std::vector<unsigned> > IntMapping;
139 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
140 IntMapping[Ints[i].Name[5]].push_back(i);
142 OS << "// Function name -> enum value recognizer code.\n";
143 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
144 OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
145 OS << " switch (Name[5]) { // Dispatch on first letter.\n";
146 OS << " default: break;\n";
147 // Emit the intrinsic matching stuff by first letter.
148 for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
149 E = IntMapping.end(); I != E; ++I) {
150 OS << " case '" << I->first << "':\n";
151 std::vector<unsigned> &IntList = I->second;
153 // Emit all the overloaded intrinsics first, build a table of the
154 // non-overloaded ones.
155 std::vector<StringMatcher::StringPair> MatchTable;
157 for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
158 unsigned IntNo = IntList[i];
159 std::string Result = "return " + TargetPrefix + "Intrinsic::" +
160 Ints[IntNo].EnumName + ";";
162 if (!Ints[IntNo].isOverloaded) {
163 MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
167 // For overloaded intrinsics, only the prefix needs to match
168 std::string TheStr = Ints[IntNo].Name.substr(6);
169 TheStr += '.'; // Require "bswap." instead of bswap.
170 OS << " if (NameR.startswith(\"" << TheStr << "\")) "
174 // Emit the matcher logic for the fixed length strings.
175 StringMatcher("NameR", MatchTable, OS).Emit(1);
176 OS << " break; // end of '" << I->first << "' case.\n";
183 void IntrinsicEmitter::
184 EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
186 OS << "// Intrinsic ID to name table\n";
187 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
188 OS << " // Note that entry #0 is the invalid intrinsic!\n";
189 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
190 OS << " \"" << Ints[i].Name << "\",\n";
194 void IntrinsicEmitter::
195 EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
197 OS << "// Intrinsic ID to overload bitset\n";
198 OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
199 OS << "static const uint8_t OTable[] = {\n";
201 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
202 // Add one to the index so we emit a null bit for the invalid #0 intrinsic.
205 if (Ints[i].isOverloaded)
206 OS << " | (1<<" << (i+1)%8 << ')';
209 // OTable contains a true bit at the position if the intrinsic is overloaded.
210 OS << "return (OTable[id/8] & (1 << (id%8))) != 0;\n";
215 // NOTE: This must be kept in synch with the copy in lib/VMCore/Function.cpp!
217 // Common values should be encoded with 0-15.
235 // Values from 16+ are only encodable with the inefficient encoding.
237 IIT_EMPTYSTRUCT = 17,
242 IIT_EXTEND_VEC_ARG = 22,
243 IIT_TRUNC_VEC_ARG = 23,
248 static void EncodeFixedValueType(MVT::SimpleValueType VT,
249 std::vector<unsigned char> &Sig) {
250 if (EVT(VT).isInteger()) {
251 unsigned BitWidth = EVT(VT).getSizeInBits();
253 default: PrintFatalError("unhandled integer type width in intrinsic!");
254 case 1: return Sig.push_back(IIT_I1);
255 case 8: return Sig.push_back(IIT_I8);
256 case 16: return Sig.push_back(IIT_I16);
257 case 32: return Sig.push_back(IIT_I32);
258 case 64: return Sig.push_back(IIT_I64);
263 default: PrintFatalError("unhandled MVT in intrinsic!");
264 case MVT::f32: return Sig.push_back(IIT_F32);
265 case MVT::f64: return Sig.push_back(IIT_F64);
266 case MVT::Metadata: return Sig.push_back(IIT_METADATA);
267 case MVT::x86mmx: return Sig.push_back(IIT_MMX);
268 // MVT::OtherVT is used to mean the empty struct type here.
269 case MVT::Other: return Sig.push_back(IIT_EMPTYSTRUCT);
274 #pragma optimize("",off) // MSVC 2010 optimizer can't deal with this function.
277 static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes,
278 std::vector<unsigned char> &Sig) {
280 if (R->isSubClassOf("LLVMMatchType")) {
281 unsigned Number = R->getValueAsInt("Number");
282 assert(Number < ArgCodes.size() && "Invalid matching number!");
283 if (R->isSubClassOf("LLVMExtendedElementVectorType"))
284 Sig.push_back(IIT_EXTEND_VEC_ARG);
285 else if (R->isSubClassOf("LLVMTruncatedElementVectorType"))
286 Sig.push_back(IIT_TRUNC_VEC_ARG);
288 Sig.push_back(IIT_ARG);
289 return Sig.push_back((Number << 2) | ArgCodes[Number]);
292 MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT"));
297 case MVT::iPTRAny: ++Tmp; // FALL THROUGH.
298 case MVT::vAny: ++Tmp; // FALL THROUGH.
299 case MVT::fAny: ++Tmp; // FALL THROUGH.
301 // If this is an "any" valuetype, then the type is the type of the next
302 // type in the list specified to getIntrinsic().
303 Sig.push_back(IIT_ARG);
305 // Figure out what arg # this is consuming, and remember what kind it was.
306 unsigned ArgNo = ArgCodes.size();
307 ArgCodes.push_back(Tmp);
309 // Encode what sort of argument it must be in the low 2 bits of the ArgNo.
310 return Sig.push_back((ArgNo << 2) | Tmp);
314 unsigned AddrSpace = 0;
315 if (R->isSubClassOf("LLVMQualPointerType")) {
316 AddrSpace = R->getValueAsInt("AddrSpace");
317 assert(AddrSpace < 256 && "Address space exceeds 255");
320 Sig.push_back(IIT_ANYPTR);
321 Sig.push_back(AddrSpace);
323 Sig.push_back(IIT_PTR);
325 return EncodeFixedType(R->getValueAsDef("ElTy"), ArgCodes, Sig);
329 if (EVT(VT).isVector()) {
331 switch (VVT.getVectorNumElements()) {
332 default: PrintFatalError("unhandled vector type width in intrinsic!");
333 case 2: Sig.push_back(IIT_V2); break;
334 case 4: Sig.push_back(IIT_V4); break;
335 case 8: Sig.push_back(IIT_V8); break;
336 case 16: Sig.push_back(IIT_V16); break;
337 case 32: Sig.push_back(IIT_V32); break;
340 return EncodeFixedValueType(VVT.getVectorElementType().
341 getSimpleVT().SimpleTy, Sig);
344 EncodeFixedValueType(VT, Sig);
348 #pragma optimize("",on)
351 /// ComputeFixedEncoding - If we can encode the type signature for this
352 /// intrinsic into 32 bits, return it. If not, return ~0U.
353 static void ComputeFixedEncoding(const CodeGenIntrinsic &Int,
354 std::vector<unsigned char> &TypeSig) {
355 std::vector<unsigned char> ArgCodes;
357 if (Int.IS.RetVTs.empty())
358 TypeSig.push_back(IIT_Done);
359 else if (Int.IS.RetVTs.size() == 1 &&
360 Int.IS.RetVTs[0] == MVT::isVoid)
361 TypeSig.push_back(IIT_Done);
363 switch (Int.IS.RetVTs.size()) {
365 case 2: TypeSig.push_back(IIT_STRUCT2); break;
366 case 3: TypeSig.push_back(IIT_STRUCT3); break;
367 case 4: TypeSig.push_back(IIT_STRUCT4); break;
368 case 5: TypeSig.push_back(IIT_STRUCT5); break;
369 default: assert(0 && "Unhandled case in struct");
372 for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
373 EncodeFixedType(Int.IS.RetTypeDefs[i], ArgCodes, TypeSig);
376 for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
377 EncodeFixedType(Int.IS.ParamTypeDefs[i], ArgCodes, TypeSig);
380 static void printIITEntry(raw_ostream &OS, unsigned char X) {
384 void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
386 // If we can compute a 32-bit fixed encoding for this intrinsic, do so and
387 // capture it in this vector, otherwise store a ~0U.
388 std::vector<unsigned> FixedEncodings;
390 SequenceToOffsetTable<std::vector<unsigned char> > LongEncodingTable;
392 std::vector<unsigned char> TypeSig;
394 // Compute the unique argument type info.
395 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
396 // Get the signature for the intrinsic.
398 ComputeFixedEncoding(Ints[i], TypeSig);
400 // Check to see if we can encode it into a 32-bit word. We can only encode
401 // 8 nibbles into a 32-bit word.
402 if (TypeSig.size() <= 8) {
405 for (unsigned i = 0, e = TypeSig.size(); i != e; ++i) {
406 // If we had an unencodable argument, bail out.
407 if (TypeSig[i] > 15) {
411 Result = (Result << 4) | TypeSig[e-i-1];
414 // If this could be encoded into a 31-bit word, return it.
415 if (!Failed && (Result >> 31) == 0) {
416 FixedEncodings.push_back(Result);
421 // Otherwise, we're going to unique the sequence into the
422 // LongEncodingTable, and use its offset in the 32-bit table instead.
423 LongEncodingTable.add(TypeSig);
425 // This is a placehold that we'll replace after the table is laid out.
426 FixedEncodings.push_back(~0U);
429 LongEncodingTable.layout();
431 OS << "// Global intrinsic function declaration type table.\n";
432 OS << "#ifdef GET_INTRINSIC_GENERATOR_GLOBAL\n";
434 OS << "static const unsigned IIT_Table[] = {\n ";
436 for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) {
440 // If the entry fit in the table, just emit it.
441 if (FixedEncodings[i] != ~0U) {
442 OS << "0x" << utohexstr(FixedEncodings[i]) << ", ";
447 ComputeFixedEncoding(Ints[i], TypeSig);
450 // Otherwise, emit the offset into the long encoding table. We emit it this
451 // way so that it is easier to read the offset in the .def file.
452 OS << "(1U<<31) | " << LongEncodingTable.get(TypeSig) << ", ";
457 // Emit the shared table of register lists.
458 OS << "static const unsigned char IIT_LongEncodingTable[] = {\n";
459 if (!LongEncodingTable.empty())
460 LongEncodingTable.emit(OS, printIITEntry);
461 OS << " 255\n};\n\n";
463 OS << "#endif\n\n"; // End of GET_INTRINSIC_GENERATOR_GLOBAL
472 static ModRefKind getModRefKind(const CodeGenIntrinsic &intrinsic) {
473 switch (intrinsic.ModRef) {
474 case CodeGenIntrinsic::NoMem:
476 case CodeGenIntrinsic::ReadArgMem:
477 case CodeGenIntrinsic::ReadMem:
479 case CodeGenIntrinsic::ReadWriteArgMem:
480 case CodeGenIntrinsic::ReadWriteMem:
483 llvm_unreachable("bad mod-ref kind");
487 struct AttributeComparator {
488 bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const {
489 // Sort throwing intrinsics after non-throwing intrinsics.
490 if (L->canThrow != R->canThrow)
493 if (L->isNoReturn != R->isNoReturn)
494 return R->isNoReturn;
496 // Try to order by readonly/readnone attribute.
497 ModRefKind LK = getModRefKind(*L);
498 ModRefKind RK = getModRefKind(*R);
499 if (LK != RK) return (LK > RK);
501 // Order by argument attributes.
502 // This is reliable because each side is already sorted internally.
503 return (L->ArgumentAttributes < R->ArgumentAttributes);
506 } // End anonymous namespace
508 /// EmitAttributes - This emits the Intrinsic::getAttributes method.
509 void IntrinsicEmitter::
510 EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
511 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
512 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
514 OS << "static AttrListPtr getAttributes(LLVMContext &C, " << TargetPrefix
515 << "Intrinsic::ID id) {\n";
517 OS << "AttrListPtr Intrinsic::getAttributes(LLVMContext &C, ID id) {\n";
519 // Compute the maximum number of attribute arguments and the map
520 typedef std::map<const CodeGenIntrinsic*, unsigned,
521 AttributeComparator> UniqAttrMapTy;
522 UniqAttrMapTy UniqAttributes;
523 unsigned maxArgAttrs = 0;
524 unsigned AttrNum = 0;
525 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
526 const CodeGenIntrinsic &intrinsic = Ints[i];
528 std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
529 unsigned &N = UniqAttributes[&intrinsic];
531 assert(AttrNum < 256 && "Too many unique attributes for table!");
535 // Emit an array of AttributeWithIndex. Most intrinsics will have
536 // at least one entry, for the function itself (index ~1), which is
538 OS << " static const uint8_t IntrinsicsToAttributesMap[] = {\n";
540 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
541 const CodeGenIntrinsic &intrinsic = Ints[i];
543 OS << " " << UniqAttributes[&intrinsic] << ", // "
544 << intrinsic.Name << "\n";
548 OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n";
549 OS << " unsigned NumAttrs = 0;\n";
550 OS << " if (id != 0) {\n";
551 OS << " SmallVector<Attributes::AttrVal, 8> AttrVec;\n";
552 OS << " switch(IntrinsicsToAttributesMap[id - ";
554 OS << "Intrinsic::num_intrinsics";
558 OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
559 for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
560 E = UniqAttributes.end(); I != E; ++I) {
561 OS << " case " << I->second << ":\n";
563 const CodeGenIntrinsic &intrinsic = *(I->first);
565 // Keep track of the number of attributes we're writing out.
566 unsigned numAttrs = 0;
568 // The argument attributes are alreadys sorted by argument index.
569 unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size();
572 unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
574 OS << " AttrVec.clear();\n";
577 switch (intrinsic.ArgumentAttributes[ai].second) {
578 case CodeGenIntrinsic::NoCapture:
579 OS << " AttrVec.push_back(Attributes::NoCapture);\n";
584 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
586 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, "
587 << argNo+1 << ", AttrVec);\n";
591 ModRefKind modRef = getModRefKind(intrinsic);
593 if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) {
594 OS << " AttrVec.clear();\n";
596 if (!intrinsic.canThrow)
597 OS << " AttrVec.push_back(Attributes::NoUnwind);\n";
598 if (intrinsic.isNoReturn)
599 OS << " AttrVec.push_back(Attributes::NoReturn);\n";
602 case MRK_none: break;
604 OS << " AttrVec.push_back(Attributes::ReadOnly);\n";
607 OS << " AttrVec.push_back(Attributes::ReadNone);\n";
610 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(C, "
611 << "AttrListPtr::FunctionIndex, AttrVec);\n";
615 OS << " NumAttrs = " << numAttrs << ";\n";
618 OS << " return AttrListPtr();\n";
624 OS << " return AttrListPtr::get(ArrayRef<AttributeWithIndex>(AWI, "
627 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
630 /// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
631 void IntrinsicEmitter::
632 EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
633 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n"
634 << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n"
635 << "assert(iid <= Intrinsic::" << Ints.back().EnumName << " && "
636 << "\"Unknown intrinsic.\");\n\n";
638 OS << "static const uint8_t IntrinsicModRefBehavior[] = {\n"
639 << " /* invalid */ UnknownModRefBehavior,\n";
640 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
641 OS << " /* " << TargetPrefix << Ints[i].EnumName << " */ ";
642 switch (Ints[i].ModRef) {
643 case CodeGenIntrinsic::NoMem:
644 OS << "DoesNotAccessMemory,\n";
646 case CodeGenIntrinsic::ReadArgMem:
647 OS << "OnlyReadsArgumentPointees,\n";
649 case CodeGenIntrinsic::ReadMem:
650 OS << "OnlyReadsMemory,\n";
652 case CodeGenIntrinsic::ReadWriteArgMem:
653 OS << "OnlyAccessesArgumentPointees,\n";
655 case CodeGenIntrinsic::ReadWriteMem:
656 OS << "UnknownModRefBehavior,\n";
661 << "return static_cast<ModRefBehavior>(IntrinsicModRefBehavior[iid]);\n"
662 << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
665 /// EmitTargetBuiltins - All of the builtins in the specified map are for the
666 /// same target, and we already checked it.
667 static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
668 const std::string &TargetPrefix,
671 std::vector<StringMatcher::StringPair> Results;
673 for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
674 E = BIM.end(); I != E; ++I) {
675 std::string ResultCode =
676 "return " + TargetPrefix + "Intrinsic::" + I->second + ";";
677 Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
680 StringMatcher("BuiltinName", Results, OS).Emit();
684 void IntrinsicEmitter::
685 EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
687 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
689 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
690 if (!Ints[i].GCCBuiltinName.empty()) {
691 // Get the map for this target prefix.
692 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
694 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
695 Ints[i].EnumName)).second)
696 PrintFatalError("Intrinsic '" + Ints[i].TheDef->getName() +
697 "': duplicate GCC builtin name!");
701 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
702 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
703 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
704 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
705 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
708 OS << "static " << TargetPrefix << "Intrinsic::ID "
709 << "getIntrinsicForGCCBuiltin(const char "
710 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
712 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
713 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
716 OS << " StringRef BuiltinName(BuiltinNameStr);\n";
717 OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
719 // Note: this could emit significantly better code if we cared.
720 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
722 if (!I->first.empty())
723 OS << "if (TargetPrefix == \"" << I->first << "\") ";
725 OS << "/* Target Independent Builtins */ ";
728 // Emit the comparisons for this target prefix.
729 EmitTargetBuiltins(I->second, TargetPrefix, OS);
733 if (!TargetPrefix.empty())
734 OS << "(" << TargetPrefix << "Intrinsic::ID)";
735 OS << "Intrinsic::not_intrinsic;\n";
742 void EmitIntrinsics(RecordKeeper &RK, raw_ostream &OS, bool TargetOnly = false) {
743 IntrinsicEmitter(RK, TargetOnly).run(OS);
746 } // End llvm namespace