Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 1 | //===- CodeGenTarget.cpp - CodeGen Target Class Wrapper -------------------===// |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 01d4582 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 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. |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 01d4582 | 2003-10-20 20:20:30 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 6cc654b | 2008-01-06 01:35:39 +0000 | [diff] [blame] | 10 | // This class wraps target description classes used by the various code |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 11 | // generation TableGen backends. This makes it easier to access the data and |
| 12 | // provides a single place that needs to check it for validity. All of these |
| 13 | // classes throw exceptions on error conditions. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Chris Lattner | 803a5f6 | 2004-08-01 04:04:35 +0000 | [diff] [blame] | 17 | #include "CodeGenTarget.h" |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 18 | #include "CodeGenIntrinsics.h" |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 19 | #include "Record.h" |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringExtras.h" |
| 21 | #include "llvm/Support/CommandLine.h" |
Chris Lattner | 75ee2eb | 2005-10-14 03:54:49 +0000 | [diff] [blame] | 22 | #include <algorithm> |
Chris Lattner | 2082ebe | 2004-08-01 03:55:39 +0000 | [diff] [blame] | 23 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 25 | static cl::opt<unsigned> |
Daniel Dunbar | 0e2771f | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 26 | AsmParserNum("asmparsernum", cl::init(0), |
| 27 | cl::desc("Make -gen-asm-parser emit assembly parser #N")); |
| 28 | |
| 29 | static cl::opt<unsigned> |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 30 | AsmWriterNum("asmwriternum", cl::init(0), |
| 31 | cl::desc("Make -gen-asm-writer emit assembly writer #N")); |
| 32 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 33 | /// getValueType - Return the EVT::SimpleValueType that the specified TableGen |
Duncan Sands | 83ec4b6 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 34 | /// record corresponds to. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 35 | EVT::SimpleValueType llvm::getValueType(Record *Rec) { |
| 36 | return (EVT::SimpleValueType)Rec->getValueAsInt("Value"); |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 39 | std::string llvm::getName(EVT::SimpleValueType T) { |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 40 | switch (T) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 41 | case EVT::Other: return "UNKNOWN"; |
| 42 | case EVT::iPTR: return "TLI.getPointerTy()"; |
| 43 | case EVT::iPTRAny: return "TLI.getPointerTy()"; |
Bob Wilson | bbf1caa | 2009-07-10 22:25:24 +0000 | [diff] [blame] | 44 | default: return getEnumName(T); |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 45 | } |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 48 | std::string llvm::getEnumName(EVT::SimpleValueType T) { |
Chris Lattner | b72fb7e | 2003-08-10 19:50:32 +0000 | [diff] [blame] | 49 | switch (T) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 50 | case EVT::Other: return "EVT::Other"; |
| 51 | case EVT::i1: return "EVT::i1"; |
| 52 | case EVT::i8: return "EVT::i8"; |
| 53 | case EVT::i16: return "EVT::i16"; |
| 54 | case EVT::i32: return "EVT::i32"; |
| 55 | case EVT::i64: return "EVT::i64"; |
| 56 | case EVT::i128: return "EVT::i128"; |
| 57 | case EVT::iAny: return "EVT::iAny"; |
| 58 | case EVT::fAny: return "EVT::fAny"; |
| 59 | case EVT::f32: return "EVT::f32"; |
| 60 | case EVT::f64: return "EVT::f64"; |
| 61 | case EVT::f80: return "EVT::f80"; |
| 62 | case EVT::f128: return "EVT::f128"; |
| 63 | case EVT::ppcf128: return "EVT::ppcf128"; |
| 64 | case EVT::Flag: return "EVT::Flag"; |
| 65 | case EVT::isVoid:return "EVT::isVoid"; |
| 66 | case EVT::v2i8: return "EVT::v2i8"; |
| 67 | case EVT::v4i8: return "EVT::v4i8"; |
| 68 | case EVT::v8i8: return "EVT::v8i8"; |
| 69 | case EVT::v16i8: return "EVT::v16i8"; |
| 70 | case EVT::v32i8: return "EVT::v32i8"; |
| 71 | case EVT::v2i16: return "EVT::v2i16"; |
| 72 | case EVT::v4i16: return "EVT::v4i16"; |
| 73 | case EVT::v8i16: return "EVT::v8i16"; |
| 74 | case EVT::v16i16: return "EVT::v16i16"; |
| 75 | case EVT::v2i32: return "EVT::v2i32"; |
| 76 | case EVT::v4i32: return "EVT::v4i32"; |
| 77 | case EVT::v8i32: return "EVT::v8i32"; |
| 78 | case EVT::v1i64: return "EVT::v1i64"; |
| 79 | case EVT::v2i64: return "EVT::v2i64"; |
| 80 | case EVT::v4i64: return "EVT::v4i64"; |
| 81 | case EVT::v2f32: return "EVT::v2f32"; |
| 82 | case EVT::v4f32: return "EVT::v4f32"; |
| 83 | case EVT::v8f32: return "EVT::v8f32"; |
| 84 | case EVT::v2f64: return "EVT::v2f64"; |
| 85 | case EVT::v4f64: return "EVT::v4f64"; |
| 86 | case EVT::Metadata: return "EVT::Metadata"; |
| 87 | case EVT::iPTR: return "EVT::iPTR"; |
| 88 | case EVT::iPTRAny: return "EVT::iPTRAny"; |
Chris Lattner | b72fb7e | 2003-08-10 19:50:32 +0000 | [diff] [blame] | 89 | default: assert(0 && "ILLEGAL VALUE TYPE!"); return ""; |
| 90 | } |
| 91 | } |
| 92 | |
Chris Lattner | 6cefb77 | 2008-01-05 22:25:12 +0000 | [diff] [blame] | 93 | /// getQualifiedName - Return the name of the specified record, with a |
| 94 | /// namespace qualifier if the record contains one. |
| 95 | /// |
| 96 | std::string llvm::getQualifiedName(const Record *R) { |
| 97 | std::string Namespace = R->getValueAsString("Namespace"); |
| 98 | if (Namespace.empty()) return R->getName(); |
| 99 | return Namespace + "::" + R->getName(); |
| 100 | } |
| 101 | |
| 102 | |
| 103 | |
Chris Lattner | d3464c1 | 2003-08-07 23:15:21 +0000 | [diff] [blame] | 104 | |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 105 | /// getTarget - Return the current instance of the Target class. |
| 106 | /// |
Evan Cheng | 2618d07 | 2006-05-17 20:37:59 +0000 | [diff] [blame] | 107 | CodeGenTarget::CodeGenTarget() { |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 108 | std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target"); |
Misha Brukman | bebdb20 | 2004-06-04 14:59:42 +0000 | [diff] [blame] | 109 | if (Targets.size() == 0) |
Misha Brukman | 3da94ae | 2005-04-22 00:00:37 +0000 | [diff] [blame] | 110 | throw std::string("ERROR: No 'Target' subclasses defined!"); |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 111 | if (Targets.size() != 1) |
| 112 | throw std::string("ERROR: Multiple subclasses of Target defined!"); |
| 113 | TargetRec = Targets[0]; |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | const std::string &CodeGenTarget::getName() const { |
| 118 | return TargetRec->getName(); |
| 119 | } |
| 120 | |
Dan Gohman | 1e0ee4b | 2008-08-20 21:45:57 +0000 | [diff] [blame] | 121 | std::string CodeGenTarget::getInstNamespace() const { |
| 122 | std::string InstNS; |
| 123 | |
| 124 | for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) { |
| 125 | InstNS = i->second.Namespace; |
| 126 | |
| 127 | // Make sure not to pick up "TargetInstrInfo" by accidentally getting |
| 128 | // the namespace off the PHI instruction or something. |
| 129 | if (InstNS != "TargetInstrInfo") |
| 130 | break; |
| 131 | } |
| 132 | |
| 133 | return InstNS; |
| 134 | } |
| 135 | |
Chris Lattner | 4587207 | 2003-08-07 05:38:11 +0000 | [diff] [blame] | 136 | Record *CodeGenTarget::getInstructionSet() const { |
| 137 | return TargetRec->getValueAsDef("InstructionSet"); |
| 138 | } |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 139 | |
Daniel Dunbar | 0e2771f | 2009-07-29 00:02:19 +0000 | [diff] [blame] | 140 | /// getAsmParser - Return the AssemblyParser definition for this target. |
| 141 | /// |
| 142 | Record *CodeGenTarget::getAsmParser() const { |
| 143 | std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers"); |
| 144 | if (AsmParserNum >= LI.size()) |
| 145 | throw "Target does not have an AsmParser #" + utostr(AsmParserNum) + "!"; |
| 146 | return LI[AsmParserNum]; |
| 147 | } |
| 148 | |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 149 | /// getAsmWriter - Return the AssemblyWriter definition for this target. |
| 150 | /// |
| 151 | Record *CodeGenTarget::getAsmWriter() const { |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 152 | std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters"); |
| 153 | if (AsmWriterNum >= LI.size()) |
Chris Lattner | 560a79f | 2004-10-03 19:34:31 +0000 | [diff] [blame] | 154 | throw "Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!"; |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 155 | return LI[AsmWriterNum]; |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | 2669311 | 2004-08-16 01:10:21 +0000 | [diff] [blame] | 158 | void CodeGenTarget::ReadRegisters() const { |
| 159 | std::vector<Record*> Regs = Records.getAllDerivedDefinitions("Register"); |
| 160 | if (Regs.empty()) |
| 161 | throw std::string("No 'Register' subclasses defined!"); |
| 162 | |
| 163 | Registers.reserve(Regs.size()); |
| 164 | Registers.assign(Regs.begin(), Regs.end()); |
| 165 | } |
| 166 | |
Chris Lattner | 7a680c6 | 2004-08-21 02:24:57 +0000 | [diff] [blame] | 167 | CodeGenRegister::CodeGenRegister(Record *R) : TheDef(R) { |
| 168 | DeclaredSpillSize = R->getValueAsInt("SpillSize"); |
| 169 | DeclaredSpillAlignment = R->getValueAsInt("SpillAlignment"); |
| 170 | } |
| 171 | |
Chris Lattner | 2669311 | 2004-08-16 01:10:21 +0000 | [diff] [blame] | 172 | const std::string &CodeGenRegister::getName() const { |
| 173 | return TheDef->getName(); |
| 174 | } |
| 175 | |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 176 | void CodeGenTarget::ReadRegisterClasses() const { |
| 177 | std::vector<Record*> RegClasses = |
| 178 | Records.getAllDerivedDefinitions("RegisterClass"); |
| 179 | if (RegClasses.empty()) |
| 180 | throw std::string("No 'RegisterClass' subclasses defined!"); |
| 181 | |
| 182 | RegisterClasses.reserve(RegClasses.size()); |
| 183 | RegisterClasses.assign(RegClasses.begin(), RegClasses.end()); |
| 184 | } |
| 185 | |
Evan Cheng | 44a65fa | 2006-05-16 07:05:30 +0000 | [diff] [blame] | 186 | std::vector<unsigned char> CodeGenTarget::getRegisterVTs(Record *R) const { |
| 187 | std::vector<unsigned char> Result; |
| 188 | const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses(); |
| 189 | for (unsigned i = 0, e = RCs.size(); i != e; ++i) { |
| 190 | const CodeGenRegisterClass &RC = RegisterClasses[i]; |
| 191 | for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) { |
| 192 | if (R == RC.Elements[ei]) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 193 | const std::vector<EVT::SimpleValueType> &InVTs = RC.getValueTypes(); |
Evan Cheng | 44a65fa | 2006-05-16 07:05:30 +0000 | [diff] [blame] | 194 | for (unsigned i = 0, e = InVTs.size(); i != e; ++i) |
| 195 | Result.push_back(InVTs[i]); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | return Result; |
| 200 | } |
| 201 | |
| 202 | |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 203 | CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) { |
Chris Lattner | c67c18f | 2005-08-19 18:45:20 +0000 | [diff] [blame] | 204 | // Rename anonymous register classes. |
| 205 | if (R->getName().size() > 9 && R->getName()[9] == '.') { |
| 206 | static unsigned AnonCounter = 0; |
| 207 | R->setName("AnonRegClass_"+utostr(AnonCounter++)); |
| 208 | } |
| 209 | |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 210 | std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes"); |
| 211 | for (unsigned i = 0, e = TypeList.size(); i != e; ++i) { |
| 212 | Record *Type = TypeList[i]; |
| 213 | if (!Type->isSubClassOf("ValueType")) |
| 214 | throw "RegTypes list member '" + Type->getName() + |
| 215 | "' does not derive from the ValueType class!"; |
| 216 | VTs.push_back(getValueType(Type)); |
| 217 | } |
| 218 | assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!"); |
Chris Lattner | ac46893 | 2005-08-19 19:12:51 +0000 | [diff] [blame] | 219 | |
Chris Lattner | b0e103d | 2005-10-28 22:49:02 +0000 | [diff] [blame] | 220 | std::vector<Record*> RegList = R->getValueAsListOfDefs("MemberList"); |
| 221 | for (unsigned i = 0, e = RegList.size(); i != e; ++i) { |
| 222 | Record *Reg = RegList[i]; |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 223 | if (!Reg->isSubClassOf("Register")) |
| 224 | throw "Register Class member '" + Reg->getName() + |
| 225 | "' does not derive from the Register class!"; |
| 226 | Elements.push_back(Reg); |
| 227 | } |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 228 | |
Christopher Lamb | a321125 | 2007-06-13 22:20:15 +0000 | [diff] [blame] | 229 | std::vector<Record*> SubRegClassList = |
| 230 | R->getValueAsListOfDefs("SubRegClassList"); |
| 231 | for (unsigned i = 0, e = SubRegClassList.size(); i != e; ++i) { |
| 232 | Record *SubRegClass = SubRegClassList[i]; |
| 233 | if (!SubRegClass->isSubClassOf("RegisterClass")) |
| 234 | throw "Register Class member '" + SubRegClass->getName() + |
| 235 | "' does not derive from the RegisterClass class!"; |
| 236 | SubRegClasses.push_back(SubRegClass); |
| 237 | } |
| 238 | |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 239 | // Allow targets to override the size in bits of the RegisterClass. |
| 240 | unsigned Size = R->getValueAsInt("Size"); |
| 241 | |
| 242 | Namespace = R->getValueAsString("Namespace"); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 243 | SpillSize = Size ? Size : EVT(VTs[0]).getSizeInBits(); |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 244 | SpillAlignment = R->getValueAsInt("Alignment"); |
Evan Cheng | a3ca314 | 2007-09-19 01:35:01 +0000 | [diff] [blame] | 245 | CopyCost = R->getValueAsInt("CopyCost"); |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 246 | MethodBodies = R->getValueAsCode("MethodBodies"); |
| 247 | MethodProtos = R->getValueAsCode("MethodProtos"); |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | const std::string &CodeGenRegisterClass::getName() const { |
| 251 | return TheDef->getName(); |
| 252 | } |
| 253 | |
Chris Lattner | e9f4ba8 | 2005-09-08 21:43:21 +0000 | [diff] [blame] | 254 | void CodeGenTarget::ReadLegalValueTypes() const { |
| 255 | const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses(); |
| 256 | for (unsigned i = 0, e = RCs.size(); i != e; ++i) |
Nate Begeman | 6510b22 | 2005-12-01 04:51:06 +0000 | [diff] [blame] | 257 | for (unsigned ri = 0, re = RCs[i].VTs.size(); ri != re; ++ri) |
| 258 | LegalValueTypes.push_back(RCs[i].VTs[ri]); |
Chris Lattner | 75ee2eb | 2005-10-14 03:54:49 +0000 | [diff] [blame] | 259 | |
| 260 | // Remove duplicates. |
| 261 | std::sort(LegalValueTypes.begin(), LegalValueTypes.end()); |
| 262 | LegalValueTypes.erase(std::unique(LegalValueTypes.begin(), |
| 263 | LegalValueTypes.end()), |
| 264 | LegalValueTypes.end()); |
Chris Lattner | e9f4ba8 | 2005-09-08 21:43:21 +0000 | [diff] [blame] | 265 | } |
Chris Lattner | 056afef | 2004-08-21 04:05:00 +0000 | [diff] [blame] | 266 | |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 267 | |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 268 | void CodeGenTarget::ReadInstructions() const { |
| 269 | std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction"); |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 270 | if (Insts.size() <= 2) |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 271 | throw std::string("No 'Instruction' subclasses defined!"); |
| 272 | |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 273 | // Parse the instructions defined in the .td file. |
Chris Lattner | 175580c | 2004-08-14 22:50:53 +0000 | [diff] [blame] | 274 | std::string InstFormatName = |
| 275 | getAsmWriter()->getValueAsString("InstFormatName"); |
| 276 | |
| 277 | for (unsigned i = 0, e = Insts.size(); i != e; ++i) { |
| 278 | std::string AsmStr = Insts[i]->getValueAsString(InstFormatName); |
| 279 | Instructions.insert(std::make_pair(Insts[i]->getName(), |
| 280 | CodeGenInstruction(Insts[i], AsmStr))); |
| 281 | } |
Chris Lattner | ec35240 | 2004-08-01 05:04:00 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 284 | /// getInstructionsByEnumValue - Return all of the instructions defined by the |
| 285 | /// target, ordered by their enum value. |
| 286 | void CodeGenTarget:: |
| 287 | getInstructionsByEnumValue(std::vector<const CodeGenInstruction*> |
| 288 | &NumberedInstructions) { |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 289 | std::map<std::string, CodeGenInstruction>::const_iterator I; |
| 290 | I = getInstructions().find("PHI"); |
| 291 | if (I == Instructions.end()) throw "Could not find 'PHI' instruction!"; |
| 292 | const CodeGenInstruction *PHI = &I->second; |
| 293 | |
| 294 | I = getInstructions().find("INLINEASM"); |
| 295 | if (I == Instructions.end()) throw "Could not find 'INLINEASM' instruction!"; |
| 296 | const CodeGenInstruction *INLINEASM = &I->second; |
| 297 | |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 298 | I = getInstructions().find("DBG_LABEL"); |
| 299 | if (I == Instructions.end()) throw "Could not find 'DBG_LABEL' instruction!"; |
| 300 | const CodeGenInstruction *DBG_LABEL = &I->second; |
| 301 | |
| 302 | I = getInstructions().find("EH_LABEL"); |
| 303 | if (I == Instructions.end()) throw "Could not find 'EH_LABEL' instruction!"; |
| 304 | const CodeGenInstruction *EH_LABEL = &I->second; |
| 305 | |
| 306 | I = getInstructions().find("GC_LABEL"); |
| 307 | if (I == Instructions.end()) throw "Could not find 'GC_LABEL' instruction!"; |
| 308 | const CodeGenInstruction *GC_LABEL = &I->second; |
Jim Laskey | a683f9b | 2007-01-26 17:29:20 +0000 | [diff] [blame] | 309 | |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 310 | I = getInstructions().find("DECLARE"); |
| 311 | if (I == Instructions.end()) throw "Could not find 'DECLARE' instruction!"; |
| 312 | const CodeGenInstruction *DECLARE = &I->second; |
| 313 | |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 314 | I = getInstructions().find("EXTRACT_SUBREG"); |
| 315 | if (I == Instructions.end()) |
| 316 | throw "Could not find 'EXTRACT_SUBREG' instruction!"; |
| 317 | const CodeGenInstruction *EXTRACT_SUBREG = &I->second; |
| 318 | |
| 319 | I = getInstructions().find("INSERT_SUBREG"); |
| 320 | if (I == Instructions.end()) |
| 321 | throw "Could not find 'INSERT_SUBREG' instruction!"; |
| 322 | const CodeGenInstruction *INSERT_SUBREG = &I->second; |
| 323 | |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 324 | I = getInstructions().find("IMPLICIT_DEF"); |
| 325 | if (I == Instructions.end()) |
| 326 | throw "Could not find 'IMPLICIT_DEF' instruction!"; |
| 327 | const CodeGenInstruction *IMPLICIT_DEF = &I->second; |
| 328 | |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 329 | I = getInstructions().find("SUBREG_TO_REG"); |
| 330 | if (I == Instructions.end()) |
| 331 | throw "Could not find 'SUBREG_TO_REG' instruction!"; |
| 332 | const CodeGenInstruction *SUBREG_TO_REG = &I->second; |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 333 | |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 334 | I = getInstructions().find("COPY_TO_REGCLASS"); |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 335 | if (I == Instructions.end()) |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 336 | throw "Could not find 'COPY_TO_REGCLASS' instruction!"; |
| 337 | const CodeGenInstruction *COPY_TO_REGCLASS = &I->second; |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 338 | |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 339 | // Print out the rest of the instructions now. |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 340 | NumberedInstructions.push_back(PHI); |
Chris Lattner | aa77d77 | 2006-01-27 01:45:06 +0000 | [diff] [blame] | 341 | NumberedInstructions.push_back(INLINEASM); |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 342 | NumberedInstructions.push_back(DBG_LABEL); |
| 343 | NumberedInstructions.push_back(EH_LABEL); |
| 344 | NumberedInstructions.push_back(GC_LABEL); |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 345 | NumberedInstructions.push_back(DECLARE); |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 346 | NumberedInstructions.push_back(EXTRACT_SUBREG); |
| 347 | NumberedInstructions.push_back(INSERT_SUBREG); |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 348 | NumberedInstructions.push_back(IMPLICIT_DEF); |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 349 | NumberedInstructions.push_back(SUBREG_TO_REG); |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 350 | NumberedInstructions.push_back(COPY_TO_REGCLASS); |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 351 | for (inst_iterator II = inst_begin(), E = inst_end(); II != E; ++II) |
Jim Laskey | a683f9b | 2007-01-26 17:29:20 +0000 | [diff] [blame] | 352 | if (&II->second != PHI && |
| 353 | &II->second != INLINEASM && |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 354 | &II->second != DBG_LABEL && |
| 355 | &II->second != EH_LABEL && |
| 356 | &II->second != GC_LABEL && |
Evan Cheng | a844bde | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 357 | &II->second != DECLARE && |
Christopher Lamb | 08d5207 | 2007-07-26 07:48:21 +0000 | [diff] [blame] | 358 | &II->second != EXTRACT_SUBREG && |
Evan Cheng | da47e6e | 2008-03-15 00:03:38 +0000 | [diff] [blame] | 359 | &II->second != INSERT_SUBREG && |
Christopher Lamb | c929823 | 2008-03-16 03:12:01 +0000 | [diff] [blame] | 360 | &II->second != IMPLICIT_DEF && |
Dan Gohman | f8c7394 | 2009-04-13 15:38:05 +0000 | [diff] [blame] | 361 | &II->second != SUBREG_TO_REG && |
Dan Gohman | 88c7af0 | 2009-04-13 21:06:25 +0000 | [diff] [blame] | 362 | &II->second != COPY_TO_REGCLASS) |
Chris Lattner | d648867 | 2005-01-22 18:58:51 +0000 | [diff] [blame] | 363 | NumberedInstructions.push_back(&II->second); |
| 364 | } |
| 365 | |
| 366 | |
Misha Brukman | 35e83cc | 2004-10-14 05:50:43 +0000 | [diff] [blame] | 367 | /// isLittleEndianEncoding - Return whether this target encodes its instruction |
| 368 | /// in little-endian format, i.e. bits laid out in the order [0..n] |
| 369 | /// |
| 370 | bool CodeGenTarget::isLittleEndianEncoding() const { |
| 371 | return getInstructionSet()->getValueAsBit("isLittleEndianEncoding"); |
| 372 | } |
| 373 | |
Evan Cheng | 0fc7198 | 2005-12-08 02:00:36 +0000 | [diff] [blame] | 374 | //===----------------------------------------------------------------------===// |
| 375 | // ComplexPattern implementation |
| 376 | // |
| 377 | ComplexPattern::ComplexPattern(Record *R) { |
Evan Cheng | 3aa39f4 | 2005-12-08 02:14:08 +0000 | [diff] [blame] | 378 | Ty = ::getValueType(R->getValueAsDef("Ty")); |
| 379 | NumOperands = R->getValueAsInt("NumOperands"); |
| 380 | SelectFunc = R->getValueAsString("SelectFunc"); |
| 381 | RootNodes = R->getValueAsListOfDefs("RootNodes"); |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 382 | |
| 383 | // Parse the properties. |
| 384 | Properties = 0; |
| 385 | std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties"); |
| 386 | for (unsigned i = 0, e = PropList.size(); i != e; ++i) |
| 387 | if (PropList[i]->getName() == "SDNPHasChain") { |
| 388 | Properties |= 1 << SDNPHasChain; |
| 389 | } else if (PropList[i]->getName() == "SDNPOptInFlag") { |
| 390 | Properties |= 1 << SDNPOptInFlag; |
Chris Lattner | ba7e756 | 2008-01-10 07:59:24 +0000 | [diff] [blame] | 391 | } else if (PropList[i]->getName() == "SDNPMayStore") { |
| 392 | Properties |= 1 << SDNPMayStore; |
| 393 | } else if (PropList[i]->getName() == "SDNPMayLoad") { |
| 394 | Properties |= 1 << SDNPMayLoad; |
| 395 | } else if (PropList[i]->getName() == "SDNPSideEffect") { |
| 396 | Properties |= 1 << SDNPSideEffect; |
Mon P Wang | 2887310 | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 397 | } else if (PropList[i]->getName() == "SDNPMemOperand") { |
| 398 | Properties |= 1 << SDNPMemOperand; |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 399 | } else { |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 400 | errs() << "Unsupported SD Node property '" << PropList[i]->getName() |
| 401 | << "' on ComplexPattern '" << R->getName() << "'!\n"; |
Evan Cheng | 94b3040 | 2006-10-11 21:02:01 +0000 | [diff] [blame] | 402 | exit(1); |
| 403 | } |
Christopher Lamb | 8535624 | 2008-01-31 07:27:46 +0000 | [diff] [blame] | 404 | |
| 405 | // Parse the attributes. |
| 406 | Attributes = 0; |
| 407 | PropList = R->getValueAsListOfDefs("Attributes"); |
| 408 | for (unsigned i = 0, e = PropList.size(); i != e; ++i) |
| 409 | if (PropList[i]->getName() == "CPAttrParentAsRoot") { |
| 410 | Attributes |= 1 << CPAttrParentAsRoot; |
| 411 | } else { |
Daniel Dunbar | 1a55180 | 2009-07-03 00:10:29 +0000 | [diff] [blame] | 412 | errs() << "Unsupported pattern attribute '" << PropList[i]->getName() |
| 413 | << "' on ComplexPattern '" << R->getName() << "'!\n"; |
Christopher Lamb | 8535624 | 2008-01-31 07:27:46 +0000 | [diff] [blame] | 414 | exit(1); |
| 415 | } |
Evan Cheng | 0fc7198 | 2005-12-08 02:00:36 +0000 | [diff] [blame] | 416 | } |
Evan Cheng | 3aa39f4 | 2005-12-08 02:14:08 +0000 | [diff] [blame] | 417 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 418 | //===----------------------------------------------------------------------===// |
| 419 | // CodeGenIntrinsic Implementation |
| 420 | //===----------------------------------------------------------------------===// |
| 421 | |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 422 | std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC, |
| 423 | bool TargetOnly) { |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 424 | std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic"); |
Chris Lattner | 8850a1b | 2006-03-27 22:48:18 +0000 | [diff] [blame] | 425 | |
| 426 | std::vector<CodeGenIntrinsic> Result; |
Chris Lattner | 6a160fb | 2006-03-28 00:15:00 +0000 | [diff] [blame] | 427 | |
Dale Johannesen | 49de982 | 2009-02-05 01:49:45 +0000 | [diff] [blame] | 428 | for (unsigned i = 0, e = I.size(); i != e; ++i) { |
| 429 | bool isTarget = I[i]->getValueAsBit("isTarget"); |
| 430 | if (isTarget == TargetOnly) |
| 431 | Result.push_back(CodeGenIntrinsic(I[i])); |
| 432 | } |
Chris Lattner | 8850a1b | 2006-03-27 22:48:18 +0000 | [diff] [blame] | 433 | return Result; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Dan Gohman | ee4fa19 | 2008-04-03 00:02:49 +0000 | [diff] [blame] | 436 | CodeGenIntrinsic::CodeGenIntrinsic(Record *R) { |
Chris Lattner | 2ca956f | 2006-03-24 20:25:01 +0000 | [diff] [blame] | 437 | TheDef = R; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 438 | std::string DefName = R->getName(); |
| 439 | ModRef = WriteMem; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 440 | isOverloaded = false; |
Evan Cheng | 6bd9567 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 441 | isCommutative = false; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 442 | |
| 443 | if (DefName.size() <= 4 || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 444 | std::string(DefName.begin(), DefName.begin() + 4) != "int_") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 445 | throw "Intrinsic '" + DefName + "' does not start with 'int_'!"; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 446 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 447 | EnumName = std::string(DefName.begin()+4, DefName.end()); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 448 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 449 | if (R->getValue("GCCBuiltinName")) // Ignore a missing GCCBuiltinName field. |
| 450 | GCCBuiltinName = R->getValueAsString("GCCBuiltinName"); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 451 | |
| 452 | TargetPrefix = R->getValueAsString("TargetPrefix"); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 453 | Name = R->getValueAsString("LLVMName"); |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 454 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 455 | if (Name == "") { |
| 456 | // If an explicit name isn't specified, derive one from the DefName. |
| 457 | Name = "llvm."; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 458 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 459 | for (unsigned i = 0, e = EnumName.size(); i != e; ++i) |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 460 | Name += (EnumName[i] == '_') ? '.' : EnumName[i]; |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 461 | } else { |
| 462 | // Verify it starts with "llvm.". |
| 463 | if (Name.size() <= 5 || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 464 | std::string(Name.begin(), Name.begin() + 5) != "llvm.") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 465 | throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!"; |
| 466 | } |
| 467 | |
| 468 | // If TargetPrefix is specified, make sure that Name starts with |
| 469 | // "llvm.<targetprefix>.". |
| 470 | if (!TargetPrefix.empty()) { |
| 471 | if (Name.size() < 6+TargetPrefix.size() || |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 472 | std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size()) |
| 473 | != (TargetPrefix + ".")) |
| 474 | throw "Intrinsic '" + DefName + "' does not start with 'llvm." + |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 475 | TargetPrefix + ".'!"; |
| 476 | } |
| 477 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 478 | // Parse the list of return types. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 479 | std::vector<EVT::SimpleValueType> OverloadedVTs; |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 480 | ListInit *TypeList = R->getValueAsListInit("RetTypes"); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 481 | for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { |
Chris Lattner | 50d4565 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 482 | Record *TyEl = TypeList->getElementAsRecord(i); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 483 | assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 484 | EVT::SimpleValueType VT; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 485 | if (TyEl->isSubClassOf("LLVMMatchType")) { |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 486 | unsigned MatchTy = TyEl->getValueAsInt("Number"); |
| 487 | assert(MatchTy < OverloadedVTs.size() && |
| 488 | "Invalid matching number!"); |
| 489 | VT = OverloadedVTs[MatchTy]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 490 | // It only makes sense to use the extended and truncated vector element |
| 491 | // variants with iAny types; otherwise, if the intrinsic is not |
| 492 | // overloaded, all the types can be specified directly. |
| 493 | assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") && |
| 494 | !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) || |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 495 | VT == EVT::iAny) && "Expected iAny type"); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 496 | } else { |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 497 | VT = getValueType(TyEl->getValueAsDef("VT")); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 498 | } |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 499 | if (VT == EVT::iAny || VT == EVT::fAny || VT == EVT::iPTRAny) { |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 500 | OverloadedVTs.push_back(VT); |
| 501 | isOverloaded |= true; |
| 502 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 503 | IS.RetVTs.push_back(VT); |
| 504 | IS.RetTypeDefs.push_back(TyEl); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 505 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 506 | |
| 507 | if (IS.RetVTs.size() == 0) |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 508 | throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!"; |
Reid Spencer | c4de3de | 2007-04-01 07:20:02 +0000 | [diff] [blame] | 509 | |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 510 | // Parse the list of parameter types. |
| 511 | TypeList = R->getValueAsListInit("ParamTypes"); |
| 512 | for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) { |
| 513 | Record *TyEl = TypeList->getElementAsRecord(i); |
| 514 | assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!"); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 515 | EVT::SimpleValueType VT; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 516 | if (TyEl->isSubClassOf("LLVMMatchType")) { |
| 517 | unsigned MatchTy = TyEl->getValueAsInt("Number"); |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 518 | assert(MatchTy < OverloadedVTs.size() && |
| 519 | "Invalid matching number!"); |
| 520 | VT = OverloadedVTs[MatchTy]; |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 521 | // It only makes sense to use the extended and truncated vector element |
| 522 | // variants with iAny types; otherwise, if the intrinsic is not |
| 523 | // overloaded, all the types can be specified directly. |
| 524 | assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") && |
| 525 | !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) || |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 526 | VT == EVT::iAny) && "Expected iAny type"); |
Bob Wilson | bc03979 | 2009-01-07 00:09:01 +0000 | [diff] [blame] | 527 | } else |
| 528 | VT = getValueType(TyEl->getValueAsDef("VT")); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame^] | 529 | if (VT == EVT::iAny || VT == EVT::fAny || VT == EVT::iPTRAny) { |
Bob Wilson | d305e70 | 2009-04-16 21:51:05 +0000 | [diff] [blame] | 530 | OverloadedVTs.push_back(VT); |
| 531 | isOverloaded |= true; |
| 532 | } |
Bill Wendling | cdcc3e6 | 2008-11-13 09:08:33 +0000 | [diff] [blame] | 533 | IS.ParamVTs.push_back(VT); |
| 534 | IS.ParamTypeDefs.push_back(TyEl); |
| 535 | } |
| 536 | |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 537 | // Parse the intrinsic properties. |
| 538 | ListInit *PropList = R->getValueAsListInit("Properties"); |
| 539 | for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) { |
Chris Lattner | 50d4565 | 2007-02-27 22:08:27 +0000 | [diff] [blame] | 540 | Record *Property = PropList->getElementAsRecord(i); |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 541 | assert(Property->isSubClassOf("IntrinsicProperty") && |
| 542 | "Expected a property!"); |
| 543 | |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 544 | if (Property->getName() == "IntrNoMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 545 | ModRef = NoMem; |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 546 | else if (Property->getName() == "IntrReadArgMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 547 | ModRef = ReadArgMem; |
| 548 | else if (Property->getName() == "IntrReadMem") |
| 549 | ModRef = ReadMem; |
Chris Lattner | 4b2362e | 2006-04-10 22:02:59 +0000 | [diff] [blame] | 550 | else if (Property->getName() == "IntrWriteArgMem") |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 551 | ModRef = WriteArgMem; |
| 552 | else if (Property->getName() == "IntrWriteMem") |
| 553 | ModRef = WriteMem; |
Evan Cheng | 6bd9567 | 2008-06-16 20:29:38 +0000 | [diff] [blame] | 554 | else if (Property->getName() == "Commutative") |
| 555 | isCommutative = true; |
Chris Lattner | a62c302 | 2009-01-12 01:12:03 +0000 | [diff] [blame] | 556 | else if (Property->isSubClassOf("NoCapture")) { |
| 557 | unsigned ArgNo = Property->getValueAsInt("ArgNo"); |
| 558 | ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture)); |
| 559 | } else |
Chris Lattner | 43fbbc3 | 2006-03-24 19:49:31 +0000 | [diff] [blame] | 560 | assert(0 && "Unknown property!"); |
| 561 | } |
| 562 | } |