CodeGenTarget.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. #include "CodeGenTarget.h"
  17. #include "CodeGenIntrinsics.h"
  18. #include "CodeGenSchedule.h"
  19. #include "llvm/ADT/STLExtras.h"
  20. #include "llvm/ADT/StringExtras.h"
  21. #include "llvm/Support/CommandLine.h"
  22. #include "llvm/TableGen/Error.h"
  23. #include "llvm/TableGen/Record.h"
  24. #include <algorithm>
  25. using namespace llvm;
  26. static cl::opt<unsigned>
  27. AsmParserNum("asmparsernum", cl::init(0),
  28. cl::desc("Make -gen-asm-parser emit assembly parser #N"));
  29. static cl::opt<unsigned>
  30. AsmWriterNum("asmwriternum", cl::init(0),
  31. cl::desc("Make -gen-asm-writer emit assembly writer #N"));
  32. /// getValueType - Return the MVT::SimpleValueType that the specified TableGen
  33. /// record corresponds to.
  34. MVT::SimpleValueType llvm::getValueType(Record *Rec) {
  35. return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
  36. }
  37. std::string llvm::getName(MVT::SimpleValueType T) {
  38. switch (T) {
  39. case MVT::Other: return "UNKNOWN";
  40. case MVT::iPTR: return "TLI.getPointerTy()";
  41. case MVT::iPTRAny: return "TLI.getPointerTy()";
  42. default: return getEnumName(T);
  43. }
  44. }
  45. std::string llvm::getEnumName(MVT::SimpleValueType T) {
  46. switch (T) {
  47. case MVT::Other: return "MVT::Other";
  48. case MVT::i1: return "MVT::i1";
  49. case MVT::i8: return "MVT::i8";
  50. case MVT::i16: return "MVT::i16";
  51. case MVT::i32: return "MVT::i32";
  52. case MVT::i64: return "MVT::i64";
  53. case MVT::i128: return "MVT::i128";
  54. case MVT::iAny: return "MVT::iAny";
  55. case MVT::fAny: return "MVT::fAny";
  56. case MVT::vAny: return "MVT::vAny";
  57. case MVT::f16: return "MVT::f16";
  58. case MVT::f32: return "MVT::f32";
  59. case MVT::f64: return "MVT::f64";
  60. case MVT::f80: return "MVT::f80";
  61. case MVT::f128: return "MVT::f128";
  62. case MVT::ppcf128: return "MVT::ppcf128";
  63. case MVT::x86mmx: return "MVT::x86mmx";
  64. case MVT::Glue: return "MVT::Glue";
  65. case MVT::isVoid: return "MVT::isVoid";
  66. case MVT::v2i1: return "MVT::v2i1";
  67. case MVT::v4i1: return "MVT::v4i1";
  68. case MVT::v8i1: return "MVT::v8i1";
  69. case MVT::v16i1: return "MVT::v16i1";
  70. case MVT::v2i8: return "MVT::v2i8";
  71. case MVT::v4i8: return "MVT::v4i8";
  72. case MVT::v8i8: return "MVT::v8i8";
  73. case MVT::v16i8: return "MVT::v16i8";
  74. case MVT::v32i8: return "MVT::v32i8";
  75. case MVT::v1i16: return "MVT::v1i16";
  76. case MVT::v2i16: return "MVT::v2i16";
  77. case MVT::v4i16: return "MVT::v4i16";
  78. case MVT::v8i16: return "MVT::v8i16";
  79. case MVT::v16i16: return "MVT::v16i16";
  80. case MVT::v1i32: return "MVT::v1i32";
  81. case MVT::v2i32: return "MVT::v2i32";
  82. case MVT::v4i32: return "MVT::v4i32";
  83. case MVT::v8i32: return "MVT::v8i32";
  84. case MVT::v16i32: return "MVT::v16i32";
  85. case MVT::v1i64: return "MVT::v1i64";
  86. case MVT::v2i64: return "MVT::v2i64";
  87. case MVT::v4i64: return "MVT::v4i64";
  88. case MVT::v8i64: return "MVT::v8i64";
  89. case MVT::v16i64: return "MVT::v16i64";
  90. case MVT::v2f16: return "MVT::v2f16";
  91. case MVT::v2f32: return "MVT::v2f32";
  92. case MVT::v4f32: return "MVT::v4f32";
  93. case MVT::v8f32: return "MVT::v8f32";
  94. case MVT::v2f64: return "MVT::v2f64";
  95. case MVT::v4f64: return "MVT::v4f64";
  96. case MVT::Metadata: return "MVT::Metadata";
  97. case MVT::iPTR: return "MVT::iPTR";
  98. case MVT::iPTRAny: return "MVT::iPTRAny";
  99. case MVT::Untyped: return "MVT::Untyped";
  100. default: llvm_unreachable("ILLEGAL VALUE TYPE!");
  101. }
  102. }
  103. /// getQualifiedName - Return the name of the specified record, with a
  104. /// namespace qualifier if the record contains one.
  105. ///
  106. std::string llvm::getQualifiedName(const Record *R) {
  107. std::string Namespace;
  108. if (R->getValue("Namespace"))
  109. Namespace = R->getValueAsString("Namespace");
  110. if (Namespace.empty()) return R->getName();
  111. return Namespace + "::" + R->getName();
  112. }
  113. /// getTarget - Return the current instance of the Target class.
  114. ///
  115. CodeGenTarget::CodeGenTarget(RecordKeeper &records)
  116. : Records(records), RegBank(0), SchedModels(0) {
  117. std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
  118. if (Targets.size() == 0)
  119. PrintFatalError("ERROR: No 'Target' subclasses defined!");
  120. if (Targets.size() != 1)
  121. PrintFatalError("ERROR: Multiple subclasses of Target defined!");
  122. TargetRec = Targets[0];
  123. }
  124. CodeGenTarget::~CodeGenTarget() {
  125. delete RegBank;
  126. delete SchedModels;
  127. }
  128. const std::string &CodeGenTarget::getName() const {
  129. return TargetRec->getName();
  130. }
  131. std::string CodeGenTarget::getInstNamespace() const {
  132. for (inst_iterator i = inst_begin(), e = inst_end(); i != e; ++i) {
  133. // Make sure not to pick up "TargetOpcode" by accidentally getting
  134. // the namespace off the PHI instruction or something.
  135. if ((*i)->Namespace != "TargetOpcode")
  136. return (*i)->Namespace;
  137. }
  138. return "";
  139. }
  140. Record *CodeGenTarget::getInstructionSet() const {
  141. return TargetRec->getValueAsDef("InstructionSet");
  142. }
  143. /// getAsmParser - Return the AssemblyParser definition for this target.
  144. ///
  145. Record *CodeGenTarget::getAsmParser() const {
  146. std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyParsers");
  147. if (AsmParserNum >= LI.size())
  148. PrintFatalError("Target does not have an AsmParser #" + utostr(AsmParserNum) + "!");
  149. return LI[AsmParserNum];
  150. }
  151. /// getAsmParserVariant - Return the AssmblyParserVariant definition for
  152. /// this target.
  153. ///
  154. Record *CodeGenTarget::getAsmParserVariant(unsigned i) const {
  155. std::vector<Record*> LI =
  156. TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
  157. if (i >= LI.size())
  158. PrintFatalError("Target does not have an AsmParserVariant #" + utostr(i) + "!");
  159. return LI[i];
  160. }
  161. /// getAsmParserVariantCount - Return the AssmblyParserVariant definition
  162. /// available for this target.
  163. ///
  164. unsigned CodeGenTarget::getAsmParserVariantCount() const {
  165. std::vector<Record*> LI =
  166. TargetRec->getValueAsListOfDefs("AssemblyParserVariants");
  167. return LI.size();
  168. }
  169. /// getAsmWriter - Return the AssemblyWriter definition for this target.
  170. ///
  171. Record *CodeGenTarget::getAsmWriter() const {
  172. std::vector<Record*> LI = TargetRec->getValueAsListOfDefs("AssemblyWriters");
  173. if (AsmWriterNum >= LI.size())
  174. PrintFatalError("Target does not have an AsmWriter #" + utostr(AsmWriterNum) + "!");
  175. return LI[AsmWriterNum];
  176. }
  177. CodeGenRegBank &CodeGenTarget::getRegBank() const {
  178. if (!RegBank)
  179. RegBank = new CodeGenRegBank(Records);
  180. return *RegBank;
  181. }
  182. void CodeGenTarget::ReadRegAltNameIndices() const {
  183. RegAltNameIndices = Records.getAllDerivedDefinitions("RegAltNameIndex");
  184. std::sort(RegAltNameIndices.begin(), RegAltNameIndices.end(), LessRecord());
  185. }
  186. /// getRegisterByName - If there is a register with the specific AsmName,
  187. /// return it.
  188. const CodeGenRegister *CodeGenTarget::getRegisterByName(StringRef Name) const {
  189. const StringMap<CodeGenRegister*> &Regs = getRegBank().getRegistersByName();
  190. StringMap<CodeGenRegister*>::const_iterator I = Regs.find(Name);
  191. if (I == Regs.end())
  192. return 0;
  193. return I->second;
  194. }
  195. std::vector<MVT::SimpleValueType> CodeGenTarget::
  196. getRegisterVTs(Record *R) const {
  197. const CodeGenRegister *Reg = getRegBank().getReg(R);
  198. std::vector<MVT::SimpleValueType> Result;
  199. ArrayRef<CodeGenRegisterClass*> RCs = getRegBank().getRegClasses();
  200. for (unsigned i = 0, e = RCs.size(); i != e; ++i) {
  201. const CodeGenRegisterClass &RC = *RCs[i];
  202. if (RC.contains(Reg)) {
  203. const std::vector<MVT::SimpleValueType> &InVTs = RC.getValueTypes();
  204. Result.insert(Result.end(), InVTs.begin(), InVTs.end());
  205. }
  206. }
  207. // Remove duplicates.
  208. array_pod_sort(Result.begin(), Result.end());
  209. Result.erase(std::unique(Result.begin(), Result.end()), Result.end());
  210. return Result;
  211. }
  212. void CodeGenTarget::ReadLegalValueTypes() const {
  213. ArrayRef<CodeGenRegisterClass*> RCs = getRegBank().getRegClasses();
  214. for (unsigned i = 0, e = RCs.size(); i != e; ++i)
  215. for (unsigned ri = 0, re = RCs[i]->VTs.size(); ri != re; ++ri)
  216. LegalValueTypes.push_back(RCs[i]->VTs[ri]);
  217. // Remove duplicates.
  218. std::sort(LegalValueTypes.begin(), LegalValueTypes.end());
  219. LegalValueTypes.erase(std::unique(LegalValueTypes.begin(),
  220. LegalValueTypes.end()),
  221. LegalValueTypes.end());
  222. }
  223. CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
  224. if (!SchedModels)
  225. SchedModels = new CodeGenSchedModels(Records, *this);
  226. return *SchedModels;
  227. }
  228. void CodeGenTarget::ReadInstructions() const {
  229. std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
  230. if (Insts.size() <= 2)
  231. PrintFatalError("No 'Instruction' subclasses defined!");
  232. // Parse the instructions defined in the .td file.
  233. for (unsigned i = 0, e = Insts.size(); i != e; ++i)
  234. Instructions[Insts[i]] = new CodeGenInstruction(Insts[i]);
  235. }
  236. static const CodeGenInstruction *
  237. GetInstByName(const char *Name,
  238. const DenseMap<const Record*, CodeGenInstruction*> &Insts,
  239. RecordKeeper &Records) {
  240. const Record *Rec = Records.getDef(Name);
  241. DenseMap<const Record*, CodeGenInstruction*>::const_iterator
  242. I = Insts.find(Rec);
  243. if (Rec == 0 || I == Insts.end())
  244. PrintFatalError(std::string("Could not find '") + Name + "' instruction!");
  245. return I->second;
  246. }
  247. namespace {
  248. /// SortInstByName - Sorting predicate to sort instructions by name.
  249. ///
  250. struct SortInstByName {
  251. bool operator()(const CodeGenInstruction *Rec1,
  252. const CodeGenInstruction *Rec2) const {
  253. return Rec1->TheDef->getName() < Rec2->TheDef->getName();
  254. }
  255. };
  256. }
  257. /// getInstructionsByEnumValue - Return all of the instructions defined by the
  258. /// target, ordered by their enum value.
  259. void CodeGenTarget::ComputeInstrsByEnum() const {
  260. // The ordering here must match the ordering in TargetOpcodes.h.
  261. const char *const FixedInstrs[] = {
  262. "PHI",
  263. "INLINEASM",
  264. "PROLOG_LABEL",
  265. "EH_LABEL",
  266. "GC_LABEL",
  267. "KILL",
  268. "EXTRACT_SUBREG",
  269. "INSERT_SUBREG",
  270. "IMPLICIT_DEF",
  271. "SUBREG_TO_REG",
  272. "COPY_TO_REGCLASS",
  273. "DBG_VALUE",
  274. "REG_SEQUENCE",
  275. "COPY",
  276. "BUNDLE",
  277. "LIFETIME_START",
  278. "LIFETIME_END",
  279. 0
  280. };
  281. const DenseMap<const Record*, CodeGenInstruction*> &Insts = getInstructions();
  282. for (const char *const *p = FixedInstrs; *p; ++p) {
  283. const CodeGenInstruction *Instr = GetInstByName(*p, Insts, Records);
  284. assert(Instr && "Missing target independent instruction");
  285. assert(Instr->Namespace == "TargetOpcode" && "Bad namespace");
  286. InstrsByEnum.push_back(Instr);
  287. }
  288. unsigned EndOfPredefines = InstrsByEnum.size();
  289. for (DenseMap<const Record*, CodeGenInstruction*>::const_iterator
  290. I = Insts.begin(), E = Insts.end(); I != E; ++I) {
  291. const CodeGenInstruction *CGI = I->second;
  292. if (CGI->Namespace != "TargetOpcode")
  293. InstrsByEnum.push_back(CGI);
  294. }
  295. assert(InstrsByEnum.size() == Insts.size() && "Missing predefined instr");
  296. // All of the instructions are now in random order based on the map iteration.
  297. // Sort them by name.
  298. std::sort(InstrsByEnum.begin()+EndOfPredefines, InstrsByEnum.end(),
  299. SortInstByName());
  300. }
  301. /// isLittleEndianEncoding - Return whether this target encodes its instruction
  302. /// in little-endian format, i.e. bits laid out in the order [0..n]
  303. ///
  304. bool CodeGenTarget::isLittleEndianEncoding() const {
  305. return getInstructionSet()->getValueAsBit("isLittleEndianEncoding");
  306. }
  307. /// guessInstructionProperties - Return true if it's OK to guess instruction
  308. /// properties instead of raising an error.
  309. ///
  310. /// This is configurable as a temporary migration aid. It will eventually be
  311. /// permanently false.
  312. bool CodeGenTarget::guessInstructionProperties() const {
  313. return getInstructionSet()->getValueAsBit("guessInstructionProperties");
  314. }
  315. //===----------------------------------------------------------------------===//
  316. // ComplexPattern implementation
  317. //
  318. ComplexPattern::ComplexPattern(Record *R) {
  319. Ty = ::getValueType(R->getValueAsDef("Ty"));
  320. NumOperands = R->getValueAsInt("NumOperands");
  321. SelectFunc = R->getValueAsString("SelectFunc");
  322. RootNodes = R->getValueAsListOfDefs("RootNodes");
  323. // Parse the properties.
  324. Properties = 0;
  325. std::vector<Record*> PropList = R->getValueAsListOfDefs("Properties");
  326. for (unsigned i = 0, e = PropList.size(); i != e; ++i)
  327. if (PropList[i]->getName() == "SDNPHasChain") {
  328. Properties |= 1 << SDNPHasChain;
  329. } else if (PropList[i]->getName() == "SDNPOptInGlue") {
  330. Properties |= 1 << SDNPOptInGlue;
  331. } else if (PropList[i]->getName() == "SDNPMayStore") {
  332. Properties |= 1 << SDNPMayStore;
  333. } else if (PropList[i]->getName() == "SDNPMayLoad") {
  334. Properties |= 1 << SDNPMayLoad;
  335. } else if (PropList[i]->getName() == "SDNPSideEffect") {
  336. Properties |= 1 << SDNPSideEffect;
  337. } else if (PropList[i]->getName() == "SDNPMemOperand") {
  338. Properties |= 1 << SDNPMemOperand;
  339. } else if (PropList[i]->getName() == "SDNPVariadic") {
  340. Properties |= 1 << SDNPVariadic;
  341. } else if (PropList[i]->getName() == "SDNPWantRoot") {
  342. Properties |= 1 << SDNPWantRoot;
  343. } else if (PropList[i]->getName() == "SDNPWantParent") {
  344. Properties |= 1 << SDNPWantParent;
  345. } else {
  346. errs() << "Unsupported SD Node property '" << PropList[i]->getName()
  347. << "' on ComplexPattern '" << R->getName() << "'!\n";
  348. exit(1);
  349. }
  350. }
  351. //===----------------------------------------------------------------------===//
  352. // CodeGenIntrinsic Implementation
  353. //===----------------------------------------------------------------------===//
  354. std::vector<CodeGenIntrinsic> llvm::LoadIntrinsics(const RecordKeeper &RC,
  355. bool TargetOnly) {
  356. std::vector<Record*> I = RC.getAllDerivedDefinitions("Intrinsic");
  357. std::vector<CodeGenIntrinsic> Result;
  358. for (unsigned i = 0, e = I.size(); i != e; ++i) {
  359. bool isTarget = I[i]->getValueAsBit("isTarget");
  360. if (isTarget == TargetOnly)
  361. Result.push_back(CodeGenIntrinsic(I[i]));
  362. }
  363. return Result;
  364. }
  365. CodeGenIntrinsic::CodeGenIntrinsic(Record *R) {
  366. TheDef = R;
  367. std::string DefName = R->getName();
  368. ModRef = ReadWriteMem;
  369. isOverloaded = false;
  370. isCommutative = false;
  371. canThrow = false;
  372. isNoReturn = false;
  373. if (DefName.size() <= 4 ||
  374. std::string(DefName.begin(), DefName.begin() + 4) != "int_")
  375. PrintFatalError("Intrinsic '" + DefName + "' does not start with 'int_'!");
  376. EnumName = std::string(DefName.begin()+4, DefName.end());
  377. if (R->getValue("GCCBuiltinName")) // Ignore a missing GCCBuiltinName field.
  378. GCCBuiltinName = R->getValueAsString("GCCBuiltinName");
  379. TargetPrefix = R->getValueAsString("TargetPrefix");
  380. Name = R->getValueAsString("LLVMName");
  381. if (Name == "") {
  382. // If an explicit name isn't specified, derive one from the DefName.
  383. Name = "llvm.";
  384. for (unsigned i = 0, e = EnumName.size(); i != e; ++i)
  385. Name += (EnumName[i] == '_') ? '.' : EnumName[i];
  386. } else {
  387. // Verify it starts with "llvm.".
  388. if (Name.size() <= 5 ||
  389. std::string(Name.begin(), Name.begin() + 5) != "llvm.")
  390. PrintFatalError("Intrinsic '" + DefName + "'s name does not start with 'llvm.'!");
  391. }
  392. // If TargetPrefix is specified, make sure that Name starts with
  393. // "llvm.<targetprefix>.".
  394. if (!TargetPrefix.empty()) {
  395. if (Name.size() < 6+TargetPrefix.size() ||
  396. std::string(Name.begin() + 5, Name.begin() + 6 + TargetPrefix.size())
  397. != (TargetPrefix + "."))
  398. PrintFatalError("Intrinsic '" + DefName + "' does not start with 'llvm." +
  399. TargetPrefix + ".'!");
  400. }
  401. // Parse the list of return types.
  402. std::vector<MVT::SimpleValueType> OverloadedVTs;
  403. ListInit *TypeList = R->getValueAsListInit("RetTypes");
  404. for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
  405. Record *TyEl = TypeList->getElementAsRecord(i);
  406. assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
  407. MVT::SimpleValueType VT;
  408. if (TyEl->isSubClassOf("LLVMMatchType")) {
  409. unsigned MatchTy = TyEl->getValueAsInt("Number");
  410. assert(MatchTy < OverloadedVTs.size() &&
  411. "Invalid matching number!");
  412. VT = OverloadedVTs[MatchTy];
  413. // It only makes sense to use the extended and truncated vector element
  414. // variants with iAny types; otherwise, if the intrinsic is not
  415. // overloaded, all the types can be specified directly.
  416. assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
  417. !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
  418. VT == MVT::iAny || VT == MVT::vAny) &&
  419. "Expected iAny or vAny type");
  420. } else {
  421. VT = getValueType(TyEl->getValueAsDef("VT"));
  422. }
  423. if (EVT(VT).isOverloaded()) {
  424. OverloadedVTs.push_back(VT);
  425. isOverloaded = true;
  426. }
  427. // Reject invalid types.
  428. if (VT == MVT::isVoid)
  429. PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
  430. IS.RetVTs.push_back(VT);
  431. IS.RetTypeDefs.push_back(TyEl);
  432. }
  433. // Parse the list of parameter types.
  434. TypeList = R->getValueAsListInit("ParamTypes");
  435. for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
  436. Record *TyEl = TypeList->getElementAsRecord(i);
  437. assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
  438. MVT::SimpleValueType VT;
  439. if (TyEl->isSubClassOf("LLVMMatchType")) {
  440. unsigned MatchTy = TyEl->getValueAsInt("Number");
  441. assert(MatchTy < OverloadedVTs.size() &&
  442. "Invalid matching number!");
  443. VT = OverloadedVTs[MatchTy];
  444. // It only makes sense to use the extended and truncated vector element
  445. // variants with iAny types; otherwise, if the intrinsic is not
  446. // overloaded, all the types can be specified directly.
  447. assert(((!TyEl->isSubClassOf("LLVMExtendedElementVectorType") &&
  448. !TyEl->isSubClassOf("LLVMTruncatedElementVectorType")) ||
  449. VT == MVT::iAny || VT == MVT::vAny) &&
  450. "Expected iAny or vAny type");
  451. } else
  452. VT = getValueType(TyEl->getValueAsDef("VT"));
  453. if (EVT(VT).isOverloaded()) {
  454. OverloadedVTs.push_back(VT);
  455. isOverloaded = true;
  456. }
  457. // Reject invalid types.
  458. if (VT == MVT::isVoid && i != e-1 /*void at end means varargs*/)
  459. PrintFatalError("Intrinsic '" + DefName + " has void in result type list!");
  460. IS.ParamVTs.push_back(VT);
  461. IS.ParamTypeDefs.push_back(TyEl);
  462. }
  463. // Parse the intrinsic properties.
  464. ListInit *PropList = R->getValueAsListInit("Properties");
  465. for (unsigned i = 0, e = PropList->getSize(); i != e; ++i) {
  466. Record *Property = PropList->getElementAsRecord(i);
  467. assert(Property->isSubClassOf("IntrinsicProperty") &&
  468. "Expected a property!");
  469. if (Property->getName() == "IntrNoMem")
  470. ModRef = NoMem;
  471. else if (Property->getName() == "IntrReadArgMem")
  472. ModRef = ReadArgMem;
  473. else if (Property->getName() == "IntrReadMem")
  474. ModRef = ReadMem;
  475. else if (Property->getName() == "IntrReadWriteArgMem")
  476. ModRef = ReadWriteArgMem;
  477. else if (Property->getName() == "Commutative")
  478. isCommutative = true;
  479. else if (Property->getName() == "Throws")
  480. canThrow = true;
  481. else if (Property->getName() == "IntrNoReturn")
  482. isNoReturn = true;
  483. else if (Property->isSubClassOf("NoCapture")) {
  484. unsigned ArgNo = Property->getValueAsInt("ArgNo");
  485. ArgumentAttributes.push_back(std::make_pair(ArgNo, NoCapture));
  486. } else
  487. llvm_unreachable("Unknown property!");
  488. }
  489. // Sort the argument attributes for later benefit.
  490. std::sort(ArgumentAttributes.begin(), ArgumentAttributes.end());
  491. }