blob: 155d1abea33182c9fcf07c0bdd33a4af7e6e7703 [file] [log] [blame]
Chris Lattner9e493cf2006-03-03 02:32:46 +00001//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner9e493cf2006-03-03 02:32:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend emits information about intrinsic functions.
11//
12//===----------------------------------------------------------------------===//
13
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000014#include "CodeGenIntrinsics.h"
Chandler Carruth69940402007-08-04 01:51:18 +000015#include "CodeGenTarget.h"
Chris Lattner387c9dc2012-05-17 15:55:41 +000016#include "SequenceToOffsetTable.h"
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000017#include "llvm/ADT/StringExtras.h"
Peter Collingbourne7c788882011-10-01 16:41:13 +000018#include "llvm/TableGen/Record.h"
Douglas Gregorf657da22012-05-02 17:32:48 +000019#include "llvm/TableGen/StringMatcher.h"
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000020#include "llvm/TableGen/TableGenBackend.h"
Jeff Cohen71c3bc32006-03-15 02:51:05 +000021#include <algorithm>
Chris Lattner9e493cf2006-03-03 02:32:46 +000022using namespace llvm;
23
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000024namespace {
25class IntrinsicEmitter {
26 RecordKeeper &Records;
27 bool TargetOnly;
28 std::string TargetPrefix;
29
30public:
31 IntrinsicEmitter(RecordKeeper &R, bool T)
32 : Records(R), TargetOnly(T) {}
33
34 void run(raw_ostream &OS);
35
36 void EmitPrefix(raw_ostream &OS);
37
38 void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
39 raw_ostream &OS);
40
41 void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
42 raw_ostream &OS);
43 void EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
44 raw_ostream &OS);
45 void EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
46 raw_ostream &OS);
47 void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
48 raw_ostream &OS);
49 void EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
50 raw_ostream &OS);
51 void EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints,
52 raw_ostream &OS);
53 void EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints,
54 raw_ostream &OS);
55 void EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
56 raw_ostream &OS);
57 void EmitSuffix(raw_ostream &OS);
58};
59} // End anonymous namespace
60
Chris Lattner9e493cf2006-03-03 02:32:46 +000061//===----------------------------------------------------------------------===//
Chris Lattner9e493cf2006-03-03 02:32:46 +000062// IntrinsicEmitter Implementation
63//===----------------------------------------------------------------------===//
64
Daniel Dunbar1a551802009-07-03 00:10:29 +000065void IntrinsicEmitter::run(raw_ostream &OS) {
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000066 emitSourceFileHeader("Intrinsic Function Source Fragment", OS);
67
Dale Johannesen49de9822009-02-05 01:49:45 +000068 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +000069
Dale Johannesen49de9822009-02-05 01:49:45 +000070 if (TargetOnly && !Ints.empty())
71 TargetPrefix = Ints[0].TargetPrefix;
Chris Lattner9e493cf2006-03-03 02:32:46 +000072
Douglas Gregor7d9663c2010-05-11 06:17:44 +000073 EmitPrefix(OS);
74
Chris Lattner9e493cf2006-03-03 02:32:46 +000075 // Emit the enum information.
76 EmitEnumInfo(Ints, OS);
Chris Lattnerfda6aff2006-03-15 01:55:21 +000077
78 // Emit the intrinsic ID -> name table.
79 EmitIntrinsicToNameTable(Ints, OS);
Mon P Wang0d52ff12009-02-24 23:17:49 +000080
81 // Emit the intrinsic ID -> overload table.
82 EmitIntrinsicToOverloadTable(Ints, OS);
83
Chris Lattner9b843b22006-03-09 20:34:19 +000084 // Emit the function name recognizer.
85 EmitFnNameRecognizer(Ints, OS);
Chris Lattnerfda6aff2006-03-15 01:55:21 +000086
Jim Laskey95af5922007-02-07 20:38:26 +000087 // Emit the intrinsic declaration generator.
88 EmitGenerator(Ints, OS);
89
Duncan Sandsa3355ff2007-12-03 20:06:50 +000090 // Emit the intrinsic parameter attributes.
91 EmitAttributes(Ints, OS);
Chris Lattner022f64f2006-03-13 23:08:44 +000092
Duncan Sandsd869b382009-02-14 10:56:35 +000093 // Emit intrinsic alias analysis mod/ref behavior.
94 EmitModRefBehavior(Ints, OS);
95
Chris Lattner3f8b8912006-03-15 01:33:26 +000096 // Emit code to translate GCC builtins into LLVM intrinsics.
97 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
Douglas Gregor7d9663c2010-05-11 06:17:44 +000098
99 EmitSuffix(OS);
100}
101
102void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
103 OS << "// VisualStudio defines setjmp as _setjmp\n"
Michael J. Spencer1f409602010-09-24 19:48:47 +0000104 "#if defined(_MSC_VER) && defined(setjmp) && \\\n"
105 " !defined(setjmp_undefined_for_msvc)\n"
Michael J. Spencer08047f62010-09-14 04:27:38 +0000106 "# pragma push_macro(\"setjmp\")\n"
107 "# undef setjmp\n"
Michael J. Spencer1f409602010-09-24 19:48:47 +0000108 "# define setjmp_undefined_for_msvc\n"
Douglas Gregor7d9663c2010-05-11 06:17:44 +0000109 "#endif\n\n";
110}
111
112void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
Michael J. Spencer1f409602010-09-24 19:48:47 +0000113 OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
Douglas Gregor7d9663c2010-05-11 06:17:44 +0000114 "// let's return it to _setjmp state\n"
Michael J. Spencer08047f62010-09-14 04:27:38 +0000115 "# pragma pop_macro(\"setjmp\")\n"
Michael J. Spencer1f409602010-09-24 19:48:47 +0000116 "# undef setjmp_undefined_for_msvc\n"
Douglas Gregor7d9663c2010-05-11 06:17:44 +0000117 "#endif\n\n";
Chris Lattner9e493cf2006-03-03 02:32:46 +0000118}
119
120void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000121 raw_ostream &OS) {
Chris Lattner9b843b22006-03-09 20:34:19 +0000122 OS << "// Enum values for Intrinsics.h\n";
Chris Lattner9e493cf2006-03-03 02:32:46 +0000123 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
124 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
125 OS << " " << Ints[i].EnumName;
126 OS << ((i != e-1) ? ", " : " ");
127 OS << std::string(40-Ints[i].EnumName.size(), ' ')
128 << "// " << Ints[i].Name << "\n";
129 }
130 OS << "#endif\n\n";
131}
Chris Lattner9b843b22006-03-09 20:34:19 +0000132
133void IntrinsicEmitter::
134EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000135 raw_ostream &OS) {
Chris Lattnercc67c752010-09-06 03:58:45 +0000136 // Build a 'first character of function name' -> intrinsic # mapping.
137 std::map<char, std::vector<unsigned> > IntMapping;
Chris Lattner9b843b22006-03-09 20:34:19 +0000138 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Chris Lattnercc67c752010-09-06 03:58:45 +0000139 IntMapping[Ints[i].Name[5]].push_back(i);
140
Chris Lattner9b843b22006-03-09 20:34:19 +0000141 OS << "// Function name -> enum value recognizer code.\n";
142 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
Chris Lattnercc67c752010-09-06 03:58:45 +0000143 OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
144 OS << " switch (Name[5]) { // Dispatch on first letter.\n";
145 OS << " default: break;\n";
146 // Emit the intrinsic matching stuff by first letter.
147 for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
Chris Lattner9b843b22006-03-09 20:34:19 +0000148 E = IntMapping.end(); I != E; ++I) {
Chris Lattnercc67c752010-09-06 03:58:45 +0000149 OS << " case '" << I->first << "':\n";
150 std::vector<unsigned> &IntList = I->second;
151
152 // Emit all the overloaded intrinsics first, build a table of the
153 // non-overloaded ones.
154 std::vector<StringMatcher::StringPair> MatchTable;
155
156 for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
157 unsigned IntNo = IntList[i];
158 std::string Result = "return " + TargetPrefix + "Intrinsic::" +
159 Ints[IntNo].EnumName + ";";
160
161 if (!Ints[IntNo].isOverloaded) {
162 MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
163 continue;
164 }
165
166 // For overloaded intrinsics, only the prefix needs to match
167 std::string TheStr = Ints[IntNo].Name.substr(6);
168 TheStr += '.'; // Require "bswap." instead of bswap.
169 OS << " if (NameR.startswith(\"" << TheStr << "\")) "
170 << Result << '\n';
Chris Lattner9b843b22006-03-09 20:34:19 +0000171 }
172
Chris Lattnercc67c752010-09-06 03:58:45 +0000173 // Emit the matcher logic for the fixed length strings.
174 StringMatcher("NameR", MatchTable, OS).Emit(1);
175 OS << " break; // end of '" << I->first << "' case.\n";
Chris Lattner9b843b22006-03-09 20:34:19 +0000176 }
Chris Lattnercc67c752010-09-06 03:58:45 +0000177
Chris Lattner9b843b22006-03-09 20:34:19 +0000178 OS << " }\n";
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000179 OS << "#endif\n\n";
180}
181
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000182void IntrinsicEmitter::
183EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000184 raw_ostream &OS) {
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000185 OS << "// Intrinsic ID to name table\n";
186 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
187 OS << " // Note that entry #0 is the invalid intrinsic!\n";
Evan Chengf065a6f2006-03-28 22:25:56 +0000188 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
189 OS << " \"" << Ints[i].Name << "\",\n";
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000190 OS << "#endif\n\n";
191}
192
Mon P Wang0d52ff12009-02-24 23:17:49 +0000193void IntrinsicEmitter::
194EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000195 raw_ostream &OS) {
Benjamin Kramer36a21382012-03-01 02:16:57 +0000196 OS << "// Intrinsic ID to overload bitset\n";
Mon P Wang0d52ff12009-02-24 23:17:49 +0000197 OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
Benjamin Kramer36a21382012-03-01 02:16:57 +0000198 OS << "static const uint8_t OTable[] = {\n";
199 OS << " 0";
Mon P Wang0d52ff12009-02-24 23:17:49 +0000200 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
Benjamin Kramer36a21382012-03-01 02:16:57 +0000201 // Add one to the index so we emit a null bit for the invalid #0 intrinsic.
202 if ((i+1)%8 == 0)
203 OS << ",\n 0";
Mon P Wang0d52ff12009-02-24 23:17:49 +0000204 if (Ints[i].isOverloaded)
Benjamin Kramer36a21382012-03-01 02:16:57 +0000205 OS << " | (1<<" << (i+1)%8 << ')';
Mon P Wang0d52ff12009-02-24 23:17:49 +0000206 }
Benjamin Kramer36a21382012-03-01 02:16:57 +0000207 OS << "\n};\n\n";
208 // OTable contains a true bit at the position if the intrinsic is overloaded.
209 OS << "return (OTable[id/8] & (1 << (id%8))) != 0;\n";
Mon P Wang0d52ff12009-02-24 23:17:49 +0000210 OS << "#endif\n\n";
211}
212
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000213
Chris Lattner908a8312012-05-27 18:28:35 +0000214// NOTE: This must be kept in synch with the copy in lib/VMCore/Function.cpp!
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000215enum IIT_Info {
Chris Lattner46aaf692012-05-17 04:30:58 +0000216 // Common values should be encoded with 0-15.
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000217 IIT_Done = 0,
218 IIT_I1 = 1,
219 IIT_I8 = 2,
220 IIT_I16 = 3,
221 IIT_I32 = 4,
222 IIT_I64 = 5,
223 IIT_F32 = 6,
224 IIT_F64 = 7,
225 IIT_V2 = 8,
226 IIT_V4 = 9,
227 IIT_V8 = 10,
228 IIT_V16 = 11,
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000229 IIT_V32 = 12,
230 IIT_MMX = 13,
231 IIT_PTR = 14,
232 IIT_ARG = 15,
Chris Lattner46aaf692012-05-17 04:30:58 +0000233
234 // Values from 16+ are only encodable with the inefficient encoding.
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000235 IIT_METADATA = 16,
236 IIT_EMPTYSTRUCT = 17,
237 IIT_STRUCT2 = 18,
238 IIT_STRUCT3 = 19,
239 IIT_STRUCT4 = 20,
240 IIT_STRUCT5 = 21,
241 IIT_EXTEND_VEC_ARG = 22,
Chris Lattnera48289a2012-05-23 05:19:18 +0000242 IIT_TRUNC_VEC_ARG = 23,
243 IIT_ANYPTR = 24
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000244};
245
Chris Lattner46aaf692012-05-17 04:30:58 +0000246
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000247static void EncodeFixedValueType(MVT::SimpleValueType VT,
Chris Lattner387c9dc2012-05-17 15:55:41 +0000248 std::vector<unsigned char> &Sig) {
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000249 if (EVT(VT).isInteger()) {
250 unsigned BitWidth = EVT(VT).getSizeInBits();
251 switch (BitWidth) {
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000252 default: throw "unhandled integer type width in intrinsic!";
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000253 case 1: return Sig.push_back(IIT_I1);
254 case 8: return Sig.push_back(IIT_I8);
255 case 16: return Sig.push_back(IIT_I16);
256 case 32: return Sig.push_back(IIT_I32);
257 case 64: return Sig.push_back(IIT_I64);
258 }
259 }
260
Chris Lattner46aaf692012-05-17 04:30:58 +0000261 switch (VT) {
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000262 default: throw "unhandled MVT in intrinsic!";
Chris Lattner46aaf692012-05-17 04:30:58 +0000263 case MVT::f32: return Sig.push_back(IIT_F32);
264 case MVT::f64: return Sig.push_back(IIT_F64);
Chris Lattner46aaf692012-05-17 04:30:58 +0000265 case MVT::Metadata: return Sig.push_back(IIT_METADATA);
266 case MVT::x86mmx: return Sig.push_back(IIT_MMX);
267 // MVT::OtherVT is used to mean the empty struct type here.
268 case MVT::Other: return Sig.push_back(IIT_EMPTYSTRUCT);
269 }
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000270}
271
Francois Pichete4807c12012-05-17 04:00:03 +0000272#ifdef _MSC_VER
Francois Pichet3aca8792012-05-17 03:38:19 +0000273#pragma optimize("",off) // MSVC 2010 optimizer can't deal with this function.
Francois Pichete4807c12012-05-17 04:00:03 +0000274#endif
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000275
Chris Lattnerb4654c12012-05-27 16:39:08 +0000276static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes,
Chris Lattner387c9dc2012-05-17 15:55:41 +0000277 std::vector<unsigned char> &Sig) {
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000278
279 if (R->isSubClassOf("LLVMMatchType")) {
Chris Lattner46aaf692012-05-17 04:30:58 +0000280 unsigned Number = R->getValueAsInt("Number");
Chris Lattnerb4654c12012-05-27 16:39:08 +0000281 assert(Number < ArgCodes.size() && "Invalid matching number!");
Chris Lattner46aaf692012-05-17 04:30:58 +0000282 if (R->isSubClassOf("LLVMExtendedElementVectorType"))
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000283 Sig.push_back(IIT_EXTEND_VEC_ARG);
284 else if (R->isSubClassOf("LLVMTruncatedElementVectorType"))
285 Sig.push_back(IIT_TRUNC_VEC_ARG);
286 else
287 Sig.push_back(IIT_ARG);
Chris Lattnerb4654c12012-05-27 16:39:08 +0000288 return Sig.push_back((Number << 2) | ArgCodes[Number]);
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000289 }
290
291 MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT"));
Chris Lattner46aaf692012-05-17 04:30:58 +0000292
Chris Lattnerb4654c12012-05-27 16:39:08 +0000293 unsigned Tmp = 0;
Chris Lattnere82d5982012-05-26 23:03:52 +0000294 switch (VT) {
295 default: break;
Chris Lattnerb4654c12012-05-27 16:39:08 +0000296 case MVT::iPTRAny: ++Tmp; // FALL THROUGH.
297 case MVT::vAny: ++Tmp; // FALL THROUGH.
298 case MVT::fAny: ++Tmp; // FALL THROUGH.
299 case MVT::iAny: {
Chris Lattnere82d5982012-05-26 23:03:52 +0000300 // If this is an "any" valuetype, then the type is the type of the next
301 // type in the list specified to getIntrinsic().
Chris Lattner46aaf692012-05-17 04:30:58 +0000302 Sig.push_back(IIT_ARG);
Chris Lattnerb4654c12012-05-27 16:39:08 +0000303
304 // Figure out what arg # this is consuming, and remember what kind it was.
305 unsigned ArgNo = ArgCodes.size();
306 ArgCodes.push_back(Tmp);
307
308 // Encode what sort of argument it must be in the low 2 bits of the ArgNo.
309 return Sig.push_back((ArgNo << 2) | Tmp);
310 }
Chris Lattnere82d5982012-05-26 23:03:52 +0000311
312 case MVT::iPTR: {
313 unsigned AddrSpace = 0;
314 if (R->isSubClassOf("LLVMQualPointerType")) {
315 AddrSpace = R->getValueAsInt("AddrSpace");
316 assert(AddrSpace < 256 && "Address space exceeds 255");
317 }
318 if (AddrSpace) {
319 Sig.push_back(IIT_ANYPTR);
320 Sig.push_back(AddrSpace);
321 } else {
322 Sig.push_back(IIT_PTR);
323 }
Chris Lattnerb4654c12012-05-27 16:39:08 +0000324 return EncodeFixedType(R->getValueAsDef("ElTy"), ArgCodes, Sig);
Chris Lattnere82d5982012-05-26 23:03:52 +0000325 }
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000326 }
327
328 if (EVT(VT).isVector()) {
329 EVT VVT = VT;
330 switch (VVT.getVectorNumElements()) {
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000331 default: throw "unhandled vector type width in intrinsic!";
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000332 case 2: Sig.push_back(IIT_V2); break;
333 case 4: Sig.push_back(IIT_V4); break;
334 case 8: Sig.push_back(IIT_V8); break;
335 case 16: Sig.push_back(IIT_V16); break;
Chris Lattner46aaf692012-05-17 04:30:58 +0000336 case 32: Sig.push_back(IIT_V32); break;
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000337 }
338
339 return EncodeFixedValueType(VVT.getVectorElementType().
340 getSimpleVT().SimpleTy, Sig);
341 }
Chris Lattnere82d5982012-05-26 23:03:52 +0000342
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000343 EncodeFixedValueType(VT, Sig);
344}
Francois Pichete4807c12012-05-17 04:00:03 +0000345
346#ifdef _MSC_VER
Francois Pichet3aca8792012-05-17 03:38:19 +0000347#pragma optimize("",on)
Francois Pichete4807c12012-05-17 04:00:03 +0000348#endif
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000349
350/// ComputeFixedEncoding - If we can encode the type signature for this
351/// intrinsic into 32 bits, return it. If not, return ~0U.
Chris Lattner387c9dc2012-05-17 15:55:41 +0000352static void ComputeFixedEncoding(const CodeGenIntrinsic &Int,
353 std::vector<unsigned char> &TypeSig) {
Chris Lattnerb4654c12012-05-27 16:39:08 +0000354 std::vector<unsigned char> ArgCodes;
Chris Lattner46aaf692012-05-17 04:30:58 +0000355
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000356 if (Int.IS.RetVTs.empty())
357 TypeSig.push_back(IIT_Done);
358 else if (Int.IS.RetVTs.size() == 1 &&
359 Int.IS.RetVTs[0] == MVT::isVoid)
360 TypeSig.push_back(IIT_Done);
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000361 else {
362 switch (Int.IS.RetVTs.size()) {
Chris Lattner387c9dc2012-05-17 15:55:41 +0000363 case 1: break;
364 case 2: TypeSig.push_back(IIT_STRUCT2); break;
365 case 3: TypeSig.push_back(IIT_STRUCT3); break;
366 case 4: TypeSig.push_back(IIT_STRUCT4); break;
367 case 5: TypeSig.push_back(IIT_STRUCT5); break;
368 default: assert(0 && "Unhandled case in struct");
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000369 }
Chris Lattner387c9dc2012-05-17 15:55:41 +0000370
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000371 for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
Chris Lattnerb4654c12012-05-27 16:39:08 +0000372 EncodeFixedType(Int.IS.RetTypeDefs[i], ArgCodes, TypeSig);
Chris Lattnerd7cf5eb2012-05-17 05:03:24 +0000373 }
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000374
375 for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
Chris Lattnerb4654c12012-05-27 16:39:08 +0000376 EncodeFixedType(Int.IS.ParamTypeDefs[i], ArgCodes, TypeSig);
Chris Lattner387c9dc2012-05-17 15:55:41 +0000377}
378
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000379static void printIITEntry(raw_ostream &OS, unsigned char X) {
Chris Lattner387c9dc2012-05-17 15:55:41 +0000380 OS << (unsigned)X;
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000381}
382
Jim Laskey95af5922007-02-07 20:38:26 +0000383void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000384 raw_ostream &OS) {
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000385 // If we can compute a 32-bit fixed encoding for this intrinsic, do so and
386 // capture it in this vector, otherwise store a ~0U.
387 std::vector<unsigned> FixedEncodings;
Jim Laskey95af5922007-02-07 20:38:26 +0000388
Chris Lattner387c9dc2012-05-17 15:55:41 +0000389 SequenceToOffsetTable<std::vector<unsigned char> > LongEncodingTable;
390
391 std::vector<unsigned char> TypeSig;
392
Jim Laskey95af5922007-02-07 20:38:26 +0000393 // Compute the unique argument type info.
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000394 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
Chris Lattner387c9dc2012-05-17 15:55:41 +0000395 // Get the signature for the intrinsic.
396 TypeSig.clear();
397 ComputeFixedEncoding(Ints[i], TypeSig);
398
399 // Check to see if we can encode it into a 32-bit word. We can only encode
400 // 8 nibbles into a 32-bit word.
401 if (TypeSig.size() <= 8) {
402 bool Failed = false;
403 unsigned Result = 0;
404 for (unsigned i = 0, e = TypeSig.size(); i != e; ++i) {
405 // If we had an unencodable argument, bail out.
406 if (TypeSig[i] > 15) {
407 Failed = true;
408 break;
409 }
410 Result = (Result << 4) | TypeSig[e-i-1];
411 }
412
413 // If this could be encoded into a 31-bit word, return it.
414 if (!Failed && (Result >> 31) == 0) {
415 FixedEncodings.push_back(Result);
416 continue;
417 }
418 }
419
420 // Otherwise, we're going to unique the sequence into the
421 // LongEncodingTable, and use its offset in the 32-bit table instead.
422 LongEncodingTable.add(TypeSig);
423
424 // This is a placehold that we'll replace after the table is laid out.
425 FixedEncodings.push_back(~0U);
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000426 }
427
Chris Lattner387c9dc2012-05-17 15:55:41 +0000428 LongEncodingTable.layout();
429
Chris Lattner908a8312012-05-27 18:28:35 +0000430 OS << "// Global intrinsic function declaration type table.\n";
431 OS << "#ifdef GET_INTRINSIC_GENERATOR_GLOBAL\n";
432
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000433 OS << "static const unsigned IIT_Table[] = {\n ";
434
435 for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) {
436 if ((i & 7) == 7)
437 OS << "\n ";
Chris Lattner387c9dc2012-05-17 15:55:41 +0000438
439 // If the entry fit in the table, just emit it.
440 if (FixedEncodings[i] != ~0U) {
Chris Lattnera98aa6a2012-05-16 06:34:44 +0000441 OS << "0x" << utohexstr(FixedEncodings[i]) << ", ";
Chris Lattner387c9dc2012-05-17 15:55:41 +0000442 continue;
Jim Laskey95af5922007-02-07 20:38:26 +0000443 }
Chris Lattner387c9dc2012-05-17 15:55:41 +0000444
445 TypeSig.clear();
446 ComputeFixedEncoding(Ints[i], TypeSig);
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000447
Chris Lattner387c9dc2012-05-17 15:55:41 +0000448
449 // Otherwise, emit the offset into the long encoding table. We emit it this
450 // way so that it is easier to read the offset in the .def file.
451 OS << "(1U<<31) | " << LongEncodingTable.get(TypeSig) << ", ";
Jim Laskey95af5922007-02-07 20:38:26 +0000452 }
Chris Lattner387c9dc2012-05-17 15:55:41 +0000453
454 OS << "0\n};\n\n";
455
456 // Emit the shared table of register lists.
457 OS << "static const unsigned char IIT_LongEncodingTable[] = {\n";
458 if (!LongEncodingTable.empty())
459 LongEncodingTable.emit(OS, printIITEntry);
460 OS << " 255\n};\n\n";
461
Patrik Hägglund9ce6f6f2012-05-23 12:34:56 +0000462 OS << "#endif\n\n"; // End of GET_INTRINSIC_GENERATOR_GLOBAL
Jim Laskey95af5922007-02-07 20:38:26 +0000463}
464
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000465enum ModRefKind {
466 MRK_none,
467 MRK_readonly,
468 MRK_readnone
469};
John McCallbd0fa4c2011-05-28 06:31:34 +0000470
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000471static ModRefKind getModRefKind(const CodeGenIntrinsic &intrinsic) {
472 switch (intrinsic.ModRef) {
473 case CodeGenIntrinsic::NoMem:
474 return MRK_readnone;
475 case CodeGenIntrinsic::ReadArgMem:
476 case CodeGenIntrinsic::ReadMem:
477 return MRK_readonly;
478 case CodeGenIntrinsic::ReadWriteArgMem:
479 case CodeGenIntrinsic::ReadWriteMem:
480 return MRK_none;
John McCallbd0fa4c2011-05-28 06:31:34 +0000481 }
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000482 llvm_unreachable("bad mod-ref kind");
John McCallbd0fa4c2011-05-28 06:31:34 +0000483}
484
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000485namespace {
486struct AttributeComparator {
487 bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const {
488 // Sort throwing intrinsics after non-throwing intrinsics.
489 if (L->canThrow != R->canThrow)
490 return R->canThrow;
491
492 if (L->isNoReturn != R->isNoReturn)
493 return R->isNoReturn;
494
495 // Try to order by readonly/readnone attribute.
496 ModRefKind LK = getModRefKind(*L);
497 ModRefKind RK = getModRefKind(*R);
498 if (LK != RK) return (LK > RK);
499
500 // Order by argument attributes.
501 // This is reliable because each side is already sorted internally.
502 return (L->ArgumentAttributes < R->ArgumentAttributes);
503 }
504};
505} // End anonymous namespace
506
Chris Lattner048ffb22009-01-12 01:18:58 +0000507/// EmitAttributes - This emits the Intrinsic::getAttributes method.
Chris Lattner4e5f3592006-03-09 22:37:52 +0000508void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000509EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000510 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
511 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000512 if (TargetOnly)
513 OS << "static AttrListPtr getAttributes(" << TargetPrefix
John McCallbd0fa4c2011-05-28 06:31:34 +0000514 << "Intrinsic::ID id) {\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000515 else
John McCallbd0fa4c2011-05-28 06:31:34 +0000516 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n";
517
Craig Topper1f595232012-02-28 06:32:00 +0000518 // Compute the maximum number of attribute arguments and the map
519 typedef std::map<const CodeGenIntrinsic*, unsigned,
520 AttributeComparator> UniqAttrMapTy;
521 UniqAttrMapTy UniqAttributes;
John McCallbd0fa4c2011-05-28 06:31:34 +0000522 unsigned maxArgAttrs = 0;
Craig Topper1f595232012-02-28 06:32:00 +0000523 unsigned AttrNum = 0;
Chris Lattner7056de32006-03-24 01:13:55 +0000524 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
John McCallbd0fa4c2011-05-28 06:31:34 +0000525 const CodeGenIntrinsic &intrinsic = Ints[i];
John McCallbd0fa4c2011-05-28 06:31:34 +0000526 maxArgAttrs =
527 std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
Craig Topper1f595232012-02-28 06:32:00 +0000528 unsigned &N = UniqAttributes[&intrinsic];
529 if (N) continue;
530 assert(AttrNum < 256 && "Too many unique attributes for table!");
531 N = ++AttrNum;
Chris Lattner7056de32006-03-24 01:13:55 +0000532 }
John McCallbd0fa4c2011-05-28 06:31:34 +0000533
534 // Emit an array of AttributeWithIndex. Most intrinsics will have
535 // at least one entry, for the function itself (index ~1), which is
536 // usually nounwind.
Craig Topper1f595232012-02-28 06:32:00 +0000537 OS << " static const uint8_t IntrinsicsToAttributesMap[] = {\n";
Craig Topper1f595232012-02-28 06:32:00 +0000538
539 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
540 const CodeGenIntrinsic &intrinsic = Ints[i];
541
542 OS << " " << UniqAttributes[&intrinsic] << ", // "
543 << intrinsic.Name << "\n";
544 }
545 OS << " };\n\n";
546
John McCallbd0fa4c2011-05-28 06:31:34 +0000547 OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000548 OS << " unsigned NumAttrs = 0;\n";
Craig Topperb57b1702012-04-13 06:14:57 +0000549 OS << " if (id != 0) {\n";
550 OS << " switch(IntrinsicsToAttributesMap[id - ";
551 if (TargetOnly)
552 OS << "Intrinsic::num_intrinsics";
553 else
554 OS << "1";
555 OS << "]) {\n";
556 OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
Craig Topper1f595232012-02-28 06:32:00 +0000557 for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
558 E = UniqAttributes.end(); I != E; ++I) {
Craig Topperb57b1702012-04-13 06:14:57 +0000559 OS << " case " << I->second << ":\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000560
Craig Topper1f595232012-02-28 06:32:00 +0000561 const CodeGenIntrinsic &intrinsic = *(I->first);
John McCallbd0fa4c2011-05-28 06:31:34 +0000562
563 // Keep track of the number of attributes we're writing out.
564 unsigned numAttrs = 0;
565
566 // The argument attributes are alreadys sorted by argument index.
567 for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) {
568 unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
Craig Topper1f595232012-02-28 06:32:00 +0000569
Craig Topperb57b1702012-04-13 06:14:57 +0000570 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
John McCallbd0fa4c2011-05-28 06:31:34 +0000571 << argNo+1 << ", ";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000572
John McCallbd0fa4c2011-05-28 06:31:34 +0000573 bool moreThanOne = false;
574
575 do {
576 if (moreThanOne) OS << '|';
577
578 switch (intrinsic.ArgumentAttributes[ai].second) {
Chris Lattnerd4a27002009-01-12 02:41:37 +0000579 case CodeGenIntrinsic::NoCapture:
John McCallbd0fa4c2011-05-28 06:31:34 +0000580 OS << "Attribute::NoCapture";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000581 break;
582 }
John McCallbd0fa4c2011-05-28 06:31:34 +0000583
584 ++ai;
585 moreThanOne = true;
586 } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
587
588 OS << ");\n";
589 }
590
591 ModRefKind modRef = getModRefKind(intrinsic);
592
Chris Lattner86208902012-05-27 23:20:41 +0000593 if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) {
Craig Topperb57b1702012-04-13 06:14:57 +0000594 OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, ";
Chris Lattner86208902012-05-27 23:20:41 +0000595 bool Emitted = false;
John McCallbd0fa4c2011-05-28 06:31:34 +0000596 if (!intrinsic.canThrow) {
597 OS << "Attribute::NoUnwind";
Chris Lattner86208902012-05-27 23:20:41 +0000598 Emitted = true;
John McCallbd0fa4c2011-05-28 06:31:34 +0000599 }
Chris Lattner86208902012-05-27 23:20:41 +0000600
601 if (intrinsic.isNoReturn) {
602 if (Emitted) OS << '|';
603 OS << "Attribute::NoReturn";
604 Emitted = true;
605 }
606
John McCallbd0fa4c2011-05-28 06:31:34 +0000607 switch (modRef) {
608 case MRK_none: break;
Chris Lattner86208902012-05-27 23:20:41 +0000609 case MRK_readonly:
610 if (Emitted) OS << '|';
611 OS << "Attribute::ReadOnly";
612 break;
613 case MRK_readnone:
614 if (Emitted) OS << '|';
615 OS << "Attribute::ReadNone";
616 break;
Chris Lattnerd4a27002009-01-12 02:41:37 +0000617 }
618 OS << ");\n";
619 }
John McCallbd0fa4c2011-05-28 06:31:34 +0000620
621 if (numAttrs) {
Craig Topperb57b1702012-04-13 06:14:57 +0000622 OS << " NumAttrs = " << numAttrs << ";\n";
623 OS << " break;\n";
John McCallbd0fa4c2011-05-28 06:31:34 +0000624 } else {
Craig Topperb57b1702012-04-13 06:14:57 +0000625 OS << " return AttrListPtr();\n";
John McCallbd0fa4c2011-05-28 06:31:34 +0000626 }
Chris Lattner10dae942009-01-12 01:27:55 +0000627 }
628
Craig Topperb57b1702012-04-13 06:14:57 +0000629 OS << " }\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000630 OS << " }\n";
Chris Lattnerd509d0b2012-05-28 01:47:44 +0000631 OS << " return AttrListPtr::get(ArrayRef<AttributeWithIndex>(AWI, "
632 "NumAttrs));\n";
Chris Lattner048ffb22009-01-12 01:18:58 +0000633 OS << "}\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000634 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000635}
Chris Lattner022f64f2006-03-13 23:08:44 +0000636
Duncan Sandsd869b382009-02-14 10:56:35 +0000637/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
638void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000639EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000640 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n"
641 << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n"
642 << "assert(iid <= Intrinsic::" << Ints.back().EnumName << " && "
643 << "\"Unknown intrinsic.\");\n\n";
644
645 OS << "static const uint8_t IntrinsicModRefBehavior[] = {\n"
646 << " /* invalid */ UnknownModRefBehavior,\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000647 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000648 OS << " /* " << TargetPrefix << Ints[i].EnumName << " */ ";
Duncan Sandsd869b382009-02-14 10:56:35 +0000649 switch (Ints[i].ModRef) {
Duncan Sandsd869b382009-02-14 10:56:35 +0000650 case CodeGenIntrinsic::NoMem:
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000651 OS << "DoesNotAccessMemory,\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000652 break;
653 case CodeGenIntrinsic::ReadArgMem:
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000654 OS << "OnlyReadsArgumentPointees,\n";
Dan Gohman9423f632010-11-09 20:07:20 +0000655 break;
Duncan Sandsd869b382009-02-14 10:56:35 +0000656 case CodeGenIntrinsic::ReadMem:
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000657 OS << "OnlyReadsMemory,\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000658 break;
Dan Gohman7365c092010-08-05 23:36:21 +0000659 case CodeGenIntrinsic::ReadWriteArgMem:
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000660 OS << "OnlyAccessesArgumentPointees,\n";
661 break;
662 case CodeGenIntrinsic::ReadWriteMem:
663 OS << "UnknownModRefBehavior,\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000664 break;
665 }
666 }
Benjamin Kramerb519a0f2012-03-01 01:18:32 +0000667 OS << "};\n\n"
668 << "return static_cast<ModRefBehavior>(IntrinsicModRefBehavior[iid]);\n"
669 << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000670}
671
Chris Lattner331bf922008-01-04 04:38:35 +0000672/// EmitTargetBuiltins - All of the builtins in the specified map are for the
673/// same target, and we already checked it.
674static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
Dale Johannesen49de9822009-02-05 01:49:45 +0000675 const std::string &TargetPrefix,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000676 raw_ostream &OS) {
Chris Lattner331bf922008-01-04 04:38:35 +0000677
Chris Lattner298b1762010-09-06 03:14:45 +0000678 std::vector<StringMatcher::StringPair> Results;
Chris Lattner331bf922008-01-04 04:38:35 +0000679
Chris Lattner298b1762010-09-06 03:14:45 +0000680 for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
681 E = BIM.end(); I != E; ++I) {
682 std::string ResultCode =
683 "return " + TargetPrefix + "Intrinsic::" + I->second + ";";
684 Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
Chris Lattner331bf922008-01-04 04:38:35 +0000685 }
Chris Lattner298b1762010-09-06 03:14:45 +0000686
687 StringMatcher("BuiltinName", Results, OS).Emit();
Chris Lattner331bf922008-01-04 04:38:35 +0000688}
689
690
Chris Lattner3f8b8912006-03-15 01:33:26 +0000691void IntrinsicEmitter::
692EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000693 raw_ostream &OS) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000694 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
Chris Lattner3f8b8912006-03-15 01:33:26 +0000695 BIMTy BuiltinMap;
696 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
697 if (!Ints[i].GCCBuiltinName.empty()) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000698 // Get the map for this target prefix.
699 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
700
701 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
702 Ints[i].EnumName)).second)
Chris Lattner3f8b8912006-03-15 01:33:26 +0000703 throw "Intrinsic '" + Ints[i].TheDef->getName() +
704 "': duplicate GCC builtin name!";
705 }
706 }
707
708 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
709 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
710 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
711 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
712 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000713
714 if (TargetOnly) {
715 OS << "static " << TargetPrefix << "Intrinsic::ID "
716 << "getIntrinsicForGCCBuiltin(const char "
Chris Lattner298b1762010-09-06 03:14:45 +0000717 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000718 } else {
719 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
Chris Lattner298b1762010-09-06 03:14:45 +0000720 << "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000721 }
722
Chris Lattner298b1762010-09-06 03:14:45 +0000723 OS << " StringRef BuiltinName(BuiltinNameStr);\n";
724 OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
Chris Lattner331bf922008-01-04 04:38:35 +0000725
Chris Lattner3f8b8912006-03-15 01:33:26 +0000726 // Note: this could emit significantly better code if we cared.
727 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000728 OS << " ";
729 if (!I->first.empty())
Chris Lattner298b1762010-09-06 03:14:45 +0000730 OS << "if (TargetPrefix == \"" << I->first << "\") ";
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000731 else
732 OS << "/* Target Independent Builtins */ ";
733 OS << "{\n";
734
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000735 // Emit the comparisons for this target prefix.
Dale Johannesen49de9822009-02-05 01:49:45 +0000736 EmitTargetBuiltins(I->second, TargetPrefix, OS);
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000737 OS << " }\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000738 }
Chris Lattner298b1762010-09-06 03:14:45 +0000739 OS << " return ";
740 if (!TargetPrefix.empty())
741 OS << "(" << TargetPrefix << "Intrinsic::ID)";
742 OS << "Intrinsic::not_intrinsic;\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000743 OS << "}\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000744 OS << "#endif\n\n";
745}
Jakob Stoklund Olesen6f36fa92012-06-11 15:37:55 +0000746
747namespace llvm {
748
749void EmitIntrinsics(RecordKeeper &RK, raw_ostream &OS, bool TargetOnly = false) {
750 IntrinsicEmitter(RK, TargetOnly).run(OS);
751}
752
753} // End llvm namespace