Fix memory leaks by avoiding extra manual dynamic allocation
[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 abort on error conditions.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #include "CodeGenTarget.h"
18 #include "CodeGenIntrinsics.h"
19 #include "CodeGenSchedule.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/ADT/StringExtras.h"
22 #include "llvm/Support/CommandLine.h"
23 #include "llvm/TableGen/Error.h"
24 #include "llvm/TableGen/Record.h"
25 #include <algorithm>
26 using namespace llvm;
27
28 static cl::opt<unsigned>
29 AsmParserNum("asmparsernum", cl::init(0),
30              cl::desc("Make -gen-asm-parser emit assembly parser #N"));
31
32 static cl::opt<unsigned>
33 AsmWriterNum("asmwriternum", cl::init(0),
34              cl::desc("Make -gen-asm-writer emit assembly writer #N"));
35
36 /// getValueType - Return the MVT::SimpleValueType that the specified TableGen
37 /// record corresponds to.
38 MVT::SimpleValueType llvm::getValueType(Record *Rec) {
39   return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
40 }
41
42 std::string llvm::getName(MVT::SimpleValueType T) {
43   switch (T) {
44   case MVT::Other:   return "UNKNOWN";
45   case MVT::iPTR:    return "TLI.getPointerTy()";
46   case MVT::iPTRAny: return "TLI.getPointerTy()";
47   default: return getEnumName(T);
48   }
49 }
50
51 std::string llvm::getEnumName(MVT::SimpleValueType T) {
52   switch (T) {
53   case MVT::Other:    return "MVT::Other";
54   case MVT::i1:       return "MVT::i1";
55   case MVT::i8:       return "MVT::i8";
56   case MVT::i16:      return "MVT::i16";
57   case MVT::i32:      return "MVT::i32";
58   case MVT::i64:      return "MVT::i64";
59   case MVT::i128:     return "MVT::i128";
60   case MVT::Any:      return "MVT::Any";
61   case MVT::iAny:     return "MVT::iAny";
62   case MVT::fAny:     return "MVT::fAny";
63   case MVT::vAny:     return "MVT::vAny";
64   case MVT::f16:      return "MVT::f16";
65   case MVT::f32:      return "MVT::f32";
66   case MVT::f64:      return "MVT::f64";
67   case MVT::f80:      return "MVT::f80";
68   case MVT::f128:     return "MVT::f128";
69   case MVT::ppcf128:  return "MVT::ppcf128";
70   case MVT::x86mmx:   return "MVT::x86mmx";
71   case MVT::Glue:     return "MVT::Glue";
72   case MVT::isVoid:   return "MVT::isVoid";
73   case MVT::v2i1:     return "MVT::v2i1";
74   case MVT::v4i1:     return "MVT::v4i1";
75   case MVT::v8i1:     return "MVT::v8i1";
76   case MVT::v16i1:    return "MVT::v16i1";
77   case MVT::v32i1:    return "MVT::v32i1";
78   case MVT::v64i1:    return "MVT::v64i1";
79   case MVT::v1i8:     return "MVT::v1i8";
80   case MVT::v2i8:     return "MVT::v2i8";
81   case MVT::v4i8:     return "MVT::v4i8";
82   case MVT::v8i8:     return "MVT::v8i8";
83   case MVT::v16i8:    return "MVT::v16i8";
84   case MVT::v32i8:    return "MVT::v32i8";
85   case MVT::v64i8:    return "MVT::v64i8";
86   case MVT::v1i16:    return "MVT::v1i16";
87   case MVT::v2i16:    return "MVT::v2i16";
88   case MVT::v4i16:    return "MVT::v4i16";
89   case MVT::v8i16:    return "MVT::v8i16";
90   case MVT::v16i16:   return "MVT::v16i16";
91   case MVT::v32i16:   return "MVT::v32i16";
92   case MVT::v1i32:    return "MVT::v1i32";
93   case MVT::v2i32:    return "MVT::v2i32";
94   case MVT::v4i32:    return "MVT::v4i32";
95   case MVT::v8i32:    return "MVT::v8i32";
96   case MVT::v16i32:   return "MVT::v16i32";
97   case MVT::v1i64:    return "MVT::v1i64";
98   case MVT::v2i64:    return "MVT::v2i64";
99   case MVT::v4i64:    return "MVT::v4i64";
100   case MVT::v8i64:    return "MVT::v8i64";
101   case MVT::v16i64:   return "MVT::v16i64";
102   case MVT::v1i128:   return "MVT::v1i128";
103   case MVT::v2f16:    return "MVT::v2f16";
104   case MVT::v4f16:    return "MVT::v4f16";
105   case MVT::v8f16:    return "MVT::v8f16";
106   case MVT::v1f32:    return "MVT::v1f32";
107   case MVT::v2f32:    return "MVT::v2f32";
108   case MVT::v4f32:    return "MVT::v4f32";
109   case MVT::v8f32:    return "MVT::v8f32";
110   case MVT::v16f32:   return "MVT::v16f32";
111   case MVT::v1f64:    return "MVT::v1f64";
112   case MVT::v2f64:    return "MVT::v2f64";
113   case MVT::v4f64:    return "MVT::v4f64";
114   case MVT::v8f64:    return "MVT::v8f64";
115   case MVT::Metadata: return "MVT::Metadata";
116   case MVT::iPTR:     return "MVT::iPTR";
117   case MVT::iPTRAny:  return "MVT::iPTRAny";
118   case MVT::Untyped:  return "MVT::Untyped";
119   default: llvm_unreachable("ILLEGAL VALUE TYPE!");
120   }
121 }
122
123 /// getQualifiedName - Return the name of the specified record, with a
124 /// namespace qualifier if the record contains one.
125 ///
126 std::string llvm::getQualifiedName(const Record *R) {
127   std::string Namespace;
128   if (R->getValue("Namespace"))
129      Namespace = R->getValueAsString("Namespace");
130   if (Namespace.empty()) return R->getName();
131   return Namespace + "::" + R->getName();
132 }
133
134
135 /// getTarget - Return the current instance of the Target class.
136 ///
137 CodeGenTarget::CodeGenTarget(RecordKeeper &records)
138   : Records(records) {
139   std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
140   if (Targets.size() == 0)
141     PrintFatalError("ERROR: No 'Target' subclasses defined!");
142   if (Targets.size() != 1)
143     PrintFatalError("ERROR: Multiple subclasses of Target defined!");
144   TargetRec = Targets[0];
145 }
146
147 CodeGenTarget::~CodeGenTarget() {
148 }
149
150 const std::string &CodeGenTarget::getName() const {
151   return TargetRec->getName();
152 }
153
154 std::string CodeGenTarget::getInstNamespace() const {
155   for (const CodeGenInstruction *Inst : instructions()) {
156     // Make sure not to pick up "TargetOpcode" by accidentally getting
157     // the namespace off the PHI instruction or something.
158     if (Inst->Namespace != "TargetOpcode")
159       return Inst->Namespace;
160   }
161
162   return "";
163 }
164
165 Record *CodeGenTarget::getInstructionSet() const {
166   return TargetRec->getValueAsDef("InstructionSet");
167 }
168
169
170 /// getAsmParser - Return the AssemblyParser definition for this target.
171 ///
172 Record *CodeGenTarget::getAsmParser() const {
173   std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
174   if (AsmParserNum >= LI.size())
175     PrintFatalError("Target does not have an AsmParser #" +
176                     Twine(AsmParserNum) + "!");
177   return LI[AsmParserNum];
178 }
179
180 /// getAsmParserVariant - Return the AssmblyParserVariant definition for
181 /// this target.
182 ///
183 Record *CodeGenTarget::getAsmParserVariant(unsigned i) const {
184   std::vector<Record*> LI =
185     TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
186   if (i >= LI.size())
187     PrintFatalError("Target does not have an AsmParserVariant #" + Twine(i) +
188                     "!");
189   return LI[i];
190 }
191
192 /// getAsmParserVariantCount - Return the AssmblyParserVariant definition
193 /// available for this target.
194 ///
195 unsigned CodeGenTarget::getAsmParserVariantCount() const {
196   std::vector<Record*> LI =
197     TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
198   return LI.size();
199 }
200
201 /// getAsmWriter - Return the AssemblyWriter definition for this target.
202 ///
203 Record *CodeGenTarget::getAsmWriter() const {
204   std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
205   if (AsmWriterNum >= LI.size())
206     PrintFatalError("Target does not have an AsmWriter #" +
207                     Twine(AsmWriterNum) + "!");
208   return LI[AsmWriterNum];
209 }
210
211 CodeGenRegBank &CodeGenTarget::getRegBank() const {
212   if (!RegBank)
213     RegBank = llvm::make_unique<CodeGenRegBank>(Records);
214   return *RegBank;
215 }
216
217 void CodeGenTarget::ReadRegAltNameIndices() const {
218   RegAltNameIndices = Records.getAllDerivedDefinitions("RegAltNameIndex");
219   std::sort(RegAltNameIndices.begin(), RegAltNameIndices.end(), LessRecord());
220 }
221
222 /// getRegisterByName - If there is a register with the specific AsmName,
223 /// return it.
224 const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {
225   const StringMap<CodeGenRegister*> &Regs = getRegBank().getRegistersByName();
226   StringMap<CodeGenRegister*>::const_iterator I = Regs.find(Name);
227   if (I == Regs.end())
228     return nullptr;
229   return I->second;
230 }
231
232 std::vector<MVT::SimpleValueType> CodeGenTarget::
233 getRegisterVTs(Record *R) const {
234   const CodeGenRegister *Reg = getRegBank().getReg(R);
235   std::vector<MVT::SimpleValueType> Result;
236   for (const auto &RC : getRegBank().getRegClasses()) {
237     if (RC.contains(Reg)) {
238       ArrayRef<MVT::SimpleValueType> InVTs = RC.getValueTypes();
239       Result.insert(Result.end(), InVTs.begin(), InVTs.end());
240     }
241   }
242
243   // Remove duplicates.
244   array_pod_sort(Result.begin(), Result.end());
245   Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
246   return Result;
247 }
248
249
250 void CodeGenTarget::ReadLegalValueTypes() const {
251   for (const auto &RC : getRegBank().getRegClasses())
252     LegalValueTypes.insert(LegalValueTypes.end(), RC.VTs.begin(), RC.VTs.end());
253
254   // Remove duplicates.
255   std::sort(LegalValueTypes.begin(), LegalValueTypes.end());
256   LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
257                                     LegalValueTypes.end()),
258                         LegalValueTypes.end());
259 }
260
261 CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
262   if (!SchedModels)
263     SchedModels = llvm::make_unique<CodeGenSchedModels>(Records, *this);
264   return *SchedModels;
265 }
266
267 void CodeGenTarget::ReadInstructions() const {
268   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
269   if (Insts.size() <= 2)
270     PrintFatalError("No 'Instruction' subclasses defined!");
271
272   // Parse the instructions defined in the .td file.
273   for (unsigned i = 0, e = Insts.size(); i != e; ++i)
274     Instructions[Insts[i]] = llvm::make_unique<CodeGenInstruction>(Insts[i]);
275 }
276
277 static const CodeGenInstruction *
278 GetInstByName(const char *Name,
279               const DenseMap<const Record*,
280                              std::unique_ptr<CodeGenInstruction>> &Insts,
281               RecordKeeper &Records) {
282   const Record *Rec = Records.getDef(Name);
283
284   const auto I = Insts.find(Rec);
285   if (!Rec || I == Insts.end())
286     PrintFatalError(Twine("Could not find '") + Name + "' instruction!");
287   return I->second.get();
288 }
289
290 /// \brief Return all of the instructions defined by the target, ordered by
291 /// their enum value.
292 void CodeGenTarget::ComputeInstrsByEnum() const {
293   // The ordering here must match the ordering in TargetOpcodes.h.
294   static const char *const FixedInstrs[] = {
295       "PHI",          "INLINEASM",     "CFI_INSTRUCTION",  "EH_LABEL",
296       "GC_LABEL",     "KILL",          "EXTRACT_SUBREG",   "INSERT_SUBREG",
297       "IMPLICIT_DEF", "SUBREG_TO_REG", "COPY_TO_REGCLASS", "DBG_VALUE",
298       "REG_SEQUENCE", "COPY",          "BUNDLE",           "LIFETIME_START",
299       "LIFETIME_END", "STACKMAP",      "PATCHPOINT",       "LOAD_STACK_GUARD",
300       "STATEPOINT",   "LOCAL_ESCAPE",   "FAULTING_LOAD_OP",
301       nullptr};
302   const auto &Insts = getInstructions();
303   for (const char *const *p = FixedInstrs; *p; ++p) {
304     const CodeGenInstruction *Instr = GetInstByName(*p, Insts, Records);
305     assert(Instr && "Missing target independent instruction");
306     assert(Instr->Namespace == "TargetOpcode" && "Bad namespace");
307     InstrsByEnum.push_back(Instr);
308   }
309   unsigned EndOfPredefines = InstrsByEnum.size();
310
311   for (const auto &I : Insts) {
312     const CodeGenInstruction *CGI = I.second.get();
313     if (CGI->Namespace != "TargetOpcode")
314       InstrsByEnum.push_back(CGI);
315   }
316
317   assert(InstrsByEnum.size() == Insts.size() && "Missing predefined instr");
318
319   // All of the instructions are now in random order based on the map iteration.
320   // Sort them by name.
321   std::sort(InstrsByEnum.begin() + EndOfPredefines, InstrsByEnum.end(),
322             [](const CodeGenInstruction *Rec1, const CodeGenInstruction *Rec2) {
323     return Rec1->TheDef->getName() < Rec2->TheDef->getName();
324   });
325 }
326
327
328 /// isLittleEndianEncoding - Return whether this target encodes its instruction
329 /// in little-endian format, i.e. bits laid out in the order [0..n]
330 ///
331 bool CodeGenTarget::isLittleEndianEncoding() const {
332   return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
333 }
334
335 /// reverseBitsForLittleEndianEncoding - For little-endian instruction bit
336 /// encodings, reverse the bit order of all instructions.
337 void CodeGenTarget::reverseBitsForLittleEndianEncoding() {
338   if (!isLittleEndianEncoding())
339     return;
340
341   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
342   for (Record *R : Insts) {
343     if (R->getValueAsString("Namespace") == "TargetOpcode" ||
344         R->getValueAsBit("isPseudo"))
345       continue;
346
347     BitsInit *BI = R->getValueAsBitsInit("Inst");
348
349     unsigned numBits = BI->getNumBits();
350  
351     SmallVector<Init *, 16> NewBits(numBits);
352  
353     for (unsigned bit = 0, end = numBits / 2; bit != end; ++bit) {
354       unsigned bitSwapIdx = numBits - bit - 1;
355       Init *OrigBit = BI->getBit(bit);
356       Init *BitSwap = BI->getBit(bitSwapIdx);
357       NewBits[bit]        = BitSwap;
358       NewBits[bitSwapIdx] = OrigBit;
359     }
360     if (numBits % 2) {
361       unsigned middle = (numBits + 1) / 2;
362       NewBits[middle] = BI->getBit(middle);
363     }
364
365     BitsInit *NewBI = BitsInit::get(NewBits);
366
367     // Update the bits in reversed order so that emitInstrOpBits will get the
368     // correct endianness.
369     R->getValue("Inst")->setValue(NewBI);
370   }
371 }
372
373 /// guessInstructionProperties - Return true if it's OK to guess instruction
374 /// properties instead of raising an error.
375 ///
376 /// This is configurable as a temporary migration aid. It will eventually be
377 /// permanently false.
378 bool CodeGenTarget::guessInstructionProperties() const {
379   return getInstructionSet()->getValueAsBit("guessInstructionProperties");
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() == "SDNPOptInGlue") {
398       Properties |= 1 << SDNPOptInGlue;
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 if (PropList[i]->getName() == "SDNPWantRoot") {
410       Properties |= 1 << SDNPWantRoot;
411     } else if (PropList[i]->getName() == "SDNPWantParent") {
412       Properties |= 1 << SDNPWantParent;
413     } else {
414       PrintFatalError("Unsupported SD Node property '" +
415                       PropList[i]->getName() + "' on ComplexPattern '" +
416                       R->getName() + "'!");
417     }
418 }
419
420 //===----------------------------------------------------------------------===//
421 // CodeGenIntrinsic Implementation
422 //===----------------------------------------------------------------------===//
423
424 std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
425                                                    bool TargetOnly) {
426   std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
427
428   std::vector<CodeGenIntrinsic> Result;
429
430   for (unsigned i = 0, e = I.size(); i != e; ++i) {
431     bool isTarget = I[i]->getValueAsBit("isTarget");
432     if (isTarget == TargetOnly)
433       Result.push_back(CodeGenIntrinsic(I[i]));
434   }
435   return Result;
436 }
437
438 CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
439   TheDef = R;
440   std::string DefName = R->getName();
441   ModRef = ReadWriteMem;
442   isOverloaded = false;
443   isCommutative = false;
444   canThrow = false;
445   isNoReturn = false;
446   isNoDuplicate = false;
447   isConvergent = false;
448
449   if (DefName.size() <= 4 ||
450       std::string(DefName.begin(), DefName.begin() + 4) != "int_")
451     PrintFatalError("Intrinsic '" + DefName + "' does not start with 'int_'!");
452
453   EnumName = std::string(DefName.begin()+4, DefName.end());
454
455   if (R->getValue("GCCBuiltinName"))  // Ignore a missing GCCBuiltinName field.
456     GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
457   if (R->getValue("MSBuiltinName"))   // Ignore a missing MSBuiltinName field.
458     MSBuiltinName = R->getValueAsString("MSBuiltinName");
459
460   TargetPrefix = R->getValueAsString("TargetPrefix");
461   Name = R->getValueAsString("LLVMName");
462
463   if (Name == "") {
464     // If an explicit name isn't specified, derive one from the DefName.
465     Name = "llvm.";
466
467     for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
468       Name += (EnumName[i] == '_') ? '.' : EnumName[i];
469   } else {
470     // Verify it starts with "llvm.".
471     if (Name.size() <= 5 ||
472         std::string(Name.begin(), Name.begin() + 5) != "llvm.")
473       PrintFatalError("Intrinsic '" + DefName + "'s name does not start with 'llvm.'!");
474   }
475
476   // If TargetPrefix is specified, make sure that Name starts with
477   // "llvm.<targetprefix>.".
478   if (!TargetPrefix.empty()) {
479     if (Name.size() < 6+TargetPrefix.size() ||
480         std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
481         != (TargetPrefix + "."))
482       PrintFatalError("Intrinsic '" + DefName + "' does not start with 'llvm." +
483         TargetPrefix + ".'!");
484   }
485
486   // Parse the list of return types.
487   std::vector<MVT::SimpleValueType> OverloadedVTs;
488   ListInit *TypeList = R->getValueAsListInit("RetTypes");
489   for (unsigned i = 0, e = TypeList->size(); i != e; ++i) {
490     Record *TyEl = TypeList->getElementAsRecord(i);
491     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
492     MVT::SimpleValueType VT;
493     if (TyEl->isSubClassOf("LLVMMatchType")) {
494       unsigned MatchTy = TyEl->getValueAsInt("Number");
495       assert(MatchTy < OverloadedVTs.size() &&
496              "Invalid matching number!");
497       VT = OverloadedVTs[MatchTy];
498       // It only makes sense to use the extended and truncated vector element
499       // variants with iAny types; otherwise, if the intrinsic is not
500       // overloaded, all the types can be specified directly.
501       assert(((!TyEl->isSubClassOf("LLVMExtendedType") &&
502                !TyEl->isSubClassOf("LLVMTruncatedType")) ||
503               VT == MVT::iAny || VT == MVT::vAny) &&
504              "Expected iAny or vAny type");
505     } else {
506       VT = getValueType(TyEl->getValueAsDef("VT"));
507     }
508     if (MVT(VT).isOverloaded()) {
509       OverloadedVTs.push_back(VT);
510       isOverloaded = true;
511     }
512
513     // Reject invalid types.
514     if (VT == MVT::isVoid)
515       PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
516
517     IS.RetVTs.push_back(VT);
518     IS.RetTypeDefs.push_back(TyEl);
519   }
520
521   // Parse the list of parameter types.
522   TypeList = R->getValueAsListInit("ParamTypes");
523   for (unsigned i = 0, e = TypeList->size(); i != e; ++i) {
524     Record *TyEl = TypeList->getElementAsRecord(i);
525     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
526     MVT::SimpleValueType VT;
527     if (TyEl->isSubClassOf("LLVMMatchType")) {
528       unsigned MatchTy = TyEl->getValueAsInt("Number");
529       assert(MatchTy < OverloadedVTs.size() &&
530              "Invalid matching number!");
531       VT = OverloadedVTs[MatchTy];
532       // It only makes sense to use the extended and truncated vector element
533       // variants with iAny types; otherwise, if the intrinsic is not
534       // overloaded, all the types can be specified directly.
535       assert(((!TyEl->isSubClassOf("LLVMExtendedType") &&
536                !TyEl->isSubClassOf("LLVMTruncatedType") &&
537                !TyEl->isSubClassOf("LLVMVectorSameWidth") &&
538                !TyEl->isSubClassOf("LLVMPointerToElt")) ||
539               VT == MVT::iAny || VT == MVT::vAny) &&
540              "Expected iAny or vAny type");
541     } else
542       VT = getValueType(TyEl->getValueAsDef("VT"));
543
544     if (MVT(VT).isOverloaded()) {
545       OverloadedVTs.push_back(VT);
546       isOverloaded = true;
547     }
548
549     // Reject invalid types.
550     if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
551       PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
552
553     IS.ParamVTs.push_back(VT);
554     IS.ParamTypeDefs.push_back(TyEl);
555   }
556
557   // Parse the intrinsic properties.
558   ListInit *PropList = R->getValueAsListInit("Properties");
559   for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
560     Record *Property = PropList->getElementAsRecord(i);
561     assert(Property->isSubClassOf("IntrinsicProperty") &&
562            "Expected a property!");
563
564     if (Property->getName() == "IntrNoMem")
565       ModRef = NoMem;
566     else if (Property->getName() == "IntrReadArgMem")
567       ModRef = ReadArgMem;
568     else if (Property->getName() == "IntrReadMem")
569       ModRef = ReadMem;
570     else if (Property->getName() == "IntrReadWriteArgMem")
571       ModRef = ReadWriteArgMem;
572     else if (Property->getName() == "Commutative")
573       isCommutative = true;
574     else if (Property->getName() == "Throws")
575       canThrow = true;
576     else if (Property->getName() == "IntrNoDuplicate")
577       isNoDuplicate = true;
578     else if (Property->getName() == "IntrConvergent")
579       isConvergent = true;
580     else if (Property->getName() == "IntrNoReturn")
581       isNoReturn = true;
582     else if (Property->isSubClassOf("NoCapture")) {
583       unsigned ArgNo = Property->getValueAsInt("ArgNo");
584       ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
585     } else if (Property->isSubClassOf("ReadOnly")) {
586       unsigned ArgNo = Property->getValueAsInt("ArgNo");
587       ArgumentAttributes.push_back(std::make_pair(ArgNo, ReadOnly));
588     } else if (Property->isSubClassOf("ReadNone")) {
589       unsigned ArgNo = Property->getValueAsInt("ArgNo");
590       ArgumentAttributes.push_back(std::make_pair(ArgNo, ReadNone));
591     } else
592       llvm_unreachable("Unknown property!");
593   }
594
595   // Sort the argument attributes for later benefit.
596   std::sort(ArgumentAttributes.begin(), ArgumentAttributes.end());
597 }