Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 1 | //===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 3060910 | 2007-12-29 20:37:13 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This tablegen backend emits information about intrinsic functions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 14 | #include "CodeGenTarget.h" |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 15 | #include "IntrinsicEmitter.h" |
Peter Collingbourne | 7c78888 | 2011-10-01 16:41:13 +0000 | [diff] [blame] | 16 | #include "llvm/TableGen/Record.h" |
Douglas Gregor | f657da2 | 2012-05-02 17:32:48 +0000 | [diff] [blame] | 17 | #include "llvm/TableGen/StringMatcher.h" |
Chris Lattner | 18faf5d | 2006-03-13 22:38:57 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/StringExtras.h" |
Jeff Cohen | 71c3bc3 | 2006-03-15 02:51:05 +0000 | [diff] [blame] | 19 | #include <algorithm> |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 23 | // IntrinsicEmitter Implementation |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 26 | void IntrinsicEmitter::run(raw_ostream &OS) { |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 27 | EmitSourceFileHeader("Intrinsic Function Source Fragment", OS); |
| 28 | |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 29 | std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly); |
| 30 | |
| 31 | if (TargetOnly && !Ints.empty()) |
| 32 | TargetPrefix = Ints[0].TargetPrefix; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 33 | |
Douglas Gregor | 7d9663c | 2010-05-11 06:17:44 +0000 | [diff] [blame] | 34 | EmitPrefix(OS); |
| 35 | |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 36 | // Emit the enum information. |
| 37 | EmitEnumInfo(Ints, OS); |
Chris Lattner | fda6aff | 2006-03-15 01:55:21 +0000 | [diff] [blame] | 38 | |
| 39 | // Emit the intrinsic ID -> name table. |
| 40 | EmitIntrinsicToNameTable(Ints, OS); |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 41 | |
| 42 | // Emit the intrinsic ID -> overload table. |
| 43 | EmitIntrinsicToOverloadTable(Ints, OS); |
| 44 | |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 45 | // Emit the function name recognizer. |
| 46 | EmitFnNameRecognizer(Ints, OS); |
Chris Lattner | fda6aff | 2006-03-15 01:55:21 +0000 | [diff] [blame] | 47 | |
Chris Lattner | f97a00e | 2006-03-09 22:05:04 +0000 | [diff] [blame] | 48 | // Emit the intrinsic verifier. |
| 49 | EmitVerifier(Ints, OS); |
Chris Lattner | 6448ee4 | 2006-03-09 22:30:49 +0000 | [diff] [blame] | 50 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 51 | // Emit the intrinsic declaration generator. |
| 52 | EmitGenerator(Ints, OS); |
| 53 | |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 54 | // Emit the intrinsic parameter attributes. |
| 55 | EmitAttributes(Ints, OS); |
Chris Lattner | 022f64f | 2006-03-13 23:08:44 +0000 | [diff] [blame] | 56 | |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 57 | // Emit intrinsic alias analysis mod/ref behavior. |
| 58 | EmitModRefBehavior(Ints, OS); |
| 59 | |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 60 | // Emit code to translate GCC builtins into LLVM intrinsics. |
| 61 | EmitIntrinsicToGCCBuiltinMap(Ints, OS); |
Douglas Gregor | 7d9663c | 2010-05-11 06:17:44 +0000 | [diff] [blame] | 62 | |
| 63 | EmitSuffix(OS); |
| 64 | } |
| 65 | |
| 66 | void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) { |
| 67 | OS << "// VisualStudio defines setjmp as _setjmp\n" |
Michael J. Spencer | 1f40960 | 2010-09-24 19:48:47 +0000 | [diff] [blame] | 68 | "#if defined(_MSC_VER) && defined(setjmp) && \\\n" |
| 69 | " !defined(setjmp_undefined_for_msvc)\n" |
Michael J. Spencer | 08047f6 | 2010-09-14 04:27:38 +0000 | [diff] [blame] | 70 | "# pragma push_macro(\"setjmp\")\n" |
| 71 | "# undef setjmp\n" |
Michael J. Spencer | 1f40960 | 2010-09-24 19:48:47 +0000 | [diff] [blame] | 72 | "# define setjmp_undefined_for_msvc\n" |
Douglas Gregor | 7d9663c | 2010-05-11 06:17:44 +0000 | [diff] [blame] | 73 | "#endif\n\n"; |
| 74 | } |
| 75 | |
| 76 | void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) { |
Michael J. Spencer | 1f40960 | 2010-09-24 19:48:47 +0000 | [diff] [blame] | 77 | OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n" |
Douglas Gregor | 7d9663c | 2010-05-11 06:17:44 +0000 | [diff] [blame] | 78 | "// let's return it to _setjmp state\n" |
Michael J. Spencer | 08047f6 | 2010-09-14 04:27:38 +0000 | [diff] [blame] | 79 | "# pragma pop_macro(\"setjmp\")\n" |
Michael J. Spencer | 1f40960 | 2010-09-24 19:48:47 +0000 | [diff] [blame] | 80 | "# undef setjmp_undefined_for_msvc\n" |
Douglas Gregor | 7d9663c | 2010-05-11 06:17:44 +0000 | [diff] [blame] | 81 | "#endif\n\n"; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 85 | raw_ostream &OS) { |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 86 | OS << "// Enum values for Intrinsics.h\n"; |
Chris Lattner | 9e493cf | 2006-03-03 02:32:46 +0000 | [diff] [blame] | 87 | OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n"; |
| 88 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
| 89 | OS << " " << Ints[i].EnumName; |
| 90 | OS << ((i != e-1) ? ", " : " "); |
| 91 | OS << std::string(40-Ints[i].EnumName.size(), ' ') |
| 92 | << "// " << Ints[i].Name << "\n"; |
| 93 | } |
| 94 | OS << "#endif\n\n"; |
| 95 | } |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 96 | |
| 97 | void IntrinsicEmitter:: |
| 98 | EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 99 | raw_ostream &OS) { |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 100 | // Build a 'first character of function name' -> intrinsic # mapping. |
| 101 | std::map<char, std::vector<unsigned> > IntMapping; |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 102 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 103 | IntMapping[Ints[i].Name[5]].push_back(i); |
| 104 | |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 105 | OS << "// Function name -> enum value recognizer code.\n"; |
| 106 | OS << "#ifdef GET_FUNCTION_RECOGNIZER\n"; |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 107 | OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n"; |
| 108 | OS << " switch (Name[5]) { // Dispatch on first letter.\n"; |
| 109 | OS << " default: break;\n"; |
| 110 | // Emit the intrinsic matching stuff by first letter. |
| 111 | for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(), |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 112 | E = IntMapping.end(); I != E; ++I) { |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 113 | OS << " case '" << I->first << "':\n"; |
| 114 | std::vector<unsigned> &IntList = I->second; |
| 115 | |
| 116 | // Emit all the overloaded intrinsics first, build a table of the |
| 117 | // non-overloaded ones. |
| 118 | std::vector<StringMatcher::StringPair> MatchTable; |
| 119 | |
| 120 | for (unsigned i = 0, e = IntList.size(); i != e; ++i) { |
| 121 | unsigned IntNo = IntList[i]; |
| 122 | std::string Result = "return " + TargetPrefix + "Intrinsic::" + |
| 123 | Ints[IntNo].EnumName + ";"; |
| 124 | |
| 125 | if (!Ints[IntNo].isOverloaded) { |
| 126 | MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result)); |
| 127 | continue; |
| 128 | } |
| 129 | |
| 130 | // For overloaded intrinsics, only the prefix needs to match |
| 131 | std::string TheStr = Ints[IntNo].Name.substr(6); |
| 132 | TheStr += '.'; // Require "bswap." instead of bswap. |
| 133 | OS << " if (NameR.startswith(\"" << TheStr << "\")) " |
| 134 | << Result << '\n'; |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 137 | // Emit the matcher logic for the fixed length strings. |
| 138 | StringMatcher("NameR", MatchTable, OS).Emit(1); |
| 139 | OS << " break; // end of '" << I->first << "' case.\n"; |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 140 | } |
Chris Lattner | cc67c75 | 2010-09-06 03:58:45 +0000 | [diff] [blame] | 141 | |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 142 | OS << " }\n"; |
Chris Lattner | f97a00e | 2006-03-09 22:05:04 +0000 | [diff] [blame] | 143 | OS << "#endif\n\n"; |
| 144 | } |
| 145 | |
Chris Lattner | fda6aff | 2006-03-15 01:55:21 +0000 | [diff] [blame] | 146 | void IntrinsicEmitter:: |
| 147 | EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 148 | raw_ostream &OS) { |
Chris Lattner | fda6aff | 2006-03-15 01:55:21 +0000 | [diff] [blame] | 149 | OS << "// Intrinsic ID to name table\n"; |
| 150 | OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n"; |
| 151 | OS << " // Note that entry #0 is the invalid intrinsic!\n"; |
Evan Cheng | f065a6f | 2006-03-28 22:25:56 +0000 | [diff] [blame] | 152 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) |
| 153 | OS << " \"" << Ints[i].Name << "\",\n"; |
Chris Lattner | fda6aff | 2006-03-15 01:55:21 +0000 | [diff] [blame] | 154 | OS << "#endif\n\n"; |
| 155 | } |
| 156 | |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 157 | void IntrinsicEmitter:: |
| 158 | EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 159 | raw_ostream &OS) { |
Benjamin Kramer | 36a2138 | 2012-03-01 02:16:57 +0000 | [diff] [blame] | 160 | OS << "// Intrinsic ID to overload bitset\n"; |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 161 | OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n"; |
Benjamin Kramer | 36a2138 | 2012-03-01 02:16:57 +0000 | [diff] [blame] | 162 | OS << "static const uint8_t OTable[] = {\n"; |
| 163 | OS << " 0"; |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 164 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
Benjamin Kramer | 36a2138 | 2012-03-01 02:16:57 +0000 | [diff] [blame] | 165 | // Add one to the index so we emit a null bit for the invalid #0 intrinsic. |
| 166 | if ((i+1)%8 == 0) |
| 167 | OS << ",\n 0"; |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 168 | if (Ints[i].isOverloaded) |
Benjamin Kramer | 36a2138 | 2012-03-01 02:16:57 +0000 | [diff] [blame] | 169 | OS << " | (1<<" << (i+1)%8 << ')'; |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 170 | } |
Benjamin Kramer | 36a2138 | 2012-03-01 02:16:57 +0000 | [diff] [blame] | 171 | OS << "\n};\n\n"; |
| 172 | // OTable contains a true bit at the position if the intrinsic is overloaded. |
| 173 | OS << "return (OTable[id/8] & (1 << (id%8))) != 0;\n"; |
Mon P Wang | 0d52ff1 | 2009-02-24 23:17:49 +0000 | [diff] [blame] | 174 | OS << "#endif\n\n"; |
| 175 | } |
| 176 | |
Jim Grosbach | da4231f | 2009-03-26 16:17:51 +0000 | [diff] [blame] | 177 | /// RecordListComparator - Provide a deterministic comparator for lists of |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 178 | /// records. |
| 179 | namespace { |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 180 | typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair; |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 181 | struct RecordListComparator { |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 182 | bool operator()(const RecPair &LHS, |
| 183 | const RecPair &RHS) const { |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 184 | unsigned i = 0; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 185 | const std::vector<Record*> *LHSVec = &LHS.first; |
| 186 | const std::vector<Record*> *RHSVec = &RHS.first; |
| 187 | unsigned RHSSize = RHSVec->size(); |
| 188 | unsigned LHSSize = LHSVec->size(); |
| 189 | |
Chris Lattner | 93dc92e | 2010-03-22 20:56:36 +0000 | [diff] [blame] | 190 | for (; i != LHSSize; ++i) { |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 191 | if (i == RHSSize) return false; // RHS is shorter than LHS. |
| 192 | if ((*LHSVec)[i] != (*RHSVec)[i]) |
| 193 | return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName(); |
Chris Lattner | 93dc92e | 2010-03-22 20:56:36 +0000 | [diff] [blame] | 194 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 195 | |
Bill Wendling | 023422a | 2008-11-13 12:03:00 +0000 | [diff] [blame] | 196 | if (i != RHSSize) return true; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 197 | |
| 198 | i = 0; |
| 199 | LHSVec = &LHS.second; |
| 200 | RHSVec = &RHS.second; |
| 201 | RHSSize = RHSVec->size(); |
| 202 | LHSSize = LHSVec->size(); |
| 203 | |
| 204 | for (i = 0; i != LHSSize; ++i) { |
| 205 | if (i == RHSSize) return false; // RHS is shorter than LHS. |
| 206 | if ((*LHSVec)[i] != (*RHSVec)[i]) |
| 207 | return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName(); |
| 208 | } |
| 209 | |
| 210 | return i != RHSSize; |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 211 | } |
| 212 | }; |
| 213 | } |
| 214 | |
Chris Lattner | f97a00e | 2006-03-09 22:05:04 +0000 | [diff] [blame] | 215 | void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 216 | raw_ostream &OS) { |
Chris Lattner | f97a00e | 2006-03-09 22:05:04 +0000 | [diff] [blame] | 217 | OS << "// Verifier::visitIntrinsicFunctionCall code.\n"; |
| 218 | OS << "#ifdef GET_INTRINSIC_VERIFIER\n"; |
| 219 | OS << " switch (ID) {\n"; |
Craig Topper | 655b8de | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 220 | OS << " default: llvm_unreachable(\"Invalid intrinsic!\");\n"; |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 221 | |
| 222 | // This checking can emit a lot of very common code. To reduce the amount of |
| 223 | // code that we emit, batch up cases that have identical types. This avoids |
| 224 | // problems where GCC can run out of memory compiling Verifier.cpp. |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 225 | typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy; |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 226 | MapTy UniqueArgInfos; |
| 227 | |
| 228 | // Compute the unique argument type info. |
| 229 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 230 | UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs, |
| 231 | Ints[i].IS.ParamTypeDefs)].push_back(i); |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 232 | |
| 233 | // Loop through the array, emitting one comparison for each batch. |
| 234 | for (MapTy::iterator I = UniqueArgInfos.begin(), |
| 235 | E = UniqueArgInfos.end(); I != E; ++I) { |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 236 | for (unsigned i = 0, e = I->second.size(); i != e; ++i) |
Chris Lattner | c4d9b24 | 2006-03-31 04:24:58 +0000 | [diff] [blame] | 237 | OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// " |
| 238 | << Ints[I->second[i]].Name << "\n"; |
Chris Lattner | f124b46 | 2006-03-31 04:48:26 +0000 | [diff] [blame] | 239 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 240 | const RecPair &ArgTypes = I->first; |
| 241 | const std::vector<Record*> &RetTys = ArgTypes.first; |
| 242 | const std::vector<Record*> &ParamTys = ArgTypes.second; |
Bob Wilson | 09b1366 | 2009-07-29 16:35:59 +0000 | [diff] [blame] | 243 | std::vector<unsigned> OverloadedTypeIndices; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 244 | |
| 245 | OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", " |
| 246 | << ParamTys.size(); |
| 247 | |
| 248 | // Emit return types. |
| 249 | for (unsigned j = 0, je = RetTys.size(); j != je; ++j) { |
| 250 | Record *ArgType = RetTys[j]; |
| 251 | OS << ", "; |
| 252 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 253 | if (ArgType->isSubClassOf("LLVMMatchType")) { |
| 254 | unsigned Number = ArgType->getValueAsInt("Number"); |
Bob Wilson | 09b1366 | 2009-07-29 16:35:59 +0000 | [diff] [blame] | 255 | assert(Number < OverloadedTypeIndices.size() && |
| 256 | "Invalid matching number!"); |
| 257 | Number = OverloadedTypeIndices[Number]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 258 | if (ArgType->isSubClassOf("LLVMExtendedElementVectorType")) |
| 259 | OS << "~(ExtendedElementVectorType | " << Number << ")"; |
| 260 | else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType")) |
| 261 | OS << "~(TruncatedElementVectorType | " << Number << ")"; |
| 262 | else |
| 263 | OS << "~" << Number; |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 264 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 265 | MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT")); |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 266 | OS << getEnumName(VT); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 267 | |
Bob Wilson | 61fc4cf | 2009-08-11 01:14:02 +0000 | [diff] [blame] | 268 | if (EVT(VT).isOverloaded()) |
Bob Wilson | 09b1366 | 2009-07-29 16:35:59 +0000 | [diff] [blame] | 269 | OverloadedTypeIndices.push_back(j); |
| 270 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 271 | if (VT == MVT::isVoid && j != 0 && j != je - 1) |
Jim Laskey | 95d97b9 | 2007-02-06 18:30:58 +0000 | [diff] [blame] | 272 | throw "Var arg type not last argument"; |
Jim Laskey | 95d97b9 | 2007-02-06 18:30:58 +0000 | [diff] [blame] | 273 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | // Emit the parameter types. |
| 277 | for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) { |
| 278 | Record *ArgType = ParamTys[j]; |
| 279 | OS << ", "; |
| 280 | |
| 281 | if (ArgType->isSubClassOf("LLVMMatchType")) { |
| 282 | unsigned Number = ArgType->getValueAsInt("Number"); |
Bob Wilson | 09b1366 | 2009-07-29 16:35:59 +0000 | [diff] [blame] | 283 | assert(Number < OverloadedTypeIndices.size() && |
| 284 | "Invalid matching number!"); |
| 285 | Number = OverloadedTypeIndices[Number]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 286 | if (ArgType->isSubClassOf("LLVMExtendedElementVectorType")) |
| 287 | OS << "~(ExtendedElementVectorType | " << Number << ")"; |
| 288 | else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType")) |
| 289 | OS << "~(TruncatedElementVectorType | " << Number << ")"; |
| 290 | else |
| 291 | OS << "~" << Number; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 292 | } else { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 293 | MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT")); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 294 | OS << getEnumName(VT); |
| 295 | |
Bob Wilson | 61fc4cf | 2009-08-11 01:14:02 +0000 | [diff] [blame] | 296 | if (EVT(VT).isOverloaded()) |
Bob Wilson | 09b1366 | 2009-07-29 16:35:59 +0000 | [diff] [blame] | 297 | OverloadedTypeIndices.push_back(j + RetTys.size()); |
| 298 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 299 | if (VT == MVT::isVoid && j != 0 && j != je - 1) |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 300 | throw "Var arg type not last argument"; |
| 301 | } |
Jim Laskey | 95d97b9 | 2007-02-06 18:30:58 +0000 | [diff] [blame] | 302 | } |
| 303 | |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 304 | OS << ");\n"; |
Chris Lattner | f97a00e | 2006-03-09 22:05:04 +0000 | [diff] [blame] | 305 | OS << " break;\n"; |
| 306 | } |
| 307 | OS << " }\n"; |
| 308 | OS << "#endif\n\n"; |
Chris Lattner | 9b843b2 | 2006-03-09 20:34:19 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 311 | static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) { |
| 312 | if (EVT(VT).isInteger()) { |
| 313 | unsigned BitWidth = EVT(VT).getSizeInBits(); |
| 314 | OS << "IntegerType::get(Context, " << BitWidth << ")"; |
| 315 | } else if (VT == MVT::Other) { |
| 316 | // MVT::OtherVT is used to mean the empty struct type here. |
| 317 | OS << "StructType::get(Context)"; |
| 318 | } else if (VT == MVT::f16) { |
| 319 | OS << "Type::getHalfTy(Context)"; |
| 320 | } else if (VT == MVT::f32) { |
| 321 | OS << "Type::getFloatTy(Context)"; |
| 322 | } else if (VT == MVT::f64) { |
| 323 | OS << "Type::getDoubleTy(Context)"; |
| 324 | } else if (VT == MVT::f80) { |
| 325 | OS << "Type::getX86_FP80Ty(Context)"; |
| 326 | } else if (VT == MVT::f128) { |
| 327 | OS << "Type::getFP128Ty(Context)"; |
| 328 | } else if (VT == MVT::ppcf128) { |
| 329 | OS << "Type::getPPC_FP128Ty(Context)"; |
| 330 | } else if (VT == MVT::isVoid) { |
| 331 | OS << "Type::getVoidTy(Context)"; |
| 332 | } else if (VT == MVT::Metadata) { |
| 333 | OS << "Type::getMetadataTy(Context)"; |
| 334 | } else if (VT == MVT::x86mmx) { |
| 335 | OS << "Type::getX86_MMXTy(Context)"; |
| 336 | } else { |
| 337 | assert(false && "Unsupported ValueType!"); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType, |
| 342 | unsigned &ArgNo); |
| 343 | |
| 344 | static void EmitTypeGenerate(raw_ostream &OS, |
| 345 | const std::vector<Record*> &ArgTypes, |
| 346 | unsigned &ArgNo) { |
| 347 | if (ArgTypes.empty()) |
| 348 | return EmitTypeForValueType(OS, MVT::isVoid); |
| 349 | |
| 350 | if (ArgTypes.size() == 1) |
| 351 | return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo); |
| 352 | |
| 353 | OS << "StructType::get("; |
| 354 | |
| 355 | for (std::vector<Record*>::const_iterator |
| 356 | I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) { |
| 357 | EmitTypeGenerate(OS, *I, ArgNo); |
| 358 | OS << ", "; |
| 359 | } |
| 360 | |
| 361 | OS << " NULL)"; |
| 362 | } |
| 363 | |
| 364 | static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType, |
| 365 | unsigned &ArgNo) { |
| 366 | MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT")); |
| 367 | |
| 368 | if (ArgType->isSubClassOf("LLVMMatchType")) { |
| 369 | unsigned Number = ArgType->getValueAsInt("Number"); |
| 370 | assert(Number < ArgNo && "Invalid matching number!"); |
| 371 | if (ArgType->isSubClassOf("LLVMExtendedElementVectorType")) |
| 372 | OS << "VectorType::getExtendedElementVectorType" |
| 373 | << "(cast<VectorType>(Tys[" << Number << "]))"; |
| 374 | else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType")) |
| 375 | OS << "VectorType::getTruncatedElementVectorType" |
| 376 | << "(cast<VectorType>(Tys[" << Number << "]))"; |
| 377 | else |
| 378 | OS << "Tys[" << Number << "]"; |
Chris Lattner | 15706cb | 2012-05-17 04:07:48 +0000 | [diff] [blame^] | 379 | } else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny || |
| 380 | VT == MVT::iPTRAny) { |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 381 | // NOTE: The ArgNo variable here is not the absolute argument number, it is |
| 382 | // the index of the "arbitrary" type in the Tys array passed to the |
| 383 | // Intrinsic::getDeclaration function. Consequently, we only want to |
| 384 | // increment it when we actually hit an overloaded type. Getting this wrong |
| 385 | // leads to very subtle bugs! |
| 386 | OS << "Tys[" << ArgNo++ << "]"; |
| 387 | } else if (EVT(VT).isVector()) { |
| 388 | EVT VVT = VT; |
| 389 | OS << "VectorType::get("; |
| 390 | EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy); |
| 391 | OS << ", " << VVT.getVectorNumElements() << ")"; |
| 392 | } else if (VT == MVT::iPTR) { |
| 393 | OS << "PointerType::getUnqual("; |
| 394 | EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo); |
| 395 | OS << ")"; |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 396 | } else if (VT == MVT::isVoid) { |
| 397 | assert(ArgNo == 0); |
| 398 | OS << "Type::getVoidTy(Context)"; |
| 399 | } else { |
| 400 | EmitTypeForValueType(OS, VT); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | |
| 405 | // NOTE: This must be kept in synch with the version emitted to the .gen file! |
| 406 | enum IIT_Info { |
| 407 | IIT_Done = 0, |
| 408 | IIT_I1 = 1, |
| 409 | IIT_I8 = 2, |
| 410 | IIT_I16 = 3, |
| 411 | IIT_I32 = 4, |
| 412 | IIT_I64 = 5, |
| 413 | IIT_F32 = 6, |
| 414 | IIT_F64 = 7, |
| 415 | IIT_V2 = 8, |
| 416 | IIT_V4 = 9, |
| 417 | IIT_V8 = 10, |
| 418 | IIT_V16 = 11, |
| 419 | IIT_MMX = 12, |
| 420 | IIT_PTR = 13, |
| 421 | IIT_ARG = 14 |
| 422 | }; |
| 423 | |
| 424 | static void EncodeFixedValueType(MVT::SimpleValueType VT, |
| 425 | SmallVectorImpl<unsigned> &Sig) { |
| 426 | if (EVT(VT).isInteger()) { |
| 427 | unsigned BitWidth = EVT(VT).getSizeInBits(); |
| 428 | switch (BitWidth) { |
| 429 | default: return Sig.push_back(~0U); |
| 430 | case 1: return Sig.push_back(IIT_I1); |
| 431 | case 8: return Sig.push_back(IIT_I8); |
| 432 | case 16: return Sig.push_back(IIT_I16); |
| 433 | case 32: return Sig.push_back(IIT_I32); |
| 434 | case 64: return Sig.push_back(IIT_I64); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /* } else if (VT == MVT::Other) { |
| 439 | // MVT::OtherVT is used to mean the empty struct type here. |
| 440 | OS << "StructType::get(Context)"; |
| 441 | } else if (VT == MVT::f16) { |
| 442 | OS << "Type::getHalfTy(Context)";*/ |
| 443 | if (VT == MVT::f32) |
| 444 | return Sig.push_back(IIT_F32); |
| 445 | if (VT == MVT::f64) |
| 446 | return Sig.push_back(IIT_F64); |
| 447 | //if (VT == MVT::f80) { |
| 448 | // OS << "Type::getX86_FP80Ty(Context)"; |
| 449 | //if (VT == MVT::f128) { |
| 450 | // OS << "Type::getFP128Ty(Context)"; |
| 451 | // if (VT == MVT::ppcf128) { |
| 452 | // OS << "Type::getPPC_FP128Ty(Context)"; |
| 453 | //if (VT == MVT::Metadata) { |
| 454 | // OS << "Type::getMetadataTy(Context)"; |
| 455 | if (VT == MVT::x86mmx) |
| 456 | return Sig.push_back(IIT_MMX); |
| 457 | |
| 458 | assert(VT != MVT::isVoid); |
| 459 | Sig.push_back(~0U); |
| 460 | } |
| 461 | |
Francois Pichet | e4807c1 | 2012-05-17 04:00:03 +0000 | [diff] [blame] | 462 | #ifdef _MSC_VER |
Francois Pichet | 3aca879 | 2012-05-17 03:38:19 +0000 | [diff] [blame] | 463 | #pragma optimize("",off) // MSVC 2010 optimizer can't deal with this function. |
Francois Pichet | e4807c1 | 2012-05-17 04:00:03 +0000 | [diff] [blame] | 464 | #endif |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 465 | |
| 466 | static void EncodeFixedType(Record *R, SmallVectorImpl<unsigned> &Sig) { |
| 467 | |
| 468 | if (R->isSubClassOf("LLVMMatchType")) { |
| 469 | return Sig.push_back(~0U); |
| 470 | /* |
| 471 | unsigned Number = ArgType->getValueAsInt("Number"); |
| 472 | assert(Number < ArgNo && "Invalid matching number!"); |
| 473 | if (ArgType->isSubClassOf("LLVMExtendedElementVectorType")) |
| 474 | OS << "VectorType::getExtendedElementVectorType" |
| 475 | << "(cast<VectorType>(Tys[" << Number << "]))"; |
| 476 | else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType")) |
| 477 | OS << "VectorType::getTruncatedElementVectorType" |
| 478 | << "(cast<VectorType>(Tys[" << Number << "]))"; |
| 479 | else |
| 480 | OS << "Tys[" << Number << "]"; |
| 481 | */ |
| 482 | } |
| 483 | |
| 484 | MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT")); |
| 485 | |
Chris Lattner | 15706cb | 2012-05-17 04:07:48 +0000 | [diff] [blame^] | 486 | if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny || |
| 487 | VT == MVT::iPTRAny) { |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 488 | return Sig.push_back(~0U); |
| 489 | /* |
| 490 | // NOTE: The ArgNo variable here is not the absolute argument number, it is |
| 491 | // the index of the "arbitrary" type in the Tys array passed to the |
| 492 | // Intrinsic::getDeclaration function. Consequently, we only want to |
| 493 | // increment it when we actually hit an overloaded type. Getting this wrong |
| 494 | // leads to very subtle bugs! |
| 495 | OS << "Tys[" << ArgNo++ << "]"; |
| 496 | */ |
| 497 | } |
| 498 | |
| 499 | if (EVT(VT).isVector()) { |
| 500 | EVT VVT = VT; |
| 501 | switch (VVT.getVectorNumElements()) { |
| 502 | default: Sig.push_back(~0U); return; |
| 503 | case 2: Sig.push_back(IIT_V2); break; |
| 504 | case 4: Sig.push_back(IIT_V4); break; |
| 505 | case 8: Sig.push_back(IIT_V8); break; |
| 506 | case 16: Sig.push_back(IIT_V16); break; |
| 507 | } |
| 508 | |
| 509 | return EncodeFixedValueType(VVT.getVectorElementType(). |
| 510 | getSimpleVT().SimpleTy, Sig); |
| 511 | } |
| 512 | |
| 513 | if (VT == MVT::iPTR) { |
| 514 | Sig.push_back(IIT_PTR); |
| 515 | return EncodeFixedType(R->getValueAsDef("ElTy"), Sig); |
| 516 | } |
| 517 | |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 518 | assert(VT != MVT::isVoid); |
| 519 | EncodeFixedValueType(VT, Sig); |
| 520 | } |
Francois Pichet | e4807c1 | 2012-05-17 04:00:03 +0000 | [diff] [blame] | 521 | |
| 522 | #ifdef _MSC_VER |
Francois Pichet | 3aca879 | 2012-05-17 03:38:19 +0000 | [diff] [blame] | 523 | #pragma optimize("",on) |
Francois Pichet | e4807c1 | 2012-05-17 04:00:03 +0000 | [diff] [blame] | 524 | #endif |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 525 | |
| 526 | /// ComputeFixedEncoding - If we can encode the type signature for this |
| 527 | /// intrinsic into 32 bits, return it. If not, return ~0U. |
| 528 | static unsigned ComputeFixedEncoding(const CodeGenIntrinsic &Int) { |
| 529 | if (Int.IS.RetVTs.size() >= 2) return ~0U; |
| 530 | |
| 531 | SmallVector<unsigned, 8> TypeSig; |
| 532 | if (Int.IS.RetVTs.empty()) |
| 533 | TypeSig.push_back(IIT_Done); |
| 534 | else if (Int.IS.RetVTs.size() == 1 && |
| 535 | Int.IS.RetVTs[0] == MVT::isVoid) |
| 536 | TypeSig.push_back(IIT_Done); |
| 537 | else |
| 538 | EncodeFixedType(Int.IS.RetTypeDefs[0], TypeSig); |
| 539 | |
| 540 | for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i) |
| 541 | EncodeFixedType(Int.IS.ParamTypeDefs[i], TypeSig); |
| 542 | |
| 543 | // Can only encode 8 nibbles into a 32-bit word. |
| 544 | if (TypeSig.size() > 8) return ~0U; |
| 545 | |
| 546 | unsigned Result = 0; |
| 547 | for (unsigned i = 0, e = TypeSig.size(); i != e; ++i) { |
| 548 | // If we had an unencodable argument, bail out. |
| 549 | if (TypeSig[i] == ~0U) |
| 550 | return ~0U; |
| 551 | Result = (Result << 4) | TypeSig[e-i-1]; |
| 552 | } |
| 553 | |
| 554 | return Result; |
| 555 | } |
| 556 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 557 | void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 558 | raw_ostream &OS) { |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 559 | OS << "// Global intrinsic function declaration type table.\n"; |
| 560 | OS << "#ifdef GET_INTRINSTIC_GENERATOR_GLOBAL\n"; |
| 561 | // NOTE: These enums must be kept in sync with the ones above! |
| 562 | OS << "enum IIT_Info {\n"; |
| 563 | OS << " IIT_Done = 0,\n"; |
| 564 | OS << " IIT_I1 = 1,\n"; |
| 565 | OS << " IIT_I8 = 2,\n"; |
| 566 | OS << " IIT_I16 = 3,\n"; |
| 567 | OS << " IIT_I32 = 4,\n"; |
| 568 | OS << " IIT_I64 = 5,\n"; |
| 569 | OS << " IIT_F32 = 6,\n"; |
| 570 | OS << " IIT_F64 = 7,\n"; |
| 571 | OS << " IIT_V2 = 8,\n"; |
| 572 | OS << " IIT_V4 = 9,\n"; |
| 573 | OS << " IIT_V8 = 10,\n"; |
| 574 | OS << " IIT_V16 = 11,\n"; |
| 575 | OS << " IIT_MMX = 12,\n"; |
| 576 | OS << " IIT_PTR = 13,\n"; |
| 577 | OS << " IIT_ARG = 14\n"; |
| 578 | // 15 is unassigned so far. |
| 579 | OS << "};\n\n"; |
| 580 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 581 | |
| 582 | // Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical |
| 583 | // types. |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 584 | typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy; |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 585 | MapTy UniqueArgInfos; |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 586 | |
| 587 | // If we can compute a 32-bit fixed encoding for this intrinsic, do so and |
| 588 | // capture it in this vector, otherwise store a ~0U. |
| 589 | std::vector<unsigned> FixedEncodings; |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 590 | |
| 591 | // Compute the unique argument type info. |
Chris Lattner | a98aa6a | 2012-05-16 06:34:44 +0000 | [diff] [blame] | 592 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
| 593 | FixedEncodings.push_back(ComputeFixedEncoding(Ints[i])); |
| 594 | |
| 595 | // If we didn't compute a compact encoding, emit a long-form variant. |
| 596 | if (FixedEncodings.back() == ~0U) |
| 597 | UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs, |
| 598 | Ints[i].IS.ParamTypeDefs)].push_back(i); |
| 599 | } |
| 600 | |
| 601 | OS << "static const unsigned IIT_Table[] = {\n "; |
| 602 | |
| 603 | for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) { |
| 604 | if ((i & 7) == 7) |
| 605 | OS << "\n "; |
| 606 | if (FixedEncodings[i] == ~0U) |
| 607 | OS << "~0U, "; |
| 608 | else |
| 609 | OS << "0x" << utohexstr(FixedEncodings[i]) << ", "; |
| 610 | } |
| 611 | |
| 612 | OS << "0\n};\n\n#endif\n\n"; // End of GET_INTRINSTIC_GENERATOR_GLOBAL |
| 613 | |
| 614 | OS << "// Code for generating Intrinsic function declarations.\n"; |
| 615 | OS << "#ifdef GET_INTRINSIC_GENERATOR\n"; |
| 616 | OS << " switch (id) {\n"; |
| 617 | OS << " default: llvm_unreachable(\"Invalid intrinsic!\");\n"; |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 618 | |
| 619 | // Loop through the array, emitting one generator for each batch. |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 620 | std::string IntrinsicStr = TargetPrefix + "Intrinsic::"; |
| 621 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 622 | for (MapTy::iterator I = UniqueArgInfos.begin(), |
| 623 | E = UniqueArgInfos.end(); I != E; ++I) { |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 624 | for (unsigned i = 0, e = I->second.size(); i != e; ++i) |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 625 | OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName |
| 626 | << ":\t\t// " << Ints[I->second[i]].Name << "\n"; |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 627 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 628 | const RecPair &ArgTypes = I->first; |
| 629 | const std::vector<Record*> &RetTys = ArgTypes.first; |
| 630 | const std::vector<Record*> &ParamTys = ArgTypes.second; |
| 631 | |
| 632 | unsigned N = ParamTys.size(); |
Reid Spencer | 84c614d | 2007-05-22 19:30:31 +0000 | [diff] [blame] | 633 | unsigned ArgNo = 0; |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 634 | OS << " ResultTy = "; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 635 | EmitTypeGenerate(OS, RetTys, ArgNo); |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 636 | OS << ";\n"; |
| 637 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 638 | for (unsigned j = 0; j != N; ++j) { |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 639 | OS << " ArgTys.push_back("; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 640 | EmitTypeGenerate(OS, ParamTys[j], ArgNo); |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 641 | OS << ");\n"; |
| 642 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 643 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 644 | OS << " break;\n"; |
| 645 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 646 | |
Jim Laskey | 95af592 | 2007-02-07 20:38:26 +0000 | [diff] [blame] | 647 | OS << " }\n"; |
| 648 | OS << "#endif\n\n"; |
| 649 | } |
| 650 | |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 651 | namespace { |
| 652 | enum ModRefKind { |
| 653 | MRK_none, |
| 654 | MRK_readonly, |
| 655 | MRK_readnone |
| 656 | }; |
| 657 | |
| 658 | ModRefKind getModRefKind(const CodeGenIntrinsic &intrinsic) { |
| 659 | switch (intrinsic.ModRef) { |
| 660 | case CodeGenIntrinsic::NoMem: |
| 661 | return MRK_readnone; |
| 662 | case CodeGenIntrinsic::ReadArgMem: |
| 663 | case CodeGenIntrinsic::ReadMem: |
| 664 | return MRK_readonly; |
| 665 | case CodeGenIntrinsic::ReadWriteArgMem: |
| 666 | case CodeGenIntrinsic::ReadWriteMem: |
| 667 | return MRK_none; |
| 668 | } |
Craig Topper | 655b8de | 2012-02-05 07:21:30 +0000 | [diff] [blame] | 669 | llvm_unreachable("bad mod-ref kind"); |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | struct AttributeComparator { |
| 673 | bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const { |
| 674 | // Sort throwing intrinsics after non-throwing intrinsics. |
| 675 | if (L->canThrow != R->canThrow) |
| 676 | return R->canThrow; |
| 677 | |
| 678 | // Try to order by readonly/readnone attribute. |
| 679 | ModRefKind LK = getModRefKind(*L); |
| 680 | ModRefKind RK = getModRefKind(*R); |
| 681 | if (LK != RK) return (LK > RK); |
| 682 | |
| 683 | // Order by argument attributes. |
| 684 | // This is reliable because each side is already sorted internally. |
| 685 | return (L->ArgumentAttributes < R->ArgumentAttributes); |
| 686 | } |
| 687 | }; |
| 688 | } |
| 689 | |
Chris Lattner | 048ffb2 | 2009-01-12 01:18:58 +0000 | [diff] [blame] | 690 | /// EmitAttributes - This emits the Intrinsic::getAttributes method. |
Chris Lattner | 4e5f359 | 2006-03-09 22:37:52 +0000 | [diff] [blame] | 691 | void IntrinsicEmitter:: |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 692 | EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) { |
Duncan Sands | a3355ff | 2007-12-03 20:06:50 +0000 | [diff] [blame] | 693 | OS << "// Add parameter attributes that are not common to all intrinsics.\n"; |
| 694 | OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 695 | if (TargetOnly) |
| 696 | OS << "static AttrListPtr getAttributes(" << TargetPrefix |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 697 | << "Intrinsic::ID id) {\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 698 | else |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 699 | OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n"; |
| 700 | |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 701 | // Compute the maximum number of attribute arguments and the map |
| 702 | typedef std::map<const CodeGenIntrinsic*, unsigned, |
| 703 | AttributeComparator> UniqAttrMapTy; |
| 704 | UniqAttrMapTy UniqAttributes; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 705 | unsigned maxArgAttrs = 0; |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 706 | unsigned AttrNum = 0; |
Chris Lattner | 7056de3 | 2006-03-24 01:13:55 +0000 | [diff] [blame] | 707 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 708 | const CodeGenIntrinsic &intrinsic = Ints[i]; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 709 | maxArgAttrs = |
| 710 | std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size())); |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 711 | unsigned &N = UniqAttributes[&intrinsic]; |
| 712 | if (N) continue; |
| 713 | assert(AttrNum < 256 && "Too many unique attributes for table!"); |
| 714 | N = ++AttrNum; |
Chris Lattner | 7056de3 | 2006-03-24 01:13:55 +0000 | [diff] [blame] | 715 | } |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 716 | |
| 717 | // Emit an array of AttributeWithIndex. Most intrinsics will have |
| 718 | // at least one entry, for the function itself (index ~1), which is |
| 719 | // usually nounwind. |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 720 | OS << " static const uint8_t IntrinsicsToAttributesMap[] = {\n"; |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 721 | |
| 722 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
| 723 | const CodeGenIntrinsic &intrinsic = Ints[i]; |
| 724 | |
| 725 | OS << " " << UniqAttributes[&intrinsic] << ", // " |
| 726 | << intrinsic.Name << "\n"; |
| 727 | } |
| 728 | OS << " };\n\n"; |
| 729 | |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 730 | OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n"; |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 731 | OS << " unsigned NumAttrs = 0;\n"; |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 732 | OS << " if (id != 0) {\n"; |
| 733 | OS << " switch(IntrinsicsToAttributesMap[id - "; |
| 734 | if (TargetOnly) |
| 735 | OS << "Intrinsic::num_intrinsics"; |
| 736 | else |
| 737 | OS << "1"; |
| 738 | OS << "]) {\n"; |
| 739 | OS << " default: llvm_unreachable(\"Invalid attribute number\");\n"; |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 740 | for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(), |
| 741 | E = UniqAttributes.end(); I != E; ++I) { |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 742 | OS << " case " << I->second << ":\n"; |
Chris Lattner | 10dae94 | 2009-01-12 01:27:55 +0000 | [diff] [blame] | 743 | |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 744 | const CodeGenIntrinsic &intrinsic = *(I->first); |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 745 | |
| 746 | // Keep track of the number of attributes we're writing out. |
| 747 | unsigned numAttrs = 0; |
| 748 | |
| 749 | // The argument attributes are alreadys sorted by argument index. |
| 750 | for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) { |
| 751 | unsigned argNo = intrinsic.ArgumentAttributes[ai].first; |
Craig Topper | 1f59523 | 2012-02-28 06:32:00 +0000 | [diff] [blame] | 752 | |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 753 | OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(" |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 754 | << argNo+1 << ", "; |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 755 | |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 756 | bool moreThanOne = false; |
| 757 | |
| 758 | do { |
| 759 | if (moreThanOne) OS << '|'; |
| 760 | |
| 761 | switch (intrinsic.ArgumentAttributes[ai].second) { |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 762 | case CodeGenIntrinsic::NoCapture: |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 763 | OS << "Attribute::NoCapture"; |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 764 | break; |
| 765 | } |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 766 | |
| 767 | ++ai; |
| 768 | moreThanOne = true; |
| 769 | } while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo); |
| 770 | |
| 771 | OS << ");\n"; |
| 772 | } |
| 773 | |
| 774 | ModRefKind modRef = getModRefKind(intrinsic); |
| 775 | |
| 776 | if (!intrinsic.canThrow || modRef) { |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 777 | OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, "; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 778 | if (!intrinsic.canThrow) { |
| 779 | OS << "Attribute::NoUnwind"; |
| 780 | if (modRef) OS << '|'; |
| 781 | } |
| 782 | switch (modRef) { |
| 783 | case MRK_none: break; |
| 784 | case MRK_readonly: OS << "Attribute::ReadOnly"; break; |
| 785 | case MRK_readnone: OS << "Attribute::ReadNone"; break; |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 786 | } |
| 787 | OS << ");\n"; |
| 788 | } |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 789 | |
| 790 | if (numAttrs) { |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 791 | OS << " NumAttrs = " << numAttrs << ";\n"; |
| 792 | OS << " break;\n"; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 793 | } else { |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 794 | OS << " return AttrListPtr();\n"; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 795 | } |
Chris Lattner | 10dae94 | 2009-01-12 01:27:55 +0000 | [diff] [blame] | 796 | } |
| 797 | |
Craig Topper | b57b170 | 2012-04-13 06:14:57 +0000 | [diff] [blame] | 798 | OS << " }\n"; |
Chris Lattner | 10dae94 | 2009-01-12 01:27:55 +0000 | [diff] [blame] | 799 | OS << " }\n"; |
John McCall | bd0fa4c | 2011-05-28 06:31:34 +0000 | [diff] [blame] | 800 | OS << " return AttrListPtr::get(AWI, NumAttrs);\n"; |
Chris Lattner | 048ffb2 | 2009-01-12 01:18:58 +0000 | [diff] [blame] | 801 | OS << "}\n"; |
Chris Lattner | d4a2700 | 2009-01-12 02:41:37 +0000 | [diff] [blame] | 802 | OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n"; |
Chris Lattner | 4e5f359 | 2006-03-09 22:37:52 +0000 | [diff] [blame] | 803 | } |
Chris Lattner | 022f64f | 2006-03-13 23:08:44 +0000 | [diff] [blame] | 804 | |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 805 | /// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior. |
| 806 | void IntrinsicEmitter:: |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 807 | EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){ |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 808 | OS << "// Determine intrinsic alias analysis mod/ref behavior.\n" |
| 809 | << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n" |
| 810 | << "assert(iid <= Intrinsic::" << Ints.back().EnumName << " && " |
| 811 | << "\"Unknown intrinsic.\");\n\n"; |
| 812 | |
| 813 | OS << "static const uint8_t IntrinsicModRefBehavior[] = {\n" |
| 814 | << " /* invalid */ UnknownModRefBehavior,\n"; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 815 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 816 | OS << " /* " << TargetPrefix << Ints[i].EnumName << " */ "; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 817 | switch (Ints[i].ModRef) { |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 818 | case CodeGenIntrinsic::NoMem: |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 819 | OS << "DoesNotAccessMemory,\n"; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 820 | break; |
| 821 | case CodeGenIntrinsic::ReadArgMem: |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 822 | OS << "OnlyReadsArgumentPointees,\n"; |
Dan Gohman | 9423f63 | 2010-11-09 20:07:20 +0000 | [diff] [blame] | 823 | break; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 824 | case CodeGenIntrinsic::ReadMem: |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 825 | OS << "OnlyReadsMemory,\n"; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 826 | break; |
Dan Gohman | 7365c09 | 2010-08-05 23:36:21 +0000 | [diff] [blame] | 827 | case CodeGenIntrinsic::ReadWriteArgMem: |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 828 | OS << "OnlyAccessesArgumentPointees,\n"; |
| 829 | break; |
| 830 | case CodeGenIntrinsic::ReadWriteMem: |
| 831 | OS << "UnknownModRefBehavior,\n"; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 832 | break; |
| 833 | } |
| 834 | } |
Benjamin Kramer | b519a0f | 2012-03-01 01:18:32 +0000 | [diff] [blame] | 835 | OS << "};\n\n" |
| 836 | << "return static_cast<ModRefBehavior>(IntrinsicModRefBehavior[iid]);\n" |
| 837 | << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n"; |
Duncan Sands | d869b38 | 2009-02-14 10:56:35 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 840 | /// EmitTargetBuiltins - All of the builtins in the specified map are for the |
| 841 | /// same target, and we already checked it. |
| 842 | static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM, |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 843 | const std::string &TargetPrefix, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 844 | raw_ostream &OS) { |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 845 | |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 846 | std::vector<StringMatcher::StringPair> Results; |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 847 | |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 848 | for (std::map<std::string, std::string>::const_iterator I = BIM.begin(), |
| 849 | E = BIM.end(); I != E; ++I) { |
| 850 | std::string ResultCode = |
| 851 | "return " + TargetPrefix + "Intrinsic::" + I->second + ";"; |
| 852 | Results.push_back(StringMatcher::StringPair(I->first, ResultCode)); |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 853 | } |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 854 | |
| 855 | StringMatcher("BuiltinName", Results, OS).Emit(); |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 859 | void IntrinsicEmitter:: |
| 860 | EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints, |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 861 | raw_ostream &OS) { |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 862 | typedef std::map<std::string, std::map<std::string, std::string> > BIMTy; |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 863 | BIMTy BuiltinMap; |
| 864 | for (unsigned i = 0, e = Ints.size(); i != e; ++i) { |
| 865 | if (!Ints[i].GCCBuiltinName.empty()) { |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 866 | // Get the map for this target prefix. |
| 867 | std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix]; |
| 868 | |
| 869 | if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName, |
| 870 | Ints[i].EnumName)).second) |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 871 | throw "Intrinsic '" + Ints[i].TheDef->getName() + |
| 872 | "': duplicate GCC builtin name!"; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n"; |
| 877 | OS << "// This is used by the C front-end. The GCC builtin name is passed\n"; |
| 878 | OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n"; |
| 879 | OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n"; |
| 880 | OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 881 | |
| 882 | if (TargetOnly) { |
| 883 | OS << "static " << TargetPrefix << "Intrinsic::ID " |
| 884 | << "getIntrinsicForGCCBuiltin(const char " |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 885 | << "*TargetPrefixStr, const char *BuiltinNameStr) {\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 886 | } else { |
| 887 | OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char " |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 888 | << "*TargetPrefixStr, const char *BuiltinNameStr) {\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 891 | OS << " StringRef BuiltinName(BuiltinNameStr);\n"; |
| 892 | OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n"; |
Chris Lattner | 331bf92 | 2008-01-04 04:38:35 +0000 | [diff] [blame] | 893 | |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 894 | // Note: this could emit significantly better code if we cared. |
| 895 | for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){ |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 896 | OS << " "; |
| 897 | if (!I->first.empty()) |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 898 | OS << "if (TargetPrefix == \"" << I->first << "\") "; |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 899 | else |
| 900 | OS << "/* Target Independent Builtins */ "; |
| 901 | OS << "{\n"; |
| 902 | |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 903 | // Emit the comparisons for this target prefix. |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 904 | EmitTargetBuiltins(I->second, TargetPrefix, OS); |
Chris Lattner | fa0fba1 | 2008-01-02 21:24:22 +0000 | [diff] [blame] | 905 | OS << " }\n"; |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 906 | } |
Chris Lattner | 298b176 | 2010-09-06 03:14:45 +0000 | [diff] [blame] | 907 | OS << " return "; |
| 908 | if (!TargetPrefix.empty()) |
| 909 | OS << "(" << TargetPrefix << "Intrinsic::ID)"; |
| 910 | OS << "Intrinsic::not_intrinsic;\n"; |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 911 | OS << "}\n"; |
Chris Lattner | 3f8b891 | 2006-03-15 01:33:26 +0000 | [diff] [blame] | 912 | OS << "#endif\n\n"; |
| 913 | } |