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