[x86] remove duplicate movq instruction defs (PR25554)
[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::token:    return "MVT::token";
116   case MVT::Metadata: return "MVT::Metadata";
117   case MVT::iPTR:     return "MVT::iPTR";
118   case MVT::iPTRAny:  return "MVT::iPTRAny";
119   case MVT::Untyped:  return "MVT::Untyped";
120   default: llvm_unreachable("ILLEGAL VALUE TYPE!");
121   }
122 }
123
124 /// getQualifiedName - Return the name of the specified record, with a
125 /// namespace qualifier if the record contains one.
126 ///
127 std::string llvm::getQualifiedName(const Record *R) {
128   std::string Namespace;
129   if (R->getValue("Namespace"))
130      Namespace = R->getValueAsString("Namespace");
131   if (Namespace.empty()) return R->getName();
132   return Namespace + "::" + R->getName();
133 }
134
135
136 /// getTarget - Return the current instance of the Target class.
137 ///
138 CodeGenTarget::CodeGenTarget(RecordKeeper &records)
139   : Records(records) {
140   std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
141   if (Targets.size() == 0)
142     PrintFatalError("ERROR: No 'Target' subclasses defined!");
143   if (Targets.size() != 1)
144     PrintFatalError("ERROR: Multiple subclasses of Target defined!");
145   TargetRec = Targets[0];
146 }
147
148 CodeGenTarget::~CodeGenTarget() {
149 }
150
151 const std::string &CodeGenTarget::getName() const {
152   return TargetRec->getName();
153 }
154
155 std::string CodeGenTarget::getInstNamespace() const {
156   for (const CodeGenInstruction *Inst : instructions()) {
157     // Make sure not to pick up "TargetOpcode" by accidentally getting
158     // the namespace off the PHI instruction or something.
159     if (Inst->Namespace != "TargetOpcode")
160       return Inst->Namespace;
161   }
162
163   return "";
164 }
165
166 Record *CodeGenTarget::getInstructionSet() const {
167   return TargetRec->getValueAsDef("InstructionSet");
168 }
169
170
171 /// getAsmParser - Return the AssemblyParser definition for this target.
172 ///
173 Record *CodeGenTarget::getAsmParser() const {
174   std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
175   if (AsmParserNum >= LI.size())
176     PrintFatalError("Target does not have an AsmParser #" +
177                     Twine(AsmParserNum) + "!");
178   return LI[AsmParserNum];
179 }
180
181 /// getAsmParserVariant - Return the AssmblyParserVariant definition for
182 /// this target.
183 ///
184 Record *CodeGenTarget::getAsmParserVariant(unsigned i) const {
185   std::vector<Record*> LI =
186     TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
187   if (i >= LI.size())
188     PrintFatalError("Target does not have an AsmParserVariant #" + Twine(i) +
189                     "!");
190   return LI[i];
191 }
192
193 /// getAsmParserVariantCount - Return the AssmblyParserVariant definition
194 /// available for this target.
195 ///
196 unsigned CodeGenTarget::getAsmParserVariantCount() const {
197   std::vector<Record*> LI =
198     TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
199   return LI.size();
200 }
201
202 /// getAsmWriter - Return the AssemblyWriter definition for this target.
203 ///
204 Record *CodeGenTarget::getAsmWriter() const {
205   std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
206   if (AsmWriterNum >= LI.size())
207     PrintFatalError("Target does not have an AsmWriter #" +
208                     Twine(AsmWriterNum) + "!");
209   return LI[AsmWriterNum];
210 }
211
212 CodeGenRegBank &CodeGenTarget::getRegBank() const {
213   if (!RegBank)
214     RegBank = llvm::make_unique<CodeGenRegBank>(Records);
215   return *RegBank;
216 }
217
218 void CodeGenTarget::ReadRegAltNameIndices() const {
219   RegAltNameIndices = Records.getAllDerivedDefinitions("RegAltNameIndex");
220   std::sort(RegAltNameIndices.begin(), RegAltNameIndices.end(), LessRecord());
221 }
222
223 /// getRegisterByName - If there is a register with the specific AsmName,
224 /// return it.
225 const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {
226   const StringMap<CodeGenRegister*> &Regs = getRegBank().getRegistersByName();
227   StringMap<CodeGenRegister*>::const_iterator I = Regs.find(Name);
228   if (I == Regs.end())
229     return nullptr;
230   return I->second;
231 }
232
233 std::vector<MVT::SimpleValueType> CodeGenTarget::
234 getRegisterVTs(Record *R) const {
235   const CodeGenRegister *Reg = getRegBank().getReg(R);
236   std::vector<MVT::SimpleValueType> Result;
237   for (const auto &RC : getRegBank().getRegClasses()) {
238     if (RC.contains(Reg)) {
239       ArrayRef<MVT::SimpleValueType> InVTs = RC.getValueTypes();
240       Result.insert(Result.end(), InVTs.begin(), InVTs.end());
241     }
242   }
243
244   // Remove duplicates.
245   array_pod_sort(Result.begin(), Result.end());
246   Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
247   return Result;
248 }
249
250
251 void CodeGenTarget::ReadLegalValueTypes() const {
252   for (const auto &RC : getRegBank().getRegClasses())
253     LegalValueTypes.insert(LegalValueTypes.end(), RC.VTs.begin(), RC.VTs.end());
254
255   // Remove duplicates.
256   array_pod_sort(LegalValueTypes.begin(), LegalValueTypes.end());
257   LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
258                                     LegalValueTypes.end()),
259                         LegalValueTypes.end());
260 }
261
262 CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
263   if (!SchedModels)
264     SchedModels = llvm::make_unique<CodeGenSchedModels>(Records, *this);
265   return *SchedModels;
266 }
267
268 void CodeGenTarget::ReadInstructions() const {
269   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
270   if (Insts.size() <= 2)
271     PrintFatalError("No 'Instruction' subclasses defined!");
272
273   // Parse the instructions defined in the .td file.
274   for (unsigned i = 0, e = Insts.size(); i != e; ++i)
275     Instructions[Insts[i]] = llvm::make_unique<CodeGenInstruction>(Insts[i]);
276 }
277
278 static const CodeGenInstruction *
279 GetInstByName(const char *Name,
280               const DenseMap<const Record*,
281                              std::unique_ptr<CodeGenInstruction>> &Insts,
282               RecordKeeper &Records) {
283   const Record *Rec = Records.getDef(Name);
284
285   const auto I = Insts.find(Rec);
286   if (!Rec || I == Insts.end())
287     PrintFatalError(Twine("Could not find '") + Name + "' instruction!");
288   return I->second.get();
289 }
290
291 /// \brief Return all of the instructions defined by the target, ordered by
292 /// their enum value.
293 void CodeGenTarget::ComputeInstrsByEnum() const {
294   // The ordering here must match the ordering in TargetOpcodes.h.
295   static const char *const FixedInstrs[] = {
296       "PHI",          "INLINEASM",     "CFI_INSTRUCTION",  "EH_LABEL",
297       "GC_LABEL",     "KILL",          "EXTRACT_SUBREG",   "INSERT_SUBREG",
298       "IMPLICIT_DEF", "SUBREG_TO_REG", "COPY_TO_REGCLASS", "DBG_VALUE",
299       "REG_SEQUENCE", "COPY",          "BUNDLE",           "LIFETIME_START",
300       "LIFETIME_END", "STACKMAP",      "PATCHPOINT",       "LOAD_STACK_GUARD",
301       "STATEPOINT",   "LOCAL_ESCAPE",   "FAULTING_LOAD_OP",
302       nullptr};
303   const auto &Insts = getInstructions();
304   for (const char *const *p = FixedInstrs; *p; ++p) {
305     const CodeGenInstruction *Instr = GetInstByName(*p, Insts, Records);
306     assert(Instr && "Missing target independent instruction");
307     assert(Instr->Namespace == "TargetOpcode" && "Bad namespace");
308     InstrsByEnum.push_back(Instr);
309   }
310   unsigned EndOfPredefines = InstrsByEnum.size();
311
312   for (const auto &I : Insts) {
313     const CodeGenInstruction *CGI = I.second.get();
314     if (CGI->Namespace != "TargetOpcode")
315       InstrsByEnum.push_back(CGI);
316   }
317
318   assert(InstrsByEnum.size() == Insts.size() && "Missing predefined instr");
319
320   // All of the instructions are now in random order based on the map iteration.
321   // Sort them by name.
322   std::sort(InstrsByEnum.begin() + EndOfPredefines, InstrsByEnum.end(),
323             [](const CodeGenInstruction *Rec1, const CodeGenInstruction *Rec2) {
324     return Rec1->TheDef->getName() < Rec2->TheDef->getName();
325   });
326 }
327
328
329 /// isLittleEndianEncoding - Return whether this target encodes its instruction
330 /// in little-endian format, i.e. bits laid out in the order [0..n]
331 ///
332 bool CodeGenTarget::isLittleEndianEncoding() const {
333   return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
334 }
335
336 /// reverseBitsForLittleEndianEncoding - For little-endian instruction bit
337 /// encodings, reverse the bit order of all instructions.
338 void CodeGenTarget::reverseBitsForLittleEndianEncoding() {
339   if (!isLittleEndianEncoding())
340     return;
341
342   std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
343   for (Record *R : Insts) {
344     if (R->getValueAsString("Namespace") == "TargetOpcode" ||
345         R->getValueAsBit("isPseudo"))
346       continue;
347
348     BitsInit *BI = R->getValueAsBitsInit("Inst");
349
350     unsigned numBits = BI->getNumBits();
351  
352     SmallVector<Init *, 16> NewBits(numBits);
353  
354     for (unsigned bit = 0, end = numBits / 2; bit != end; ++bit) {
355       unsigned bitSwapIdx = numBits - bit - 1;
356       Init *OrigBit = BI->getBit(bit);
357       Init *BitSwap = BI->getBit(bitSwapIdx);
358       NewBits[bit]        = BitSwap;
359       NewBits[bitSwapIdx] = OrigBit;
360     }
361     if (numBits % 2) {
362       unsigned middle = (numBits + 1) / 2;
363       NewBits[middle] = BI->getBit(middle);
364     }
365
366     BitsInit *NewBI = BitsInit::get(NewBits);
367
368     // Update the bits in reversed order so that emitInstrOpBits will get the
369     // correct endianness.
370     R->getValue("Inst")->setValue(NewBI);
371   }
372 }
373
374 /// guessInstructionProperties - Return true if it's OK to guess instruction
375 /// properties instead of raising an error.
376 ///
377 /// This is configurable as a temporary migration aid. It will eventually be
378 /// permanently false.
379 bool CodeGenTarget::guessInstructionProperties() const {
380   return getInstructionSet()->getValueAsBit("guessInstructionProperties");
381 }
382
383 //===----------------------------------------------------------------------===//
384 // ComplexPattern implementation
385 //
386 ComplexPattern::ComplexPattern(Record *R) {
387   Ty          = ::getValueType(R->getValueAsDef("Ty"));
388   NumOperands = R->getValueAsInt("NumOperands");
389   SelectFunc  = R->getValueAsString("SelectFunc");
390   RootNodes   = R->getValueAsListOfDefs("RootNodes");
391
392   // Parse the properties.
393   Properties = 0;
394   std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties");
395   for (unsigned i = 0, e = PropList.size(); i != e; ++i)
396     if (PropList[i]->getName() == "SDNPHasChain") {
397       Properties |= 1 << SDNPHasChain;
398     } else if (PropList[i]->getName() == "SDNPOptInGlue") {
399       Properties |= 1 << SDNPOptInGlue;
400     } else if (PropList[i]->getName() == "SDNPMayStore") {
401       Properties |= 1 << SDNPMayStore;
402     } else if (PropList[i]->getName() == "SDNPMayLoad") {
403       Properties |= 1 << SDNPMayLoad;
404     } else if (PropList[i]->getName() == "SDNPSideEffect") {
405       Properties |= 1 << SDNPSideEffect;
406     } else if (PropList[i]->getName() == "SDNPMemOperand") {
407       Properties |= 1 << SDNPMemOperand;
408     } else if (PropList[i]->getName() == "SDNPVariadic") {
409       Properties |= 1 << SDNPVariadic;
410     } else if (PropList[i]->getName() == "SDNPWantRoot") {
411       Properties |= 1 << SDNPWantRoot;
412     } else if (PropList[i]->getName() == "SDNPWantParent") {
413       Properties |= 1 << SDNPWantParent;
414     } else {
415       PrintFatalError("Unsupported SD Node property '" +
416                       PropList[i]->getName() + "' on ComplexPattern '" +
417                       R->getName() + "'!");
418     }
419 }
420
421 //===----------------------------------------------------------------------===//
422 // CodeGenIntrinsic Implementation
423 //===----------------------------------------------------------------------===//
424
425 std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
426                                                    bool TargetOnly) {
427   std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
428
429   std::vector<CodeGenIntrinsic> Result;
430
431   for (unsigned i = 0, e = I.size(); i != e; ++i) {
432     bool isTarget = I[i]->getValueAsBit("isTarget");
433     if (isTarget == TargetOnly)
434       Result.push_back(CodeGenIntrinsic(I[i]));
435   }
436   return Result;
437 }
438
439 CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
440   TheDef = R;
441   std::string DefName = R->getName();
442   ModRef = ReadWriteMem;
443   isOverloaded = false;
444   isCommutative = false;
445   canThrow = false;
446   isNoReturn = false;
447   isNoDuplicate = false;
448   isConvergent = false;
449
450   if (DefName.size() <= 4 ||
451       std::string(DefName.begin(), DefName.begin() + 4) != "int_")
452     PrintFatalError("Intrinsic '" + DefName + "' does not start with 'int_'!");
453
454   EnumName = std::string(DefName.begin()+4, DefName.end());
455
456   if (R->getValue("GCCBuiltinName"))  // Ignore a missing GCCBuiltinName field.
457     GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
458   if (R->getValue("MSBuiltinName"))   // Ignore a missing MSBuiltinName field.
459     MSBuiltinName = R->getValueAsString("MSBuiltinName");
460
461   TargetPrefix = R->getValueAsString("TargetPrefix");
462   Name = R->getValueAsString("LLVMName");
463
464   if (Name == "") {
465     // If an explicit name isn't specified, derive one from the DefName.
466     Name = "llvm.";
467
468     for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
469       Name += (EnumName[i] == '_') ? '.' : EnumName[i];
470   } else {
471     // Verify it starts with "llvm.".
472     if (Name.size() <= 5 ||
473         std::string(Name.begin(), Name.begin() + 5) != "llvm.")
474       PrintFatalError("Intrinsic '" + DefName + "'s name does not start with 'llvm.'!");
475   }
476
477   // If TargetPrefix is specified, make sure that Name starts with
478   // "llvm.<targetprefix>.".
479   if (!TargetPrefix.empty()) {
480     if (Name.size() < 6+TargetPrefix.size() ||
481         std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
482         != (TargetPrefix + "."))
483       PrintFatalError("Intrinsic '" + DefName + "' does not start with 'llvm." +
484         TargetPrefix + ".'!");
485   }
486
487   // Parse the list of return types.
488   std::vector<MVT::SimpleValueType> OverloadedVTs;
489   ListInit *TypeList = R->getValueAsListInit("RetTypes");
490   for (unsigned i = 0, e = TypeList->size(); i != e; ++i) {
491     Record *TyEl = TypeList->getElementAsRecord(i);
492     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
493     MVT::SimpleValueType VT;
494     if (TyEl->isSubClassOf("LLVMMatchType")) {
495       unsigned MatchTy = TyEl->getValueAsInt("Number");
496       assert(MatchTy < OverloadedVTs.size() &&
497              "Invalid matching number!");
498       VT = OverloadedVTs[MatchTy];
499       // It only makes sense to use the extended and truncated vector element
500       // variants with iAny types; otherwise, if the intrinsic is not
501       // overloaded, all the types can be specified directly.
502       assert(((!TyEl->isSubClassOf("LLVMExtendedType") &&
503                !TyEl->isSubClassOf("LLVMTruncatedType")) ||
504               VT == MVT::iAny || VT == MVT::vAny) &&
505              "Expected iAny or vAny type");
506     } else {
507       VT = getValueType(TyEl->getValueAsDef("VT"));
508     }
509     if (MVT(VT).isOverloaded()) {
510       OverloadedVTs.push_back(VT);
511       isOverloaded = true;
512     }
513
514     // Reject invalid types.
515     if (VT == MVT::isVoid)
516       PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
517
518     IS.RetVTs.push_back(VT);
519     IS.RetTypeDefs.push_back(TyEl);
520   }
521
522   // Parse the list of parameter types.
523   TypeList = R->getValueAsListInit("ParamTypes");
524   for (unsigned i = 0, e = TypeList->size(); i != e; ++i) {
525     Record *TyEl = TypeList->getElementAsRecord(i);
526     assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
527     MVT::SimpleValueType VT;
528     if (TyEl->isSubClassOf("LLVMMatchType")) {
529       unsigned MatchTy = TyEl->getValueAsInt("Number");
530       assert(MatchTy < OverloadedVTs.size() &&
531              "Invalid matching number!");
532       VT = OverloadedVTs[MatchTy];
533       // It only makes sense to use the extended and truncated vector element
534       // variants with iAny types; otherwise, if the intrinsic is not
535       // overloaded, all the types can be specified directly.
536       assert(((!TyEl->isSubClassOf("LLVMExtendedType") &&
537                !TyEl->isSubClassOf("LLVMTruncatedType") &&
538                !TyEl->isSubClassOf("LLVMVectorSameWidth") &&
539                !TyEl->isSubClassOf("LLVMPointerToElt")) ||
540               VT == MVT::iAny || VT == MVT::vAny) &&
541              "Expected iAny or vAny type");
542     } else
543       VT = getValueType(TyEl->getValueAsDef("VT"));
544
545     if (MVT(VT).isOverloaded()) {
546       OverloadedVTs.push_back(VT);
547       isOverloaded = true;
548     }
549
550     // Reject invalid types.
551     if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
552       PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
553
554     IS.ParamVTs.push_back(VT);
555     IS.ParamTypeDefs.push_back(TyEl);
556   }
557
558   // Parse the intrinsic properties.
559   ListInit *PropList = R->getValueAsListInit("Properties");
560   for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
561     Record *Property = PropList->getElementAsRecord(i);
562     assert(Property->isSubClassOf("IntrinsicProperty") &&
563            "Expected a property!");
564
565     if (Property->getName() == "IntrNoMem")
566       ModRef = NoMem;
567     else if (Property->getName() == "IntrReadArgMem")
568       ModRef = ReadArgMem;
569     else if (Property->getName() == "IntrReadMem")
570       ModRef = ReadMem;
571     else if (Property->getName() == "IntrReadWriteArgMem")
572       ModRef = ReadWriteArgMem;
573     else if (Property->getName() == "Commutative")
574       isCommutative = true;
575     else if (Property->getName() == "Throws")
576       canThrow = true;
577     else if (Property->getName() == "IntrNoDuplicate")
578       isNoDuplicate = true;
579     else if (Property->getName() == "IntrConvergent")
580       isConvergent = true;
581     else if (Property->getName() == "IntrNoReturn")
582       isNoReturn = true;
583     else if (Property->isSubClassOf("NoCapture")) {
584       unsigned ArgNo = Property->getValueAsInt("ArgNo");
585       ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
586     } else if (Property->isSubClassOf("ReadOnly")) {
587       unsigned ArgNo = Property->getValueAsInt("ArgNo");
588       ArgumentAttributes.push_back(std::make_pair(ArgNo, ReadOnly));
589     } else if (Property->isSubClassOf("ReadNone")) {
590       unsigned ArgNo = Property->getValueAsInt("ArgNo");
591       ArgumentAttributes.push_back(std::make_pair(ArgNo, ReadNone));
592     } else
593       llvm_unreachable("Unknown property!");
594   }
595
596   // Sort the argument attributes for later benefit.
597   std::sort(ArgumentAttributes.begin(), ArgumentAttributes.end());
598 }