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