blob: 417aca7cb37b1f9cf4204f80065292d6b5574f9f [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) {
Chris Lattner93dc92e2010-03-22 20:56:36 +0000175 if (ArgTypes.empty())
176 return EmitTypeForValueType(OS, MVT::isVoid);
177
178 if (ArgTypes.size() == 1)
179 return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000180
Owen Andersond7f2a6c2009-08-05 23:16:16 +0000181 OS << "StructType::get(Context, ";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000182
183 for (std::vector<Record*>::const_iterator
Bill Wendling20072af2008-11-13 10:18:35 +0000184 I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000185 EmitTypeGenerate(OS, *I, ArgNo);
Bill Wendling20072af2008-11-13 10:18:35 +0000186 OS << ", ";
187 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000188
Bill Wendling20072af2008-11-13 10:18:35 +0000189 OS << " NULL)";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000190}
191
Daniel Dunbar1a551802009-07-03 00:10:29 +0000192static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
Reid Spencer84c614d2007-05-22 19:30:31 +0000193 unsigned &ArgNo) {
Owen Anderson825b72b2009-08-11 20:47:22 +0000194 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Chandler Carruth69940402007-08-04 01:51:18 +0000195
196 if (ArgType->isSubClassOf("LLVMMatchType")) {
197 unsigned Number = ArgType->getValueAsInt("Number");
198 assert(Number < ArgNo && "Invalid matching number!");
Bob Wilsonbc039792009-01-07 00:09:01 +0000199 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
200 OS << "VectorType::getExtendedElementVectorType"
201 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
202 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
203 OS << "VectorType::getTruncatedElementVectorType"
204 << "(dyn_cast<VectorType>(Tys[" << Number << "]))";
205 else
206 OS << "Tys[" << Number << "]";
Owen Anderson825b72b2009-08-11 20:47:22 +0000207 } else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny) {
Reid Spencer84c614d2007-05-22 19:30:31 +0000208 // NOTE: The ArgNo variable here is not the absolute argument number, it is
209 // the index of the "arbitrary" type in the Tys array passed to the
210 // Intrinsic::getDeclaration function. Consequently, we only want to
Chandler Carruth69940402007-08-04 01:51:18 +0000211 // increment it when we actually hit an overloaded type. Getting this wrong
212 // leads to very subtle bugs!
213 OS << "Tys[" << ArgNo++ << "]";
Owen Andersone50ed302009-08-10 22:56:29 +0000214 } else if (EVT(VT).isVector()) {
215 EVT VVT = VT;
Reid Spencer9d6565a2007-02-15 02:26:10 +0000216 OS << "VectorType::get(";
Owen Anderson825b72b2009-08-11 20:47:22 +0000217 EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy);
Duncan Sands83ec4b62008-06-06 12:08:01 +0000218 OS << ", " << VVT.getVectorNumElements() << ")";
Owen Anderson825b72b2009-08-11 20:47:22 +0000219 } else if (VT == MVT::iPTR) {
Christopher Lamb43ad6b32007-12-17 01:12:55 +0000220 OS << "PointerType::getUnqual(";
Reid Spencerc4de3de2007-04-01 07:20:02 +0000221 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000222 OS << ")";
Owen Anderson825b72b2009-08-11 20:47:22 +0000223 } else if (VT == MVT::iPTRAny) {
Mon P Wange3b3a722008-07-30 04:36:53 +0000224 // Make sure the user has passed us an argument type to overload. If not,
225 // treat it as an ordinary (not overloaded) intrinsic.
226 OS << "(" << ArgNo << " < numTys) ? Tys[" << ArgNo
227 << "] : PointerType::getUnqual(";
228 EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
229 OS << ")";
230 ++ArgNo;
Owen Anderson825b72b2009-08-11 20:47:22 +0000231 } else if (VT == MVT::isVoid) {
Chandler Carruth69940402007-08-04 01:51:18 +0000232 if (ArgNo == 0)
Owen Anderson1d0be152009-08-13 21:58:54 +0000233 OS << "Type::getVoidTy(Context)";
Chandler Carruth69940402007-08-04 01:51:18 +0000234 else
Owen Anderson825b72b2009-08-11 20:47:22 +0000235 // MVT::isVoid is used to mean varargs here.
Chandler Carruth69940402007-08-04 01:51:18 +0000236 OS << "...";
Jim Laskey95af5922007-02-07 20:38:26 +0000237 } else {
Chandler Carruth69940402007-08-04 01:51:18 +0000238 EmitTypeForValueType(OS, VT);
Jim Laskey95af5922007-02-07 20:38:26 +0000239 }
240}
241
Jim Grosbachda4231f2009-03-26 16:17:51 +0000242/// RecordListComparator - Provide a deterministic comparator for lists of
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000243/// records.
244namespace {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000245 typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000246 struct RecordListComparator {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000247 bool operator()(const RecPair &LHS,
248 const RecPair &RHS) const {
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000249 unsigned i = 0;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000250 const std::vector<Record*> *LHSVec = &LHS.first;
251 const std::vector<Record*> *RHSVec = &RHS.first;
252 unsigned RHSSize = RHSVec->size();
253 unsigned LHSSize = LHSVec->size();
254
Chris Lattner93dc92e2010-03-22 20:56:36 +0000255 for (; i != LHSSize; ++i) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000256 if (i == RHSSize) return false; // RHS is shorter than LHS.
257 if ((*LHSVec)[i] != (*RHSVec)[i])
258 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
Chris Lattner93dc92e2010-03-22 20:56:36 +0000259 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000260
Bill Wendling023422a2008-11-13 12:03:00 +0000261 if (i != RHSSize) return true;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000262
263 i = 0;
264 LHSVec = &LHS.second;
265 RHSVec = &RHS.second;
266 RHSSize = RHSVec->size();
267 LHSSize = LHSVec->size();
268
269 for (i = 0; i != LHSSize; ++i) {
270 if (i == RHSSize) return false; // RHS is shorter than LHS.
271 if ((*LHSVec)[i] != (*RHSVec)[i])
272 return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
273 }
274
275 return i != RHSSize;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000276 }
277 };
278}
279
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000280void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000281 raw_ostream &OS) {
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000282 OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
283 OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
284 OS << " switch (ID) {\n";
285 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000286
287 // This checking can emit a lot of very common code. To reduce the amount of
288 // code that we emit, batch up cases that have identical types. This avoids
289 // problems where GCC can run out of memory compiling Verifier.cpp.
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000290 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000291 MapTy UniqueArgInfos;
292
293 // Compute the unique argument type info.
294 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000295 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
296 Ints[i].IS.ParamTypeDefs)].push_back(i);
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000297
298 // Loop through the array, emitting one comparison for each batch.
299 for (MapTy::iterator I = UniqueArgInfos.begin(),
300 E = UniqueArgInfos.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000301 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
Chris Lattnerc4d9b242006-03-31 04:24:58 +0000302 OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
303 << Ints[I->second[i]].Name << "\n";
Chris Lattnerf124b462006-03-31 04:48:26 +0000304
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000305 const RecPair &ArgTypes = I->first;
306 const std::vector<Record*> &RetTys = ArgTypes.first;
307 const std::vector<Record*> &ParamTys = ArgTypes.second;
Bob Wilson09b13662009-07-29 16:35:59 +0000308 std::vector<unsigned> OverloadedTypeIndices;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000309
310 OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
311 << ParamTys.size();
312
313 // Emit return types.
314 for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
315 Record *ArgType = RetTys[j];
316 OS << ", ";
317
Chandler Carruth69940402007-08-04 01:51:18 +0000318 if (ArgType->isSubClassOf("LLVMMatchType")) {
319 unsigned Number = ArgType->getValueAsInt("Number");
Bob Wilson09b13662009-07-29 16:35:59 +0000320 assert(Number < OverloadedTypeIndices.size() &&
321 "Invalid matching number!");
322 Number = OverloadedTypeIndices[Number];
Bob Wilsonbc039792009-01-07 00:09:01 +0000323 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
324 OS << "~(ExtendedElementVectorType | " << Number << ")";
325 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
326 OS << "~(TruncatedElementVectorType | " << Number << ")";
327 else
328 OS << "~" << Number;
Chandler Carruth69940402007-08-04 01:51:18 +0000329 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000330 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Chandler Carruth69940402007-08-04 01:51:18 +0000331 OS << getEnumName(VT);
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000332
Bob Wilson61fc4cf2009-08-11 01:14:02 +0000333 if (EVT(VT).isOverloaded())
Bob Wilson09b13662009-07-29 16:35:59 +0000334 OverloadedTypeIndices.push_back(j);
335
Owen Anderson825b72b2009-08-11 20:47:22 +0000336 if (VT == MVT::isVoid && j != 0 && j != je - 1)
Jim Laskey95d97b92007-02-06 18:30:58 +0000337 throw "Var arg type not last argument";
Jim Laskey95d97b92007-02-06 18:30:58 +0000338 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000339 }
340
341 // Emit the parameter types.
342 for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
343 Record *ArgType = ParamTys[j];
344 OS << ", ";
345
346 if (ArgType->isSubClassOf("LLVMMatchType")) {
347 unsigned Number = ArgType->getValueAsInt("Number");
Bob Wilson09b13662009-07-29 16:35:59 +0000348 assert(Number < OverloadedTypeIndices.size() &&
349 "Invalid matching number!");
350 Number = OverloadedTypeIndices[Number];
Bob Wilsonbc039792009-01-07 00:09:01 +0000351 if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
352 OS << "~(ExtendedElementVectorType | " << Number << ")";
353 else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
354 OS << "~(TruncatedElementVectorType | " << Number << ")";
355 else
356 OS << "~" << Number;
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000357 } else {
Owen Anderson825b72b2009-08-11 20:47:22 +0000358 MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000359 OS << getEnumName(VT);
360
Bob Wilson61fc4cf2009-08-11 01:14:02 +0000361 if (EVT(VT).isOverloaded())
Bob Wilson09b13662009-07-29 16:35:59 +0000362 OverloadedTypeIndices.push_back(j + RetTys.size());
363
Owen Anderson825b72b2009-08-11 20:47:22 +0000364 if (VT == MVT::isVoid && j != 0 && j != je - 1)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000365 throw "Var arg type not last argument";
366 }
Jim Laskey95d97b92007-02-06 18:30:58 +0000367 }
368
Chandler Carruth69940402007-08-04 01:51:18 +0000369 OS << ");\n";
Chris Lattnerf97a00e2006-03-09 22:05:04 +0000370 OS << " break;\n";
371 }
372 OS << " }\n";
373 OS << "#endif\n\n";
Chris Lattner9b843b22006-03-09 20:34:19 +0000374}
375
Jim Laskey95af5922007-02-07 20:38:26 +0000376void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000377 raw_ostream &OS) {
Jim Laskey95af5922007-02-07 20:38:26 +0000378 OS << "// Code for generating Intrinsic function declarations.\n";
379 OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
380 OS << " switch (id) {\n";
381 OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
382
383 // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
384 // types.
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000385 typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
Jim Laskey95af5922007-02-07 20:38:26 +0000386 MapTy UniqueArgInfos;
387
388 // Compute the unique argument type info.
389 for (unsigned i = 0, e = Ints.size(); i != e; ++i)
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000390 UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
391 Ints[i].IS.ParamTypeDefs)].push_back(i);
Jim Laskey95af5922007-02-07 20:38:26 +0000392
393 // Loop through the array, emitting one generator for each batch.
Dale Johannesen49de9822009-02-05 01:49:45 +0000394 std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
395
Jim Laskey95af5922007-02-07 20:38:26 +0000396 for (MapTy::iterator I = UniqueArgInfos.begin(),
397 E = UniqueArgInfos.end(); I != E; ++I) {
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000398 for (unsigned i = 0, e = I->second.size(); i != e; ++i)
Dale Johannesen49de9822009-02-05 01:49:45 +0000399 OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
400 << ":\t\t// " << Ints[I->second[i]].Name << "\n";
Jim Laskey95af5922007-02-07 20:38:26 +0000401
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000402 const RecPair &ArgTypes = I->first;
403 const std::vector<Record*> &RetTys = ArgTypes.first;
404 const std::vector<Record*> &ParamTys = ArgTypes.second;
405
406 unsigned N = ParamTys.size();
Jim Laskey95af5922007-02-07 20:38:26 +0000407
Chandler Carruth69940402007-08-04 01:51:18 +0000408 if (N > 1 &&
Owen Anderson825b72b2009-08-11 20:47:22 +0000409 getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
Jim Laskey95af5922007-02-07 20:38:26 +0000410 OS << " IsVarArg = true;\n";
411 --N;
412 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000413
Reid Spencer84c614d2007-05-22 19:30:31 +0000414 unsigned ArgNo = 0;
Jim Laskey95af5922007-02-07 20:38:26 +0000415 OS << " ResultTy = ";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000416 EmitTypeGenerate(OS, RetTys, ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000417 OS << ";\n";
418
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000419 for (unsigned j = 0; j != N; ++j) {
Jim Laskey95af5922007-02-07 20:38:26 +0000420 OS << " ArgTys.push_back(";
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000421 EmitTypeGenerate(OS, ParamTys[j], ArgNo);
Jim Laskey95af5922007-02-07 20:38:26 +0000422 OS << ");\n";
423 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000424
Jim Laskey95af5922007-02-07 20:38:26 +0000425 OS << " break;\n";
426 }
Bill Wendlingcdcc3e62008-11-13 09:08:33 +0000427
Jim Laskey95af5922007-02-07 20:38:26 +0000428 OS << " }\n";
429 OS << "#endif\n\n";
430}
431
Chris Lattner048ffb22009-01-12 01:18:58 +0000432/// EmitAttributes - This emits the Intrinsic::getAttributes method.
Chris Lattner4e5f3592006-03-09 22:37:52 +0000433void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000434EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000435 OS << "// Add parameter attributes that are not common to all intrinsics.\n";
436 OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000437 if (TargetOnly)
438 OS << "static AttrListPtr getAttributes(" << TargetPrefix
439 << "Intrinsic::ID id) {";
440 else
441 OS << "AttrListPtr Intrinsic::getAttributes(ID id) {";
Chris Lattner048ffb22009-01-12 01:18:58 +0000442 OS << " // No intrinsic can throw exceptions.\n";
443 OS << " Attributes Attr = Attribute::NoUnwind;\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000444 OS << " switch (id) {\n";
Chris Lattner7056de32006-03-24 01:13:55 +0000445 OS << " default: break;\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000446 unsigned MaxArgAttrs = 0;
Chris Lattner7056de32006-03-24 01:13:55 +0000447 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
Chris Lattner10dae942009-01-12 01:27:55 +0000448 MaxArgAttrs =
449 std::max(MaxArgAttrs, unsigned(Ints[i].ArgumentAttributes.size()));
Chris Lattner7056de32006-03-24 01:13:55 +0000450 switch (Ints[i].ModRef) {
451 default: break;
452 case CodeGenIntrinsic::NoMem:
Dale Johannesen49de9822009-02-05 01:49:45 +0000453 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
454 << ":\n";
Chris Lattner7056de32006-03-24 01:13:55 +0000455 break;
456 }
457 }
Devang Patel05988662008-09-25 21:00:45 +0000458 OS << " Attr |= Attribute::ReadNone; // These do not access memory.\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000459 OS << " break;\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000460 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
461 switch (Ints[i].ModRef) {
Chris Lattner022f64f2006-03-13 23:08:44 +0000462 default: break;
Chris Lattner022f64f2006-03-13 23:08:44 +0000463 case CodeGenIntrinsic::ReadArgMem:
464 case CodeGenIntrinsic::ReadMem:
Dale Johannesen49de9822009-02-05 01:49:45 +0000465 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
466 << ":\n";
Chris Lattner022f64f2006-03-13 23:08:44 +0000467 break;
Chris Lattner4e5f3592006-03-09 22:37:52 +0000468 }
469 }
Devang Patel05988662008-09-25 21:00:45 +0000470 OS << " Attr |= Attribute::ReadOnly; // These do not write memory.\n";
Duncan Sandsa3355ff2007-12-03 20:06:50 +0000471 OS << " break;\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000472 OS << " }\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000473 OS << " AttributeWithIndex AWI[" << MaxArgAttrs+1 << "];\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000474 OS << " unsigned NumAttrs = 0;\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000475 OS << " switch (id) {\n";
476 OS << " default: break;\n";
477
478 // Add argument attributes for any intrinsics that have them.
479 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
480 if (Ints[i].ArgumentAttributes.empty()) continue;
481
Dale Johannesen49de9822009-02-05 01:49:45 +0000482 OS << " case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
483 << ":\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000484
485 std::vector<std::pair<unsigned, CodeGenIntrinsic::ArgAttribute> > ArgAttrs =
486 Ints[i].ArgumentAttributes;
487 // Sort by argument index.
488 std::sort(ArgAttrs.begin(), ArgAttrs.end());
489
490 unsigned NumArgsWithAttrs = 0;
491
Chris Lattnerd4a27002009-01-12 02:41:37 +0000492 while (!ArgAttrs.empty()) {
493 unsigned ArgNo = ArgAttrs[0].first;
494
495 OS << " AWI[" << NumArgsWithAttrs++ << "] = AttributeWithIndex::get("
496 << ArgNo+1 << ", 0";
497
498 while (!ArgAttrs.empty() && ArgAttrs[0].first == ArgNo) {
499 switch (ArgAttrs[0].second) {
500 default: assert(0 && "Unknown arg attribute");
501 case CodeGenIntrinsic::NoCapture:
502 OS << "|Attribute::NoCapture";
503 break;
504 }
505 ArgAttrs.erase(ArgAttrs.begin());
506 }
507 OS << ");\n";
508 }
Chris Lattner10dae942009-01-12 01:27:55 +0000509
Chris Lattnerd4a27002009-01-12 02:41:37 +0000510 OS << " NumAttrs = " << NumArgsWithAttrs << ";\n";
Chris Lattner10dae942009-01-12 01:27:55 +0000511 OS << " break;\n";
512 }
513
514 OS << " }\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000515 OS << " AWI[NumAttrs] = AttributeWithIndex::get(~0, Attr);\n";
516 OS << " return AttrListPtr::get(AWI, NumAttrs+1);\n";
Chris Lattner048ffb22009-01-12 01:18:58 +0000517 OS << "}\n";
Chris Lattnerd4a27002009-01-12 02:41:37 +0000518 OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
Chris Lattner4e5f3592006-03-09 22:37:52 +0000519}
Chris Lattner022f64f2006-03-13 23:08:44 +0000520
Duncan Sandsd869b382009-02-14 10:56:35 +0000521/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
522void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000523EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
Duncan Sandsd869b382009-02-14 10:56:35 +0000524 OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
525 OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
Duncan Sands7c422ac2010-01-06 08:45:52 +0000526 OS << "switch (iid) {\n";
Duncan Sandsd869b382009-02-14 10:56:35 +0000527 OS << "default:\n return UnknownModRefBehavior;\n";
528 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
529 if (Ints[i].ModRef == CodeGenIntrinsic::WriteMem)
530 continue;
531 OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
532 << ":\n";
533 switch (Ints[i].ModRef) {
534 default:
535 assert(false && "Unknown Mod/Ref type!");
536 case CodeGenIntrinsic::NoMem:
537 OS << " return DoesNotAccessMemory;\n";
538 break;
539 case CodeGenIntrinsic::ReadArgMem:
540 case CodeGenIntrinsic::ReadMem:
541 OS << " return OnlyReadsMemory;\n";
542 break;
543 case CodeGenIntrinsic::WriteArgMem:
544 OS << " return AccessesArguments;\n";
545 break;
546 }
547 }
548 OS << "}\n";
549 OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
550}
551
Chris Lattner022f64f2006-03-13 23:08:44 +0000552void IntrinsicEmitter::
Daniel Dunbar1a551802009-07-03 00:10:29 +0000553EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
Chris Lattner022f64f2006-03-13 23:08:44 +0000554 OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
555 OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
556 OS << " switch (F->getIntrinsicID()) {\n";
557 OS << " default: BuiltinName = \"\"; break;\n";
558 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
559 if (!Ints[i].GCCBuiltinName.empty()) {
560 OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
561 << Ints[i].GCCBuiltinName << "\"; break;\n";
562 }
563 }
564 OS << " }\n";
565 OS << "#endif\n\n";
Reid Spencer767a25b2006-03-14 05:59:52 +0000566}
Chris Lattner3f8b8912006-03-15 01:33:26 +0000567
Chris Lattner331bf922008-01-04 04:38:35 +0000568/// EmitBuiltinComparisons - Emit comparisons to determine whether the specified
569/// sorted range of builtin names is equal to the current builtin. This breaks
570/// it down into a simple tree.
571///
572/// At this point, we know that all the builtins in the range have the same name
573/// for the first 'CharStart' characters. Only the end of the name needs to be
574/// discriminated.
575typedef std::map<std::string, std::string>::const_iterator StrMapIterator;
576static void EmitBuiltinComparisons(StrMapIterator Start, StrMapIterator End,
577 unsigned CharStart, unsigned Indent,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000578 std::string TargetPrefix, raw_ostream &OS) {
Chris Lattner331bf922008-01-04 04:38:35 +0000579 if (Start == End) return; // empty range.
580
581 // Determine what, if anything, is the same about all these strings.
582 std::string CommonString = Start->first;
583 unsigned NumInRange = 0;
584 for (StrMapIterator I = Start; I != End; ++I, ++NumInRange) {
585 // Find the first character that doesn't match.
586 const std::string &ThisStr = I->first;
587 unsigned NonMatchChar = CharStart;
588 while (NonMatchChar < CommonString.size() &&
589 NonMatchChar < ThisStr.size() &&
590 CommonString[NonMatchChar] == ThisStr[NonMatchChar])
591 ++NonMatchChar;
592 // Truncate off pieces that don't match.
593 CommonString.resize(NonMatchChar);
594 }
595
596 // Just compare the rest of the string.
597 if (NumInRange == 1) {
598 if (CharStart != CommonString.size()) {
599 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
600 if (CharStart) OS << "+" << CharStart;
601 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
602 OS << CommonString.size() - CharStart << "))\n";
603 ++Indent;
604 }
Dale Johannesen49de9822009-02-05 01:49:45 +0000605 OS << std::string(Indent*2, ' ') << "IntrinsicID = " << TargetPrefix
606 << "Intrinsic::";
Chris Lattner331bf922008-01-04 04:38:35 +0000607 OS << Start->second << ";\n";
608 return;
609 }
610
611 // At this point, we potentially have a common prefix for these builtins, emit
612 // a check for this common prefix.
613 if (CommonString.size() != CharStart) {
614 OS << std::string(Indent*2, ' ') << "if (!memcmp(BuiltinName";
615 if (CharStart) OS << "+" << CharStart;
616 OS << ", \"" << (CommonString.c_str()+CharStart) << "\", ";
617 OS << CommonString.size()-CharStart << ")) {\n";
618
Dale Johannesen49de9822009-02-05 01:49:45 +0000619 EmitBuiltinComparisons(Start, End, CommonString.size(), Indent+1,
620 TargetPrefix, OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000621 OS << std::string(Indent*2, ' ') << "}\n";
622 return;
623 }
624
625 // Output a switch on the character that differs across the set.
626 OS << std::string(Indent*2, ' ') << "switch (BuiltinName[" << CharStart
627 << "]) {";
628 if (CharStart)
629 OS << " // \"" << std::string(Start->first.begin(),
630 Start->first.begin()+CharStart) << "\"";
631 OS << "\n";
632
633 for (StrMapIterator I = Start; I != End; ) {
634 char ThisChar = I->first[CharStart];
635 OS << std::string(Indent*2, ' ') << "case '" << ThisChar << "':\n";
636 // Figure out the range that has this common character.
637 StrMapIterator NextChar = I;
638 for (++NextChar; NextChar != End && NextChar->first[CharStart] == ThisChar;
639 ++NextChar)
640 /*empty*/;
Dale Johannesen49de9822009-02-05 01:49:45 +0000641 EmitBuiltinComparisons(I, NextChar, CharStart+1, Indent+1, TargetPrefix,OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000642 OS << std::string(Indent*2, ' ') << " break;\n";
643 I = NextChar;
644 }
645 OS << std::string(Indent*2, ' ') << "}\n";
646}
647
648/// EmitTargetBuiltins - All of the builtins in the specified map are for the
649/// same target, and we already checked it.
650static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
Dale Johannesen49de9822009-02-05 01:49:45 +0000651 const std::string &TargetPrefix,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000652 raw_ostream &OS) {
Chris Lattner331bf922008-01-04 04:38:35 +0000653 // Rearrange the builtins by length.
654 std::vector<std::map<std::string, std::string> > BuiltinsByLen;
655 BuiltinsByLen.reserve(100);
656
657 for (StrMapIterator I = BIM.begin(), E = BIM.end(); I != E; ++I) {
658 if (I->first.size() >= BuiltinsByLen.size())
659 BuiltinsByLen.resize(I->first.size()+1);
660 BuiltinsByLen[I->first.size()].insert(*I);
661 }
662
663 // Now that we have all the builtins by their length, emit a switch stmt.
664 OS << " switch (strlen(BuiltinName)) {\n";
665 OS << " default: break;\n";
666 for (unsigned i = 0, e = BuiltinsByLen.size(); i != e; ++i) {
667 if (BuiltinsByLen[i].empty()) continue;
668 OS << " case " << i << ":\n";
669 EmitBuiltinComparisons(BuiltinsByLen[i].begin(), BuiltinsByLen[i].end(),
Dale Johannesen49de9822009-02-05 01:49:45 +0000670 0, 3, TargetPrefix, OS);
Chris Lattner331bf922008-01-04 04:38:35 +0000671 OS << " break;\n";
672 }
673 OS << " }\n";
674}
675
676
Chris Lattner3f8b8912006-03-15 01:33:26 +0000677void IntrinsicEmitter::
678EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000679 raw_ostream &OS) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000680 typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
Chris Lattner3f8b8912006-03-15 01:33:26 +0000681 BIMTy BuiltinMap;
682 for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
683 if (!Ints[i].GCCBuiltinName.empty()) {
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000684 // Get the map for this target prefix.
685 std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
686
687 if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
688 Ints[i].EnumName)).second)
Chris Lattner3f8b8912006-03-15 01:33:26 +0000689 throw "Intrinsic '" + Ints[i].TheDef->getName() +
690 "': duplicate GCC builtin name!";
691 }
692 }
693
694 OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
695 OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
696 OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
697 OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
698 OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
Dale Johannesen49de9822009-02-05 01:49:45 +0000699
700 if (TargetOnly) {
701 OS << "static " << TargetPrefix << "Intrinsic::ID "
702 << "getIntrinsicForGCCBuiltin(const char "
703 << "*TargetPrefix, const char *BuiltinName) {\n";
704 OS << " " << TargetPrefix << "Intrinsic::ID IntrinsicID = ";
705 } else {
706 OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
707 << "*TargetPrefix, const char *BuiltinName) {\n";
708 OS << " Intrinsic::ID IntrinsicID = ";
709 }
710
711 if (TargetOnly)
712 OS << "(" << TargetPrefix<< "Intrinsic::ID)";
713
714 OS << "Intrinsic::not_intrinsic;\n";
Chris Lattner331bf922008-01-04 04:38:35 +0000715
Chris Lattner3f8b8912006-03-15 01:33:26 +0000716 // Note: this could emit significantly better code if we cared.
717 for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000718 OS << " ";
719 if (!I->first.empty())
720 OS << "if (!strcmp(TargetPrefix, \"" << I->first << "\")) ";
721 else
722 OS << "/* Target Independent Builtins */ ";
723 OS << "{\n";
724
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000725 // Emit the comparisons for this target prefix.
Dale Johannesen49de9822009-02-05 01:49:45 +0000726 EmitTargetBuiltins(I->second, TargetPrefix, OS);
Chris Lattnerfa0fba12008-01-02 21:24:22 +0000727 OS << " }\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000728 }
Dale Johannesen49de9822009-02-05 01:49:45 +0000729 OS << " return IntrinsicID;\n";
730 OS << "}\n";
Chris Lattner3f8b8912006-03-15 01:33:26 +0000731 OS << "#endif\n\n";
732}