Add StringRef::compare_numeric and use it to sort TableGen register records.
[oota-llvm.git] / utils / TableGen / CodeGenTarget.cpp
1 //===- CodeGenTarget.cpp - CodeGen Target Class Wrapper -------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This class wraps target description classes used by the various code
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
17 #include "CodeGenTarget.h"
18 #include "CodeGenIntrinsics.h"
19 #include "Record.h"
20 #include "llvm/ADT/StringExtras.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/Support/CommandLine.h"
23 #include <algorithm>
24 using namespace llvm;
25
26 static cl::opt<unsigned>
27 AsmParserNum("asmparsernum", cl::init(0),
28              cl::desc("Make -gen-asm-parser emit assembly parser #N"));
29
30 static cl::opt<unsigned>
31 AsmWriterNum("asmwriternum", cl::init(0),
32              cl::desc("Make -gen-asm-writer emit assembly writer #N"));
33
34 /// getValueType - Return the MVT::SimpleValueType that the specified TableGen
35 /// record corresponds to.
36 MVT::SimpleValueType llvm::getValueType(Record *Rec) {
37   return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
38 }
39
40 std::string llvm::getName(MVT::SimpleValueType T) {
41   switch (T) {
42   case MVT::Other:   return "UNKNOWN";
43   case MVT::iPTR:    return "TLI.getPointerTy()";
44   case MVT::iPTRAny: return "TLI.getPointerTy()";
45   default: return getEnumName(T);
46   }
47 }
48
49 std::string llvm::getEnumName(MVT::SimpleValueType T) {
50   switch (T) {
51   case MVT::Other: return "MVT::Other";
52   case MVT::i1:    return "MVT::i1";
53   case MVT::i8:    return "MVT::i8";
54   case MVT::i16:   return "MVT::i16";
55   case MVT::i32:   return "MVT::i32";
56   case MVT::i64:   return "MVT::i64";
57   case MVT::i128:  return "MVT::i128";
58   case MVT::iAny:  return "MVT::iAny";
59   case MVT::fAny:  return "MVT::fAny";
60   case MVT::vAny:  return "MVT::vAny";
61   case MVT::f32:   return "MVT::f32";
62   case MVT::f64:   return "MVT::f64";
63   case MVT::f80:   return "MVT::f80";
64   case MVT::f128:  return "MVT::f128";
65   case MVT::ppcf128:  return "MVT::ppcf128";
66   case MVT::Flag:  return "MVT::Flag";
67   case MVT::isVoid:return "MVT::isVoid";
68   case MVT::v2i8:  return "MVT::v2i8";
69   case MVT::v4i8:  return "MVT::v4i8";
70   case MVT::v8i8:  return "MVT::v8i8";
71   case MVT::v16i8: return "MVT::v16i8";
72   case MVT::v32i8: return "MVT::v32i8";
73   case MVT::v2i16: return "MVT::v2i16";
74   case MVT::v4i16: return "MVT::v4i16";
75   case MVT::v8i16: return "MVT::v8i16";
76   case MVT::v16i16: return "MVT::v16i16";
77   case MVT::v2i32: return "MVT::v2i32";
78   case MVT::v4i32: return "MVT::v4i32";
79   case MVT::v8i32: return "MVT::v8i32";
80   case MVT::v1i64: return "MVT::v1i64";
81   case MVT::v2i64: return "MVT::v2i64";
82   case MVT::v4i64: return "MVT::v4i64";
83   case MVT::v8i64: return "MVT::v8i64";
84   case MVT::v2f32: return "MVT::v2f32";
85   case MVT::v4f32: return "MVT::v4f32";
86   case MVT::v8f32: return "MVT::v8f32";
87   case MVT::v2f64: return "MVT::v2f64";
88   case MVT::v4f64: return "MVT::v4f64";
89   case MVT::Metadata: return "MVT::Metadata";
90   case MVT::iPTR:  return "MVT::iPTR";
91   case MVT::iPTRAny:  return "MVT::iPTRAny";
92   default: assert(0 && "ILLEGAL VALUE TYPE!"); return "";
93   }
94 }
95
96 /// getQualifiedName - Return the name of the specified record, with a
97 /// namespace qualifier if the record contains one.
98 ///
99 std::string llvm::getQualifiedName(const Record *R) {
100   std::string Namespace = R->getValueAsString("Namespace");
101   if (Namespace.empty()) return R->getName();
102   return Namespace + "::" + R->getName();
103 }
104
105
106
107
108 /// getTarget - Return the current instance of the Target class.
109 ///
110 CodeGenTarget::CodeGenTarget() {
111   std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
112   if (Targets.size() == 0)
113     throw std::string("ERROR: No 'Target' subclasses defined!");
114   if (Targets.size() != 1)
115     throw std::string("ERROR: Multiple subclasses of Target defined!");
116   TargetRec = Targets[0];
117 }
118
119
120 const std::string &CodeGenTarget::getName() const {
121   return TargetRec->getName();
122 }
123
124 std::string CodeGenTarget::getInstNamespace() const {
125   for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) {
126     // Make sure not to pick up "TargetOpcode" by accidentally getting
127     // the namespace off the PHI instruction or something.
128     if ((*i)->Namespace != "TargetOpcode")
129       return (*i)->Namespace;
130   }
131
132   return "";
133 }
134
135 Record *CodeGenTarget::getInstructionSet() const {
136   return TargetRec->getValueAsDef("InstructionSet");
137 }
138
139
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
149 /// getAsmWriter - Return the AssemblyWriter definition for this target.
150 ///
151 Record *CodeGenTarget::getAsmWriter() const {
152   std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
153   if (AsmWriterNum >= LI.size())
154     throw "Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!";
155   return LI[AsmWriterNum];
156 }
157
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   std::sort(Regs.begin(), Regs.end(), LessRecord());
163
164   Registers.reserve(Regs.size());
165   Registers.assign(Regs.begin(), Regs.end());
166 }
167
168 CodeGenRegister::CodeGenRegister(Record *R) : TheDef(R) {
169   DeclaredSpillSize = R->getValueAsInt("SpillSize");
170   DeclaredSpillAlignment = R->getValueAsInt("SpillAlignment");
171 }
172
173 const std::string &CodeGenRegister::getName() const {
174   return TheDef->getName();
175 }
176
177 void CodeGenTarget::ReadSubRegIndices() const {
178   SubRegIndices = Records.getAllDerivedDefinitions("SubRegIndex");
179   std::sort(SubRegIndices.begin(), SubRegIndices.end(), LessRecord());
180 }
181
182 void CodeGenTarget::ReadRegisterClasses() const {
183   std::vector<Record*> RegClasses =
184     Records.getAllDerivedDefinitions("RegisterClass");
185   if (RegClasses.empty())
186     throw std::string("No 'RegisterClass' subclasses defined!");
187
188   RegisterClasses.reserve(RegClasses.size());
189   RegisterClasses.assign(RegClasses.begin(), RegClasses.end());
190 }
191
192 std::vector<MVT::SimpleValueType> CodeGenTarget::
193 getRegisterVTs(Record *R) const {
194   std::vector<MVT::SimpleValueType> Result;
195   const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
196   for (unsigned i = 0, e = RCs.size(); i != e; ++i) {
197     const CodeGenRegisterClass &RC = RegisterClasses[i];
198     for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) {
199       if (R == RC.Elements[ei]) {
200         const std::vector<MVT::SimpleValueType> &InVTs = RC.getValueTypes();
201         Result.insert(Result.end(), InVTs.begin(), InVTs.end());
202       }
203     }
204   }
205   
206   // Remove duplicates.
207   array_pod_sort(Result.begin(), Result.end());
208   Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
209   return Result;
210 }
211
212
213 CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) {
214   // Rename anonymous register classes.
215   if (R->getName().size() > 9 && R->getName()[9] == '.') {
216     static unsigned AnonCounter = 0;
217     R->setName("AnonRegClass_"+utostr(AnonCounter++));
218   } 
219   
220   std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes");
221   for (unsigned i = 0, e = TypeList.size(); i != e; ++i) {
222     Record *Type = TypeList[i];
223     if (!Type->isSubClassOf("ValueType"))
224       throw "RegTypes list member '" + Type->getName() +
225         "' does not derive from the ValueType class!";
226     VTs.push_back(getValueType(Type));
227   }
228   assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!");
229   
230   std::vector<Record*> RegList = R->getValueAsListOfDefs("MemberList");
231   for (unsigned i = 0, e = RegList.size(); i != e; ++i) {
232     Record *Reg = RegList[i];
233     if (!Reg->isSubClassOf("Register"))
234       throw "Register Class member '" + Reg->getName() +
235             "' does not derive from the Register class!";
236     Elements.push_back(Reg);
237   }
238
239   // SubRegClasses is a list<dag> containing (RC, subregindex, ...) dags.
240   ListInit *SRC = R->getValueAsListInit("SubRegClasses");
241   for (ListInit::const_iterator i = SRC->begin(), e = SRC->end(); i != e; ++i) {
242     DagInit *DAG = dynamic_cast<DagInit*>(*i);
243     if (!DAG) throw "SubRegClasses must contain DAGs";
244     DefInit *DAGOp = dynamic_cast<DefInit*>(DAG->getOperator());
245     Record *RCRec;
246     if (!DAGOp || !(RCRec = DAGOp->getDef())->isSubClassOf("RegisterClass"))
247       throw "Operator '" + DAG->getOperator()->getAsString() +
248         "' in SubRegClasses is not a RegisterClass";
249     // Iterate over args, all SubRegIndex instances.
250     for (DagInit::const_arg_iterator ai = DAG->arg_begin(), ae = DAG->arg_end();
251          ai != ae; ++ai) {
252       DefInit *Idx = dynamic_cast<DefInit*>(*ai);
253       Record *IdxRec;
254       if (!Idx || !(IdxRec = Idx->getDef())->isSubClassOf("SubRegIndex"))
255         throw "Argument '" + (*ai)->getAsString() +
256           "' in SubRegClasses is not a SubRegIndex";
257       if (!SubRegClasses.insert(std::make_pair(IdxRec, RCRec)).second)
258         throw "SubRegIndex '" + IdxRec->getName() + "' mentioned twice";
259     }
260   }
261
262   // Allow targets to override the size in bits of the RegisterClass.
263   unsigned Size = R->getValueAsInt("Size");
264
265   Namespace = R->getValueAsString("Namespace");
266   SpillSize = Size ? Size : EVT(VTs[0]).getSizeInBits();
267   SpillAlignment = R->getValueAsInt("Alignment");
268   CopyCost = R->getValueAsInt("CopyCost");
269   MethodBodies = R->getValueAsCode("MethodBodies");
270   MethodProtos = R->getValueAsCode("MethodProtos");
271 }
272
273 const std::string &CodeGenRegisterClass::getName() const {
274   return TheDef->getName();
275 }
276
277 void CodeGenTarget::ReadLegalValueTypes() const {
278   const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
279   for (unsigned i = 0, e = RCs.size(); i != e; ++i)
280     for (unsigned ri = 0, re = RCs[i].VTs.size(); ri != re; ++ri)
281       LegalValueTypes.push_back(RCs[i].VTs[ri]);
282   
283   // Remove duplicates.
284   std::sort(LegalValueTypes.begin(), LegalValueTypes.end());
285   LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
286                                     LegalValueTypes.end()),
287                         LegalValueTypes.end());
288 }
289
290
291 void CodeGenTarget::ReadInstructions() const {
292   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
293   if (Insts.size() <= 2)
294     throw std::string("No 'Instruction' subclasses defined!");
295
296   // Parse the instructions defined in the .td file.
297   std::string InstFormatName =
298     getAsmWriter()->getValueAsString("InstFormatName");
299
300   for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
301     std::string AsmStr = Insts[i]->getValueAsString(InstFormatName);
302     Instructions[Insts[i]] = new CodeGenInstruction(Insts[i], AsmStr);
303   }
304 }
305
306 static const CodeGenInstruction *
307 GetInstByName(const char *Name,
308               const DenseMap<const Record*, CodeGenInstruction*> &Insts) {
309   const Record *Rec = Records.getDef(Name);
310   
311   DenseMap<const Record*, CodeGenInstruction*>::const_iterator
312     I = Insts.find(Rec);
313   if (Rec == 0 || I == Insts.end())
314     throw std::string("Could not find '") + Name + "' instruction!";
315   return I->second;
316 }
317
318 namespace {
319 /// SortInstByName - Sorting predicate to sort instructions by name.
320 ///
321 struct SortInstByName {
322   bool operator()(const CodeGenInstruction *Rec1,
323                   const CodeGenInstruction *Rec2) const {
324     return Rec1->TheDef->getName() < Rec2->TheDef->getName();
325   }
326 };
327 }
328
329 /// getInstructionsByEnumValue - Return all of the instructions defined by the
330 /// target, ordered by their enum value.
331 void CodeGenTarget::ComputeInstrsByEnum() const {
332   const DenseMap<const Record*, CodeGenInstruction*> &Insts = getInstructions();
333   const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
334   const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
335   const CodeGenInstruction *DBG_LABEL = GetInstByName("DBG_LABEL", Insts);
336   const CodeGenInstruction *EH_LABEL = GetInstByName("EH_LABEL", Insts);
337   const CodeGenInstruction *GC_LABEL = GetInstByName("GC_LABEL", Insts);
338   const CodeGenInstruction *KILL = GetInstByName("KILL", Insts);
339   const CodeGenInstruction *EXTRACT_SUBREG =
340     GetInstByName("EXTRACT_SUBREG", Insts);
341   const CodeGenInstruction *INSERT_SUBREG =
342     GetInstByName("INSERT_SUBREG", Insts);
343   const CodeGenInstruction *IMPLICIT_DEF = GetInstByName("IMPLICIT_DEF", Insts);
344   const CodeGenInstruction *SUBREG_TO_REG =
345     GetInstByName("SUBREG_TO_REG", Insts);
346   const CodeGenInstruction *COPY_TO_REGCLASS =
347     GetInstByName("COPY_TO_REGCLASS", Insts);
348   const CodeGenInstruction *DBG_VALUE = GetInstByName("DBG_VALUE", Insts);
349   const CodeGenInstruction *REG_SEQUENCE = GetInstByName("REG_SEQUENCE", Insts);
350
351   // Print out the rest of the instructions now.
352   InstrsByEnum.push_back(PHI);
353   InstrsByEnum.push_back(INLINEASM);
354   InstrsByEnum.push_back(DBG_LABEL);
355   InstrsByEnum.push_back(EH_LABEL);
356   InstrsByEnum.push_back(GC_LABEL);
357   InstrsByEnum.push_back(KILL);
358   InstrsByEnum.push_back(EXTRACT_SUBREG);
359   InstrsByEnum.push_back(INSERT_SUBREG);
360   InstrsByEnum.push_back(IMPLICIT_DEF);
361   InstrsByEnum.push_back(SUBREG_TO_REG);
362   InstrsByEnum.push_back(COPY_TO_REGCLASS);
363   InstrsByEnum.push_back(DBG_VALUE);
364   InstrsByEnum.push_back(REG_SEQUENCE);
365   
366   unsigned EndOfPredefines = InstrsByEnum.size();
367   
368   for (DenseMap<const Record*, CodeGenInstruction*>::const_iterator
369        I = Insts.begin(), E = Insts.end(); I != E; ++I) {
370     const CodeGenInstruction *CGI = I->second;
371     if (CGI != PHI &&
372         CGI != INLINEASM &&
373         CGI != DBG_LABEL &&
374         CGI != EH_LABEL &&
375         CGI != GC_LABEL &&
376         CGI != KILL &&
377         CGI != EXTRACT_SUBREG &&
378         CGI != INSERT_SUBREG &&
379         CGI != IMPLICIT_DEF &&
380         CGI != SUBREG_TO_REG &&
381         CGI != COPY_TO_REGCLASS &&
382         CGI != DBG_VALUE &&
383         CGI != REG_SEQUENCE)
384       InstrsByEnum.push_back(CGI);
385   }
386   
387   // All of the instructions are now in random order based on the map iteration.
388   // Sort them by name.
389   std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
390             SortInstByName());
391 }
392
393
394 /// isLittleEndianEncoding - Return whether this target encodes its instruction
395 /// in little-endian format, i.e. bits laid out in the order [0..n]
396 ///
397 bool CodeGenTarget::isLittleEndianEncoding() const {
398   return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
399 }
400
401 //===----------------------------------------------------------------------===//
402 // ComplexPattern implementation
403 //
404 ComplexPattern::ComplexPattern(Record *R) {
405   Ty          = ::getValueType(R->getValueAsDef("Ty"));
406   NumOperands = R->getValueAsInt("NumOperands");
407   SelectFunc  = R->getValueAsString("SelectFunc");
408   RootNodes   = R->getValueAsListOfDefs("RootNodes");
409
410   // Parse the properties.
411   Properties = 0;
412   std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties");
413   for (unsigned i = 0, e = PropList.size(); i != e; ++i)
414     if (PropList[i]->getName() == "SDNPHasChain") {
415       Properties |= 1 << SDNPHasChain;
416     } else if (PropList[i]->getName() == "SDNPOptInFlag") {
417       Properties |= 1 << SDNPOptInFlag;
418     } else if (PropList[i]->getName() == "SDNPMayStore") {
419       Properties |= 1 << SDNPMayStore;
420     } else if (PropList[i]->getName() == "SDNPMayLoad") {
421       Properties |= 1 << SDNPMayLoad;
422     } else if (PropList[i]->getName() == "SDNPSideEffect") {
423       Properties |= 1 << SDNPSideEffect;
424     } else if (PropList[i]->getName() == "SDNPMemOperand") {
425       Properties |= 1 << SDNPMemOperand;
426     } else if (PropList[i]->getName() == "SDNPVariadic") {
427       Properties |= 1 << SDNPVariadic;
428     } else {
429       errs() << "Unsupported SD Node property '" << PropList[i]->getName()
430              << "' on ComplexPattern '" << R->getName() << "'!\n";
431       exit(1);
432     }
433 }
434
435 //===----------------------------------------------------------------------===//
436 // CodeGenIntrinsic Implementation
437 //===----------------------------------------------------------------------===//
438
439 std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
440                                                    bool TargetOnly) {
441   std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
442   
443   std::vector<CodeGenIntrinsic> Result;
444
445   for (unsigned i = 0, e = I.size(); i != e; ++i) {
446     bool isTarget = I[i]->getValueAsBit("isTarget");
447     if (isTarget == TargetOnly)
448       Result.push_back(CodeGenIntrinsic(I[i]));
449   }
450   return Result;
451 }
452
453 CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
454   TheDef = R;
455   std::string DefName = R->getName();
456   ModRef = WriteMem;
457   isOverloaded = false;
458   isCommutative = false;
459   
460   if (DefName.size() <= 4 || 
461       std::string(DefName.begin(), DefName.begin() + 4) != "int_")
462     throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
463
464   EnumName = std::string(DefName.begin()+4, DefName.end());
465
466   if (R->getValue("GCCBuiltinName"))  // Ignore a missing GCCBuiltinName field.
467     GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
468
469   TargetPrefix = R->getValueAsString("TargetPrefix");
470   Name = R->getValueAsString("LLVMName");
471
472   if (Name == "") {
473     // If an explicit name isn't specified, derive one from the DefName.
474     Name = "llvm.";
475
476     for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
477       Name += (EnumName[i] == '_') ? '.' : EnumName[i];
478   } else {
479     // Verify it starts with "llvm.".
480     if (Name.size() <= 5 || 
481         std::string(Name.begin(), Name.begin() + 5) != "llvm.")
482       throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!";
483   }
484   
485   // If TargetPrefix is specified, make sure that Name starts with
486   // "llvm.<targetprefix>.".
487   if (!TargetPrefix.empty()) {
488     if (Name.size() < 6+TargetPrefix.size() ||
489         std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
490         != (TargetPrefix + "."))
491       throw "Intrinsic '" + DefName + "' does not start with 'llvm." +
492         TargetPrefix + ".'!";
493   }
494   
495   // Parse the list of return types.
496   std::vector<MVT::SimpleValueType> OverloadedVTs;
497   ListInit *TypeList = R->getValueAsListInit("RetTypes");
498   for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
499     Record *TyEl = TypeList->getElementAsRecord(i);
500     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
501     MVT::SimpleValueType VT;
502     if (TyEl->isSubClassOf("LLVMMatchType")) {
503       unsigned MatchTy = TyEl->getValueAsInt("Number");
504       assert(MatchTy < OverloadedVTs.size() &&
505              "Invalid matching number!");
506       VT = OverloadedVTs[MatchTy];
507       // It only makes sense to use the extended and truncated vector element
508       // variants with iAny types; otherwise, if the intrinsic is not
509       // overloaded, all the types can be specified directly.
510       assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
511                !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
512               VT == MVT::iAny || VT == MVT::vAny) &&
513              "Expected iAny or vAny type");
514     } else {
515       VT = getValueType(TyEl->getValueAsDef("VT"));
516     }
517     if (EVT(VT).isOverloaded()) {
518       OverloadedVTs.push_back(VT);
519       isOverloaded = true;
520     }
521
522     // Reject invalid types.
523     if (VT == MVT::isVoid)
524       throw "Intrinsic '" + DefName + " has void in result type list!";
525     
526     IS.RetVTs.push_back(VT);
527     IS.RetTypeDefs.push_back(TyEl);
528   }
529   
530   // Parse the list of parameter types.
531   TypeList = R->getValueAsListInit("ParamTypes");
532   for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
533     Record *TyEl = TypeList->getElementAsRecord(i);
534     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
535     MVT::SimpleValueType VT;
536     if (TyEl->isSubClassOf("LLVMMatchType")) {
537       unsigned MatchTy = TyEl->getValueAsInt("Number");
538       assert(MatchTy < OverloadedVTs.size() &&
539              "Invalid matching number!");
540       VT = OverloadedVTs[MatchTy];
541       // It only makes sense to use the extended and truncated vector element
542       // variants with iAny types; otherwise, if the intrinsic is not
543       // overloaded, all the types can be specified directly.
544       assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
545                !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
546               VT == MVT::iAny || VT == MVT::vAny) &&
547              "Expected iAny or vAny type");
548     } else
549       VT = getValueType(TyEl->getValueAsDef("VT"));
550     
551     if (EVT(VT).isOverloaded()) {
552       OverloadedVTs.push_back(VT);
553       isOverloaded = true;
554     }
555     
556     // Reject invalid types.
557     if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
558       throw "Intrinsic '" + DefName + " has void in result type list!";
559     
560     IS.ParamVTs.push_back(VT);
561     IS.ParamTypeDefs.push_back(TyEl);
562   }
563
564   // Parse the intrinsic properties.
565   ListInit *PropList = R->getValueAsListInit("Properties");
566   for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) {
567     Record *Property = PropList->getElementAsRecord(i);
568     assert(Property->isSubClassOf("IntrinsicProperty") &&
569            "Expected a property!");
570     
571     if (Property->getName() == "IntrNoMem")
572       ModRef = NoMem;
573     else if (Property->getName() == "IntrReadArgMem")
574       ModRef = ReadArgMem;
575     else if (Property->getName() == "IntrReadMem")
576       ModRef = ReadMem;
577     else if (Property->getName() == "IntrWriteArgMem")
578       ModRef = WriteArgMem;
579     else if (Property->getName() == "IntrWriteMem")
580       ModRef = WriteMem;
581     else if (Property->getName() == "Commutative")
582       isCommutative = true;
583     else if (Property->isSubClassOf("NoCapture")) {
584       unsigned ArgNo = Property->getValueAsInt("ArgNo");
585       ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
586     } else
587       assert(0 && "Unknown property!");
588   }
589 }