f13f969dd35f3a71f34aa9cc0f086c3d48242036
[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
163   Registers.reserve(Regs.size());
164   Registers.assign(Regs.begin(), Regs.end());
165 }
166
167 CodeGenRegister::CodeGenRegister(Record *R) : TheDef(R) {
168   DeclaredSpillSize = R->getValueAsInt("SpillSize");
169   DeclaredSpillAlignment = R->getValueAsInt("SpillAlignment");
170 }
171
172 const std::string &CodeGenRegister::getName() const {
173   return TheDef->getName();
174 }
175
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
186 std::vector<MVT::SimpleValueType> CodeGenTarget::
187 getRegisterVTs(Record *R) const {
188   std::vector<MVT::SimpleValueType> Result;
189   const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
190   for (unsigned i = 0, e = RCs.size(); i != e; ++i) {
191     const CodeGenRegisterClass &RC = RegisterClasses[i];
192     for (unsigned ei = 0, ee = RC.Elements.size(); ei != ee; ++ei) {
193       if (R == RC.Elements[ei]) {
194         const std::vector<MVT::SimpleValueType> &InVTs = RC.getValueTypes();
195         Result.insert(Result.end(), InVTs.begin(), InVTs.end());
196       }
197     }
198   }
199   
200   // Remove duplicates.
201   array_pod_sort(Result.begin(), Result.end());
202   Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
203   return Result;
204 }
205
206
207 CodeGenRegisterClass::CodeGenRegisterClass(Record *R) : TheDef(R) {
208   // Rename anonymous register classes.
209   if (R->getName().size() > 9 && R->getName()[9] == '.') {
210     static unsigned AnonCounter = 0;
211     R->setName("AnonRegClass_"+utostr(AnonCounter++));
212   } 
213   
214   std::vector<Record*> TypeList = R->getValueAsListOfDefs("RegTypes");
215   for (unsigned i = 0, e = TypeList.size(); i != e; ++i) {
216     Record *Type = TypeList[i];
217     if (!Type->isSubClassOf("ValueType"))
218       throw "RegTypes list member '" + Type->getName() +
219         "' does not derive from the ValueType class!";
220     VTs.push_back(getValueType(Type));
221   }
222   assert(!VTs.empty() && "RegisterClass must contain at least one ValueType!");
223   
224   std::vector<Record*> RegList = R->getValueAsListOfDefs("MemberList");
225   for (unsigned i = 0, e = RegList.size(); i != e; ++i) {
226     Record *Reg = RegList[i];
227     if (!Reg->isSubClassOf("Register"))
228       throw "Register Class member '" + Reg->getName() +
229             "' does not derive from the Register class!";
230     Elements.push_back(Reg);
231   }
232   
233   std::vector<Record*> SubRegClassList = 
234                         R->getValueAsListOfDefs("SubRegClassList");
235   for (unsigned i = 0, e = SubRegClassList.size(); i != e; ++i) {
236     Record *SubRegClass = SubRegClassList[i];
237     if (!SubRegClass->isSubClassOf("RegisterClass"))
238       throw "Register Class member '" + SubRegClass->getName() +
239             "' does not derive from the RegisterClass class!";
240     SubRegClasses.push_back(SubRegClass);
241   }  
242   
243   // Allow targets to override the size in bits of the RegisterClass.
244   unsigned Size = R->getValueAsInt("Size");
245
246   Namespace = R->getValueAsString("Namespace");
247   SpillSize = Size ? Size : EVT(VTs[0]).getSizeInBits();
248   SpillAlignment = R->getValueAsInt("Alignment");
249   CopyCost = R->getValueAsInt("CopyCost");
250   MethodBodies = R->getValueAsCode("MethodBodies");
251   MethodProtos = R->getValueAsCode("MethodProtos");
252 }
253
254 const std::string &CodeGenRegisterClass::getName() const {
255   return TheDef->getName();
256 }
257
258 void CodeGenTarget::ReadLegalValueTypes() const {
259   const std::vector<CodeGenRegisterClass> &RCs = getRegisterClasses();
260   for (unsigned i = 0, e = RCs.size(); i != e; ++i)
261     for (unsigned ri = 0, re = RCs[i].VTs.size(); ri != re; ++ri)
262       LegalValueTypes.push_back(RCs[i].VTs[ri]);
263   
264   // Remove duplicates.
265   std::sort(LegalValueTypes.begin(), LegalValueTypes.end());
266   LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
267                                     LegalValueTypes.end()),
268                         LegalValueTypes.end());
269 }
270
271
272 void CodeGenTarget::ReadInstructions() const {
273   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
274   if (Insts.size() <= 2)
275     throw std::string("No 'Instruction' subclasses defined!");
276
277   // Parse the instructions defined in the .td file.
278   std::string InstFormatName =
279     getAsmWriter()->getValueAsString("InstFormatName");
280
281   for (unsigned i = 0, e = Insts.size(); i != e; ++i) {
282     std::string AsmStr = Insts[i]->getValueAsString(InstFormatName);
283     Instructions[Insts[i]] = new CodeGenInstruction(Insts[i], AsmStr);
284   }
285 }
286
287 static const CodeGenInstruction *
288 GetInstByName(const char *Name,
289               const DenseMap<const Record*, CodeGenInstruction*> &Insts) {
290   const Record *Rec = Records.getDef(Name);
291   
292   DenseMap<const Record*, CodeGenInstruction*>::const_iterator
293     I = Insts.find(Rec);
294   if (Rec == 0 || I == Insts.end())
295     throw std::string("Could not find '") + Name + "' instruction!";
296   return I->second;
297 }
298
299 namespace {
300 /// SortInstByName - Sorting predicate to sort instructions by name.
301 ///
302 struct SortInstByName {
303   bool operator()(const CodeGenInstruction *Rec1,
304                   const CodeGenInstruction *Rec2) const {
305     return Rec1->TheDef->getName() < Rec2->TheDef->getName();
306   }
307 };
308 }
309
310 /// getInstructionsByEnumValue - Return all of the instructions defined by the
311 /// target, ordered by their enum value.
312 void CodeGenTarget::ComputeInstrsByEnum() const {
313   const DenseMap<const Record*, CodeGenInstruction*> &Insts = getInstructions();
314   const CodeGenInstruction *PHI = GetInstByName("PHI", Insts);
315   const CodeGenInstruction *INLINEASM = GetInstByName("INLINEASM", Insts);
316   const CodeGenInstruction *DBG_LABEL = GetInstByName("DBG_LABEL", Insts);
317   const CodeGenInstruction *EH_LABEL = GetInstByName("EH_LABEL", Insts);
318   const CodeGenInstruction *GC_LABEL = GetInstByName("GC_LABEL", Insts);
319   const CodeGenInstruction *KILL = GetInstByName("KILL", Insts);
320   const CodeGenInstruction *EXTRACT_SUBREG =
321     GetInstByName("EXTRACT_SUBREG", Insts);
322   const CodeGenInstruction *INSERT_SUBREG =
323     GetInstByName("INSERT_SUBREG", Insts);
324   const CodeGenInstruction *IMPLICIT_DEF = GetInstByName("IMPLICIT_DEF", Insts);
325   const CodeGenInstruction *SUBREG_TO_REG =
326     GetInstByName("SUBREG_TO_REG", Insts);
327   const CodeGenInstruction *COPY_TO_REGCLASS =
328     GetInstByName("COPY_TO_REGCLASS", Insts);
329   const CodeGenInstruction *DBG_VALUE = GetInstByName("DBG_VALUE", Insts);
330   const CodeGenInstruction *REG_SEQUENCE = GetInstByName("REG_SEQUENCE", Insts);
331
332   // Print out the rest of the instructions now.
333   InstrsByEnum.push_back(PHI);
334   InstrsByEnum.push_back(INLINEASM);
335   InstrsByEnum.push_back(DBG_LABEL);
336   InstrsByEnum.push_back(EH_LABEL);
337   InstrsByEnum.push_back(GC_LABEL);
338   InstrsByEnum.push_back(KILL);
339   InstrsByEnum.push_back(EXTRACT_SUBREG);
340   InstrsByEnum.push_back(INSERT_SUBREG);
341   InstrsByEnum.push_back(IMPLICIT_DEF);
342   InstrsByEnum.push_back(SUBREG_TO_REG);
343   InstrsByEnum.push_back(COPY_TO_REGCLASS);
344   InstrsByEnum.push_back(DBG_VALUE);
345   InstrsByEnum.push_back(REG_SEQUENCE);
346   
347   unsigned EndOfPredefines = InstrsByEnum.size();
348   
349   for (DenseMap<const Record*, CodeGenInstruction*>::const_iterator
350        I = Insts.begin(), E = Insts.end(); I != E; ++I) {
351     const CodeGenInstruction *CGI = I->second;
352     if (CGI != PHI &&
353         CGI != INLINEASM &&
354         CGI != DBG_LABEL &&
355         CGI != EH_LABEL &&
356         CGI != GC_LABEL &&
357         CGI != KILL &&
358         CGI != EXTRACT_SUBREG &&
359         CGI != INSERT_SUBREG &&
360         CGI != IMPLICIT_DEF &&
361         CGI != SUBREG_TO_REG &&
362         CGI != COPY_TO_REGCLASS &&
363         CGI != DBG_VALUE &&
364         CGI != REG_SEQUENCE)
365       InstrsByEnum.push_back(CGI);
366   }
367   
368   // All of the instructions are now in random order based on the map iteration.
369   // Sort them by name.
370   std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
371             SortInstByName());
372 }
373
374
375 /// isLittleEndianEncoding - Return whether this target encodes its instruction
376 /// in little-endian format, i.e. bits laid out in the order [0..n]
377 ///
378 bool CodeGenTarget::isLittleEndianEncoding() const {
379   return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
380 }
381
382 //===----------------------------------------------------------------------===//
383 // ComplexPattern implementation
384 //
385 ComplexPattern::ComplexPattern(Record *R) {
386   Ty          = ::getValueType(R->getValueAsDef("Ty"));
387   NumOperands = R->getValueAsInt("NumOperands");
388   SelectFunc  = R->getValueAsString("SelectFunc");
389   RootNodes   = R->getValueAsListOfDefs("RootNodes");
390
391   // Parse the properties.
392   Properties = 0;
393   std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties");
394   for (unsigned i = 0, e = PropList.size(); i != e; ++i)
395     if (PropList[i]->getName() == "SDNPHasChain") {
396       Properties |= 1 << SDNPHasChain;
397     } else if (PropList[i]->getName() == "SDNPOptInFlag") {
398       Properties |= 1 << SDNPOptInFlag;
399     } else if (PropList[i]->getName() == "SDNPMayStore") {
400       Properties |= 1 << SDNPMayStore;
401     } else if (PropList[i]->getName() == "SDNPMayLoad") {
402       Properties |= 1 << SDNPMayLoad;
403     } else if (PropList[i]->getName() == "SDNPSideEffect") {
404       Properties |= 1 << SDNPSideEffect;
405     } else if (PropList[i]->getName() == "SDNPMemOperand") {
406       Properties |= 1 << SDNPMemOperand;
407     } else if (PropList[i]->getName() == "SDNPVariadic") {
408       Properties |= 1 << SDNPVariadic;
409     } else {
410       errs() << "Unsupported SD Node property '" << PropList[i]->getName()
411              << "' on ComplexPattern '" << R->getName() << "'!\n";
412       exit(1);
413     }
414 }
415
416 //===----------------------------------------------------------------------===//
417 // CodeGenIntrinsic Implementation
418 //===----------------------------------------------------------------------===//
419
420 std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
421                                                    bool TargetOnly) {
422   std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
423   
424   std::vector<CodeGenIntrinsic> Result;
425
426   for (unsigned i = 0, e = I.size(); i != e; ++i) {
427     bool isTarget = I[i]->getValueAsBit("isTarget");
428     if (isTarget == TargetOnly)
429       Result.push_back(CodeGenIntrinsic(I[i]));
430   }
431   return Result;
432 }
433
434 CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
435   TheDef = R;
436   std::string DefName = R->getName();
437   ModRef = WriteMem;
438   isOverloaded = false;
439   isCommutative = false;
440   
441   if (DefName.size() <= 4 || 
442       std::string(DefName.begin(), DefName.begin() + 4) != "int_")
443     throw "Intrinsic '" + DefName + "' does not start with 'int_'!";
444
445   EnumName = std::string(DefName.begin()+4, DefName.end());
446
447   if (R->getValue("GCCBuiltinName"))  // Ignore a missing GCCBuiltinName field.
448     GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
449
450   TargetPrefix = R->getValueAsString("TargetPrefix");
451   Name = R->getValueAsString("LLVMName");
452
453   if (Name == "") {
454     // If an explicit name isn't specified, derive one from the DefName.
455     Name = "llvm.";
456
457     for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
458       Name += (EnumName[i] == '_') ? '.' : EnumName[i];
459   } else {
460     // Verify it starts with "llvm.".
461     if (Name.size() <= 5 || 
462         std::string(Name.begin(), Name.begin() + 5) != "llvm.")
463       throw "Intrinsic '" + DefName + "'s name does not start with 'llvm.'!";
464   }
465   
466   // If TargetPrefix is specified, make sure that Name starts with
467   // "llvm.<targetprefix>.".
468   if (!TargetPrefix.empty()) {
469     if (Name.size() < 6+TargetPrefix.size() ||
470         std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
471         != (TargetPrefix + "."))
472       throw "Intrinsic '" + DefName + "' does not start with 'llvm." +
473         TargetPrefix + ".'!";
474   }
475   
476   // Parse the list of return types.
477   std::vector<MVT::SimpleValueType> OverloadedVTs;
478   ListInit *TypeList = R->getValueAsListInit("RetTypes");
479   for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
480     Record *TyEl = TypeList->getElementAsRecord(i);
481     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
482     MVT::SimpleValueType VT;
483     if (TyEl->isSubClassOf("LLVMMatchType")) {
484       unsigned MatchTy = TyEl->getValueAsInt("Number");
485       assert(MatchTy < OverloadedVTs.size() &&
486              "Invalid matching number!");
487       VT = OverloadedVTs[MatchTy];
488       // It only makes sense to use the extended and truncated vector element
489       // variants with iAny types; otherwise, if the intrinsic is not
490       // overloaded, all the types can be specified directly.
491       assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
492                !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
493               VT == MVT::iAny || VT == MVT::vAny) &&
494              "Expected iAny or vAny type");
495     } else {
496       VT = getValueType(TyEl->getValueAsDef("VT"));
497     }
498     if (EVT(VT).isOverloaded()) {
499       OverloadedVTs.push_back(VT);
500       isOverloaded = true;
501     }
502
503     // Reject invalid types.
504     if (VT == MVT::isVoid)
505       throw "Intrinsic '" + DefName + " has void in result type list!";
506     
507     IS.RetVTs.push_back(VT);
508     IS.RetTypeDefs.push_back(TyEl);
509   }
510   
511   // Parse the list of parameter types.
512   TypeList = R->getValueAsListInit("ParamTypes");
513   for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
514     Record *TyEl = TypeList->getElementAsRecord(i);
515     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
516     MVT::SimpleValueType VT;
517     if (TyEl->isSubClassOf("LLVMMatchType")) {
518       unsigned MatchTy = TyEl->getValueAsInt("Number");
519       assert(MatchTy < OverloadedVTs.size() &&
520              "Invalid matching number!");
521       VT = OverloadedVTs[MatchTy];
522       // It only makes sense to use the extended and truncated vector element
523       // variants with iAny types; otherwise, if the intrinsic is not
524       // overloaded, all the types can be specified directly.
525       assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
526                !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
527               VT == MVT::iAny || VT == MVT::vAny) &&
528              "Expected iAny or vAny type");
529     } else
530       VT = getValueType(TyEl->getValueAsDef("VT"));
531     
532     if (EVT(VT).isOverloaded()) {
533       OverloadedVTs.push_back(VT);
534       isOverloaded = true;
535     }
536     
537     // Reject invalid types.
538     if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
539       throw "Intrinsic '" + DefName + " has void in result type list!";
540     
541     IS.ParamVTs.push_back(VT);
542     IS.ParamTypeDefs.push_back(TyEl);
543   }
544
545   // Parse the intrinsic properties.
546   ListInit *PropList = R->getValueAsListInit("Properties");
547   for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) {
548     Record *Property = PropList->getElementAsRecord(i);
549     assert(Property->isSubClassOf("IntrinsicProperty") &&
550            "Expected a property!");
551     
552     if (Property->getName() == "IntrNoMem")
553       ModRef = NoMem;
554     else if (Property->getName() == "IntrReadArgMem")
555       ModRef = ReadArgMem;
556     else if (Property->getName() == "IntrReadMem")
557       ModRef = ReadMem;
558     else if (Property->getName() == "IntrWriteArgMem")
559       ModRef = WriteArgMem;
560     else if (Property->getName() == "IntrWriteMem")
561       ModRef = WriteMem;
562     else if (Property->getName() == "Commutative")
563       isCommutative = true;
564     else if (Property->isSubClassOf("NoCapture")) {
565       unsigned ArgNo = Property->getValueAsInt("ArgNo");
566       ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
567     } else
568       assert(0 && "Unknown property!");
569   }
570 }