blob: c71cdbb6d6f62551850fabb42ad2b0b0fdfdb2dd [file] [log] [blame]
Alex Lorenz8e0a1b42015-06-22 17:02:30 +00001//===- 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
14#include "MIParser.h"
Alex Lorenz91370c52015-06-22 20:37:46 +000015#include "MILexer.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000016#include "llvm/ADT/StringMap.h"
Alex Lorenzad156fb2015-07-31 20:49:21 +000017#include "llvm/AsmParser/Parser.h"
Alex Lorenz5d6108e2015-06-26 22:56:48 +000018#include "llvm/AsmParser/SlotMapping.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000019#include "llvm/CodeGen/MachineBasicBlock.h"
20#include "llvm/CodeGen/MachineFunction.h"
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000021#include "llvm/CodeGen/MachineFrameInfo.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000022#include "llvm/CodeGen/MachineInstr.h"
Alex Lorenzcb268d42015-07-06 23:07:26 +000023#include "llvm/CodeGen/MachineInstrBuilder.h"
Alex Lorenz4af7e612015-08-03 23:08:19 +000024#include "llvm/CodeGen/MachineMemOperand.h"
Alex Lorenzf4baeb52015-07-21 22:28:27 +000025#include "llvm/CodeGen/MachineModuleInfo.h"
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000026#include "llvm/IR/Instructions.h"
Alex Lorenzdeb53492015-07-28 17:28:03 +000027#include "llvm/IR/Constants.h"
Alex Lorenz5d6108e2015-06-26 22:56:48 +000028#include "llvm/IR/Module.h"
Alex Lorenz8a1915b2015-07-27 22:42:41 +000029#include "llvm/IR/ModuleSlotTracker.h"
Alex Lorenzdeb53492015-07-28 17:28:03 +000030#include "llvm/IR/ValueSymbolTable.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000031#include "llvm/Support/raw_ostream.h"
32#include "llvm/Support/SourceMgr.h"
33#include "llvm/Target/TargetSubtargetInfo.h"
34#include "llvm/Target/TargetInstrInfo.h"
35
36using namespace llvm;
37
38namespace {
39
Alex Lorenz36962cd2015-07-07 02:08:46 +000040/// A wrapper struct around the 'MachineOperand' struct that includes a source
41/// range.
42struct MachineOperandWithLocation {
43 MachineOperand Operand;
44 StringRef::iterator Begin;
45 StringRef::iterator End;
46
47 MachineOperandWithLocation(const MachineOperand &Operand,
48 StringRef::iterator Begin, StringRef::iterator End)
49 : Operand(Operand), Begin(Begin), End(End) {}
50};
51
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000052class MIParser {
53 SourceMgr &SM;
54 MachineFunction &MF;
55 SMDiagnostic &Error;
Alex Lorenz91370c52015-06-22 20:37:46 +000056 StringRef Source, CurrentSource;
57 MIToken Token;
Alex Lorenz7a503fa2015-07-07 17:46:43 +000058 const PerFunctionMIParsingState &PFS;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000059 /// Maps from indices to unnamed global values and metadata nodes.
60 const SlotMapping &IRSlots;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000061 /// Maps from instruction names to op codes.
62 StringMap<unsigned> Names2InstrOpCodes;
Alex Lorenzf3db51de2015-06-23 16:35:26 +000063 /// Maps from register names to registers.
64 StringMap<unsigned> Names2Regs;
Alex Lorenz8f6f4282015-06-29 16:57:06 +000065 /// Maps from register mask names to register masks.
66 StringMap<const uint32_t *> Names2RegMasks;
Alex Lorenz2eacca82015-07-13 23:24:34 +000067 /// Maps from subregister names to subregister indices.
68 StringMap<unsigned> Names2SubRegIndices;
Alex Lorenz8a1915b2015-07-27 22:42:41 +000069 /// Maps from slot numbers to function's unnamed basic blocks.
70 DenseMap<unsigned, const BasicBlock *> Slots2BasicBlocks;
Alex Lorenzef5c1962015-07-28 23:02:45 +000071 /// Maps from target index names to target indices.
72 StringMap<int> Names2TargetIndices;
Alex Lorenz49873a82015-08-06 00:44:07 +000073 /// Maps from direct target flag names to the direct target flag values.
74 StringMap<unsigned> Names2DirectTargetFlags;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000075
76public:
77 MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error,
Alex Lorenz7a503fa2015-07-07 17:46:43 +000078 StringRef Source, const PerFunctionMIParsingState &PFS,
Alex Lorenz5d6108e2015-06-26 22:56:48 +000079 const SlotMapping &IRSlots);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000080
Alex Lorenz91370c52015-06-22 20:37:46 +000081 void lex();
82
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000083 /// Report an error at the current location with the given message.
84 ///
85 /// This function always return true.
86 bool error(const Twine &Msg);
87
Alex Lorenz91370c52015-06-22 20:37:46 +000088 /// Report an error at the given location with the given message.
89 ///
90 /// This function always return true.
91 bool error(StringRef::iterator Loc, const Twine &Msg);
92
Alex Lorenz3708a642015-06-30 17:47:50 +000093 bool parse(MachineInstr *&MI);
Alex Lorenz1ea60892015-07-27 20:29:27 +000094 bool parseStandaloneMBB(MachineBasicBlock *&MBB);
95 bool parseStandaloneNamedRegister(unsigned &Reg);
Alex Lorenz12045a42015-07-27 17:42:45 +000096 bool parseStandaloneVirtualRegister(unsigned &Reg);
Alex Lorenz8a1915b2015-07-27 22:42:41 +000097 bool parseStandaloneIRBlockReference(const BasicBlock *&BB);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000098
Alex Lorenzf3db51de2015-06-23 16:35:26 +000099 bool parseRegister(unsigned &Reg);
Alex Lorenzcb268d42015-07-06 23:07:26 +0000100 bool parseRegisterFlag(unsigned &Flags);
Alex Lorenz2eacca82015-07-13 23:24:34 +0000101 bool parseSubRegisterIndex(unsigned &SubReg);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000102 bool parseRegisterOperand(MachineOperand &Dest, bool IsDef = false);
Alex Lorenz240fc1e2015-06-23 23:42:28 +0000103 bool parseImmediateOperand(MachineOperand &Dest);
Alex Lorenz7eaff4c2015-08-05 18:44:00 +0000104 bool parseIRConstant(StringRef::iterator Loc, const Constant *&C);
Alex Lorenz05e38822015-08-05 18:52:21 +0000105 bool parseTypedImmediateOperand(MachineOperand &Dest);
Alex Lorenzad156fb2015-07-31 20:49:21 +0000106 bool parseFPImmediateOperand(MachineOperand &Dest);
Alex Lorenzf09df002015-06-30 18:16:42 +0000107 bool parseMBBReference(MachineBasicBlock *&MBB);
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000108 bool parseMBBOperand(MachineOperand &Dest);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000109 bool parseStackObjectOperand(MachineOperand &Dest);
110 bool parseFixedStackObjectOperand(MachineOperand &Dest);
Alex Lorenz41df7d32015-07-28 17:09:52 +0000111 bool parseGlobalValue(GlobalValue *&GV);
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000112 bool parseGlobalAddressOperand(MachineOperand &Dest);
Alex Lorenzab980492015-07-20 20:51:18 +0000113 bool parseConstantPoolIndexOperand(MachineOperand &Dest);
Alex Lorenz31d70682015-07-15 23:38:35 +0000114 bool parseJumpTableIndexOperand(MachineOperand &Dest);
Alex Lorenz6ede3742015-07-21 16:59:53 +0000115 bool parseExternalSymbolOperand(MachineOperand &Dest);
Alex Lorenz44f29252015-07-22 21:07:04 +0000116 bool parseMDNode(MDNode *&Node);
Alex Lorenz35e44462015-07-22 17:58:46 +0000117 bool parseMetadataOperand(MachineOperand &Dest);
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000118 bool parseCFIOffset(int &Offset);
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000119 bool parseCFIRegister(unsigned &Reg);
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000120 bool parseCFIOperand(MachineOperand &Dest);
Alex Lorenzdeb53492015-07-28 17:28:03 +0000121 bool parseIRBlock(BasicBlock *&BB, const Function &F);
122 bool parseBlockAddressOperand(MachineOperand &Dest);
Alex Lorenzef5c1962015-07-28 23:02:45 +0000123 bool parseTargetIndexOperand(MachineOperand &Dest);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000124 bool parseMachineOperand(MachineOperand &Dest);
Alex Lorenz49873a82015-08-06 00:44:07 +0000125 bool parseMachineOperandAndTargetFlags(MachineOperand &Dest);
Alex Lorenz5672a892015-08-05 22:26:15 +0000126 bool parseOperandsOffset(MachineOperand &Op);
Alex Lorenz4af7e612015-08-03 23:08:19 +0000127 bool parseIRValue(Value *&V);
Alex Lorenza518b792015-08-04 00:24:45 +0000128 bool parseMemoryOperandFlag(unsigned &Flags);
Alex Lorenz4af7e612015-08-03 23:08:19 +0000129 bool parseMachineMemoryOperand(MachineMemOperand *&Dest);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000130
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000131private:
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000132 /// Convert the integer literal in the current token into an unsigned integer.
133 ///
134 /// Return true if an error occurred.
135 bool getUnsigned(unsigned &Result);
136
Alex Lorenz4af7e612015-08-03 23:08:19 +0000137 /// Convert the integer literal in the current token into an uint64.
138 ///
139 /// Return true if an error occurred.
140 bool getUint64(uint64_t &Result);
141
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000142 /// If the current token is of the given kind, consume it and return false.
143 /// Otherwise report an error and return true.
144 bool expectAndConsume(MIToken::TokenKind TokenKind);
145
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000146 void initNames2InstrOpCodes();
147
148 /// Try to convert an instruction name to an opcode. Return true if the
149 /// instruction name is invalid.
150 bool parseInstrName(StringRef InstrName, unsigned &OpCode);
Alex Lorenz91370c52015-06-22 20:37:46 +0000151
Alex Lorenze5a44662015-07-17 00:24:15 +0000152 bool parseInstruction(unsigned &OpCode, unsigned &Flags);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000153
Alex Lorenz36962cd2015-07-07 02:08:46 +0000154 bool verifyImplicitOperands(ArrayRef<MachineOperandWithLocation> Operands,
155 const MCInstrDesc &MCID);
156
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000157 void initNames2Regs();
158
159 /// Try to convert a register name to a register number. Return true if the
160 /// register name is invalid.
161 bool getRegisterByName(StringRef RegName, unsigned &Reg);
Alex Lorenz8f6f4282015-06-29 16:57:06 +0000162
163 void initNames2RegMasks();
164
165 /// Check if the given identifier is a name of a register mask.
166 ///
167 /// Return null if the identifier isn't a register mask.
168 const uint32_t *getRegMask(StringRef Identifier);
Alex Lorenz2eacca82015-07-13 23:24:34 +0000169
170 void initNames2SubRegIndices();
171
172 /// Check if the given identifier is a name of a subregister index.
173 ///
174 /// Return 0 if the name isn't a subregister index class.
175 unsigned getSubRegIndex(StringRef Name);
Alex Lorenz8a1915b2015-07-27 22:42:41 +0000176
Alex Lorenz8a1915b2015-07-27 22:42:41 +0000177 const BasicBlock *getIRBlock(unsigned Slot);
Alex Lorenzcba8c5f2015-08-06 23:57:04 +0000178 const BasicBlock *getIRBlock(unsigned Slot, const Function &F);
Alex Lorenzef5c1962015-07-28 23:02:45 +0000179
180 void initNames2TargetIndices();
181
182 /// Try to convert a name of target index to the corresponding target index.
183 ///
184 /// Return true if the name isn't a name of a target index.
185 bool getTargetIndex(StringRef Name, int &Index);
Alex Lorenz49873a82015-08-06 00:44:07 +0000186
187 void initNames2DirectTargetFlags();
188
189 /// Try to convert a name of a direct target flag to the corresponding
190 /// target flag.
191 ///
192 /// Return true if the name isn't a name of a direct flag.
193 bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000194};
195
196} // end anonymous namespace
197
198MIParser::MIParser(SourceMgr &SM, MachineFunction &MF, SMDiagnostic &Error,
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000199 StringRef Source, const PerFunctionMIParsingState &PFS,
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000200 const SlotMapping &IRSlots)
Alex Lorenz91370c52015-06-22 20:37:46 +0000201 : SM(SM), MF(MF), Error(Error), Source(Source), CurrentSource(Source),
Alex Lorenz3fb77682015-08-06 23:17:42 +0000202 PFS(PFS), IRSlots(IRSlots) {}
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000203
Alex Lorenz91370c52015-06-22 20:37:46 +0000204void MIParser::lex() {
205 CurrentSource = lexMIToken(
206 CurrentSource, Token,
207 [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); });
208}
209
210bool MIParser::error(const Twine &Msg) { return error(Token.location(), Msg); }
211
212bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) {
Alex Lorenz91370c52015-06-22 20:37:46 +0000213 assert(Loc >= Source.data() && Loc <= (Source.data() + Source.size()));
214 Error = SMDiagnostic(
215 SM, SMLoc(),
216 SM.getMemoryBuffer(SM.getMainFileID())->getBufferIdentifier(), 1,
217 Loc - Source.data(), SourceMgr::DK_Error, Msg.str(), Source, None, None);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000218 return true;
219}
220
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000221static const char *toString(MIToken::TokenKind TokenKind) {
222 switch (TokenKind) {
223 case MIToken::comma:
224 return "','";
Alex Lorenzfbe9c042015-07-29 18:51:21 +0000225 case MIToken::equal:
226 return "'='";
Alex Lorenzdeb53492015-07-28 17:28:03 +0000227 case MIToken::lparen:
228 return "'('";
229 case MIToken::rparen:
230 return "')'";
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000231 default:
232 return "<unknown token>";
233 }
234}
235
236bool MIParser::expectAndConsume(MIToken::TokenKind TokenKind) {
237 if (Token.isNot(TokenKind))
238 return error(Twine("expected ") + toString(TokenKind));
239 lex();
240 return false;
241}
242
Alex Lorenz3708a642015-06-30 17:47:50 +0000243bool MIParser::parse(MachineInstr *&MI) {
Alex Lorenz91370c52015-06-22 20:37:46 +0000244 lex();
245
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000246 // Parse any register operands before '='
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000247 MachineOperand MO = MachineOperand::CreateImm(0);
Alex Lorenz36962cd2015-07-07 02:08:46 +0000248 SmallVector<MachineOperandWithLocation, 8> Operands;
Alex Lorenzfbe9c042015-07-29 18:51:21 +0000249 while (Token.isRegister() || Token.isRegisterFlag()) {
Alex Lorenz36962cd2015-07-07 02:08:46 +0000250 auto Loc = Token.location();
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000251 if (parseRegisterOperand(MO, /*IsDef=*/true))
Alex Lorenz3708a642015-06-30 17:47:50 +0000252 return true;
Alex Lorenz36962cd2015-07-07 02:08:46 +0000253 Operands.push_back(MachineOperandWithLocation(MO, Loc, Token.location()));
Alex Lorenzfbe9c042015-07-29 18:51:21 +0000254 if (Token.isNot(MIToken::comma))
255 break;
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000256 lex();
257 }
Alex Lorenzfbe9c042015-07-29 18:51:21 +0000258 if (!Operands.empty() && expectAndConsume(MIToken::equal))
259 return true;
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000260
Alex Lorenze5a44662015-07-17 00:24:15 +0000261 unsigned OpCode, Flags = 0;
262 if (Token.isError() || parseInstruction(OpCode, Flags))
Alex Lorenz3708a642015-06-30 17:47:50 +0000263 return true;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000264
Alex Lorenz4af7e612015-08-03 23:08:19 +0000265 // TODO: Parse the bundle instruction flags.
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000266
267 // Parse the remaining machine operands.
Alex Lorenz4af7e612015-08-03 23:08:19 +0000268 while (Token.isNot(MIToken::Eof) && Token.isNot(MIToken::kw_debug_location) &&
269 Token.isNot(MIToken::coloncolon)) {
Alex Lorenz36962cd2015-07-07 02:08:46 +0000270 auto Loc = Token.location();
Alex Lorenz49873a82015-08-06 00:44:07 +0000271 if (parseMachineOperandAndTargetFlags(MO))
Alex Lorenz3708a642015-06-30 17:47:50 +0000272 return true;
Alex Lorenz36962cd2015-07-07 02:08:46 +0000273 Operands.push_back(MachineOperandWithLocation(MO, Loc, Token.location()));
Alex Lorenz4af7e612015-08-03 23:08:19 +0000274 if (Token.is(MIToken::Eof) || Token.is(MIToken::coloncolon))
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000275 break;
Alex Lorenz3708a642015-06-30 17:47:50 +0000276 if (Token.isNot(MIToken::comma))
277 return error("expected ',' before the next machine operand");
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000278 lex();
279 }
280
Alex Lorenz46d760d2015-07-22 21:15:11 +0000281 DebugLoc DebugLocation;
282 if (Token.is(MIToken::kw_debug_location)) {
283 lex();
284 if (Token.isNot(MIToken::exclaim))
285 return error("expected a metadata node after 'debug-location'");
286 MDNode *Node = nullptr;
287 if (parseMDNode(Node))
288 return true;
289 DebugLocation = DebugLoc(Node);
290 }
291
Alex Lorenz4af7e612015-08-03 23:08:19 +0000292 // Parse the machine memory operands.
293 SmallVector<MachineMemOperand *, 2> MemOperands;
294 if (Token.is(MIToken::coloncolon)) {
295 lex();
296 while (Token.isNot(MIToken::Eof)) {
297 MachineMemOperand *MemOp = nullptr;
298 if (parseMachineMemoryOperand(MemOp))
299 return true;
300 MemOperands.push_back(MemOp);
301 if (Token.is(MIToken::Eof))
302 break;
303 if (Token.isNot(MIToken::comma))
304 return error("expected ',' before the next machine memory operand");
305 lex();
306 }
307 }
308
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000309 const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
Alex Lorenz36962cd2015-07-07 02:08:46 +0000310 if (!MCID.isVariadic()) {
311 // FIXME: Move the implicit operand verification to the machine verifier.
312 if (verifyImplicitOperands(Operands, MCID))
313 return true;
314 }
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000315
Alex Lorenzcb268d42015-07-06 23:07:26 +0000316 // TODO: Check for extraneous machine operands.
Alex Lorenz46d760d2015-07-22 21:15:11 +0000317 MI = MF.CreateMachineInstr(MCID, DebugLocation, /*NoImplicit=*/true);
Alex Lorenze5a44662015-07-17 00:24:15 +0000318 MI->setFlags(Flags);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000319 for (const auto &Operand : Operands)
Alex Lorenz36962cd2015-07-07 02:08:46 +0000320 MI->addOperand(MF, Operand.Operand);
Alex Lorenz4af7e612015-08-03 23:08:19 +0000321 if (MemOperands.empty())
322 return false;
323 MachineInstr::mmo_iterator MemRefs =
324 MF.allocateMemRefsArray(MemOperands.size());
325 std::copy(MemOperands.begin(), MemOperands.end(), MemRefs);
326 MI->setMemRefs(MemRefs, MemRefs + MemOperands.size());
Alex Lorenz3708a642015-06-30 17:47:50 +0000327 return false;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000328}
329
Alex Lorenz1ea60892015-07-27 20:29:27 +0000330bool MIParser::parseStandaloneMBB(MachineBasicBlock *&MBB) {
Alex Lorenzf09df002015-06-30 18:16:42 +0000331 lex();
332 if (Token.isNot(MIToken::MachineBasicBlock))
333 return error("expected a machine basic block reference");
334 if (parseMBBReference(MBB))
335 return true;
336 lex();
337 if (Token.isNot(MIToken::Eof))
338 return error(
339 "expected end of string after the machine basic block reference");
340 return false;
341}
342
Alex Lorenz1ea60892015-07-27 20:29:27 +0000343bool MIParser::parseStandaloneNamedRegister(unsigned &Reg) {
Alex Lorenz9fab3702015-07-14 21:24:41 +0000344 lex();
345 if (Token.isNot(MIToken::NamedRegister))
346 return error("expected a named register");
347 if (parseRegister(Reg))
348 return 0;
349 lex();
350 if (Token.isNot(MIToken::Eof))
351 return error("expected end of string after the register reference");
352 return false;
353}
354
Alex Lorenz12045a42015-07-27 17:42:45 +0000355bool MIParser::parseStandaloneVirtualRegister(unsigned &Reg) {
356 lex();
357 if (Token.isNot(MIToken::VirtualRegister))
358 return error("expected a virtual register");
359 if (parseRegister(Reg))
360 return 0;
361 lex();
362 if (Token.isNot(MIToken::Eof))
363 return error("expected end of string after the register reference");
364 return false;
365}
366
Alex Lorenz8a1915b2015-07-27 22:42:41 +0000367bool MIParser::parseStandaloneIRBlockReference(const BasicBlock *&BB) {
368 lex();
369 if (Token.isNot(MIToken::IRBlock))
370 return error("expected an IR block reference");
371 unsigned SlotNumber = 0;
372 if (getUnsigned(SlotNumber))
373 return true;
374 BB = getIRBlock(SlotNumber);
375 if (!BB)
376 return error(Twine("use of undefined IR block '%ir-block.") +
377 Twine(SlotNumber) + "'");
378 lex();
379 if (Token.isNot(MIToken::Eof))
380 return error("expected end of string after the IR block reference");
381 return false;
382}
383
Alex Lorenz36962cd2015-07-07 02:08:46 +0000384static const char *printImplicitRegisterFlag(const MachineOperand &MO) {
385 assert(MO.isImplicit());
386 return MO.isDef() ? "implicit-def" : "implicit";
387}
388
389static std::string getRegisterName(const TargetRegisterInfo *TRI,
390 unsigned Reg) {
391 assert(TargetRegisterInfo::isPhysicalRegister(Reg) && "expected phys reg");
392 return StringRef(TRI->getName(Reg)).lower();
393}
394
395bool MIParser::verifyImplicitOperands(
396 ArrayRef<MachineOperandWithLocation> Operands, const MCInstrDesc &MCID) {
397 if (MCID.isCall())
398 // We can't verify call instructions as they can contain arbitrary implicit
399 // register and register mask operands.
400 return false;
401
402 // Gather all the expected implicit operands.
403 SmallVector<MachineOperand, 4> ImplicitOperands;
404 if (MCID.ImplicitDefs)
405 for (const uint16_t *ImpDefs = MCID.getImplicitDefs(); *ImpDefs; ++ImpDefs)
406 ImplicitOperands.push_back(
407 MachineOperand::CreateReg(*ImpDefs, true, true));
408 if (MCID.ImplicitUses)
409 for (const uint16_t *ImpUses = MCID.getImplicitUses(); *ImpUses; ++ImpUses)
410 ImplicitOperands.push_back(
411 MachineOperand::CreateReg(*ImpUses, false, true));
412
413 const auto *TRI = MF.getSubtarget().getRegisterInfo();
414 assert(TRI && "Expected target register info");
415 size_t I = ImplicitOperands.size(), J = Operands.size();
416 while (I) {
417 --I;
418 if (J) {
419 --J;
420 const auto &ImplicitOperand = ImplicitOperands[I];
421 const auto &Operand = Operands[J].Operand;
422 if (ImplicitOperand.isIdenticalTo(Operand))
423 continue;
424 if (Operand.isReg() && Operand.isImplicit()) {
425 return error(Operands[J].Begin,
426 Twine("expected an implicit register operand '") +
427 printImplicitRegisterFlag(ImplicitOperand) + " %" +
428 getRegisterName(TRI, ImplicitOperand.getReg()) + "'");
429 }
430 }
431 // TODO: Fix source location when Operands[J].end is right before '=', i.e:
432 // insead of reporting an error at this location:
433 // %eax = MOV32r0
434 // ^
435 // report the error at the following location:
436 // %eax = MOV32r0
437 // ^
438 return error(J < Operands.size() ? Operands[J].End : Token.location(),
439 Twine("missing implicit register operand '") +
440 printImplicitRegisterFlag(ImplicitOperands[I]) + " %" +
441 getRegisterName(TRI, ImplicitOperands[I].getReg()) + "'");
442 }
443 return false;
444}
445
Alex Lorenze5a44662015-07-17 00:24:15 +0000446bool MIParser::parseInstruction(unsigned &OpCode, unsigned &Flags) {
447 if (Token.is(MIToken::kw_frame_setup)) {
448 Flags |= MachineInstr::FrameSetup;
449 lex();
450 }
Alex Lorenz91370c52015-06-22 20:37:46 +0000451 if (Token.isNot(MIToken::Identifier))
452 return error("expected a machine instruction");
453 StringRef InstrName = Token.stringValue();
454 if (parseInstrName(InstrName, OpCode))
455 return error(Twine("unknown machine instruction name '") + InstrName + "'");
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000456 lex();
457 return false;
458}
459
460bool MIParser::parseRegister(unsigned &Reg) {
461 switch (Token.kind()) {
Alex Lorenz12b554e2015-06-24 17:34:58 +0000462 case MIToken::underscore:
463 Reg = 0;
464 break;
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000465 case MIToken::NamedRegister: {
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000466 StringRef Name = Token.stringValue();
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000467 if (getRegisterByName(Name, Reg))
468 return error(Twine("unknown register name '") + Name + "'");
469 break;
470 }
Alex Lorenz53464512015-07-10 22:51:20 +0000471 case MIToken::VirtualRegister: {
472 unsigned ID;
473 if (getUnsigned(ID))
474 return true;
475 const auto RegInfo = PFS.VirtualRegisterSlots.find(ID);
476 if (RegInfo == PFS.VirtualRegisterSlots.end())
477 return error(Twine("use of undefined virtual register '%") + Twine(ID) +
478 "'");
479 Reg = RegInfo->second;
480 break;
481 }
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000482 // TODO: Parse other register kinds.
483 default:
484 llvm_unreachable("The current token should be a register");
485 }
486 return false;
487}
488
Alex Lorenzcb268d42015-07-06 23:07:26 +0000489bool MIParser::parseRegisterFlag(unsigned &Flags) {
Alex Lorenz2b3cf192015-08-05 18:09:03 +0000490 const unsigned OldFlags = Flags;
Alex Lorenzcb268d42015-07-06 23:07:26 +0000491 switch (Token.kind()) {
492 case MIToken::kw_implicit:
493 Flags |= RegState::Implicit;
494 break;
495 case MIToken::kw_implicit_define:
496 Flags |= RegState::ImplicitDefine;
497 break;
Alex Lorenzcbbfd0b2015-07-07 20:34:53 +0000498 case MIToken::kw_dead:
499 Flags |= RegState::Dead;
500 break;
Alex Lorenz495ad872015-07-08 21:23:34 +0000501 case MIToken::kw_killed:
502 Flags |= RegState::Kill;
503 break;
Alex Lorenz4d026b892015-07-08 23:58:31 +0000504 case MIToken::kw_undef:
505 Flags |= RegState::Undef;
506 break;
Alex Lorenz01c1a5e2015-08-05 17:49:03 +0000507 case MIToken::kw_early_clobber:
508 Flags |= RegState::EarlyClobber;
509 break;
Alex Lorenz90752582015-08-05 17:41:17 +0000510 case MIToken::kw_debug_use:
511 Flags |= RegState::Debug;
512 break;
Alex Lorenzcb268d42015-07-06 23:07:26 +0000513 // TODO: parse the other register flags.
514 default:
515 llvm_unreachable("The current token should be a register flag");
516 }
Alex Lorenz2b3cf192015-08-05 18:09:03 +0000517 if (OldFlags == Flags)
518 // We know that the same flag is specified more than once when the flags
519 // weren't modified.
520 return error("duplicate '" + Token.stringValue() + "' register flag");
Alex Lorenzcb268d42015-07-06 23:07:26 +0000521 lex();
522 return false;
523}
524
Alex Lorenz2eacca82015-07-13 23:24:34 +0000525bool MIParser::parseSubRegisterIndex(unsigned &SubReg) {
526 assert(Token.is(MIToken::colon));
527 lex();
528 if (Token.isNot(MIToken::Identifier))
529 return error("expected a subregister index after ':'");
530 auto Name = Token.stringValue();
531 SubReg = getSubRegIndex(Name);
532 if (!SubReg)
533 return error(Twine("use of unknown subregister index '") + Name + "'");
534 lex();
535 return false;
536}
537
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000538bool MIParser::parseRegisterOperand(MachineOperand &Dest, bool IsDef) {
539 unsigned Reg;
Alex Lorenzcb268d42015-07-06 23:07:26 +0000540 unsigned Flags = IsDef ? RegState::Define : 0;
541 while (Token.isRegisterFlag()) {
542 if (parseRegisterFlag(Flags))
543 return true;
544 }
545 if (!Token.isRegister())
546 return error("expected a register after register flags");
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000547 if (parseRegister(Reg))
548 return true;
549 lex();
Alex Lorenz2eacca82015-07-13 23:24:34 +0000550 unsigned SubReg = 0;
551 if (Token.is(MIToken::colon)) {
552 if (parseSubRegisterIndex(SubReg))
553 return true;
554 }
Alex Lorenz495ad872015-07-08 21:23:34 +0000555 Dest = MachineOperand::CreateReg(
556 Reg, Flags & RegState::Define, Flags & RegState::Implicit,
Alex Lorenz2eacca82015-07-13 23:24:34 +0000557 Flags & RegState::Kill, Flags & RegState::Dead, Flags & RegState::Undef,
Alex Lorenz01c1a5e2015-08-05 17:49:03 +0000558 Flags & RegState::EarlyClobber, SubReg, Flags & RegState::Debug);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000559 return false;
560}
561
Alex Lorenz240fc1e2015-06-23 23:42:28 +0000562bool MIParser::parseImmediateOperand(MachineOperand &Dest) {
563 assert(Token.is(MIToken::IntegerLiteral));
564 const APSInt &Int = Token.integerValue();
565 if (Int.getMinSignedBits() > 64)
Alex Lorenz3f2058d2015-08-05 19:03:42 +0000566 return error("integer literal is too large to be an immediate operand");
Alex Lorenz240fc1e2015-06-23 23:42:28 +0000567 Dest = MachineOperand::CreateImm(Int.getExtValue());
568 lex();
569 return false;
570}
571
Alex Lorenz7eaff4c2015-08-05 18:44:00 +0000572bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {
Alex Lorenz3fb77682015-08-06 23:17:42 +0000573 auto Source = StringRef(Loc, Token.range().end() - Loc).str();
Alex Lorenz7eaff4c2015-08-05 18:44:00 +0000574 lex();
575 SMDiagnostic Err;
576 C = parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent());
577 if (!C)
578 return error(Loc + Err.getColumnNo(), Err.getMessage());
579 return false;
580}
581
Alex Lorenz05e38822015-08-05 18:52:21 +0000582bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {
583 assert(Token.is(MIToken::IntegerType));
584 auto Loc = Token.location();
585 lex();
586 if (Token.isNot(MIToken::IntegerLiteral))
587 return error("expected an integer literal");
588 const Constant *C = nullptr;
589 if (parseIRConstant(Loc, C))
590 return true;
591 Dest = MachineOperand::CreateCImm(cast<ConstantInt>(C));
592 return false;
593}
594
Alex Lorenzad156fb2015-07-31 20:49:21 +0000595bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
596 auto Loc = Token.location();
597 lex();
598 if (Token.isNot(MIToken::FloatingPointLiteral))
599 return error("expected a floating point literal");
Alex Lorenz7eaff4c2015-08-05 18:44:00 +0000600 const Constant *C = nullptr;
601 if (parseIRConstant(Loc, C))
602 return true;
Alex Lorenzad156fb2015-07-31 20:49:21 +0000603 Dest = MachineOperand::CreateFPImm(cast<ConstantFP>(C));
604 return false;
605}
606
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000607bool MIParser::getUnsigned(unsigned &Result) {
608 assert(Token.hasIntegerValue() && "Expected a token with an integer value");
609 const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1;
610 uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
611 if (Val64 == Limit)
612 return error("expected 32-bit integer (too large)");
613 Result = Val64;
614 return false;
615}
616
Alex Lorenzf09df002015-06-30 18:16:42 +0000617bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000618 assert(Token.is(MIToken::MachineBasicBlock));
619 unsigned Number;
620 if (getUnsigned(Number))
621 return true;
Alex Lorenz7a503fa2015-07-07 17:46:43 +0000622 auto MBBInfo = PFS.MBBSlots.find(Number);
623 if (MBBInfo == PFS.MBBSlots.end())
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000624 return error(Twine("use of undefined machine basic block #") +
625 Twine(Number));
Alex Lorenzf09df002015-06-30 18:16:42 +0000626 MBB = MBBInfo->second;
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000627 if (!Token.stringValue().empty() && Token.stringValue() != MBB->getName())
628 return error(Twine("the name of machine basic block #") + Twine(Number) +
629 " isn't '" + Token.stringValue() + "'");
Alex Lorenzf09df002015-06-30 18:16:42 +0000630 return false;
631}
632
633bool MIParser::parseMBBOperand(MachineOperand &Dest) {
634 MachineBasicBlock *MBB;
635 if (parseMBBReference(MBB))
636 return true;
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000637 Dest = MachineOperand::CreateMBB(MBB);
638 lex();
639 return false;
640}
641
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000642bool MIParser::parseStackObjectOperand(MachineOperand &Dest) {
643 assert(Token.is(MIToken::StackObject));
644 unsigned ID;
645 if (getUnsigned(ID))
646 return true;
647 auto ObjectInfo = PFS.StackObjectSlots.find(ID);
648 if (ObjectInfo == PFS.StackObjectSlots.end())
649 return error(Twine("use of undefined stack object '%stack.") + Twine(ID) +
650 "'");
651 StringRef Name;
652 if (const auto *Alloca =
653 MF.getFrameInfo()->getObjectAllocation(ObjectInfo->second))
654 Name = Alloca->getName();
655 if (!Token.stringValue().empty() && Token.stringValue() != Name)
656 return error(Twine("the name of the stack object '%stack.") + Twine(ID) +
657 "' isn't '" + Token.stringValue() + "'");
658 lex();
659 Dest = MachineOperand::CreateFI(ObjectInfo->second);
660 return false;
661}
662
663bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {
664 assert(Token.is(MIToken::FixedStackObject));
665 unsigned ID;
666 if (getUnsigned(ID))
667 return true;
668 auto ObjectInfo = PFS.FixedStackObjectSlots.find(ID);
669 if (ObjectInfo == PFS.FixedStackObjectSlots.end())
670 return error(Twine("use of undefined fixed stack object '%fixed-stack.") +
671 Twine(ID) + "'");
672 lex();
673 Dest = MachineOperand::CreateFI(ObjectInfo->second);
674 return false;
675}
676
Alex Lorenz41df7d32015-07-28 17:09:52 +0000677bool MIParser::parseGlobalValue(GlobalValue *&GV) {
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000678 switch (Token.kind()) {
Alex Lorenz970c12e2015-08-05 17:35:55 +0000679 case MIToken::NamedGlobalValue: {
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000680 const Module *M = MF.getFunction()->getParent();
Alex Lorenz970c12e2015-08-05 17:35:55 +0000681 GV = M->getNamedValue(Token.stringValue());
Alex Lorenz41df7d32015-07-28 17:09:52 +0000682 if (!GV)
Alex Lorenz3fb77682015-08-06 23:17:42 +0000683 return error(Twine("use of undefined global value '") + Token.range() +
684 "'");
Alex Lorenz41df7d32015-07-28 17:09:52 +0000685 break;
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000686 }
687 case MIToken::GlobalValue: {
688 unsigned GVIdx;
689 if (getUnsigned(GVIdx))
690 return true;
691 if (GVIdx >= IRSlots.GlobalValues.size())
692 return error(Twine("use of undefined global value '@") + Twine(GVIdx) +
693 "'");
Alex Lorenz41df7d32015-07-28 17:09:52 +0000694 GV = IRSlots.GlobalValues[GVIdx];
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000695 break;
696 }
697 default:
698 llvm_unreachable("The current token should be a global value");
699 }
Alex Lorenz41df7d32015-07-28 17:09:52 +0000700 return false;
701}
702
703bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
704 GlobalValue *GV = nullptr;
705 if (parseGlobalValue(GV))
706 return true;
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000707 lex();
Alex Lorenz5672a892015-08-05 22:26:15 +0000708 Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
Alex Lorenz5672a892015-08-05 22:26:15 +0000709 if (parseOperandsOffset(Dest))
710 return true;
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000711 return false;
712}
713
Alex Lorenzab980492015-07-20 20:51:18 +0000714bool MIParser::parseConstantPoolIndexOperand(MachineOperand &Dest) {
715 assert(Token.is(MIToken::ConstantPoolItem));
716 unsigned ID;
717 if (getUnsigned(ID))
718 return true;
719 auto ConstantInfo = PFS.ConstantPoolSlots.find(ID);
720 if (ConstantInfo == PFS.ConstantPoolSlots.end())
721 return error("use of undefined constant '%const." + Twine(ID) + "'");
722 lex();
Alex Lorenzab980492015-07-20 20:51:18 +0000723 Dest = MachineOperand::CreateCPI(ID, /*Offset=*/0);
Alex Lorenz5672a892015-08-05 22:26:15 +0000724 if (parseOperandsOffset(Dest))
725 return true;
Alex Lorenzab980492015-07-20 20:51:18 +0000726 return false;
727}
728
Alex Lorenz31d70682015-07-15 23:38:35 +0000729bool MIParser::parseJumpTableIndexOperand(MachineOperand &Dest) {
730 assert(Token.is(MIToken::JumpTableIndex));
731 unsigned ID;
732 if (getUnsigned(ID))
733 return true;
734 auto JumpTableEntryInfo = PFS.JumpTableSlots.find(ID);
735 if (JumpTableEntryInfo == PFS.JumpTableSlots.end())
736 return error("use of undefined jump table '%jump-table." + Twine(ID) + "'");
737 lex();
Alex Lorenz31d70682015-07-15 23:38:35 +0000738 Dest = MachineOperand::CreateJTI(JumpTableEntryInfo->second);
739 return false;
740}
741
Alex Lorenz6ede3742015-07-21 16:59:53 +0000742bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) {
Alex Lorenz970c12e2015-08-05 17:35:55 +0000743 assert(Token.is(MIToken::ExternalSymbol));
744 const char *Symbol = MF.createExternalSymbolName(Token.stringValue());
Alex Lorenz6ede3742015-07-21 16:59:53 +0000745 lex();
Alex Lorenz6ede3742015-07-21 16:59:53 +0000746 Dest = MachineOperand::CreateES(Symbol);
Alex Lorenz5672a892015-08-05 22:26:15 +0000747 if (parseOperandsOffset(Dest))
748 return true;
Alex Lorenz6ede3742015-07-21 16:59:53 +0000749 return false;
750}
751
Alex Lorenz44f29252015-07-22 21:07:04 +0000752bool MIParser::parseMDNode(MDNode *&Node) {
Alex Lorenz35e44462015-07-22 17:58:46 +0000753 assert(Token.is(MIToken::exclaim));
754 auto Loc = Token.location();
755 lex();
756 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
757 return error("expected metadata id after '!'");
758 unsigned ID;
759 if (getUnsigned(ID))
760 return true;
761 auto NodeInfo = IRSlots.MetadataNodes.find(ID);
762 if (NodeInfo == IRSlots.MetadataNodes.end())
763 return error(Loc, "use of undefined metadata '!" + Twine(ID) + "'");
764 lex();
Alex Lorenz44f29252015-07-22 21:07:04 +0000765 Node = NodeInfo->second.get();
766 return false;
767}
768
769bool MIParser::parseMetadataOperand(MachineOperand &Dest) {
770 MDNode *Node = nullptr;
771 if (parseMDNode(Node))
772 return true;
773 Dest = MachineOperand::CreateMetadata(Node);
Alex Lorenz35e44462015-07-22 17:58:46 +0000774 return false;
775}
776
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000777bool MIParser::parseCFIOffset(int &Offset) {
778 if (Token.isNot(MIToken::IntegerLiteral))
779 return error("expected a cfi offset");
780 if (Token.integerValue().getMinSignedBits() > 32)
781 return error("expected a 32 bit integer (the cfi offset is too large)");
782 Offset = (int)Token.integerValue().getExtValue();
783 lex();
784 return false;
785}
786
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000787bool MIParser::parseCFIRegister(unsigned &Reg) {
788 if (Token.isNot(MIToken::NamedRegister))
789 return error("expected a cfi register");
790 unsigned LLVMReg;
791 if (parseRegister(LLVMReg))
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000792 return true;
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000793 const auto *TRI = MF.getSubtarget().getRegisterInfo();
794 assert(TRI && "Expected target register info");
795 int DwarfReg = TRI->getDwarfRegNum(LLVMReg, true);
796 if (DwarfReg < 0)
797 return error("invalid DWARF register");
798 Reg = (unsigned)DwarfReg;
799 lex();
800 return false;
801}
802
803bool MIParser::parseCFIOperand(MachineOperand &Dest) {
804 auto Kind = Token.kind();
805 lex();
806 auto &MMI = MF.getMMI();
807 int Offset;
808 unsigned Reg;
809 unsigned CFIIndex;
810 switch (Kind) {
811 case MIToken::kw_cfi_offset:
812 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
813 parseCFIOffset(Offset))
814 return true;
815 CFIIndex =
816 MMI.addFrameInst(MCCFIInstruction::createOffset(nullptr, Reg, Offset));
817 break;
Alex Lorenz5b0d5f62015-07-27 20:39:03 +0000818 case MIToken::kw_cfi_def_cfa_register:
819 if (parseCFIRegister(Reg))
820 return true;
821 CFIIndex =
822 MMI.addFrameInst(MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
823 break;
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000824 case MIToken::kw_cfi_def_cfa_offset:
825 if (parseCFIOffset(Offset))
826 return true;
827 // NB: MCCFIInstruction::createDefCfaOffset negates the offset.
828 CFIIndex = MMI.addFrameInst(
829 MCCFIInstruction::createDefCfaOffset(nullptr, -Offset));
830 break;
Alex Lorenzb1393232015-07-29 18:57:23 +0000831 case MIToken::kw_cfi_def_cfa:
832 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
833 parseCFIOffset(Offset))
834 return true;
835 // NB: MCCFIInstruction::createDefCfa negates the offset.
836 CFIIndex =
837 MMI.addFrameInst(MCCFIInstruction::createDefCfa(nullptr, Reg, -Offset));
838 break;
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000839 default:
840 // TODO: Parse the other CFI operands.
841 llvm_unreachable("The current token should be a cfi operand");
842 }
843 Dest = MachineOperand::CreateCFIIndex(CFIIndex);
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000844 return false;
845}
846
Alex Lorenzdeb53492015-07-28 17:28:03 +0000847bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) {
848 switch (Token.kind()) {
Alex Lorenz970c12e2015-08-05 17:35:55 +0000849 case MIToken::NamedIRBlock: {
850 BB = dyn_cast_or_null<BasicBlock>(
851 F.getValueSymbolTable().lookup(Token.stringValue()));
Alex Lorenzdeb53492015-07-28 17:28:03 +0000852 if (!BB)
Alex Lorenz3fb77682015-08-06 23:17:42 +0000853 return error(Twine("use of undefined IR block '") + Token.range() + "'");
Alex Lorenzdeb53492015-07-28 17:28:03 +0000854 break;
855 }
856 case MIToken::IRBlock: {
857 unsigned SlotNumber = 0;
858 if (getUnsigned(SlotNumber))
859 return true;
Alex Lorenzcba8c5f2015-08-06 23:57:04 +0000860 BB = const_cast<BasicBlock *>(getIRBlock(SlotNumber, F));
Alex Lorenzdeb53492015-07-28 17:28:03 +0000861 if (!BB)
862 return error(Twine("use of undefined IR block '%ir-block.") +
863 Twine(SlotNumber) + "'");
864 break;
865 }
866 default:
867 llvm_unreachable("The current token should be an IR block reference");
868 }
869 return false;
870}
871
872bool MIParser::parseBlockAddressOperand(MachineOperand &Dest) {
873 assert(Token.is(MIToken::kw_blockaddress));
874 lex();
875 if (expectAndConsume(MIToken::lparen))
876 return true;
877 if (Token.isNot(MIToken::GlobalValue) &&
Alex Lorenz970c12e2015-08-05 17:35:55 +0000878 Token.isNot(MIToken::NamedGlobalValue))
Alex Lorenzdeb53492015-07-28 17:28:03 +0000879 return error("expected a global value");
880 GlobalValue *GV = nullptr;
881 if (parseGlobalValue(GV))
882 return true;
883 auto *F = dyn_cast<Function>(GV);
884 if (!F)
885 return error("expected an IR function reference");
886 lex();
887 if (expectAndConsume(MIToken::comma))
888 return true;
889 BasicBlock *BB = nullptr;
Alex Lorenz970c12e2015-08-05 17:35:55 +0000890 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
Alex Lorenzdeb53492015-07-28 17:28:03 +0000891 return error("expected an IR block reference");
892 if (parseIRBlock(BB, *F))
893 return true;
894 lex();
895 if (expectAndConsume(MIToken::rparen))
896 return true;
Alex Lorenzdeb53492015-07-28 17:28:03 +0000897 Dest = MachineOperand::CreateBA(BlockAddress::get(F, BB), /*Offset=*/0);
Alex Lorenz5672a892015-08-05 22:26:15 +0000898 if (parseOperandsOffset(Dest))
899 return true;
Alex Lorenzdeb53492015-07-28 17:28:03 +0000900 return false;
901}
902
Alex Lorenzef5c1962015-07-28 23:02:45 +0000903bool MIParser::parseTargetIndexOperand(MachineOperand &Dest) {
904 assert(Token.is(MIToken::kw_target_index));
905 lex();
906 if (expectAndConsume(MIToken::lparen))
907 return true;
908 if (Token.isNot(MIToken::Identifier))
909 return error("expected the name of the target index");
910 int Index = 0;
911 if (getTargetIndex(Token.stringValue(), Index))
912 return error("use of undefined target index '" + Token.stringValue() + "'");
913 lex();
914 if (expectAndConsume(MIToken::rparen))
915 return true;
Alex Lorenzef5c1962015-07-28 23:02:45 +0000916 Dest = MachineOperand::CreateTargetIndex(unsigned(Index), /*Offset=*/0);
Alex Lorenz5672a892015-08-05 22:26:15 +0000917 if (parseOperandsOffset(Dest))
918 return true;
Alex Lorenzef5c1962015-07-28 23:02:45 +0000919 return false;
920}
921
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000922bool MIParser::parseMachineOperand(MachineOperand &Dest) {
923 switch (Token.kind()) {
Alex Lorenzcb268d42015-07-06 23:07:26 +0000924 case MIToken::kw_implicit:
925 case MIToken::kw_implicit_define:
Alex Lorenzcbbfd0b2015-07-07 20:34:53 +0000926 case MIToken::kw_dead:
Alex Lorenz495ad872015-07-08 21:23:34 +0000927 case MIToken::kw_killed:
Alex Lorenz4d026b892015-07-08 23:58:31 +0000928 case MIToken::kw_undef:
Alex Lorenz01c1a5e2015-08-05 17:49:03 +0000929 case MIToken::kw_early_clobber:
Alex Lorenz90752582015-08-05 17:41:17 +0000930 case MIToken::kw_debug_use:
Alex Lorenz12b554e2015-06-24 17:34:58 +0000931 case MIToken::underscore:
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000932 case MIToken::NamedRegister:
Alex Lorenz53464512015-07-10 22:51:20 +0000933 case MIToken::VirtualRegister:
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000934 return parseRegisterOperand(Dest);
Alex Lorenz240fc1e2015-06-23 23:42:28 +0000935 case MIToken::IntegerLiteral:
936 return parseImmediateOperand(Dest);
Alex Lorenz05e38822015-08-05 18:52:21 +0000937 case MIToken::IntegerType:
938 return parseTypedImmediateOperand(Dest);
Alex Lorenzad156fb2015-07-31 20:49:21 +0000939 case MIToken::kw_half:
940 case MIToken::kw_float:
941 case MIToken::kw_double:
942 case MIToken::kw_x86_fp80:
943 case MIToken::kw_fp128:
944 case MIToken::kw_ppc_fp128:
945 return parseFPImmediateOperand(Dest);
Alex Lorenz33f0aef2015-06-26 16:46:11 +0000946 case MIToken::MachineBasicBlock:
947 return parseMBBOperand(Dest);
Alex Lorenz7feaf7c2015-07-16 23:37:45 +0000948 case MIToken::StackObject:
949 return parseStackObjectOperand(Dest);
950 case MIToken::FixedStackObject:
951 return parseFixedStackObjectOperand(Dest);
Alex Lorenz5d6108e2015-06-26 22:56:48 +0000952 case MIToken::GlobalValue:
953 case MIToken::NamedGlobalValue:
954 return parseGlobalAddressOperand(Dest);
Alex Lorenzab980492015-07-20 20:51:18 +0000955 case MIToken::ConstantPoolItem:
956 return parseConstantPoolIndexOperand(Dest);
Alex Lorenz31d70682015-07-15 23:38:35 +0000957 case MIToken::JumpTableIndex:
958 return parseJumpTableIndexOperand(Dest);
Alex Lorenz6ede3742015-07-21 16:59:53 +0000959 case MIToken::ExternalSymbol:
Alex Lorenz6ede3742015-07-21 16:59:53 +0000960 return parseExternalSymbolOperand(Dest);
Alex Lorenz35e44462015-07-22 17:58:46 +0000961 case MIToken::exclaim:
962 return parseMetadataOperand(Dest);
Alex Lorenz8cfc6862015-07-23 23:09:07 +0000963 case MIToken::kw_cfi_offset:
Alex Lorenz5b0d5f62015-07-27 20:39:03 +0000964 case MIToken::kw_cfi_def_cfa_register:
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000965 case MIToken::kw_cfi_def_cfa_offset:
Alex Lorenzb1393232015-07-29 18:57:23 +0000966 case MIToken::kw_cfi_def_cfa:
Alex Lorenzf4baeb52015-07-21 22:28:27 +0000967 return parseCFIOperand(Dest);
Alex Lorenzdeb53492015-07-28 17:28:03 +0000968 case MIToken::kw_blockaddress:
969 return parseBlockAddressOperand(Dest);
Alex Lorenzef5c1962015-07-28 23:02:45 +0000970 case MIToken::kw_target_index:
971 return parseTargetIndexOperand(Dest);
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000972 case MIToken::Error:
973 return true;
Alex Lorenz8f6f4282015-06-29 16:57:06 +0000974 case MIToken::Identifier:
975 if (const auto *RegMask = getRegMask(Token.stringValue())) {
976 Dest = MachineOperand::CreateRegMask(RegMask);
977 lex();
978 break;
979 }
980 // fallthrough
Alex Lorenzf3db51de2015-06-23 16:35:26 +0000981 default:
982 // TODO: parse the other machine operands.
983 return error("expected a machine operand");
984 }
Alex Lorenz91370c52015-06-22 20:37:46 +0000985 return false;
986}
987
Alex Lorenz49873a82015-08-06 00:44:07 +0000988bool MIParser::parseMachineOperandAndTargetFlags(MachineOperand &Dest) {
989 unsigned TF = 0;
990 bool HasTargetFlags = false;
991 if (Token.is(MIToken::kw_target_flags)) {
992 HasTargetFlags = true;
993 lex();
994 if (expectAndConsume(MIToken::lparen))
995 return true;
996 if (Token.isNot(MIToken::Identifier))
997 return error("expected the name of the target flag");
998 if (getDirectTargetFlag(Token.stringValue(), TF))
999 return error("use of undefined target flag '" + Token.stringValue() +
1000 "'");
1001 lex();
1002 // TODO: Parse target's bit target flags.
1003 if (expectAndConsume(MIToken::rparen))
1004 return true;
1005 }
1006 auto Loc = Token.location();
1007 if (parseMachineOperand(Dest))
1008 return true;
1009 if (!HasTargetFlags)
1010 return false;
1011 if (Dest.isReg())
1012 return error(Loc, "register operands can't have target flags");
1013 Dest.setTargetFlags(TF);
1014 return false;
1015}
1016
Alex Lorenz5672a892015-08-05 22:26:15 +00001017bool MIParser::parseOperandsOffset(MachineOperand &Op) {
1018 if (Token.isNot(MIToken::plus) && Token.isNot(MIToken::minus))
1019 return false;
Alex Lorenz3fb77682015-08-06 23:17:42 +00001020 StringRef Sign = Token.range();
Alex Lorenz5672a892015-08-05 22:26:15 +00001021 bool IsNegative = Token.is(MIToken::minus);
1022 lex();
1023 if (Token.isNot(MIToken::IntegerLiteral))
1024 return error("expected an integer literal after '" + Sign + "'");
1025 if (Token.integerValue().getMinSignedBits() > 64)
1026 return error("expected 64-bit integer (too large)");
1027 int64_t Offset = Token.integerValue().getExtValue();
1028 if (IsNegative)
1029 Offset = -Offset;
1030 lex();
1031 Op.setOffset(Offset);
1032 return false;
1033}
1034
Alex Lorenz4af7e612015-08-03 23:08:19 +00001035bool MIParser::parseIRValue(Value *&V) {
1036 switch (Token.kind()) {
Alex Lorenz970c12e2015-08-05 17:35:55 +00001037 case MIToken::NamedIRValue: {
1038 V = MF.getFunction()->getValueSymbolTable().lookup(Token.stringValue());
Alex Lorenz4af7e612015-08-03 23:08:19 +00001039 if (!V)
Alex Lorenz3fb77682015-08-06 23:17:42 +00001040 return error(Twine("use of undefined IR value '") + Token.range() + "'");
Alex Lorenz4af7e612015-08-03 23:08:19 +00001041 break;
1042 }
1043 // TODO: Parse unnamed IR value references.
1044 default:
1045 llvm_unreachable("The current token should be an IR block reference");
1046 }
1047 return false;
1048}
1049
1050bool MIParser::getUint64(uint64_t &Result) {
1051 assert(Token.hasIntegerValue());
1052 if (Token.integerValue().getActiveBits() > 64)
1053 return error("expected 64-bit integer (too large)");
1054 Result = Token.integerValue().getZExtValue();
1055 return false;
1056}
1057
Alex Lorenza518b792015-08-04 00:24:45 +00001058bool MIParser::parseMemoryOperandFlag(unsigned &Flags) {
Alex Lorenze86d5152015-08-06 18:26:36 +00001059 const unsigned OldFlags = Flags;
Alex Lorenza518b792015-08-04 00:24:45 +00001060 switch (Token.kind()) {
1061 case MIToken::kw_volatile:
1062 Flags |= MachineMemOperand::MOVolatile;
1063 break;
Alex Lorenz10fd0382015-08-06 16:49:30 +00001064 case MIToken::kw_non_temporal:
1065 Flags |= MachineMemOperand::MONonTemporal;
1066 break;
Alex Lorenzdc8de2a2015-08-06 16:55:53 +00001067 case MIToken::kw_invariant:
1068 Flags |= MachineMemOperand::MOInvariant;
1069 break;
Alex Lorenzdc8de2a2015-08-06 16:55:53 +00001070 // TODO: parse the target specific memory operand flags.
Alex Lorenza518b792015-08-04 00:24:45 +00001071 default:
1072 llvm_unreachable("The current token should be a memory operand flag");
1073 }
Alex Lorenze86d5152015-08-06 18:26:36 +00001074 if (OldFlags == Flags)
1075 // We know that the same flag is specified more than once when the flags
1076 // weren't modified.
1077 return error("duplicate '" + Token.stringValue() + "' memory operand flag");
Alex Lorenza518b792015-08-04 00:24:45 +00001078 lex();
1079 return false;
1080}
1081
Alex Lorenz4af7e612015-08-03 23:08:19 +00001082bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
1083 if (expectAndConsume(MIToken::lparen))
1084 return true;
Alex Lorenza518b792015-08-04 00:24:45 +00001085 unsigned Flags = 0;
1086 while (Token.isMemoryOperandFlag()) {
1087 if (parseMemoryOperandFlag(Flags))
1088 return true;
1089 }
Alex Lorenz4af7e612015-08-03 23:08:19 +00001090 if (Token.isNot(MIToken::Identifier) ||
1091 (Token.stringValue() != "load" && Token.stringValue() != "store"))
1092 return error("expected 'load' or 'store' memory operation");
Alex Lorenz4af7e612015-08-03 23:08:19 +00001093 if (Token.stringValue() == "load")
1094 Flags |= MachineMemOperand::MOLoad;
1095 else
1096 Flags |= MachineMemOperand::MOStore;
1097 lex();
1098
1099 if (Token.isNot(MIToken::IntegerLiteral))
1100 return error("expected the size integer literal after memory operation");
1101 uint64_t Size;
1102 if (getUint64(Size))
1103 return true;
1104 lex();
1105
1106 const char *Word = Flags & MachineMemOperand::MOLoad ? "from" : "into";
1107 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != Word)
1108 return error(Twine("expected '") + Word + "'");
1109 lex();
1110
1111 // TODO: Parse pseudo source values.
Alex Lorenz970c12e2015-08-05 17:35:55 +00001112 if (Token.isNot(MIToken::NamedIRValue))
Alex Lorenz4af7e612015-08-03 23:08:19 +00001113 return error("expected an IR value reference");
1114 Value *V = nullptr;
1115 if (parseIRValue(V))
1116 return true;
1117 if (!V->getType()->isPointerTy())
1118 return error("expected a pointer IR value");
1119 lex();
1120 // TODO: Parse the base alignment.
1121 // TODO: Parse the attached metadata nodes.
1122 if (expectAndConsume(MIToken::rparen))
1123 return true;
1124
1125 Dest = MF.getMachineMemOperand(MachinePointerInfo(V), Flags, Size, Size);
1126 return false;
1127}
1128
Alex Lorenz8e0a1b42015-06-22 17:02:30 +00001129void MIParser::initNames2InstrOpCodes() {
1130 if (!Names2InstrOpCodes.empty())
1131 return;
1132 const auto *TII = MF.getSubtarget().getInstrInfo();
1133 assert(TII && "Expected target instruction info");
1134 for (unsigned I = 0, E = TII->getNumOpcodes(); I < E; ++I)
1135 Names2InstrOpCodes.insert(std::make_pair(StringRef(TII->getName(I)), I));
1136}
1137
1138bool MIParser::parseInstrName(StringRef InstrName, unsigned &OpCode) {
1139 initNames2InstrOpCodes();
1140 auto InstrInfo = Names2InstrOpCodes.find(InstrName);
1141 if (InstrInfo == Names2InstrOpCodes.end())
1142 return true;
1143 OpCode = InstrInfo->getValue();
1144 return false;
1145}
1146
Alex Lorenzf3db51de2015-06-23 16:35:26 +00001147void MIParser::initNames2Regs() {
1148 if (!Names2Regs.empty())
1149 return;
Alex Lorenz12b554e2015-06-24 17:34:58 +00001150 // The '%noreg' register is the register 0.
1151 Names2Regs.insert(std::make_pair("noreg", 0));
Alex Lorenzf3db51de2015-06-23 16:35:26 +00001152 const auto *TRI = MF.getSubtarget().getRegisterInfo();
1153 assert(TRI && "Expected target register info");
1154 for (unsigned I = 0, E = TRI->getNumRegs(); I < E; ++I) {
1155 bool WasInserted =
1156 Names2Regs.insert(std::make_pair(StringRef(TRI->getName(I)).lower(), I))
1157 .second;
1158 (void)WasInserted;
1159 assert(WasInserted && "Expected registers to be unique case-insensitively");
1160 }
1161}
1162
1163bool MIParser::getRegisterByName(StringRef RegName, unsigned &Reg) {
1164 initNames2Regs();
1165 auto RegInfo = Names2Regs.find(RegName);
1166 if (RegInfo == Names2Regs.end())
1167 return true;
1168 Reg = RegInfo->getValue();
1169 return false;
1170}
1171
Alex Lorenz8f6f4282015-06-29 16:57:06 +00001172void MIParser::initNames2RegMasks() {
1173 if (!Names2RegMasks.empty())
1174 return;
1175 const auto *TRI = MF.getSubtarget().getRegisterInfo();
1176 assert(TRI && "Expected target register info");
1177 ArrayRef<const uint32_t *> RegMasks = TRI->getRegMasks();
1178 ArrayRef<const char *> RegMaskNames = TRI->getRegMaskNames();
1179 assert(RegMasks.size() == RegMaskNames.size());
1180 for (size_t I = 0, E = RegMasks.size(); I < E; ++I)
1181 Names2RegMasks.insert(
1182 std::make_pair(StringRef(RegMaskNames[I]).lower(), RegMasks[I]));
1183}
1184
1185const uint32_t *MIParser::getRegMask(StringRef Identifier) {
1186 initNames2RegMasks();
1187 auto RegMaskInfo = Names2RegMasks.find(Identifier);
1188 if (RegMaskInfo == Names2RegMasks.end())
1189 return nullptr;
1190 return RegMaskInfo->getValue();
1191}
1192
Alex Lorenz2eacca82015-07-13 23:24:34 +00001193void MIParser::initNames2SubRegIndices() {
1194 if (!Names2SubRegIndices.empty())
1195 return;
1196 const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
1197 for (unsigned I = 1, E = TRI->getNumSubRegIndices(); I < E; ++I)
1198 Names2SubRegIndices.insert(
1199 std::make_pair(StringRef(TRI->getSubRegIndexName(I)).lower(), I));
1200}
1201
1202unsigned MIParser::getSubRegIndex(StringRef Name) {
1203 initNames2SubRegIndices();
1204 auto SubRegInfo = Names2SubRegIndices.find(Name);
1205 if (SubRegInfo == Names2SubRegIndices.end())
1206 return 0;
1207 return SubRegInfo->getValue();
1208}
1209
Alex Lorenzcba8c5f2015-08-06 23:57:04 +00001210static void initSlots2BasicBlocks(
1211 const Function &F,
1212 DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
1213 ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
Alex Lorenz8a1915b2015-07-27 22:42:41 +00001214 MST.incorporateFunction(F);
1215 for (auto &BB : F) {
1216 if (BB.hasName())
1217 continue;
1218 int Slot = MST.getLocalSlot(&BB);
1219 if (Slot == -1)
1220 continue;
1221 Slots2BasicBlocks.insert(std::make_pair(unsigned(Slot), &BB));
1222 }
1223}
1224
Alex Lorenzcba8c5f2015-08-06 23:57:04 +00001225static const BasicBlock *getIRBlockFromSlot(
1226 unsigned Slot,
1227 const DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
Alex Lorenz8a1915b2015-07-27 22:42:41 +00001228 auto BlockInfo = Slots2BasicBlocks.find(Slot);
1229 if (BlockInfo == Slots2BasicBlocks.end())
1230 return nullptr;
1231 return BlockInfo->second;
1232}
1233
Alex Lorenzcba8c5f2015-08-06 23:57:04 +00001234const BasicBlock *MIParser::getIRBlock(unsigned Slot) {
1235 if (Slots2BasicBlocks.empty())
1236 initSlots2BasicBlocks(*MF.getFunction(), Slots2BasicBlocks);
1237 return getIRBlockFromSlot(Slot, Slots2BasicBlocks);
1238}
1239
1240const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) {
1241 if (&F == MF.getFunction())
1242 return getIRBlock(Slot);
1243 DenseMap<unsigned, const BasicBlock *> CustomSlots2BasicBlocks;
1244 initSlots2BasicBlocks(F, CustomSlots2BasicBlocks);
1245 return getIRBlockFromSlot(Slot, CustomSlots2BasicBlocks);
1246}
1247
Alex Lorenzef5c1962015-07-28 23:02:45 +00001248void MIParser::initNames2TargetIndices() {
1249 if (!Names2TargetIndices.empty())
1250 return;
1251 const auto *TII = MF.getSubtarget().getInstrInfo();
1252 assert(TII && "Expected target instruction info");
1253 auto Indices = TII->getSerializableTargetIndices();
1254 for (const auto &I : Indices)
1255 Names2TargetIndices.insert(std::make_pair(StringRef(I.second), I.first));
1256}
1257
1258bool MIParser::getTargetIndex(StringRef Name, int &Index) {
1259 initNames2TargetIndices();
1260 auto IndexInfo = Names2TargetIndices.find(Name);
1261 if (IndexInfo == Names2TargetIndices.end())
1262 return true;
1263 Index = IndexInfo->second;
1264 return false;
1265}
1266
Alex Lorenz49873a82015-08-06 00:44:07 +00001267void MIParser::initNames2DirectTargetFlags() {
1268 if (!Names2DirectTargetFlags.empty())
1269 return;
1270 const auto *TII = MF.getSubtarget().getInstrInfo();
1271 assert(TII && "Expected target instruction info");
1272 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
1273 for (const auto &I : Flags)
1274 Names2DirectTargetFlags.insert(
1275 std::make_pair(StringRef(I.second), I.first));
1276}
1277
1278bool MIParser::getDirectTargetFlag(StringRef Name, unsigned &Flag) {
1279 initNames2DirectTargetFlags();
1280 auto FlagInfo = Names2DirectTargetFlags.find(Name);
1281 if (FlagInfo == Names2DirectTargetFlags.end())
1282 return true;
1283 Flag = FlagInfo->second;
1284 return false;
1285}
1286
Alex Lorenz7a503fa2015-07-07 17:46:43 +00001287bool llvm::parseMachineInstr(MachineInstr *&MI, SourceMgr &SM,
1288 MachineFunction &MF, StringRef Src,
1289 const PerFunctionMIParsingState &PFS,
1290 const SlotMapping &IRSlots, SMDiagnostic &Error) {
1291 return MIParser(SM, MF, Error, Src, PFS, IRSlots).parse(MI);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +00001292}
Alex Lorenzf09df002015-06-30 18:16:42 +00001293
Alex Lorenz7a503fa2015-07-07 17:46:43 +00001294bool llvm::parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
1295 MachineFunction &MF, StringRef Src,
1296 const PerFunctionMIParsingState &PFS,
1297 const SlotMapping &IRSlots, SMDiagnostic &Error) {
Alex Lorenz1ea60892015-07-27 20:29:27 +00001298 return MIParser(SM, MF, Error, Src, PFS, IRSlots).parseStandaloneMBB(MBB);
Alex Lorenzf09df002015-06-30 18:16:42 +00001299}
Alex Lorenz9fab3702015-07-14 21:24:41 +00001300
1301bool llvm::parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
1302 MachineFunction &MF, StringRef Src,
1303 const PerFunctionMIParsingState &PFS,
1304 const SlotMapping &IRSlots,
1305 SMDiagnostic &Error) {
Alex Lorenz1ea60892015-07-27 20:29:27 +00001306 return MIParser(SM, MF, Error, Src, PFS, IRSlots)
1307 .parseStandaloneNamedRegister(Reg);
Alex Lorenz9fab3702015-07-14 21:24:41 +00001308}
Alex Lorenz12045a42015-07-27 17:42:45 +00001309
1310bool llvm::parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM,
1311 MachineFunction &MF, StringRef Src,
1312 const PerFunctionMIParsingState &PFS,
1313 const SlotMapping &IRSlots,
1314 SMDiagnostic &Error) {
1315 return MIParser(SM, MF, Error, Src, PFS, IRSlots)
1316 .parseStandaloneVirtualRegister(Reg);
1317}
Alex Lorenz8a1915b2015-07-27 22:42:41 +00001318
1319bool llvm::parseIRBlockReference(const BasicBlock *&BB, SourceMgr &SM,
1320 MachineFunction &MF, StringRef Src,
1321 const PerFunctionMIParsingState &PFS,
1322 const SlotMapping &IRSlots,
1323 SMDiagnostic &Error) {
1324 return MIParser(SM, MF, Error, Src, PFS, IRSlots)
1325 .parseStandaloneIRBlockReference(BB);
1326}