MIParser.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //===- MIParser.cpp - Machine instructions parser implementation ----------===//
  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 file implements the parsing of machine instructions.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "MIParser.h"
  14. #include "MILexer.h"
  15. #include "llvm/ADT/StringMap.h"
  16. #include "llvm/AsmParser/SlotMapping.h"
  17. #include "llvm/CodeGen/MachineBasicBlock.h"
  18. #include "llvm/CodeGen/MachineFunction.h"
  19. #include "llvm/CodeGen/MachineInstr.h"
  20. #include "llvm/CodeGen/MachineInstrBuilder.h"
  21. #include "llvm/IR/Module.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include "llvm/Support/SourceMgr.h"
  24. #include "llvm/Target/TargetSubtargetInfo.h"
  25. #include "llvm/Target/TargetInstrInfo.h"
  26. using namespace llvm;
  27. namespace {
  28. /// A wrapper struct around the 'MachineOperand' struct that includes a source
  29. /// range.
  30. struct MachineOperandWithLocation {
  31. MachineOperand Operand;
  32. StringRef::iterator Begin;
  33. StringRef::iterator End;
  34. MachineOperandWithLocation(const MachineOperand &Operand,
  35. StringRef::iterator Begin, StringRef::iterator End)
  36. : Operand(Operand), Begin(Begin), End(End) {}
  37. };
  38. class MIParser {
  39. SourceMgr &SM;
  40. MachineFunction &MF;
  41. SMDiagnostic &Error;
  42. StringRef Source, CurrentSource;
  43. MIToken Token;
  44. const PerFunctionMIParsingState &PFS;
  45. /// Maps from indices to unnamed global values and metadata nodes.
  46. const SlotMapping &IRSlots;
  47. /// Maps from instruction names to op codes.
  48. StringMap<unsigned> Names2InstrOpCodes;
  49. /// Maps from register names to registers.
  50. StringMap<unsigned> Names2Regs;
  51. /// Maps from register mask names to register masks.
  52. StringMap<const uint32_t *> Names2RegMasks;
  53. /// Maps from subregister names to subregister indices.
  54. StringMap<unsigned> Names2SubRegIndices;
  55. public:
  56. MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error,
  57. StringRef Source, const PerFunctionMIParsingState &PFS,
  58. const SlotMapping &IRSlots);
  59. void lex();
  60. /// Report an error at the current location with the given message.
  61. ///
  62. /// This function always return true.
  63. bool error(const Twine &Msg);
  64. /// Report an error at the given location with the given message.
  65. ///
  66. /// This function always return true.
  67. bool error(StringRef::iterator Loc, const Twine &Msg);
  68. bool parse(MachineInstr *&MI);
  69. bool parseMBB(MachineBasicBlock *&MBB);
  70. bool parseNamedRegister(unsigned &Reg);
  71. bool parseRegister(unsigned &Reg);
  72. bool parseRegisterFlag(unsigned &Flags);
  73. bool parseSubRegisterIndex(unsigned &SubReg);
  74. bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false);
  75. bool parseImmediateOperand(MachineOperand &Dest);
  76. bool parseMBBReference(MachineBasicBlock *&MBB);
  77. bool parseMBBOperand(MachineOperand &Dest);
  78. bool parseGlobalAddressOperand(MachineOperand &Dest);
  79. bool parseMachineOperand(MachineOperand &Dest);
  80. private:
  81. /// Convert the integer literal in the current token into an unsigned integer.
  82. ///
  83. /// Return true if an error occurred.
  84. bool getUnsigned(unsigned &Result);
  85. void initNames2InstrOpCodes();
  86. /// Try to convert an instruction name to an opcode. Return true if the
  87. /// instruction name is invalid.
  88. bool parseInstrName(StringRef InstrName, unsigned &OpCode);
  89. bool parseInstruction(unsigned &OpCode);
  90. bool verifyImplicitOperands(ArrayRef<MachineOperandWithLocation> Operands,
  91. const MCInstrDesc &MCID);
  92. void initNames2Regs();
  93. /// Try to convert a register name to a register number. Return true if the
  94. /// register name is invalid.
  95. bool getRegisterByName(StringRef RegName, unsigned &Reg);
  96. void initNames2RegMasks();
  97. /// Check if the given identifier is a name of a register mask.
  98. ///
  99. /// Return null if the identifier isn't a register mask.
  100. const uint32_t *getRegMask(StringRef Identifier);
  101. void initNames2SubRegIndices();
  102. /// Check if the given identifier is a name of a subregister index.
  103. ///
  104. /// Return 0 if the name isn't a subregister index class.
  105. unsigned getSubRegIndex(StringRef Name);
  106. };
  107. } // end anonymous namespace
  108. MIParser::MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error,
  109. StringRef Source, const PerFunctionMIParsingState &PFS,
  110. const SlotMapping &IRSlots)
  111. : SM(SM), MF(MF), Error(Error), Source(Source), CurrentSource(Source),
  112. Token(MIToken::Error, StringRef()), PFS(PFS), IRSlots(IRSlots) {}
  113. void MIParser::lex() {
  114. CurrentSource = lexMIToken(
  115. CurrentSource, Token,
  116. [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); });
  117. }
  118. bool MIParser::error(const Twine &Msg) { return error(Token.location(), Msg); }
  119. bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) {
  120. assert(Loc >= Source.data() && Loc <= (Source.data() + Source.size()));
  121. Error = SMDiagnostic(
  122. SM, SMLoc(),
  123. SM.getMemoryBuffer(SM.getMainFileID())->getBufferIdentifier(), 1,
  124. Loc - Source.data(), SourceMgr::DK_Error, Msg.str(), Source, None, None);
  125. return true;
  126. }
  127. bool MIParser::parse(MachineInstr *&MI) {
  128. lex();
  129. // Parse any register operands before '='
  130. // TODO: Allow parsing of multiple operands before '='
  131. MachineOperand MO = MachineOperand::CreateImm(0);
  132. SmallVector<MachineOperandWithLocation, 8> Operands;
  133. if (Token.isRegister() || Token.isRegisterFlag()) {
  134. auto Loc = Token.location();
  135. if (parseRegisterOperand(MO, /*IsDef=*/true))
  136. return true;
  137. Operands.push_back(MachineOperandWithLocation(MO, Loc, Token.location()));
  138. if (Token.isNot(MIToken::equal))
  139. return error("expected '='");
  140. lex();
  141. }
  142. unsigned OpCode;
  143. if (Token.isError() || parseInstruction(OpCode))
  144. return true;
  145. // TODO: Parse the instruction flags and memory operands.
  146. // Parse the remaining machine operands.
  147. while (Token.isNot(MIToken::Eof)) {
  148. auto Loc = Token.location();
  149. if (parseMachineOperand(MO))
  150. return true;
  151. Operands.push_back(MachineOperandWithLocation(MO, Loc, Token.location()));
  152. if (Token.is(MIToken::Eof))
  153. break;
  154. if (Token.isNot(MIToken::comma))
  155. return error("expected ',' before the next machine operand");
  156. lex();
  157. }
  158. const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
  159. if (!MCID.isVariadic()) {
  160. // FIXME: Move the implicit operand verification to the machine verifier.
  161. if (verifyImplicitOperands(Operands, MCID))
  162. return true;
  163. }
  164. // TODO: Check for extraneous machine operands.
  165. MI = MF.CreateMachineInstr(MCID, DebugLoc(), /*NoImplicit=*/true);
  166. for (const auto &Operand : Operands)
  167. MI->addOperand(MF, Operand.Operand);
  168. return false;
  169. }
  170. bool MIParser::parseMBB(MachineBasicBlock *&MBB) {
  171. lex();
  172. if (Token.isNot(MIToken::MachineBasicBlock))
  173. return error("expected a machine basic block reference");
  174. if (parseMBBReference(MBB))
  175. return true;
  176. lex();
  177. if (Token.isNot(MIToken::Eof))
  178. return error(
  179. "expected end of string after the machine basic block reference");
  180. return false;
  181. }
  182. bool MIParser::parseNamedRegister(unsigned &Reg) {
  183. lex();
  184. if (Token.isNot(MIToken::NamedRegister))
  185. return error("expected a named register");
  186. if (parseRegister(Reg))
  187. return 0;
  188. lex();
  189. if (Token.isNot(MIToken::Eof))
  190. return error("expected end of string after the register reference");
  191. return false;
  192. }
  193. static const char *printImplicitRegisterFlag(const MachineOperand &MO) {
  194. assert(MO.isImplicit());
  195. return MO.isDef() ? "implicit-def" : "implicit";
  196. }
  197. static std::string getRegisterName(const TargetRegisterInfo *TRI,
  198. unsigned Reg) {
  199. assert(TargetRegisterInfo::isPhysicalRegister(Reg) && "expected phys reg");
  200. return StringRef(TRI->getName(Reg)).lower();
  201. }
  202. bool MIParser::verifyImplicitOperands(
  203. ArrayRef<MachineOperandWithLocation> Operands, const MCInstrDesc &MCID) {
  204. if (MCID.isCall())
  205. // We can't verify call instructions as they can contain arbitrary implicit
  206. // register and register mask operands.
  207. return false;
  208. // Gather all the expected implicit operands.
  209. SmallVector<MachineOperand, 4> ImplicitOperands;
  210. if (MCID.ImplicitDefs)
  211. for (const uint16_t *ImpDefs = MCID.getImplicitDefs(); *ImpDefs; ++ImpDefs)
  212. ImplicitOperands.push_back(
  213. MachineOperand::CreateReg(*ImpDefs, true, true));
  214. if (MCID.ImplicitUses)
  215. for (const uint16_t *ImpUses = MCID.getImplicitUses(); *ImpUses; ++ImpUses)
  216. ImplicitOperands.push_back(
  217. MachineOperand::CreateReg(*ImpUses, false, true));
  218. const auto *TRI = MF.getSubtarget().getRegisterInfo();
  219. assert(TRI && "Expected target register info");
  220. size_t I = ImplicitOperands.size(), J = Operands.size();
  221. while (I) {
  222. --I;
  223. if (J) {
  224. --J;
  225. const auto &ImplicitOperand = ImplicitOperands[I];
  226. const auto &Operand = Operands[J].Operand;
  227. if (ImplicitOperand.isIdenticalTo(Operand))
  228. continue;
  229. if (Operand.isReg() && Operand.isImplicit()) {
  230. return error(Operands[J].Begin,
  231. Twine("expected an implicit register operand '") +
  232. printImplicitRegisterFlag(ImplicitOperand) + " %" +
  233. getRegisterName(TRI, ImplicitOperand.getReg()) + "'");
  234. }
  235. }
  236. // TODO: Fix source location when Operands[J].end is right before '=', i.e:
  237. // insead of reporting an error at this location:
  238. // %eax = MOV32r0
  239. // ^
  240. // report the error at the following location:
  241. // %eax = MOV32r0
  242. // ^
  243. return error(J < Operands.size() ? Operands[J].End : Token.location(),
  244. Twine("missing implicit register operand '") +
  245. printImplicitRegisterFlag(ImplicitOperands[I]) + " %" +
  246. getRegisterName(TRI, ImplicitOperands[I].getReg()) + "'");
  247. }
  248. return false;
  249. }
  250. bool MIParser::parseInstruction(unsigned &OpCode) {
  251. if (Token.isNot(MIToken::Identifier))
  252. return error("expected a machine instruction");
  253. StringRef InstrName = Token.stringValue();
  254. if (parseInstrName(InstrName, OpCode))
  255. return error(Twine("unknown machine instruction name '") + InstrName + "'");
  256. lex();
  257. return false;
  258. }
  259. bool MIParser::parseRegister(unsigned &Reg) {
  260. switch (Token.kind()) {
  261. case MIToken::underscore:
  262. Reg = 0;
  263. break;
  264. case MIToken::NamedRegister: {
  265. StringRef Name = Token.stringValue();
  266. if (getRegisterByName(Name, Reg))
  267. return error(Twine("unknown register name '") + Name + "'");
  268. break;
  269. }
  270. case MIToken::VirtualRegister: {
  271. unsigned ID;
  272. if (getUnsigned(ID))
  273. return true;
  274. const auto RegInfo = PFS.VirtualRegisterSlots.find(ID);
  275. if (RegInfo == PFS.VirtualRegisterSlots.end())
  276. return error(Twine("use of undefined virtual register '%") + Twine(ID) +
  277. "'");
  278. Reg = RegInfo->second;
  279. break;
  280. }
  281. // TODO: Parse other register kinds.
  282. default:
  283. llvm_unreachable("The current token should be a register");
  284. }
  285. return false;
  286. }
  287. bool MIParser::parseRegisterFlag(unsigned &Flags) {
  288. switch (Token.kind()) {
  289. case MIToken::kw_implicit:
  290. Flags |= RegState::Implicit;
  291. break;
  292. case MIToken::kw_implicit_define:
  293. Flags |= RegState::ImplicitDefine;
  294. break;
  295. case MIToken::kw_dead:
  296. Flags |= RegState::Dead;
  297. break;
  298. case MIToken::kw_killed:
  299. Flags |= RegState::Kill;
  300. break;
  301. case MIToken::kw_undef:
  302. Flags |= RegState::Undef;
  303. break;
  304. // TODO: report an error when we specify the same flag more than once.
  305. // TODO: parse the other register flags.
  306. default:
  307. llvm_unreachable("The current token should be a register flag");
  308. }
  309. lex();
  310. return false;
  311. }
  312. bool MIParser::parseSubRegisterIndex(unsigned &SubReg) {
  313. assert(Token.is(MIToken::colon));
  314. lex();
  315. if (Token.isNot(MIToken::Identifier))
  316. return error("expected a subregister index after ':'");
  317. auto Name = Token.stringValue();
  318. SubReg = getSubRegIndex(Name);
  319. if (!SubReg)
  320. return error(Twine("use of unknown subregister index '") + Name + "'");
  321. lex();
  322. return false;
  323. }
  324. bool MIParser::parseRegisterOperand(MachineOperand &Dest, bool IsDef) {
  325. unsigned Reg;
  326. unsigned Flags = IsDef ? RegState::Define : 0;
  327. while (Token.isRegisterFlag()) {
  328. if (parseRegisterFlag(Flags))
  329. return true;
  330. }
  331. if (!Token.isRegister())
  332. return error("expected a register after register flags");
  333. if (parseRegister(Reg))
  334. return true;
  335. lex();
  336. unsigned SubReg = 0;
  337. if (Token.is(MIToken::colon)) {
  338. if (parseSubRegisterIndex(SubReg))
  339. return true;
  340. }
  341. Dest = MachineOperand::CreateReg(
  342. Reg, Flags & RegState::Define, Flags & RegState::Implicit,
  343. Flags & RegState::Kill, Flags & RegState::Dead, Flags & RegState::Undef,
  344. /*isEarlyClobber=*/false, SubReg);
  345. return false;
  346. }
  347. bool MIParser::parseImmediateOperand(MachineOperand &Dest) {
  348. assert(Token.is(MIToken::IntegerLiteral));
  349. const APSInt &Int = Token.integerValue();
  350. if (Int.getMinSignedBits() > 64)
  351. // TODO: Replace this with an error when we can parse CIMM Machine Operands.
  352. llvm_unreachable("Can't parse large integer literals yet!");
  353. Dest = MachineOperand::CreateImm(Int.getExtValue());
  354. lex();
  355. return false;
  356. }
  357. bool MIParser::getUnsigned(unsigned &Result) {
  358. assert(Token.hasIntegerValue() && "Expected a token with an integer value");
  359. const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1;
  360. uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
  361. if (Val64 == Limit)
  362. return error("expected 32-bit integer (too large)");
  363. Result = Val64;
  364. return false;
  365. }
  366. bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {
  367. assert(Token.is(MIToken::MachineBasicBlock));
  368. unsigned Number;
  369. if (getUnsigned(Number))
  370. return true;
  371. auto MBBInfo = PFS.MBBSlots.find(Number);
  372. if (MBBInfo == PFS.MBBSlots.end())
  373. return error(Twine("use of undefined machine basic block #") +
  374. Twine(Number));
  375. MBB = MBBInfo->second;
  376. if (!Token.stringValue().empty() && Token.stringValue() != MBB->getName())
  377. return error(Twine("the name of machine basic block #") + Twine(Number) +
  378. " isn't '" + Token.stringValue() + "'");
  379. return false;
  380. }
  381. bool MIParser::parseMBBOperand(MachineOperand &Dest) {
  382. MachineBasicBlock *MBB;
  383. if (parseMBBReference(MBB))
  384. return true;
  385. Dest = MachineOperand::CreateMBB(MBB);
  386. lex();
  387. return false;
  388. }
  389. bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
  390. switch (Token.kind()) {
  391. case MIToken::NamedGlobalValue: {
  392. auto Name = Token.stringValue();
  393. const Module *M = MF.getFunction()->getParent();
  394. if (const auto *GV = M->getNamedValue(Name)) {
  395. Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
  396. break;
  397. }
  398. return error(Twine("use of undefined global value '@") + Name + "'");
  399. }
  400. case MIToken::GlobalValue: {
  401. unsigned GVIdx;
  402. if (getUnsigned(GVIdx))
  403. return true;
  404. if (GVIdx >= IRSlots.GlobalValues.size())
  405. return error(Twine("use of undefined global value '@") + Twine(GVIdx) +
  406. "'");
  407. Dest = MachineOperand::CreateGA(IRSlots.GlobalValues[GVIdx],
  408. /*Offset=*/0);
  409. break;
  410. }
  411. default:
  412. llvm_unreachable("The current token should be a global value");
  413. }
  414. // TODO: Parse offset and target flags.
  415. lex();
  416. return false;
  417. }
  418. bool MIParser::parseMachineOperand(MachineOperand &Dest) {
  419. switch (Token.kind()) {
  420. case MIToken::kw_implicit:
  421. case MIToken::kw_implicit_define:
  422. case MIToken::kw_dead:
  423. case MIToken::kw_killed:
  424. case MIToken::kw_undef:
  425. case MIToken::underscore:
  426. case MIToken::NamedRegister:
  427. case MIToken::VirtualRegister:
  428. return parseRegisterOperand(Dest);
  429. case MIToken::IntegerLiteral:
  430. return parseImmediateOperand(Dest);
  431. case MIToken::MachineBasicBlock:
  432. return parseMBBOperand(Dest);
  433. case MIToken::GlobalValue:
  434. case MIToken::NamedGlobalValue:
  435. return parseGlobalAddressOperand(Dest);
  436. case MIToken::Error:
  437. return true;
  438. case MIToken::Identifier:
  439. if (const auto *RegMask = getRegMask(Token.stringValue())) {
  440. Dest = MachineOperand::CreateRegMask(RegMask);
  441. lex();
  442. break;
  443. }
  444. // fallthrough
  445. default:
  446. // TODO: parse the other machine operands.
  447. return error("expected a machine operand");
  448. }
  449. return false;
  450. }
  451. void MIParser::initNames2InstrOpCodes() {
  452. if (!Names2InstrOpCodes.empty())
  453. return;
  454. const auto *TII = MF.getSubtarget().getInstrInfo();
  455. assert(TII && "Expected target instruction info");
  456. for (unsigned I = 0, E = TII->getNumOpcodes(); I < E; ++I)
  457. Names2InstrOpCodes.insert(std::make_pair(StringRef(TII->getName(I)), I));
  458. }
  459. bool MIParser::parseInstrName(StringRef InstrName, unsigned &OpCode) {
  460. initNames2InstrOpCodes();
  461. auto InstrInfo = Names2InstrOpCodes.find(InstrName);
  462. if (InstrInfo == Names2InstrOpCodes.end())
  463. return true;
  464. OpCode = InstrInfo->getValue();
  465. return false;
  466. }
  467. void MIParser::initNames2Regs() {
  468. if (!Names2Regs.empty())
  469. return;
  470. // The '%noreg' register is the register 0.
  471. Names2Regs.insert(std::make_pair("noreg", 0));
  472. const auto *TRI = MF.getSubtarget().getRegisterInfo();
  473. assert(TRI && "Expected target register info");
  474. for (unsigned I = 0, E = TRI->getNumRegs(); I < E; ++I) {
  475. bool WasInserted =
  476. Names2Regs.insert(std::make_pair(StringRef(TRI->getName(I)).lower(), I))
  477. .second;
  478. (void)WasInserted;
  479. assert(WasInserted && "Expected registers to be unique case-insensitively");
  480. }
  481. }
  482. bool MIParser::getRegisterByName(StringRef RegName, unsigned &Reg) {
  483. initNames2Regs();
  484. auto RegInfo = Names2Regs.find(RegName);
  485. if (RegInfo == Names2Regs.end())
  486. return true;
  487. Reg = RegInfo->getValue();
  488. return false;
  489. }
  490. void MIParser::initNames2RegMasks() {
  491. if (!Names2RegMasks.empty())
  492. return;
  493. const auto *TRI = MF.getSubtarget().getRegisterInfo();
  494. assert(TRI && "Expected target register info");
  495. ArrayRef<const uint32_t *> RegMasks = TRI->getRegMasks();
  496. ArrayRef<const char *> RegMaskNames = TRI->getRegMaskNames();
  497. assert(RegMasks.size() == RegMaskNames.size());
  498. for (size_t I = 0, E = RegMasks.size(); I < E; ++I)
  499. Names2RegMasks.insert(
  500. std::make_pair(StringRef(RegMaskNames[I]).lower(), RegMasks[I]));
  501. }
  502. const uint32_t *MIParser::getRegMask(StringRef Identifier) {
  503. initNames2RegMasks();
  504. auto RegMaskInfo = Names2RegMasks.find(Identifier);
  505. if (RegMaskInfo == Names2RegMasks.end())
  506. return nullptr;
  507. return RegMaskInfo->getValue();
  508. }
  509. void MIParser::initNames2SubRegIndices() {
  510. if (!Names2SubRegIndices.empty())
  511. return;
  512. const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
  513. for (unsigned I = 1, E = TRI->getNumSubRegIndices(); I < E; ++I)
  514. Names2SubRegIndices.insert(
  515. std::make_pair(StringRef(TRI->getSubRegIndexName(I)).lower(), I));
  516. }
  517. unsigned MIParser::getSubRegIndex(StringRef Name) {
  518. initNames2SubRegIndices();
  519. auto SubRegInfo = Names2SubRegIndices.find(Name);
  520. if (SubRegInfo == Names2SubRegIndices.end())
  521. return 0;
  522. return SubRegInfo->getValue();
  523. }
  524. bool llvm::parseMachineInstr(MachineInstr *&MI, SourceMgr &SM,
  525. MachineFunction &MF, StringRef Src,
  526. const PerFunctionMIParsingState &PFS,
  527. const SlotMapping &IRSlots, SMDiagnostic &Error) {
  528. return MIParser(SM, MF, Error, Src, PFS, IRSlots).parse(MI);
  529. }
  530. bool llvm::parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
  531. MachineFunction &MF, StringRef Src,
  532. const PerFunctionMIParsingState &PFS,
  533. const SlotMapping &IRSlots, SMDiagnostic &Error) {
  534. return MIParser(SM, MF, Error, Src, PFS, IRSlots).parseMBB(MBB);
  535. }
  536. bool llvm::parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
  537. MachineFunction &MF, StringRef Src,
  538. const PerFunctionMIParsingState &PFS,
  539. const SlotMapping &IRSlots,
  540. SMDiagnostic &Error) {
  541. return MIParser(SM, MF, Error, Src, PFS, IRSlots).parseNamedRegister(Reg);
  542. }