blob: 23919d97f2bf1903daa4ea237b8e39c5bdb76943 [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
Chandler Carruth69940402007-08-04 01:51:18 +000014#include "CodeGenTarget.h"
Chris Lattner9e493cf2006-03-03 02:32:46 +000015#include "IntrinsicEmitter.h"
16#include "Record.h"
Chris Lattner18faf5d2006-03-13 22:38:57 +000017#include "llvm/ADT/StringExtras.h"
Jeff Cohen71c3bc32006-03-15 02:51:05 +000018#include <algorithm>
Chris Lattner9e493cf2006-03-03 02:32:46 +000019using namespace llvm;
20
21//===----------------------------------------------------------------------===//
Chris Lattner9e493cf2006-03-03 02:32:46 +000022// IntrinsicEmitter Implementation
23//===----------------------------------------------------------------------===//
24
Daniel Dunbar1a551802009-07-03 00:10:29 +000025void IntrinsicEmitter::run(raw_ostream &OS) {
Chris Lattner9e493cf2006-03-03 02:32:46 +000026 EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
27
Dale Johannesen49de9822009-02-05 01:49:45 +000028 std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
29
30 if (TargetOnly && !Ints.empty())
31 TargetPrefix = Ints[0].TargetPrefix;
Chris Lattner9e493cf2006-03-03 02:32:46 +000032
33 // Emit the enum information.
34 EmitEnumInfo(Ints, OS);
Chris Lattnerfda6aff2006-03-15 01:55:21 +000035
36 // Emit the intrinsic ID -> name table.
37 EmitIntrinsicToNameTable(Ints, OS);
Mon P Wang0d52ff12009-02-24 23:17:49 +000038
39 // Emit the intrinsic ID -> overload table.
40 EmitIntrinsicToOverloadTable(Ints, OS);
41
Chris Lattner9b843b22006-03-09 20:34:19 +000042 // Emit the function name recognizer.
43 EmitFnNameRecognizer(Ints, OS);
Chris Lattnerfda6aff2006-03-15 01:55:21 +000044
Chris Lattnerf97a00e2006-03-09 22:05:04 +000045 // Emit the intrinsic verifier.
46 EmitVerifier(Ints, OS);
Chris Lattner6448ee42006-03-09 22:30:49 +000047
Jim Laskey95af5922007-02-07 20:38:26 +000048 // Emit the intrinsic declaration generator.
49 EmitGenerator(Ints, OS);
50
Duncan Sandsa3355ff2007-12-03 20:06:50 +000051 // Emit the intrinsic parameter attributes.
52 EmitAttributes(Ints, OS);
Chris Lattner022f64f2006-03-13 23:08:44 +000053
Duncan Sandsd869b382009-02-14 10:56:35 +000054 // Emit intrinsic alias analysis mod/ref behavior.
55 EmitModRefBehavior(Ints, OS);
56
Chris Lattner022f64f2006-03-13 23:08:44 +000057 // Emit a list of intrinsics with corresponding GCC builtins.
58 EmitGCCBuiltinList(Ints, OS);
Chris Lattner3f8b8912006-03-15 01:33:26 +000059
60 // Emit code to translate GCC builtins into LLVM intrinsics.
61 EmitIntrinsicToGCCBuiltinMap(Ints, OS);
Chris Lattner9e493cf2006-03-03 02:32:46 +000062}
63
64void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +000065 raw_ostream &OS) {
Chris Lattner9b843b22006-03-09 20:34:19 +000066 OS << "// Enum values for Intrinsics.h\n";
Chris Lattner9e493cf2006-03-03 02:32:46 +000067 OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
68 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
69 OS << " " << Ints[i].EnumName;
70 OS << ((i != e-1) ? ", " : " ");
71 OS << std::string(40-Ints[i].EnumName.size(), ' ')
72 << "// " << Ints[i].Name << "\n";
73 }
74 OS << "#endif\n\n";
75}
Chris Lattner9b843b22006-03-09 20:34:19 +000076
77void IntrinsicEmitter::
78EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +000079 raw_ostream &OS) {
Chris Lattner9b843b22006-03-09 20:34:19 +000080 // Build a function name -> intrinsic name mapping.
Reid Spencerc4de3de2007-04-01 07:20:02 +000081 std::map<std::string, unsigned> IntMapping;
Chris Lattner9b843b22006-03-09 20:34:19 +000082 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Reid Spencerc4de3de2007-04-01 07:20:02 +000083 IntMapping[Ints[i].Name] = i;
Chris Lattner9b843b22006-03-09 20:34:19 +000084
85 OS << "// Function name -> enum value recognizer code.\n";
86 OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
87 OS << " switch (Name[5]) {\n";
Chris Lattner3b515802007-02-15 19:17:16 +000088 OS << " default:\n";
Chris Lattner9b843b22006-03-09 20:34:19 +000089 // Emit the intrinsics in sorted order.
90 char LastChar = 0;
Reid Spencerc4de3de2007-04-01 07:20:02 +000091 for (std::map<std::string, unsigned>::iterator I = IntMapping.begin(),
Chris Lattner9b843b22006-03-09 20:34:19 +000092 E = IntMapping.end(); I != E; ++I) {
Chris Lattner9b843b22006-03-09 20:34:19 +000093 if (I->first[5] != LastChar) {
94 LastChar = I->first[5];
Chris Lattner3b515802007-02-15 19:17:16 +000095 OS << " break;\n";
Chris Lattner9b843b22006-03-09 20:34:19 +000096 OS << " case '" << LastChar << "':\n";
97 }
98
Reid Spencerc4de3de2007-04-01 07:20:02 +000099 // For overloaded intrinsics, only the prefix needs to match
100 if (Ints[I->second].isOverloaded)
Chandler Carruth69940402007-08-04 01:51:18 +0000101 OS << " if (Len > " << I->first.size()
102 << " && !memcmp(Name, \"" << I->first << ".\", "
Dale Johannesen49de9822009-02-05 01:49:45 +0000103 << (I->first.size() + 1) << ")) return " << TargetPrefix << "Intrinsic::"
Chandler Carruth69940402007-08-04 01:51:18 +0000104 << Ints[I->second].EnumName << ";\n";
Reid Spencerc4de3de2007-04-01 07:20:02 +0000105 else
106 OS << " if (Len == " << I->first.size()
Chandler Carruth69940402007-08-04 01:51:18 +0000107 << " && !memcmp(Name, \"" << I->first << "\", "
Dale Johannesen49de9822009-02-05 01:49:45 +0000108 << I->first.size() << ")) return " << TargetPrefix << "Intrinsic::"
Reid Spencerc4de3de2007-04-01 07:20:02 +0000109 << Ints[I->second].EnumName << ";\n";
Chris Lattner9b843b22006-03-09 20:34:19 +0000110 }
111 OS << " }\n";
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000112 OS << "#endif\n\n";
113}
114
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000115void IntrinsicEmitter::
116EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000117 raw_ostream &OS) {
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000118 OS << "// Intrinsic ID to name table\n";
119 OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
120 OS << " // Note that entry #0 is the invalid intrinsic!\n";
Evan Chengf065a6f2006-03-28 22:25:56 +0000121 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
122 OS << " \"" << Ints[i].Name << "\",\n";
Chris Lattnerfda6aff2006-03-15 01:55:21 +0000123 OS << "#endif\n\n";
124}
125
Mon P Wang0d52ff12009-02-24 23:17:49 +0000126void IntrinsicEmitter::
127EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000128 raw_ostream &OS) {
Mon P Wang0d52ff12009-02-24 23:17:49 +0000129 OS << "// Intrinsic ID to overload table\n";
130 OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
131 OS << " // Note that entry #0 is the invalid intrinsic!\n";
132 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
133 OS << " ";
134 if (Ints[i].isOverloaded)
135 OS << "true";
136 else
137 OS << "false";
138 OS << ",\n";
139 }
140 OS << "#endif\n\n";
141}
142
Owen Anderson825b72b2009-08-11 20:47:22 +0000143static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) {
Owen Andersone50ed302009-08-10 22:56:29 +0000144 if (EVT(VT).isInteger()) {
145 unsigned BitWidth = EVT(VT).getSizeInBits();
Owen Anderson1d0be152009-08-13 21:58:54 +0000146 OS << "IntegerType::get(Context, " << BitWidth << ")";
Owen Anderson825b72b2009-08-11 20:47:22 +0000147 } else if (VT == MVT::Other) {
148 // MVT::OtherVT is used to mean the empty struct type here.
Owen Andersond7f2a6c2009-08-05 23:16:16 +0000149 OS << "StructType::get(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000150 } else if (VT == MVT::f32) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000151 OS << "Type::getFloatTy(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000152 } else if (VT == MVT::f64) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000153 OS << "Type::getDoubleTy(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000154 } else if (VT == MVT::f80) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000155 OS << "Type::getX86_FP80Ty(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000156 } else if (VT == MVT::f128) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000157 OS << "Type::getFP128Ty(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000158 } else if (VT == MVT::ppcf128) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000159 OS << "Type::getPPC_FP128Ty(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000160 } else if (VT == MVT::isVoid) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000161 OS << "Type::getVoidTy(Context)";
Owen Anderson825b72b2009-08-11 20:47:22 +0000162 } else if (VT == MVT::Metadata) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000163 OS << "Type::getMetadataTy(Context)";
Chandler Carruth69940402007-08-04 01:51:18 +0000164 } else {
165 assert(false && "Unsupported ValueType!");
Chris Lattner18faf5d2006-03-13 22:38:57 +0000166 }
167}
168
Daniel Dunbar1a551802009-07-03 00:10:29 +0000169static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000170 unsigned &ArgNo);
171
Daniel Dunbar1a551802009-07-03 00:10:29 +0000172static void EmitTypeGenerate(raw_ostream &OS,
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000173 const std::vector<Record*> &ArgTypes,
174 unsigned &ArgNo) {
175 if (ArgTypes.size() == 1) {
176 EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
177 return;
178 }
179
Owen Andersond7f2a6c2009-08-05 23:16:16 +0000180 OS << "StructType::get(Context, ";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000181
182 for (std::vector<Record*>::const_iterator
Bill Wendling20072af2008-11-13 10:18:35 +0000183 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000184 EmitTypeGenerate(OS, *I, ArgNo);
Bill Wendling20072af2008-11-13 10:18:35 +0000185 OS << ", ";
186 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000187
Bill Wendling20072af2008-11-13 10:18:35 +0000188 OS << " NULL)";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000189}
190
Daniel Dunbar1a551802009-07-03 00:10:29 +0000191static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
Reid Spencer84c614d2007-05-22 19:30:31 +0000192 unsigned &ArgNo) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000193 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Chandler Carruth69940402007-08-04 01:51:18 +0000194
195 if (ArgType->isSubClassOf("LLVMMatchType")) {
196 unsigned Number = ArgType->getValueAsInt("Number");
197 assert(Number < ArgNo && "Invalid matching number!");
Bob Wilsonbc039792009-01-07 00:09:01 +0000198 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
199 OS << "VectorType::getExtendedElementVectorType"
200 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
201 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
202 OS << "VectorType::getTruncatedElementVectorType"
203 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
204 else
205 OS << "Tys[" << Number << "]";
Owen Anderson825b72b2009-08-11 20:47:22 +0000206 } else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny) {
Reid Spencer84c614d2007-05-22 19:30:31 +0000207 // NOTE: The ArgNo variable here is not the absolute argument number, it is
208 // the index of the "arbitrary" type in the Tys array passed to the
209 // Intrinsic::getDeclaration function. Consequently, we only want to
Chandler Carruth69940402007-08-04 01:51:18 +0000210 // increment it when we actually hit an overloaded type. Getting this wrong
211 // leads to very subtle bugs!
212 OS << "Tys[" << ArgNo++ << "]";
Owen Andersone50ed302009-08-10 22:56:29 +0000213 } else if (EVT(VT).isVector()) {
214 EVT VVT = VT;
Reid Spencer9d6565a2007-02-15 02:26:10 +0000215 OS << "VectorType::get(";
Owen Anderson825b72b2009-08-11 20:47:22 +0000216 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy);
Duncan Sands83ec4b62008-06-06 12:08:01 +0000217 OS << ", " << VVT.getVectorNumElements() << ")";
Owen Anderson825b72b2009-08-11 20:47:22 +0000218 } else if (VT == MVT::iPTR) {
Christopher Lamb43ad6b32007-12-17 01:12:55 +0000219 OS << "PointerType::getUnqual(";
Reid Spencerc4de3de2007-04-01 07:20:02 +0000220 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000221 OS << ")";
Owen Anderson825b72b2009-08-11 20:47:22 +0000222 } else if (VT == MVT::iPTRAny) {
Mon P Wange3b3a722008-07-30 04:36:53 +0000223 // Make sure the user has passed us an argument type to overload. If not,
224 // treat it as an ordinary (not overloaded) intrinsic.
225 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
226 << "] : PointerType::getUnqual(";
227 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
228 OS << ")";
229 ++ArgNo;
Owen Anderson825b72b2009-08-11 20:47:22 +0000230 } else if (VT == MVT::isVoid) {
Chandler Carruth69940402007-08-04 01:51:18 +0000231 if (ArgNo == 0)
Owen Anderson1d0be152009-08-13 21:58:54 +0000232 OS << "Type::getVoidTy(Context)";
Chandler Carruth69940402007-08-04 01:51:18 +0000233 else
Owen Anderson825b72b2009-08-11 20:47:22 +0000234 // MVT::isVoid is used to mean varargs here.
Chandler Carruth69940402007-08-04 01:51:18 +0000235 OS << "...";
Jim Laskey95af5922007-02-07 20:38:26 +0000236 } else {
Chandler Carruth69940402007-08-04 01:51:18 +0000237 EmitTypeForValueType(OS, VT);
Jim Laskey95af5922007-02-07 20:38:26 +0000238 }
239}
240
Jim Grosbachda4231f2009-03-26 16:17:51 +0000241/// RecordListComparator - Provide a deterministic comparator for lists of
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000242/// records.
243namespace {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000244 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000245 struct RecordListComparator {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000246 bool operator()(const RecPair &LHS,
247 const RecPair &RHS) const {
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000248 unsigned i = 0;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000249 const std::vector<Record*> *LHSVec = &LHS.first;
250 const std::vector<Record*> *RHSVec = &RHS.first;
251 unsigned RHSSize = RHSVec->size();
252 unsigned LHSSize = LHSVec->size();
253
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000254 do {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000255 if (i == RHSSize) return false; // RHS is shorter than LHS.
256 if ((*LHSVec)[i] != (*RHSVec)[i])
257 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
258 } while (++i != LHSSize);
259
Bill Wendling023422a2008-11-13 12:03:00 +0000260 if (i != RHSSize) return true;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000261
262 i = 0;
263 LHSVec = &LHS.second;
264 RHSVec = &RHS.second;
265 RHSSize = RHSVec->size();
266 LHSSize = LHSVec->size();
267
268 for (i = 0; i != LHSSize; ++i) {
269 if (i == RHSSize) return false; // RHS is shorter than LHS.
270 if ((*LHSVec)[i] != (*RHSVec)[i])
271 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
272 }
273
274 return i != RHSSize;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000275 }
276 };
277}
278
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000279void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000280 raw_ostream &OS) {
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000281 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
282 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
283 OS << " switch (ID) {\n";
284 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000285
286 // This checking can emit a lot of very common code. To reduce the amount of
287 // code that we emit, batch up cases that have identical types. This avoids
288 // problems where GCC can run out of memory compiling Verifier.cpp.
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000289 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000290 MapTy UniqueArgInfos;
291
292 // Compute the unique argument type info.
293 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000294 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
295 Ints[i].IS.ParamTypeDefs)].push_back(i);
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000296
297 // Loop through the array, emitting one comparison for each batch.
298 for (MapTy::iterator I = UniqueArgInfos.begin(),
299 E = UniqueArgInfos.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000300 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000301 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
302 << Ints[I->second[i]].Name << "\n";
Chris Lattnerf124b462006-03-31 04:48:26 +0000303
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000304 const RecPair &ArgTypes = I->first;
305 const std::vector<Record*> &RetTys = ArgTypes.first;
306 const std::vector<Record*> &ParamTys = ArgTypes.second;
Bob Wilson09b13662009-07-29 16:35:59 +0000307 std::vector<unsigned> OverloadedTypeIndices;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000308
309 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
310 << ParamTys.size();
311
312 // Emit return types.
313 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
314 Record *ArgType = RetTys[j];
315 OS << ", ";
316
Chandler Carruth69940402007-08-04 01:51:18 +0000317 if (ArgType->isSubClassOf("LLVMMatchType")) {
318 unsigned Number = ArgType->getValueAsInt("Number");
Bob Wilson09b13662009-07-29 16:35:59 +0000319 assert(Number < OverloadedTypeIndices.size() &&
320 "Invalid matching number!");
321 Number = OverloadedTypeIndices[Number];
Bob Wilsonbc039792009-01-07 00:09:01 +0000322 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
323 OS << "~(ExtendedElementVectorType | " << Number << ")";
324 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
325 OS << "~(TruncatedElementVectorType | " << Number << ")";
326 else
327 OS << "~" << Number;
Chandler Carruth69940402007-08-04 01:51:18 +0000328 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000329 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Chandler Carruth69940402007-08-04 01:51:18 +0000330 OS << getEnumName(VT);
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000331
Bob Wilson61fc4cf2009-08-11 01:14:02 +0000332 if (EVT(VT).isOverloaded())
Bob Wilson09b13662009-07-29 16:35:59 +0000333 OverloadedTypeIndices.push_back(j);
334
Owen Anderson825b72b2009-08-11 20:47:22 +0000335 if (VT == MVT::isVoid && j != 0 && j != je - 1)
Jim Laskey95d97b92007-02-06 18:30:58 +0000336 throw "Var arg type not last argument";
Jim Laskey95d97b92007-02-06 18:30:58 +0000337 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000338 }
339
340 // Emit the parameter types.
341 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
342 Record *ArgType = ParamTys[j];
343 OS << ", ";
344
345 if (ArgType->isSubClassOf("LLVMMatchType")) {
346 unsigned Number = ArgType->getValueAsInt("Number");
Bob Wilson09b13662009-07-29 16:35:59 +0000347 assert(Number < OverloadedTypeIndices.size() &&
348 "Invalid matching number!");
349 Number = OverloadedTypeIndices[Number];
Bob Wilsonbc039792009-01-07 00:09:01 +0000350 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
351 OS << "~(ExtendedElementVectorType | " << Number << ")";
352 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
353 OS << "~(TruncatedElementVectorType | " << Number << ")";
354 else
355 OS << "~" << Number;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000356 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000357 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000358 OS << getEnumName(VT);
359
Bob Wilson61fc4cf2009-08-11 01:14:02 +0000360 if (EVT(VT).isOverloaded())
Bob Wilson09b13662009-07-29 16:35:59 +0000361 OverloadedTypeIndices.push_back(j + RetTys.size());
362
Owen Anderson825b72b2009-08-11 20:47:22 +0000363 if (VT == MVT::isVoid && j != 0 && j != je - 1)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000364 throw "Var arg type not last argument";
365 }
Jim Laskey95d97b92007-02-06 18:30:58 +0000366 }
367
Chandler Carruth69940402007-08-04 01:51:18 +0000368 OS << ");\n";
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000369 OS << " break;\n";
370 }
371 OS << " }\n";
372 OS << "#endif\n\n";
Chris Lattner9b843b22006-03-09 20:34:19 +0000373}
374
Jim Laskey95af5922007-02-07 20:38:26 +0000375void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000376 raw_ostream &OS) {
Jim Laskey95af5922007-02-07 20:38:26 +0000377 OS << "// Code for generating Intrinsic function declarations.\n";
378 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
379 OS << " switch (id) {\n";
380 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
381
382 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
383 // types.
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000384 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
Jim Laskey95af5922007-02-07 20:38:26 +0000385 MapTy UniqueArgInfos;
386
387 // Compute the unique argument type info.
388 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000389 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
390 Ints[i].IS.ParamTypeDefs)].push_back(i);
Jim Laskey95af5922007-02-07 20:38:26 +0000391
392 // Loop through the array, emitting one generator for each batch.
Dale Johannesen49de9822009-02-05 01:49:45 +0000393 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
394
Jim Laskey95af5922007-02-07 20:38:26 +0000395 for (MapTy::iterator I = UniqueArgInfos.begin(),
396 E = UniqueArgInfos.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000397 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
Dale Johannesen49de9822009-02-05 01:49:45 +0000398 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
399 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
Jim Laskey95af5922007-02-07 20:38:26 +0000400
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000401 const RecPair &ArgTypes = I->first;
402 const std::vector<Record*> &RetTys = ArgTypes.first;
403 const std::vector<Record*> &ParamTys = ArgTypes.second;
404
405 unsigned N = ParamTys.size();
Jim Laskey95af5922007-02-07 20:38:26 +0000406
Chandler Carruth69940402007-08-04 01:51:18 +0000407 if (N > 1 &&
Owen Anderson825b72b2009-08-11 20:47:22 +0000408 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
Jim Laskey95af5922007-02-07 20:38:26 +0000409 OS << " IsVarArg = true;\n";
410 --N;
411 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000412
Reid Spencer84c614d2007-05-22 19:30:31 +0000413 unsigned ArgNo = 0;
Jim Laskey95af5922007-02-07 20:38:26 +0000414 OS << " ResultTy = ";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000415 EmitTypeGenerate(OS, RetTys, ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000416 OS << ";\n";
417
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000418 for (unsigned j = 0; j != N; ++j) {
Jim Laskey95af5922007-02-07 20:38:26 +0000419 OS << " ArgTys.push_back(";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000420 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000421 OS << ");\n";
422 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000423
Jim Laskey95af5922007-02-07 20:38:26 +0000424 OS << " break;\n";
425 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000426
Jim Laskey95af5922007-02-07 20:38:26 +0000427 OS << " }\n";
428 OS << "#endif\n\n";
429}
430
Chris Lattner048ffb22009-01-12 01:18:58 +0000431/// EmitAttributes - This emits the Intrinsic::getAttributes method.
Chris Lattner4e5f3592006-03-09 22:37:52 +0000432void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000433EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000434 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
435 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000436 if (TargetOnly)
437 OS << "static AttrListPtr getAttributes(" << TargetPrefix
438 << "Intrinsic::ID id) {";
439 else
440 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
Chris Lattner048ffb22009-01-12 01:18:58 +0000441 OS << " // No intrinsic can throw exceptions.\n";
442 OS << " Attributes Attr = Attribute::NoUnwind;\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000443 OS << " switch (id) {\n";
Chris Lattner7056de32006-03-24 01:13:55 +0000444 OS << " default: break;\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000445 unsigned MaxArgAttrs = 0;
Chris Lattner7056de32006-03-24 01:13:55 +0000446 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
Chris Lattner10dae942009-01-12 01:27:55 +0000447 MaxArgAttrs =
448 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
Chris Lattner7056de32006-03-24 01:13:55 +0000449 switch (Ints[i].ModRef) {
450 default: break;
451 case CodeGenIntrinsic::NoMem:
Dale Johannesen49de9822009-02-05 01:49:45 +0000452 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
453 << ":\n";
Chris Lattner7056de32006-03-24 01:13:55 +0000454 break;
455 }
456 }
Devang Patel05988662008-09-25 21:00:45 +0000457 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000458 OS << " break;\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000459 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
460 switch (Ints[i].ModRef) {
Chris Lattner022f64f2006-03-13 23:08:44 +0000461 default: break;
Chris Lattner022f64f2006-03-13 23:08:44 +0000462 case CodeGenIntrinsic::ReadArgMem:
463 case CodeGenIntrinsic::ReadMem:
Dale Johannesen49de9822009-02-05 01:49:45 +0000464 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
465 << ":\n";
Chris Lattner022f64f2006-03-13 23:08:44 +0000466 break;
Chris Lattner4e5f3592006-03-09 22:37:52 +0000467 }
468 }
Devang Patel05988662008-09-25 21:00:45 +0000469 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000470 OS << " break;\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000471 OS << " }\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000472 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000473 OS << " unsigned NumAttrs = 0;\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000474 OS << " switch (id) {\n";
475 OS << " default: break;\n";
476
477 // Add argument attributes for any intrinsics that have them.
478 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
479 if (Ints[i].ArgumentAttributes.empty()) continue;
480
Dale Johannesen49de9822009-02-05 01:49:45 +0000481 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
482 << ":\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000483
484 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
485 Ints[i].ArgumentAttributes;
486 // Sort by argument index.
487 std::sort(ArgAttrs.begin(), ArgAttrs.end());
488
489 unsigned NumArgsWithAttrs = 0;
490
Chris Lattnerd4a27002009-01-12 02:41:37 +0000491 while (!ArgAttrs.empty()) {
492 unsigned ArgNo = ArgAttrs[0].first;
493
494 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
495 << ArgNo+1 << ", 0";
496
497 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
498 switch (ArgAttrs[0].second) {
499 default: assert(0 && "Unknown arg attribute");
500 case CodeGenIntrinsic::NoCapture:
501 OS << "|Attribute::NoCapture";
502 break;
503 }
504 ArgAttrs.erase(ArgAttrs.begin());
505 }
506 OS << ");\n";
507 }
Chris Lattner10dae942009-01-12 01:27:55 +0000508
Chris Lattnerd4a27002009-01-12 02:41:37 +0000509 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000510 OS << " break;\n";
511 }
512
513 OS << " }\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000514 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
515 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
Chris Lattner048ffb22009-01-12 01:18:58 +0000516 OS << "}\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000517 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000518}
Chris Lattner022f64f2006-03-13 23:08:44 +0000519
Duncan Sandsd869b382009-02-14 10:56:35 +0000520/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
521void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000522EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
Duncan Sandsd869b382009-02-14 10:56:35 +0000523 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
524 OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
525 OS << "switch (id) {\n";
526 OS << "default:\n return UnknownModRefBehavior;\n";
527 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
528 if (Ints[i].ModRef == CodeGenIntrinsic::WriteMem)
529 continue;
530 OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
531 << ":\n";
532 switch (Ints[i].ModRef) {
533 default:
534 assert(false && "Unknown Mod/Ref type!");
535 case CodeGenIntrinsic::NoMem:
536 OS << " return DoesNotAccessMemory;\n";
537 break;
538 case CodeGenIntrinsic::ReadArgMem:
539 case CodeGenIntrinsic::ReadMem:
540 OS << " return OnlyReadsMemory;\n";
541 break;
542 case CodeGenIntrinsic::WriteArgMem:
543 OS << " return AccessesArguments;\n";
544 break;
545 }
546 }
547 OS << "}\n";
548 OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
549}
550
Chris Lattner022f64f2006-03-13 23:08:44 +0000551void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000552EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
Chris Lattner022f64f2006-03-13 23:08:44 +0000553 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
554 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
555 OS << " switch (F->getIntrinsicID()) {\n";
556 OS << " default: BuiltinName = \"\"; break;\n";
557 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
558 if (!Ints[i].GCCBuiltinName.empty()) {
559 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
560 << Ints[i].GCCBuiltinName << "\"; break;\n";
561 }
562 }
563 OS << " }\n";
564 OS << "#endif\n\n";
Reid Spencer767a25b2006-03-14 05:59:52 +0000565}
Chris Lattner3f8b8912006-03-15 01:33:26 +0000566
Chris Lattner331bf922008-01-04 04:38:35 +0000567/// EmitBuiltinComparisons - Emit comparisons to determine whether the specified
568/// sorted range of builtin names is equal to the current builtin. This breaks
569/// it down into a simple tree.
570///
571/// At this point, we know that all the builtins in the range have the same name
572/// for the first 'CharStart' characters. Only the end of the name needs to be
573/// discriminated.
574typedef std::map<std::string, std::string>::const_iterator StrMapIterator;
575static void EmitBuiltinComparisons(StrMapIterator Start, StrMapIterator End,
576 unsigned CharStart, unsigned Indent,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000577 std::string TargetPrefix, raw_ostream &OS) {
Chris Lattner331bf922008-01-04 04:38:35 +0000578 if (Start == End) return; // empty range.
579
580 // Determine what, if anything, is the same about all these strings.
581 std::string CommonString = Start->first;
582 unsigned NumInRange = 0;
583 for (StrMapIterator I = Start; I != End; ++I, ++NumInRange) {
584 // Find the first character that doesn't match.
585 const std::string &ThisStr = I->first;
586 unsigned NonMatchChar = CharStart;
587 while (NonMatchChar < CommonString.size() &&
588 NonMatchChar < ThisStr.size() &&
589 CommonString[NonMatchChar] == ThisStr[NonMatchChar])
590 ++NonMatchChar;
591 // Truncate off pieces that don't match.
592 CommonString.resize(NonMatchChar);
593 }
594
595 // Just compare the rest of the string.
596 if (NumInRange == 1) {
597 if (CharStart != CommonString.size()) {
598 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
599 if (CharStart) OS << "+" << CharStart;
600 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
601 OS << CommonString.size() - CharStart << "))\n";
602 ++Indent;
603 }
Dale Johannesen49de9822009-02-05 01:49:45 +0000604 OS << std::string(Indent*2, ' ') << "IntrinsicID = " << TargetPrefix
605 << "Intrinsic::";
Chris Lattner331bf922008-01-04 04:38:35 +0000606 OS << Start->second << ";\n";
607 return;
608 }
609
610 // At this point, we potentially have a common prefix for these builtins, emit
611 // a check for this common prefix.
612 if (CommonString.size() != CharStart) {
613 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
614 if (CharStart) OS << "+" << CharStart;
615 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
616 OS << CommonString.size()-CharStart << ")) {\n";
617
Dale Johannesen49de9822009-02-05 01:49:45 +0000618 EmitBuiltinComparisons(Start, End, CommonString.size(), Indent+1,
619 TargetPrefix, OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000620 OS << std::string(Indent*2, ' ') << "}\n";
621 return;
622 }
623
624 // Output a switch on the character that differs across the set.
625 OS << std::string(Indent*2, ' ') << "switch (BuiltinName[" << CharStart
626 << "]) {";
627 if (CharStart)
628 OS << " // \"" << std::string(Start->first.begin(),
629 Start->first.begin()+CharStart) << "\"";
630 OS << "\n";
631
632 for (StrMapIterator I = Start; I != End; ) {
633 char ThisChar = I->first[CharStart];
634 OS << std::string(Indent*2, ' ') << "case '" << ThisChar << "':\n";
635 // Figure out the range that has this common character.
636 StrMapIterator NextChar = I;
637 for (++NextChar; NextChar != End && NextChar->first[CharStart] == ThisChar;
638 ++NextChar)
639 /*empty*/;
Dale Johannesen49de9822009-02-05 01:49:45 +0000640 EmitBuiltinComparisons(I, NextChar, CharStart+1, Indent+1, TargetPrefix,OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000641 OS << std::string(Indent*2, ' ') << " break;\n";
642 I = NextChar;
643 }
644 OS << std::string(Indent*2, ' ') << "}\n";
645}
646
647/// EmitTargetBuiltins - All of the builtins in the specified map are for the
648/// same target, and we already checked it.
649static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
Dale Johannesen49de9822009-02-05 01:49:45 +0000650 const std::string &TargetPrefix,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000651 raw_ostream &OS) {
Chris Lattner331bf922008-01-04 04:38:35 +0000652 // Rearrange the builtins by length.
653 std::vector<std::map<std::string, std::string> > BuiltinsByLen;
654 BuiltinsByLen.reserve(100);
655
656 for (StrMapIterator I = BIM.begin(), E = BIM.end(); I != E; ++I) {
657 if (I->first.size() >= BuiltinsByLen.size())
658 BuiltinsByLen.resize(I->first.size()+1);
659 BuiltinsByLen[I->first.size()].insert(*I);
660 }
661
662 // Now that we have all the builtins by their length, emit a switch stmt.
663 OS << " switch (strlen(BuiltinName)) {\n";
664 OS << " default: break;\n";
665 for (unsigned i = 0, e = BuiltinsByLen.size(); i != e; ++i) {
666 if (BuiltinsByLen[i].empty()) continue;
667 OS << " case " << i << ":\n";
668 EmitBuiltinComparisons(BuiltinsByLen[i].begin(), BuiltinsByLen[i].end(),
Dale Johannesen49de9822009-02-05 01:49:45 +0000669 0, 3, TargetPrefix, OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000670 OS << " break;\n";
671 }
672 OS << " }\n";
673}
674
675
Chris Lattner3f8b8912006-03-15 01:33:26 +0000676void IntrinsicEmitter::
677EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000678 raw_ostream &OS) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000679 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
Chris Lattner3f8b8912006-03-15 01:33:26 +0000680 BIMTy BuiltinMap;
681 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
682 if (!Ints[i].GCCBuiltinName.empty()) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000683 // Get the map for this target prefix.
684 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
685
686 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
687 Ints[i].EnumName)).second)
Chris Lattner3f8b8912006-03-15 01:33:26 +0000688 throw "Intrinsic '" + Ints[i].TheDef->getName() +
689 "': duplicate GCC builtin name!";
690 }
691 }
692
693 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
694 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
695 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
696 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
697 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000698
699 if (TargetOnly) {
700 OS << "static " << TargetPrefix << "Intrinsic::ID "
701 << "getIntrinsicForGCCBuiltin(const char "
702 << "*TargetPrefix, const char *BuiltinName) {\n";
703 OS << " " << TargetPrefix << "Intrinsic::ID IntrinsicID = ";
704 } else {
705 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
706 << "*TargetPrefix, const char *BuiltinName) {\n";
707 OS << " Intrinsic::ID IntrinsicID = ";
708 }
709
710 if (TargetOnly)
711 OS << "(" << TargetPrefix<< "Intrinsic::ID)";
712
713 OS << "Intrinsic::not_intrinsic;\n";
Chris Lattner331bf922008-01-04 04:38:35 +0000714
Chris Lattner3f8b8912006-03-15 01:33:26 +0000715 // Note: this could emit significantly better code if we cared.
716 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000717 OS << " ";
718 if (!I->first.empty())
719 OS << "if (!strcmp(TargetPrefix, \"" << I->first << "\")) ";
720 else
721 OS << "/* Target Independent Builtins */ ";
722 OS << "{\n";
723
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000724 // Emit the comparisons for this target prefix.
Dale Johannesen49de9822009-02-05 01:49:45 +0000725 EmitTargetBuiltins(I->second, TargetPrefix, OS);
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000726 OS << " }\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000727 }
Dale Johannesen49de9822009-02-05 01:49:45 +0000728 OS << " return IntrinsicID;\n";
729 OS << "}\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000730 OS << "#endif\n\n";
731}