LLVM 24.0.0git
MIParser.cpp
Go to the documentation of this file.
1//===- MIParser.cpp - Machine instructions parser implementation ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the parsing of machine instructions.
10//
11//===----------------------------------------------------------------------===//
12
14#include "MILexer.h"
15#include "llvm/ADT/APInt.h"
16#include "llvm/ADT/APSInt.h"
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/StringMap.h"
21#include "llvm/ADT/StringRef.h"
23#include "llvm/ADT/Twine.h"
43#include "llvm/IR/BasicBlock.h"
44#include "llvm/IR/Constants.h"
45#include "llvm/IR/DataLayout.h"
47#include "llvm/IR/DebugLoc.h"
48#include "llvm/IR/Function.h"
49#include "llvm/IR/InlineAsm.h"
50#include "llvm/IR/InstrTypes.h"
52#include "llvm/IR/Intrinsics.h"
53#include "llvm/IR/Metadata.h"
54#include "llvm/IR/Module.h"
56#include "llvm/IR/Type.h"
57#include "llvm/IR/Value.h"
59#include "llvm/MC/LaneBitmask.h"
60#include "llvm/MC/MCContext.h"
61#include "llvm/MC/MCDwarf.h"
62#include "llvm/MC/MCInstrDesc.h"
68#include "llvm/Support/SMLoc.h"
71#include <cassert>
72#include <cctype>
73#include <cstddef>
74#include <cstdint>
75#include <limits>
76#include <string>
77#include <utility>
78
79using namespace llvm;
80
82 const TargetSubtargetInfo &NewSubtarget) {
83
84 // If the subtarget changed, over conservatively assume everything is invalid.
85 if (&Subtarget == &NewSubtarget)
86 return;
87
88 Names2InstrOpCodes.clear();
89 Names2Regs.clear();
90 Names2RegMasks.clear();
91 Names2SubRegIndices.clear();
92 Names2TargetIndices.clear();
93 Names2DirectTargetFlags.clear();
94 Names2BitmaskTargetFlags.clear();
95 Names2MMOTargetFlags.clear();
96
97 initNames2RegClasses();
98 initNames2RegBanks();
99}
100
101void PerTargetMIParsingState::initNames2Regs() {
102 if (!Names2Regs.empty())
103 return;
104
105 // The '%noreg' register is the register 0.
106 Names2Regs.insert(std::make_pair("noreg", 0));
107 const auto *TRI = Subtarget.getRegisterInfo();
108 assert(TRI && "Expected target register info");
109
110 for (unsigned I = 0, E = TRI->getNumRegs(); I < E; ++I) {
111 bool WasInserted =
112 Names2Regs.insert(std::make_pair(StringRef(TRI->getName(I)).lower(), I))
113 .second;
114 (void)WasInserted;
115 assert(WasInserted && "Expected registers to be unique case-insensitively");
116 }
117}
118
120 Register &Reg) {
121 initNames2Regs();
122 auto RegInfo = Names2Regs.find(RegName);
123 if (RegInfo == Names2Regs.end())
124 return true;
125 Reg = RegInfo->getValue();
126 return false;
127}
128
130 uint8_t &FlagValue) const {
131 const auto *TRI = Subtarget.getRegisterInfo();
132 std::optional<uint8_t> FV = TRI->getVRegFlagValue(FlagName);
133 if (!FV)
134 return true;
135 FlagValue = *FV;
136 return false;
137}
138
139void PerTargetMIParsingState::initNames2InstrOpCodes() {
140 if (!Names2InstrOpCodes.empty())
141 return;
142 const auto *TII = Subtarget.getInstrInfo();
143 assert(TII && "Expected target instruction info");
144 for (unsigned I = 0, E = TII->getNumOpcodes(); I < E; ++I)
145 Names2InstrOpCodes.insert(std::make_pair(StringRef(TII->getName(I)), I));
146}
147
149 unsigned &OpCode) {
150 initNames2InstrOpCodes();
151 auto InstrInfo = Names2InstrOpCodes.find(InstrName);
152 if (InstrInfo == Names2InstrOpCodes.end())
153 return true;
154 OpCode = InstrInfo->getValue();
155 return false;
156}
157
158void PerTargetMIParsingState::initNames2RegMasks() {
159 if (!Names2RegMasks.empty())
160 return;
161 const auto *TRI = Subtarget.getRegisterInfo();
162 assert(TRI && "Expected target register info");
163 ArrayRef<const uint32_t *> RegMasks = TRI->getRegMasks();
164 ArrayRef<const char *> RegMaskNames = TRI->getRegMaskNames();
165 assert(RegMasks.size() == RegMaskNames.size());
166 for (size_t I = 0, E = RegMasks.size(); I < E; ++I)
167 Names2RegMasks.insert(
168 std::make_pair(StringRef(RegMaskNames[I]).lower(), RegMasks[I]));
169}
170
172 initNames2RegMasks();
173 auto RegMaskInfo = Names2RegMasks.find(Identifier);
174 if (RegMaskInfo == Names2RegMasks.end())
175 return nullptr;
176 return RegMaskInfo->getValue();
177}
178
179void PerTargetMIParsingState::initNames2SubRegIndices() {
180 if (!Names2SubRegIndices.empty())
181 return;
182 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
183 for (unsigned I = 1, E = TRI->getNumSubRegIndices(); I < E; ++I)
184 Names2SubRegIndices.insert(
185 std::make_pair(TRI->getSubRegIndexName(I), I));
186}
187
189 initNames2SubRegIndices();
190 auto SubRegInfo = Names2SubRegIndices.find(Name);
191 if (SubRegInfo == Names2SubRegIndices.end())
192 return 0;
193 return SubRegInfo->getValue();
194}
195
196void PerTargetMIParsingState::initNames2TargetIndices() {
197 if (!Names2TargetIndices.empty())
198 return;
199 const auto *TII = Subtarget.getInstrInfo();
200 assert(TII && "Expected target instruction info");
201 auto Indices = TII->getSerializableTargetIndices();
202 for (const auto &I : Indices)
203 Names2TargetIndices.insert(std::make_pair(StringRef(I.second), I.first));
204}
205
207 initNames2TargetIndices();
208 auto IndexInfo = Names2TargetIndices.find(Name);
209 if (IndexInfo == Names2TargetIndices.end())
210 return true;
211 Index = IndexInfo->second;
212 return false;
213}
214
215void PerTargetMIParsingState::initNames2DirectTargetFlags() {
216 if (!Names2DirectTargetFlags.empty())
217 return;
218
219 const auto *TII = Subtarget.getInstrInfo();
220 assert(TII && "Expected target instruction info");
221 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
222 for (const auto &I : Flags)
223 Names2DirectTargetFlags.insert(
224 std::make_pair(StringRef(I.second), I.first));
225}
226
228 unsigned &Flag) {
229 initNames2DirectTargetFlags();
230 auto FlagInfo = Names2DirectTargetFlags.find(Name);
231 if (FlagInfo == Names2DirectTargetFlags.end())
232 return true;
233 Flag = FlagInfo->second;
234 return false;
235}
236
237void PerTargetMIParsingState::initNames2BitmaskTargetFlags() {
238 if (!Names2BitmaskTargetFlags.empty())
239 return;
240
241 const auto *TII = Subtarget.getInstrInfo();
242 assert(TII && "Expected target instruction info");
243 auto Flags = TII->getSerializableBitmaskMachineOperandTargetFlags();
244 for (const auto &I : Flags)
245 Names2BitmaskTargetFlags.insert(
246 std::make_pair(StringRef(I.second), I.first));
247}
248
250 unsigned &Flag) {
251 initNames2BitmaskTargetFlags();
252 auto FlagInfo = Names2BitmaskTargetFlags.find(Name);
253 if (FlagInfo == Names2BitmaskTargetFlags.end())
254 return true;
255 Flag = FlagInfo->second;
256 return false;
257}
258
259void PerTargetMIParsingState::initNames2MMOTargetFlags() {
260 if (!Names2MMOTargetFlags.empty())
261 return;
262
263 const auto *TII = Subtarget.getInstrInfo();
264 assert(TII && "Expected target instruction info");
265 auto Flags = TII->getSerializableMachineMemOperandTargetFlags();
266 for (const auto &I : Flags)
267 Names2MMOTargetFlags.insert(std::make_pair(StringRef(I.second), I.first));
268}
269
272 initNames2MMOTargetFlags();
273 auto FlagInfo = Names2MMOTargetFlags.find(Name);
274 if (FlagInfo == Names2MMOTargetFlags.end())
275 return true;
276 Flag = FlagInfo->second;
277 return false;
278}
279
280void PerTargetMIParsingState::initNames2RegClasses() {
281 if (!Names2RegClasses.empty())
282 return;
283
284 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
285 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
286 const auto *RC = TRI->getRegClass(I);
287 Names2RegClasses.insert(
288 std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
289 }
290}
291
292void PerTargetMIParsingState::initNames2RegBanks() {
293 if (!Names2RegBanks.empty())
294 return;
295
296 const RegisterBankInfo *RBI = Subtarget.getRegBankInfo();
297 // If the target does not support GlobalISel, we may not have a
298 // register bank info.
299 if (!RBI)
300 return;
301
302 for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
303 const auto &RegBank = RBI->getRegBank(I);
304 Names2RegBanks.insert(
305 std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
306 }
307}
308
311 auto RegClassInfo = Names2RegClasses.find(Name);
312 if (RegClassInfo == Names2RegClasses.end())
313 return nullptr;
314 return RegClassInfo->getValue();
315}
316
318 auto RegBankInfo = Names2RegBanks.find(Name);
319 if (RegBankInfo == Names2RegBanks.end())
320 return nullptr;
321 return RegBankInfo->getValue();
322}
323
328
330 auto I = VRegInfos.try_emplace(Num);
331 if (I.second) {
332 MachineRegisterInfo &MRI = MF.getRegInfo();
333 VRegInfo *Info = new (Allocator) VRegInfo;
335 I.first->second = Info;
336 }
337 return *I.first->second;
338}
339
341 assert(RegName != "" && "Expected named reg.");
342
343 auto I = VRegInfosNamed.try_emplace(RegName.str());
344 if (I.second) {
345 VRegInfo *Info = new (Allocator) VRegInfo;
346 Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName);
347 I.first->second = Info;
348 }
349 return *I.first->second;
350}
351
352static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST,
353 DenseMap<unsigned, const Value *> &Slots2Values) {
354 int Slot = MST.getLocalSlot(V);
355 if (Slot == -1)
356 return;
357 Slots2Values.insert(std::make_pair(unsigned(Slot), V));
358}
359
360/// Creates the mapping from slot numbers to function's unnamed IR values.
361static void initSlots2Values(const Function &F,
362 DenseMap<unsigned, const Value *> &Slots2Values) {
363 ModuleSlotTracker MST(F.getParent());
365 for (const auto &Arg : F.args())
366 mapValueToSlot(&Arg, MST, Slots2Values);
367 for (const auto &BB : F) {
368 mapValueToSlot(&BB, MST, Slots2Values);
369 for (const auto &I : BB)
370 mapValueToSlot(&I, MST, Slots2Values);
371 }
372}
373
375 if (Slots2Values.empty())
376 initSlots2Values(MF.getFunction(), Slots2Values);
377 return Slots2Values.lookup(Slot);
378}
379
380namespace {
381
382/// A wrapper struct around the 'MachineOperand' struct that includes a source
383/// range and other attributes.
384struct ParsedMachineOperand {
385 MachineOperand Operand;
388 std::optional<unsigned> TiedDefIdx;
389
390 ParsedMachineOperand(const MachineOperand &Operand, StringRef::iterator Begin,
392 std::optional<unsigned> &TiedDefIdx)
393 : Operand(Operand), Begin(Begin), End(End), TiedDefIdx(TiedDefIdx) {
394 if (TiedDefIdx)
395 assert(Operand.isReg() && Operand.isUse() &&
396 "Only used register operands can be tied");
397 }
398};
399
400class MIParser {
401 MachineFunction &MF;
402 SMDiagnostic &Error;
403 StringRef Source, CurrentSource;
404 MIToken Token;
405 PerFunctionMIParsingState &PFS;
406 /// Maps from slot numbers to function's unnamed basic blocks.
407 DenseMap<unsigned, const BasicBlock *> Slots2BasicBlocks;
408
409public:
410 MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
411 StringRef Source);
412
413 /// \p SkipChar gives the number of characters to skip before looking
414 /// for the next token.
415 void lex(unsigned SkipChar = 0);
416
417 /// Report an error at the current location with the given message.
418 ///
419 /// This function always return true.
420 bool error(const Twine &Msg);
421
422 /// Report an error at the given location with the given message.
423 ///
424 /// This function always return true.
425 bool error(StringRef::iterator Loc, const Twine &Msg);
426
427 bool
428 parseBasicBlockDefinitions(DenseMap<unsigned, MachineBasicBlock *> &MBBSlots);
429 bool parseBasicBlocks();
430 bool parse(MachineInstr *&MI);
431 bool parseStandaloneMBB(MachineBasicBlock *&MBB);
432 bool parseStandaloneNamedRegister(Register &Reg);
433 bool parseStandaloneVirtualRegister(VRegInfo *&Info);
434 bool parseStandaloneRegister(Register &Reg);
435 bool parseStandaloneStackObject(int &FI);
436 bool parseStandaloneMDNode(MDNode *&Node);
437
438 bool
439 parseBasicBlockDefinition(DenseMap<unsigned, MachineBasicBlock *> &MBBSlots);
440 bool parseBasicBlock(MachineBasicBlock &MBB,
441 MachineBasicBlock *&AddFalthroughFrom);
442 bool parseBasicBlockLiveins(MachineBasicBlock &MBB);
443 bool parseBasicBlockSuccessors(MachineBasicBlock &MBB);
444
445 bool parseNamedRegister(Register &Reg);
446 bool parseVirtualRegister(VRegInfo *&Info);
447 bool parseNamedVirtualRegister(VRegInfo *&Info);
448 bool parseRegister(Register &Reg, VRegInfo *&VRegInfo);
449 bool parseRegisterFlag(RegState &Flags);
450 bool parseRegisterClassOrBank(VRegInfo &RegInfo);
451 bool parseSubRegisterIndex(unsigned &SubReg);
452 bool parseRegisterTiedDefIndex(unsigned &TiedDefIdx);
453 bool parseRegisterOperand(MachineOperand &Dest,
454 std::optional<unsigned> &TiedDefIdx,
455 bool IsDef = false);
456 bool parseImmediateOperand(MachineOperand &Dest);
457 bool parseSymbolicInlineAsmOperand(unsigned OpIdx, MachineOperand &Dest);
458 bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
459 const Constant *&C);
460 bool parseIRConstant(StringRef::iterator Loc, const Constant *&C);
461 bool parseLowLevelType(StringRef::iterator Loc, LLT &Ty);
462 bool parseTypedImmediateOperand(MachineOperand &Dest);
463 bool parseFPImmediateOperand(MachineOperand &Dest);
464 bool parseMBBReference(MachineBasicBlock *&MBB);
465 bool parseMBBOperand(MachineOperand &Dest);
466 bool parseStackFrameIndex(int &FI);
467 bool parseStackObjectOperand(MachineOperand &Dest);
468 bool parseFixedStackFrameIndex(int &FI);
469 bool parseFixedStackObjectOperand(MachineOperand &Dest);
470 bool parseGlobalValue(GlobalValue *&GV);
471 bool parseGlobalAddressOperand(MachineOperand &Dest);
472 bool parseConstantPoolIndexOperand(MachineOperand &Dest);
473 bool parseSubRegisterIndexOperand(MachineOperand &Dest);
474 bool parseJumpTableIndexOperand(MachineOperand &Dest);
475 bool parseExternalSymbolOperand(MachineOperand &Dest);
476 bool parseMCSymbolOperand(MachineOperand &Dest);
477 [[nodiscard]] bool parseMDNode(MDNode *&Node);
478 bool parseDIExpression(MDNode *&Expr);
479 bool parseDILocation(MDNode *&Expr);
480 bool parseMetadataOperand(MachineOperand &Dest);
481 bool parseCFIOffset(int &Offset);
482 bool parseCFIUnsigned(unsigned &Value);
483 bool parseCFIRegister(unsigned &Reg);
484 bool parseCFIAddressSpace(unsigned &AddressSpace);
485 bool parseCFIEscapeValues(std::string& Values);
486 bool parseCFIOperand(MachineOperand &Dest);
487 bool parseIRBlock(BasicBlock *&BB, const Function &F);
488 bool parseBlockAddressOperand(MachineOperand &Dest);
489 bool parseIntrinsicOperand(MachineOperand &Dest);
490 bool parsePredicateOperand(MachineOperand &Dest);
491 bool parseShuffleMaskOperand(MachineOperand &Dest);
492 bool parseTargetIndexOperand(MachineOperand &Dest);
493 bool parseDbgInstrRefOperand(MachineOperand &Dest);
494 bool parseCustomRegisterMaskOperand(MachineOperand &Dest);
495 bool parseLaneMaskOperand(MachineOperand &Dest);
496 bool parseLiveoutRegisterMaskOperand(MachineOperand &Dest);
497 bool parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
498 MachineOperand &Dest,
499 std::optional<unsigned> &TiedDefIdx);
500 bool parseMachineOperandAndTargetFlags(const unsigned OpCode,
501 const unsigned OpIdx,
502 MachineOperand &Dest,
503 std::optional<unsigned> &TiedDefIdx);
504 bool parseOffset(int64_t &Offset);
505 bool parseIRBlockAddressTaken(BasicBlock *&BB);
506 bool parseAlignment(uint64_t &Alignment);
507 bool parseAddrspace(unsigned &Addrspace);
508 bool parseSectionID(std::optional<MBBSectionID> &SID);
509 bool parseBBID(std::optional<UniqueBBID> &BBID);
510 bool parseCallFrameSize(unsigned &CallFrameSize);
511 bool parsePrefetchTarget(CallsiteID &Target);
512 bool parseOperandsOffset(MachineOperand &Op);
513 bool parseIRValue(const Value *&V);
514 bool parseMemoryOperandFlag(MachineMemOperand::Flags &Flags);
515 bool parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV);
516 bool parseMachinePointerInfo(MachinePointerInfo &Dest);
517 bool parseOptionalScope(LLVMContext &Context, SyncScope::ID &SSID);
518 bool parseOptionalAtomicOrdering(AtomicOrdering &Order);
519 bool parseMachineMemoryOperand(MachineMemOperand *&Dest);
520 bool parsePreOrPostInstrSymbol(MCSymbol *&Symbol);
521 bool parseHeapAllocMarker(MDNode *&Node);
522 bool parsePCSections(MDNode *&Node);
523 bool parseMMRA(MDNode *&Node);
524
525 bool parseTargetImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
526 MachineOperand &Dest, const MIRFormatter &MF);
527
528private:
529 /// Convert the integer literal in the current token into an unsigned integer.
530 ///
531 /// Return true if an error occurred.
532 bool getUnsigned(unsigned &Result);
533
534 /// Convert the integer literal in the current token into an uint64.
535 ///
536 /// Return true if an error occurred.
537 bool getUint64(uint64_t &Result);
538
539 /// Convert the hexadecimal literal in the current token into an unsigned
540 /// APInt with a minimum bitwidth required to represent the value.
541 ///
542 /// Return true if the literal does not represent an integer value.
543 bool getHexUint(APInt &Result);
544
545 /// If the current token is of the given kind, consume it and return false.
546 /// Otherwise report an error and return true.
547 bool expectAndConsume(MIToken::TokenKind TokenKind);
548
549 /// If the current token is of the given kind, consume it and return true.
550 /// Otherwise return false.
551 bool consumeIfPresent(MIToken::TokenKind TokenKind);
552
553 bool parseInstruction(unsigned &OpCode, unsigned &Flags);
554
555 bool assignRegisterTies(MachineInstr &MI,
557
558 bool verifyImplicitOperands(ArrayRef<ParsedMachineOperand> Operands,
559 const MCInstrDesc &MCID);
560
561 const BasicBlock *getIRBlock(unsigned Slot);
562 const BasicBlock *getIRBlock(unsigned Slot, const Function &F);
563
564 /// Get or create an MCSymbol for a given name.
565 MCSymbol *getOrCreateMCSymbol(StringRef Name);
566
567 /// parseStringConstant
568 /// ::= StringConstant
569 bool parseStringConstant(std::string &Result);
570};
571
572} // end anonymous namespace
573
574MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
575 StringRef Source)
576 : MF(PFS.MF), Error(Error), Source(Source), CurrentSource(Source), PFS(PFS)
577{}
578
579void MIParser::lex(unsigned SkipChar) {
580 CurrentSource = lexMIToken(
581 CurrentSource.substr(SkipChar), Token,
582 [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); });
583}
584
585bool MIParser::error(const Twine &Msg) { return error(Token.location(), Msg); }
586
587bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) {
588 const SourceMgr &SM = *PFS.SM;
589 assert(Loc >= Source.data() && Loc <= (Source.data() + Source.size()));
590 const MemoryBuffer &Buffer = *SM.getMemoryBuffer(SM.getMainFileID());
591 if (Loc >= Buffer.getBufferStart() && Loc <= Buffer.getBufferEnd()) {
592 // Create an ordinary diagnostic when the source manager's buffer is the
593 // source string.
595 return true;
596 }
597 // Create a diagnostic for a YAML string literal.
598 Error = SMDiagnostic(SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
599 Loc - Source.data(), SourceMgr::DK_Error, Msg.str(),
600 Source, {}, {});
601 return true;
602}
603
604typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
606
607static const char *toString(MIToken::TokenKind TokenKind) {
608 switch (TokenKind) {
609 case MIToken::comma:
610 return "','";
611 case MIToken::equal:
612 return "'='";
613 case MIToken::colon:
614 return "':'";
615 case MIToken::lparen:
616 return "'('";
617 case MIToken::rparen:
618 return "')'";
619 default:
620 return "<unknown token>";
621 }
622}
623
624bool MIParser::expectAndConsume(MIToken::TokenKind TokenKind) {
625 if (Token.isNot(TokenKind))
626 return error(Twine("expected ") + toString(TokenKind));
627 lex();
628 return false;
629}
630
631bool MIParser::consumeIfPresent(MIToken::TokenKind TokenKind) {
632 if (Token.isNot(TokenKind))
633 return false;
634 lex();
635 return true;
636}
637
638// Parse Machine Basic Block Section ID.
639bool MIParser::parseSectionID(std::optional<MBBSectionID> &SID) {
641 lex();
642 if (Token.is(MIToken::IntegerLiteral)) {
643 unsigned Value = 0;
644 if (getUnsigned(Value))
645 return error("Unknown Section ID");
646 SID = MBBSectionID{Value};
647 } else {
648 const StringRef &S = Token.stringValue();
649 if (S == "Exception")
651 else if (S == "Cold")
653 else
654 return error("Unknown Section ID");
655 }
656 lex();
657 return false;
658}
659
660// Parse Machine Basic Block ID.
661bool MIParser::parseBBID(std::optional<UniqueBBID> &BBID) {
662 if (Token.isNot(MIToken::kw_bb_id))
663 return error("expected 'bb_id'");
664 lex();
665 unsigned BaseID = 0;
666 unsigned CloneID = 0;
667 if (Token.is(MIToken::FloatingPointLiteral)) {
668 StringRef S = Token.range();
669 auto Parts = S.split('.');
670 if (Parts.first.getAsInteger(10, BaseID) ||
671 Parts.second.getAsInteger(10, CloneID))
672 return error("Unknown BB ID");
673 lex();
674 } else {
675 if (getUnsigned(BaseID))
676 return error("Unknown BB ID");
677 lex();
678 if (Token.is(MIToken::comma) || Token.is(MIToken::dot)) {
679 lex();
680 if (getUnsigned(CloneID))
681 return error("Unknown Clone ID");
682 lex();
683 } else if (Token.is(MIToken::IntegerLiteral)) {
684 if (getUnsigned(CloneID))
685 return error("Unknown Clone ID");
686 lex();
687 }
688 }
689 BBID = {BaseID, CloneID};
690 return false;
691}
692
693// Parse basic block call frame size.
694bool MIParser::parseCallFrameSize(unsigned &CallFrameSize) {
696 lex();
697 unsigned Value = 0;
698 if (getUnsigned(Value))
699 return error("Unknown call frame size");
700 CallFrameSize = Value;
701 lex();
702 return false;
703}
704
705bool MIParser::parsePrefetchTarget(CallsiteID &Target) {
706 lex();
707 std::optional<UniqueBBID> BBID;
708 if (parseBBID(BBID))
709 return true;
710 Target.BBID = *BBID;
711 if (expectAndConsume(MIToken::comma))
712 return true;
713 return getUnsigned(Target.CallsiteIndex);
714}
715
716bool MIParser::parseBasicBlockDefinition(
719 unsigned ID = 0;
720 if (getUnsigned(ID))
721 return true;
722 auto Loc = Token.location();
723 auto Name = Token.stringValue();
724 lex();
725 bool MachineBlockAddressTaken = false;
726 BasicBlock *AddressTakenIRBlock = nullptr;
727 bool IsLandingPad = false;
728 bool IsInlineAsmBrIndirectTarget = false;
729 bool IsEHFuncletEntry = false;
730 bool IsEHScopeEntry = false;
731 std::optional<MBBSectionID> SectionID;
733 std::optional<UniqueBBID> BBID;
734 unsigned CallFrameSize = 0;
735 BasicBlock *BB = nullptr;
736 if (consumeIfPresent(MIToken::lparen)) {
737 do {
738 // TODO: Report an error when multiple same attributes are specified.
739 switch (Token.kind()) {
741 MachineBlockAddressTaken = true;
742 lex();
743 break;
745 if (parseIRBlockAddressTaken(AddressTakenIRBlock))
746 return true;
747 break;
749 IsLandingPad = true;
750 lex();
751 break;
753 IsInlineAsmBrIndirectTarget = true;
754 lex();
755 break;
757 IsEHFuncletEntry = true;
758 lex();
759 break;
761 IsEHScopeEntry = true;
762 lex();
763 break;
765 if (parseAlignment(Alignment))
766 return true;
767 break;
768 case MIToken::IRBlock:
770 // TODO: Report an error when both name and ir block are specified.
771 if (parseIRBlock(BB, MF.getFunction()))
772 return true;
773 lex();
774 break;
776 if (parseSectionID(SectionID))
777 return true;
778 break;
780 if (parseBBID(BBID))
781 return true;
782 break;
784 if (parseCallFrameSize(CallFrameSize))
785 return true;
786 break;
787 default:
788 break;
789 }
790 } while (consumeIfPresent(MIToken::comma));
791 if (expectAndConsume(MIToken::rparen))
792 return true;
793 }
794 if (expectAndConsume(MIToken::colon))
795 return true;
796
797 if (!Name.empty()) {
799 MF.getFunction().getValueSymbolTable()->lookup(Name));
800 if (!BB)
801 return error(Loc, Twine("basic block '") + Name +
802 "' is not defined in the function '" +
803 MF.getName() + "'");
804 }
805 auto *MBB = MF.CreateMachineBasicBlock(BB, BBID);
806 MF.insert(MF.end(), MBB);
807 bool WasInserted = MBBSlots.insert(std::make_pair(ID, MBB)).second;
808 if (!WasInserted)
809 return error(Loc, Twine("redefinition of machine basic block with id #") +
810 Twine(ID));
811 if (Alignment)
812 MBB->setAlignment(Align(Alignment));
813 if (MachineBlockAddressTaken)
815 if (AddressTakenIRBlock)
816 MBB->setAddressTakenIRBlock(AddressTakenIRBlock);
817 MBB->setIsEHPad(IsLandingPad);
818 MBB->setIsInlineAsmBrIndirectTarget(IsInlineAsmBrIndirectTarget);
819 MBB->setIsEHFuncletEntry(IsEHFuncletEntry);
820 MBB->setIsEHScopeEntry(IsEHScopeEntry);
821 if (SectionID) {
822 MBB->setSectionID(*SectionID);
823 MF.setBBSectionsType(BasicBlockSection::List);
824 }
825 MBB->setCallFrameSize(CallFrameSize);
826 return false;
827}
828
829bool MIParser::parseBasicBlockDefinitions(
831 lex();
832 // Skip until the first machine basic block.
833 while (Token.is(MIToken::Newline))
834 lex();
835 if (Token.isErrorOrEOF())
836 return Token.isError();
837 if (Token.isNot(MIToken::MachineBasicBlockLabel))
838 return error("expected a basic block definition before instructions");
839 unsigned BraceDepth = 0;
840 do {
841 if (parseBasicBlockDefinition(MBBSlots))
842 return true;
843 bool IsAfterNewline = false;
844 // Skip until the next machine basic block.
845 while (true) {
846 if ((Token.is(MIToken::MachineBasicBlockLabel) && IsAfterNewline) ||
847 Token.isErrorOrEOF())
848 break;
849 else if (Token.is(MIToken::MachineBasicBlockLabel))
850 return error("basic block definition should be located at the start of "
851 "the line");
852 else if (consumeIfPresent(MIToken::Newline)) {
853 IsAfterNewline = true;
854 continue;
855 }
856 IsAfterNewline = false;
857 if (Token.is(MIToken::lbrace))
858 ++BraceDepth;
859 if (Token.is(MIToken::rbrace)) {
860 if (!BraceDepth)
861 return error("extraneous closing brace ('}')");
862 --BraceDepth;
863 }
864 lex();
865 }
866 // Verify that we closed all of the '{' at the end of a file or a block.
867 if (!Token.isError() && BraceDepth)
868 return error("expected '}'"); // FIXME: Report a note that shows '{'.
869 } while (!Token.isErrorOrEOF());
870 return Token.isError();
871}
872
873bool MIParser::parseBasicBlockLiveins(MachineBasicBlock &MBB) {
874 assert(Token.is(MIToken::kw_liveins));
875 lex();
876 if (expectAndConsume(MIToken::colon))
877 return true;
878 if (Token.isNewlineOrEOF()) // Allow an empty list of liveins.
879 return false;
880 do {
881 if (Token.isNot(MIToken::NamedRegister))
882 return error("expected a named register");
884 if (parseNamedRegister(Reg))
885 return true;
886 lex();
888 if (consumeIfPresent(MIToken::colon)) {
889 // Parse lane mask.
890 if (Token.isNot(MIToken::IntegerLiteral) &&
891 Token.isNot(MIToken::HexLiteral))
892 return error("expected a lane mask");
893 static_assert(sizeof(LaneBitmask::Type) == sizeof(uint64_t),
894 "Use correct get-function for lane mask");
896 if (getUint64(V))
897 return error("invalid lane mask value");
898 Mask = LaneBitmask(V);
899 lex();
900 }
901 MBB.addLiveIn(Reg, Mask);
902 } while (consumeIfPresent(MIToken::comma));
903 return false;
904}
905
906bool MIParser::parseBasicBlockSuccessors(MachineBasicBlock &MBB) {
908 lex();
909 if (expectAndConsume(MIToken::colon))
910 return true;
911 if (Token.isNewlineOrEOF()) // Allow an empty list of successors.
912 return false;
913 do {
914 if (Token.isNot(MIToken::MachineBasicBlock))
915 return error("expected a machine basic block reference");
916 MachineBasicBlock *SuccMBB = nullptr;
917 if (parseMBBReference(SuccMBB))
918 return true;
919 lex();
920 unsigned Weight = 0;
921 if (consumeIfPresent(MIToken::lparen)) {
922 if (Token.isNot(MIToken::IntegerLiteral) &&
923 Token.isNot(MIToken::HexLiteral))
924 return error("expected an integer literal after '('");
925 if (getUnsigned(Weight))
926 return true;
927 lex();
928 if (expectAndConsume(MIToken::rparen))
929 return true;
930 }
932 } while (consumeIfPresent(MIToken::comma));
934 return false;
935}
936
937bool MIParser::parseBasicBlock(MachineBasicBlock &MBB,
938 MachineBasicBlock *&AddFalthroughFrom) {
939 // Skip the definition.
941 lex();
942 if (consumeIfPresent(MIToken::lparen)) {
943 while (Token.isNot(MIToken::rparen) && !Token.isErrorOrEOF())
944 lex();
945 consumeIfPresent(MIToken::rparen);
946 }
947 consumeIfPresent(MIToken::colon);
948
949 // Parse the liveins and successors.
950 // N.B: Multiple lists of successors and liveins are allowed and they're
951 // merged into one.
952 // Example:
953 // liveins: $edi
954 // liveins: $esi
955 //
956 // is equivalent to
957 // liveins: $edi, $esi
958 bool ExplicitSuccessors = false;
959 while (true) {
960 if (Token.is(MIToken::kw_successors)) {
961 if (parseBasicBlockSuccessors(MBB))
962 return true;
963 ExplicitSuccessors = true;
964 } else if (Token.is(MIToken::kw_liveins)) {
965 if (parseBasicBlockLiveins(MBB))
966 return true;
967 } else if (consumeIfPresent(MIToken::Newline)) {
968 continue;
969 } else {
970 break;
971 }
972 if (!Token.isNewlineOrEOF())
973 return error("expected line break at the end of a list");
974 lex();
975 }
976
977 // Parse the instructions.
978 bool IsInBundle = false;
979 MachineInstr *PrevMI = nullptr;
980 while (!Token.is(MIToken::MachineBasicBlockLabel) &&
981 !Token.is(MIToken::Eof)) {
982 if (consumeIfPresent(MIToken::Newline))
983 continue;
984 if (consumeIfPresent(MIToken::rbrace)) {
985 // The first parsing pass should verify that all closing '}' have an
986 // opening '{'.
987 assert(IsInBundle);
988 IsInBundle = false;
989 continue;
990 }
991 MachineInstr *MI = nullptr;
992 if (parse(MI))
993 return true;
994 MBB.insert(MBB.end(), MI);
995 if (IsInBundle) {
998 }
999 PrevMI = MI;
1000 if (Token.is(MIToken::lbrace)) {
1001 if (IsInBundle)
1002 return error("nested instruction bundles are not allowed");
1003 lex();
1004 // This instruction is the start of the bundle.
1005 MI->setFlag(MachineInstr::BundledSucc);
1006 IsInBundle = true;
1007 if (!Token.is(MIToken::Newline))
1008 // The next instruction can be on the same line.
1009 continue;
1010 }
1011 assert(Token.isNewlineOrEOF() && "MI is not fully parsed");
1012 lex();
1013 }
1014
1015 // Construct successor list by searching for basic block machine operands.
1016 if (!ExplicitSuccessors) {
1018 bool IsFallthrough;
1019 guessSuccessors(MBB, Successors, IsFallthrough);
1020 for (MachineBasicBlock *Succ : Successors)
1021 MBB.addSuccessor(Succ);
1022
1023 if (IsFallthrough) {
1024 AddFalthroughFrom = &MBB;
1025 } else {
1027 }
1028 }
1029
1030 return false;
1031}
1032
1033bool MIParser::parseBasicBlocks() {
1034 lex();
1035 // Skip until the first machine basic block.
1036 while (Token.is(MIToken::Newline))
1037 lex();
1038 if (Token.isErrorOrEOF())
1039 return Token.isError();
1040 // The first parsing pass should have verified that this token is a MBB label
1041 // in the 'parseBasicBlockDefinitions' method.
1043 MachineBasicBlock *AddFalthroughFrom = nullptr;
1044 do {
1045 MachineBasicBlock *MBB = nullptr;
1047 return true;
1048 if (AddFalthroughFrom) {
1049 if (!AddFalthroughFrom->isSuccessor(MBB))
1050 AddFalthroughFrom->addSuccessor(MBB);
1051 AddFalthroughFrom->normalizeSuccProbs();
1052 AddFalthroughFrom = nullptr;
1053 }
1054 if (parseBasicBlock(*MBB, AddFalthroughFrom))
1055 return true;
1056 // The method 'parseBasicBlock' should parse the whole block until the next
1057 // block or the end of file.
1058 assert(Token.is(MIToken::MachineBasicBlockLabel) || Token.is(MIToken::Eof));
1059 } while (Token.isNot(MIToken::Eof));
1060 return false;
1061}
1062
1063bool MIParser::parse(MachineInstr *&MI) {
1064 // Parse any register operands before '='
1067 while (Token.isRegister() || Token.isRegisterFlag()) {
1068 auto Loc = Token.location();
1069 std::optional<unsigned> TiedDefIdx;
1070 if (parseRegisterOperand(MO, TiedDefIdx, /*IsDef=*/true))
1071 return true;
1072 Operands.push_back(
1073 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1074 if (Token.isNot(MIToken::comma))
1075 break;
1076 lex();
1077 }
1078 if (!Operands.empty() && expectAndConsume(MIToken::equal))
1079 return true;
1080
1081 unsigned OpCode, Flags = 0;
1082 if (Token.isError() || parseInstruction(OpCode, Flags))
1083 return true;
1084
1085 // Parse the remaining machine operands.
1086 while (!Token.isNewlineOrEOF() && Token.isNot(MIToken::kw_pre_instr_symbol) &&
1087 Token.isNot(MIToken::kw_post_instr_symbol) &&
1088 Token.isNot(MIToken::kw_heap_alloc_marker) &&
1089 Token.isNot(MIToken::kw_pcsections) && Token.isNot(MIToken::kw_mmra) &&
1090 Token.isNot(MIToken::kw_cfi_type) &&
1091 Token.isNot(MIToken::kw_deactivation_symbol) &&
1092 Token.isNot(MIToken::kw_debug_location) &&
1093 Token.isNot(MIToken::kw_debug_instr_number) &&
1094 Token.isNot(MIToken::coloncolon) && Token.isNot(MIToken::lbrace)) {
1095 auto Loc = Token.location();
1096 std::optional<unsigned> TiedDefIdx;
1097 if (parseMachineOperandAndTargetFlags(OpCode, Operands.size(), MO, TiedDefIdx))
1098 return true;
1099 Operands.push_back(
1100 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1101 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
1102 Token.is(MIToken::lbrace))
1103 break;
1104 if (Token.isNot(MIToken::comma))
1105 return error("expected ',' before the next machine operand");
1106 lex();
1107 }
1108
1109 MCSymbol *PreInstrSymbol = nullptr;
1110 if (Token.is(MIToken::kw_pre_instr_symbol))
1111 if (parsePreOrPostInstrSymbol(PreInstrSymbol))
1112 return true;
1113 MCSymbol *PostInstrSymbol = nullptr;
1114 if (Token.is(MIToken::kw_post_instr_symbol))
1115 if (parsePreOrPostInstrSymbol(PostInstrSymbol))
1116 return true;
1117 MDNode *HeapAllocMarker = nullptr;
1118 if (Token.is(MIToken::kw_heap_alloc_marker))
1119 if (parseHeapAllocMarker(HeapAllocMarker))
1120 return true;
1121 MDNode *PCSections = nullptr;
1122 if (Token.is(MIToken::kw_pcsections))
1123 if (parsePCSections(PCSections))
1124 return true;
1125 MDNode *MMRA = nullptr;
1126 if (Token.is(MIToken::kw_mmra) && parseMMRA(MMRA))
1127 return true;
1128 unsigned CFIType = 0;
1129 if (Token.is(MIToken::kw_cfi_type)) {
1130 lex();
1131 if (Token.isNot(MIToken::IntegerLiteral))
1132 return error("expected an integer literal after 'cfi-type'");
1133 // getUnsigned is sufficient for 32-bit integers.
1134 if (getUnsigned(CFIType))
1135 return true;
1136 lex();
1137 // Lex past trailing comma if present.
1138 if (Token.is(MIToken::comma))
1139 lex();
1140 }
1141
1142 GlobalValue *DS = nullptr;
1143 if (Token.is(MIToken::kw_deactivation_symbol)) {
1144 lex();
1145 if (parseGlobalValue(DS))
1146 return true;
1147 lex();
1148 }
1149
1150 unsigned InstrNum = 0;
1151 if (Token.is(MIToken::kw_debug_instr_number)) {
1152 lex();
1153 if (Token.isNot(MIToken::IntegerLiteral))
1154 return error("expected an integer literal after 'debug-instr-number'");
1155 if (getUnsigned(InstrNum))
1156 return true;
1157 lex();
1158 // Lex past trailing comma if present.
1159 if (Token.is(MIToken::comma))
1160 lex();
1161 }
1162
1163 DebugLoc DebugLocation;
1164 if (Token.is(MIToken::kw_debug_location)) {
1165 lex();
1166 MDNode *Node = nullptr;
1167 if (Token.is(MIToken::exclaim)) {
1168 if (parseMDNode(Node))
1169 return true;
1170 } else if (Token.is(MIToken::md_dilocation)) {
1171 if (parseDILocation(Node))
1172 return true;
1173 } else {
1174 return error("expected a metadata node after 'debug-location'");
1175 }
1176 DebugLocation = DebugLoc(dyn_cast<DILocation>(Node));
1177 if (!DebugLocation)
1178 return error("referenced metadata is not a DILocation");
1179 }
1180
1181 // Parse the machine memory operands.
1183 if (Token.is(MIToken::coloncolon)) {
1184 lex();
1185 while (!Token.isNewlineOrEOF()) {
1186 MachineMemOperand *MemOp = nullptr;
1187 if (parseMachineMemoryOperand(MemOp))
1188 return true;
1189 MemOperands.push_back(MemOp);
1190 if (Token.isNewlineOrEOF())
1191 break;
1192 if (OpCode == TargetOpcode::BUNDLE && Token.is(MIToken::lbrace))
1193 break;
1194 if (Token.isNot(MIToken::comma))
1195 return error("expected ',' before the next machine memory operand");
1196 lex();
1197 }
1198 }
1199
1200 const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
1201 if (!MCID.isVariadic()) {
1202 // FIXME: Move the implicit operand verification to the machine verifier.
1203 if (verifyImplicitOperands(Operands, MCID))
1204 return true;
1205 }
1206
1207 MI = MF.CreateMachineInstr(MCID, DebugLocation, /*NoImplicit=*/true);
1208 MI->setFlags(Flags);
1209
1210 // Don't check the operands make sense, let the verifier catch any
1211 // improprieties.
1212 for (const auto &Operand : Operands)
1213 MI->addOperand(MF, Operand.Operand);
1214
1215 if (assignRegisterTies(*MI, Operands))
1216 return true;
1217 if (PreInstrSymbol)
1218 MI->setPreInstrSymbol(MF, PreInstrSymbol);
1219 if (PostInstrSymbol)
1220 MI->setPostInstrSymbol(MF, PostInstrSymbol);
1221 if (HeapAllocMarker)
1222 MI->setHeapAllocMarker(MF, HeapAllocMarker);
1223 if (PCSections)
1224 MI->setPCSections(MF, PCSections);
1225 if (MMRA)
1226 MI->setMMRAMetadata(MF, MMRA);
1227 if (CFIType)
1228 MI->setCFIType(MF, CFIType);
1229 if (DS)
1230 MI->setDeactivationSymbol(MF, DS);
1231 if (!MemOperands.empty())
1232 MI->setMemRefs(MF, MemOperands);
1233 if (InstrNum)
1234 MI->setDebugInstrNum(InstrNum);
1235 return false;
1236}
1237
1238bool MIParser::parseStandaloneMBB(MachineBasicBlock *&MBB) {
1239 lex();
1240 if (Token.isNot(MIToken::MachineBasicBlock))
1241 return error("expected a machine basic block reference");
1243 return true;
1244 lex();
1245 if (Token.isNot(MIToken::Eof))
1246 return error(
1247 "expected end of string after the machine basic block reference");
1248 return false;
1249}
1250
1251bool MIParser::parseStandaloneNamedRegister(Register &Reg) {
1252 lex();
1253 if (Token.isNot(MIToken::NamedRegister))
1254 return error("expected a named register");
1255 if (parseNamedRegister(Reg))
1256 return true;
1257 lex();
1258 if (Token.isNot(MIToken::Eof))
1259 return error("expected end of string after the register reference");
1260 return false;
1261}
1262
1263bool MIParser::parseStandaloneVirtualRegister(VRegInfo *&Info) {
1264 lex();
1265 if (Token.isNot(MIToken::VirtualRegister))
1266 return error("expected a virtual register");
1267 if (parseVirtualRegister(Info))
1268 return true;
1269 lex();
1270 if (Token.isNot(MIToken::Eof))
1271 return error("expected end of string after the register reference");
1272 return false;
1273}
1274
1275bool MIParser::parseStandaloneRegister(Register &Reg) {
1276 lex();
1277 if (Token.isNot(MIToken::NamedRegister) &&
1278 Token.isNot(MIToken::VirtualRegister))
1279 return error("expected either a named or virtual register");
1280
1281 VRegInfo *Info;
1282 if (parseRegister(Reg, Info))
1283 return true;
1284
1285 lex();
1286 if (Token.isNot(MIToken::Eof))
1287 return error("expected end of string after the register reference");
1288 return false;
1289}
1290
1291bool MIParser::parseStandaloneStackObject(int &FI) {
1292 lex();
1293 if (Token.isNot(MIToken::StackObject))
1294 return error("expected a stack object");
1295 if (parseStackFrameIndex(FI))
1296 return true;
1297 if (Token.isNot(MIToken::Eof))
1298 return error("expected end of string after the stack object reference");
1299 return false;
1300}
1301
1302bool MIParser::parseStandaloneMDNode(MDNode *&Node) {
1303 lex();
1304 if (Token.is(MIToken::exclaim)) {
1305 if (parseMDNode(Node))
1306 return true;
1307 } else if (Token.is(MIToken::md_diexpr)) {
1308 if (parseDIExpression(Node))
1309 return true;
1310 } else if (Token.is(MIToken::md_dilocation)) {
1311 if (parseDILocation(Node))
1312 return true;
1313 } else {
1314 return error("expected a metadata node");
1315 }
1316 if (Token.isNot(MIToken::Eof))
1317 return error("expected end of string after the metadata node");
1318 return false;
1319}
1320
1321static const char *printImplicitRegisterFlag(const MachineOperand &MO) {
1322 assert(MO.isImplicit());
1323 return MO.isDef() ? "implicit-def" : "implicit";
1324}
1325
1326static std::string getRegisterName(const TargetRegisterInfo *TRI,
1327 Register Reg) {
1328 assert(Reg.isPhysical() && "expected phys reg");
1329 return StringRef(TRI->getName(Reg)).lower();
1330}
1331
1332/// Return true if the parsed machine operands contain a given machine operand.
1333static bool isImplicitOperandIn(const MachineOperand &ImplicitOperand,
1335 for (const auto &I : Operands) {
1336 if (ImplicitOperand.isIdenticalTo(I.Operand))
1337 return true;
1338 }
1339 return false;
1340}
1341
1342bool MIParser::verifyImplicitOperands(ArrayRef<ParsedMachineOperand> Operands,
1343 const MCInstrDesc &MCID) {
1344 if (MCID.isCall())
1345 // We can't verify call instructions as they can contain arbitrary implicit
1346 // register and register mask operands.
1347 return false;
1348
1349 // Gather all the expected implicit operands.
1350 SmallVector<MachineOperand, 4> ImplicitOperands;
1351 for (MCPhysReg ImpDef : MCID.implicit_defs())
1352 ImplicitOperands.push_back(MachineOperand::CreateReg(ImpDef, true, true));
1353 for (MCPhysReg ImpUse : MCID.implicit_uses())
1354 ImplicitOperands.push_back(MachineOperand::CreateReg(ImpUse, false, true));
1355
1356 const auto *TRI = MF.getSubtarget().getRegisterInfo();
1357 assert(TRI && "Expected target register info");
1358 for (const auto &I : ImplicitOperands) {
1360 continue;
1361 return error(Operands.empty() ? Token.location() : Operands.back().End,
1362 Twine("missing implicit register operand '") +
1364 getRegisterName(TRI, I.getReg()) + "'");
1365 }
1366 return false;
1367}
1368
1369bool MIParser::parseInstruction(unsigned &OpCode, unsigned &Flags) {
1370 // Allow frame and fast math flags for OPCODE
1371 // clang-format off
1372 while (Token.is(MIToken::kw_frame_setup) ||
1373 Token.is(MIToken::kw_frame_destroy) ||
1374 Token.is(MIToken::kw_nnan) ||
1375 Token.is(MIToken::kw_ninf) ||
1376 Token.is(MIToken::kw_nsz) ||
1377 Token.is(MIToken::kw_arcp) ||
1378 Token.is(MIToken::kw_contract) ||
1379 Token.is(MIToken::kw_afn) ||
1380 Token.is(MIToken::kw_reassoc) ||
1381 Token.is(MIToken::kw_nuw) ||
1382 Token.is(MIToken::kw_nsw) ||
1383 Token.is(MIToken::kw_exact) ||
1384 Token.is(MIToken::kw_nofpexcept) ||
1385 Token.is(MIToken::kw_noconvergent) ||
1386 Token.is(MIToken::kw_unpredictable) ||
1387 Token.is(MIToken::kw_nneg) ||
1388 Token.is(MIToken::kw_disjoint) ||
1389 Token.is(MIToken::kw_nusw) ||
1390 Token.is(MIToken::kw_samesign) ||
1391 Token.is(MIToken::kw_inbounds) ||
1392 Token.is(MIToken::kw_lr_split)) {
1393 // clang-format on
1394 // Mine frame and fast math flags
1395 if (Token.is(MIToken::kw_frame_setup))
1397 if (Token.is(MIToken::kw_frame_destroy))
1399 if (Token.is(MIToken::kw_nnan))
1401 if (Token.is(MIToken::kw_ninf))
1403 if (Token.is(MIToken::kw_nsz))
1405 if (Token.is(MIToken::kw_arcp))
1407 if (Token.is(MIToken::kw_contract))
1409 if (Token.is(MIToken::kw_afn))
1411 if (Token.is(MIToken::kw_reassoc))
1413 if (Token.is(MIToken::kw_nuw))
1415 if (Token.is(MIToken::kw_nsw))
1417 if (Token.is(MIToken::kw_exact))
1419 if (Token.is(MIToken::kw_nofpexcept))
1421 if (Token.is(MIToken::kw_unpredictable))
1423 if (Token.is(MIToken::kw_noconvergent))
1425 if (Token.is(MIToken::kw_nneg))
1427 if (Token.is(MIToken::kw_disjoint))
1429 if (Token.is(MIToken::kw_nusw))
1431 if (Token.is(MIToken::kw_samesign))
1433 if (Token.is(MIToken::kw_inbounds))
1435 if (Token.is(MIToken::kw_lr_split))
1437
1438 lex();
1439 }
1440 if (Token.isNot(MIToken::Identifier))
1441 return error("expected a machine instruction");
1442 StringRef InstrName = Token.stringValue();
1443 if (PFS.Target.parseInstrName(InstrName, OpCode))
1444 return error(Twine("unknown machine instruction name '") + InstrName + "'");
1445 lex();
1446 return false;
1447}
1448
1449bool MIParser::parseNamedRegister(Register &Reg) {
1450 assert(Token.is(MIToken::NamedRegister) && "Needs NamedRegister token");
1451 StringRef Name = Token.stringValue();
1452 if (PFS.Target.getRegisterByName(Name, Reg))
1453 return error(Twine("unknown register name '") + Name + "'");
1454 return false;
1455}
1456
1457bool MIParser::parseNamedVirtualRegister(VRegInfo *&Info) {
1458 assert(Token.is(MIToken::NamedVirtualRegister) && "Expected NamedVReg token");
1459 StringRef Name = Token.stringValue();
1460 // TODO: Check that the VReg name is not the same as a physical register name.
1461 // If it is, then print a warning (when warnings are implemented).
1462 Info = &PFS.getVRegInfoNamed(Name);
1463 return false;
1464}
1465
1466bool MIParser::parseVirtualRegister(VRegInfo *&Info) {
1467 if (Token.is(MIToken::NamedVirtualRegister))
1468 return parseNamedVirtualRegister(Info);
1469 assert(Token.is(MIToken::VirtualRegister) && "Needs VirtualRegister token");
1470 unsigned ID;
1471 if (getUnsigned(ID))
1472 return true;
1473 Info = &PFS.getVRegInfo(ID);
1474 return false;
1475}
1476
1477bool MIParser::parseRegister(Register &Reg, VRegInfo *&Info) {
1478 switch (Token.kind()) {
1480 Reg = 0;
1481 return false;
1483 return parseNamedRegister(Reg);
1486 if (parseVirtualRegister(Info))
1487 return true;
1488 Reg = Info->VReg;
1489 return false;
1490 // TODO: Parse other register kinds.
1491 default:
1492 llvm_unreachable("The current token should be a register");
1493 }
1494}
1495
1496bool MIParser::parseRegisterClassOrBank(VRegInfo &RegInfo) {
1497 if (Token.isNot(MIToken::Identifier) && Token.isNot(MIToken::underscore))
1498 return error("expected '_', register class, or register bank name");
1499 StringRef::iterator Loc = Token.location();
1500 StringRef Name = Token.stringValue();
1501
1502 // Was it a register class?
1503 const TargetRegisterClass *RC = PFS.Target.getRegClass(Name);
1504 if (RC) {
1505 lex();
1506
1507 switch (RegInfo.Kind) {
1508 case VRegInfo::UNKNOWN:
1509 case VRegInfo::NORMAL:
1510 RegInfo.Kind = VRegInfo::NORMAL;
1511 if (RegInfo.Explicit && RegInfo.D.RC != RC) {
1512 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
1513 return error(Loc, Twine("conflicting register classes, previously: ") +
1514 Twine(TRI.getRegClassName(RegInfo.D.RC)));
1515 }
1516 RegInfo.D.RC = RC;
1517 RegInfo.Explicit = true;
1518 return false;
1519
1520 case VRegInfo::GENERIC:
1521 case VRegInfo::REGBANK:
1522 return error(Loc, "register class specification on generic register");
1523 }
1524 llvm_unreachable("Unexpected register kind");
1525 }
1526
1527 // Should be a register bank or a generic register.
1528 const RegisterBank *RegBank = nullptr;
1529 if (Name != "_") {
1530 RegBank = PFS.Target.getRegBank(Name);
1531 if (!RegBank)
1532 return error(Loc, "expected '_', register class, or register bank name");
1533 }
1534
1535 lex();
1536
1537 switch (RegInfo.Kind) {
1538 case VRegInfo::UNKNOWN:
1539 case VRegInfo::GENERIC:
1540 case VRegInfo::REGBANK:
1541 RegInfo.Kind = RegBank ? VRegInfo::REGBANK : VRegInfo::GENERIC;
1542 if (RegInfo.Explicit && RegInfo.D.RegBank != RegBank)
1543 return error(Loc, "conflicting generic register banks");
1544 RegInfo.D.RegBank = RegBank;
1545 RegInfo.Explicit = true;
1546 return false;
1547
1548 case VRegInfo::NORMAL:
1549 return error(Loc, "register bank specification on normal register");
1550 }
1551 llvm_unreachable("Unexpected register kind");
1552}
1553
1554bool MIParser::parseRegisterFlag(RegState &Flags) {
1555 const RegState OldFlags = Flags;
1556 switch (Token.kind()) {
1559 break;
1562 break;
1563 case MIToken::kw_def:
1565 break;
1566 case MIToken::kw_dead:
1568 break;
1569 case MIToken::kw_killed:
1571 break;
1572 case MIToken::kw_undef:
1574 break;
1577 break;
1580 break;
1583 break;
1586 break;
1587 default:
1588 llvm_unreachable("The current token should be a register flag");
1589 }
1590 if (OldFlags == Flags)
1591 // We know that the same flag is specified more than once when the flags
1592 // weren't modified.
1593 return error("duplicate '" + Token.stringValue() + "' register flag");
1594 lex();
1595 return false;
1596}
1597
1598bool MIParser::parseSubRegisterIndex(unsigned &SubReg) {
1599 assert(Token.is(MIToken::dot));
1600 lex();
1601 if (Token.isNot(MIToken::Identifier))
1602 return error("expected a subregister index after '.'");
1603 auto Name = Token.stringValue();
1604 SubReg = PFS.Target.getSubRegIndex(Name);
1605 if (!SubReg)
1606 return error(Twine("use of unknown subregister index '") + Name + "'");
1607 lex();
1608 return false;
1609}
1610
1611bool MIParser::parseRegisterTiedDefIndex(unsigned &TiedDefIdx) {
1612 assert(Token.is(MIToken::kw_tied_def));
1613 lex();
1614 if (Token.isNot(MIToken::IntegerLiteral))
1615 return error("expected an integer literal after 'tied-def'");
1616 if (getUnsigned(TiedDefIdx))
1617 return true;
1618 lex();
1619 return expectAndConsume(MIToken::rparen);
1620}
1621
1622bool MIParser::assignRegisterTies(MachineInstr &MI,
1624 SmallVector<std::pair<unsigned, unsigned>, 4> TiedRegisterPairs;
1625 for (unsigned I = 0, E = Operands.size(); I != E; ++I) {
1626 if (!Operands[I].TiedDefIdx)
1627 continue;
1628 // The parser ensures that this operand is a register use, so we just have
1629 // to check the tied-def operand.
1630 unsigned DefIdx = *Operands[I].TiedDefIdx;
1631 if (DefIdx >= E)
1632 return error(Operands[I].Begin,
1633 Twine("use of invalid tied-def operand index '" +
1634 Twine(DefIdx) + "'; instruction has only ") +
1635 Twine(E) + " operands");
1636 const auto &DefOperand = Operands[DefIdx].Operand;
1637 if (!DefOperand.isReg() || !DefOperand.isDef())
1638 // FIXME: add note with the def operand.
1639 return error(Operands[I].Begin,
1640 Twine("use of invalid tied-def operand index '") +
1641 Twine(DefIdx) + "'; the operand #" + Twine(DefIdx) +
1642 " isn't a defined register");
1643 // Check that the tied-def operand wasn't tied elsewhere.
1644 for (const auto &TiedPair : TiedRegisterPairs) {
1645 if (TiedPair.first == DefIdx)
1646 return error(Operands[I].Begin,
1647 Twine("the tied-def operand #") + Twine(DefIdx) +
1648 " is already tied with another register operand");
1649 }
1650 TiedRegisterPairs.push_back(std::make_pair(DefIdx, I));
1651 }
1652 // FIXME: Verify that for non INLINEASM instructions, the def and use tied
1653 // indices must be less than tied max.
1654 for (const auto &TiedPair : TiedRegisterPairs)
1655 MI.tieOperands(TiedPair.first, TiedPair.second);
1656 return false;
1657}
1658
1659bool MIParser::parseRegisterOperand(MachineOperand &Dest,
1660 std::optional<unsigned> &TiedDefIdx,
1661 bool IsDef) {
1662 RegState Flags = getDefRegState(IsDef);
1663 while (Token.isRegisterFlag()) {
1664 if (parseRegisterFlag(Flags))
1665 return true;
1666 }
1667 // Update IsDef as we may have read a def flag.
1668 IsDef = hasRegState(Flags, RegState::Define);
1669 if (!Token.isRegister())
1670 return error("expected a register after register flags");
1671 Register Reg;
1672 VRegInfo *RegInfo;
1673 if (parseRegister(Reg, RegInfo))
1674 return true;
1675 lex();
1676 unsigned SubReg = 0;
1677 if (Token.is(MIToken::dot)) {
1678 if (parseSubRegisterIndex(SubReg))
1679 return true;
1680 if (!Reg.isVirtual())
1681 return error("subregister index expects a virtual register");
1682 }
1683 if (Token.is(MIToken::colon)) {
1684 if (!Reg.isVirtual())
1685 return error("register class specification expects a virtual register");
1686 lex();
1687 if (parseRegisterClassOrBank(*RegInfo))
1688 return true;
1689 }
1690
1691 if (consumeIfPresent(MIToken::lparen)) {
1692 // For a def, we only expect a type. For use we expect either a type or a
1693 // tied-def. Additionally, for physical registers, we don't expect a type.
1694 if (Token.is(MIToken::kw_tied_def)) {
1695 if (IsDef)
1696 return error("tied-def not supported for defs");
1697 unsigned Idx;
1698 if (parseRegisterTiedDefIndex(Idx))
1699 return true;
1700 TiedDefIdx = Idx;
1701 } else {
1702 if (!Reg.isVirtual())
1703 return error("unexpected type on physical register");
1704
1705 LLT Ty;
1706 // If type parsing fails, forwad the parse error for defs.
1707 if (parseLowLevelType(Token.location(), Ty))
1708 return IsDef ? true
1709 : error("expected tied-def or low-level type after '('");
1710
1711 if (expectAndConsume(MIToken::rparen))
1712 return true;
1713
1714 MachineRegisterInfo &MRI = MF.getRegInfo();
1715 if (MRI.getType(Reg).isValid() && MRI.getType(Reg) != Ty)
1716 return error("inconsistent type for generic virtual register");
1717
1718 MRI.setRegClassOrRegBank(Reg, static_cast<RegisterBank *>(nullptr));
1719 MRI.setType(Reg, Ty);
1721 }
1722 } else if (IsDef && Reg.isVirtual()) {
1723 // Generic virtual registers defs must have a type.
1724 if (RegInfo->Kind == VRegInfo::GENERIC ||
1725 RegInfo->Kind == VRegInfo::REGBANK)
1726 return error("generic virtual registers must have a type");
1727 }
1728
1729 if (IsDef) {
1730 if (hasRegState(Flags, RegState::Kill))
1731 return error("cannot have a killed def operand");
1732 } else {
1733 if (hasRegState(Flags, RegState::Dead))
1734 return error("cannot have a dead use operand");
1735 }
1736
1738 Reg, IsDef, hasRegState(Flags, RegState::Implicit),
1741 hasRegState(Flags, RegState::EarlyClobber), SubReg,
1745
1746 return false;
1747}
1748
1749bool MIParser::parseImmediateOperand(MachineOperand &Dest) {
1751 const APSInt &Int = Token.integerValue();
1752 if (auto SImm = Int.trySExtValue(); Int.isSigned() && SImm.has_value())
1753 Dest = MachineOperand::CreateImm(*SImm);
1754 else if (auto UImm = Int.tryZExtValue(); !Int.isSigned() && UImm.has_value())
1755 Dest = MachineOperand::CreateImm(*UImm);
1756 else
1757 return error("integer literal is too large to be an immediate operand");
1758 lex();
1759 return false;
1760}
1761
1762bool MIParser::parseSymbolicInlineAsmOperand(unsigned OpIdx,
1763 MachineOperand &Dest) {
1765 assert(Token.is(MIToken::Identifier) &&
1766 "expected symbolic inline asm operand");
1767
1768 // Parse ExtraInfo flags.
1769 if (OpIdx == InlineAsm::MIOp_ExtraInfo) {
1770 unsigned ExtraInfo = 0;
1771 for (;;) {
1772 if (Token.isNot(MIToken::Identifier))
1773 break;
1774
1775 StringRef FlagName = Token.stringValue();
1776 unsigned Flag = StringSwitch<unsigned>(FlagName)
1778 .Case("mayload", InlineAsm::Extra_MayLoad)
1779 .Case("maystore", InlineAsm::Extra_MayStore)
1780 .Case("isconvergent", InlineAsm::Extra_IsConvergent)
1781 .Case("alignstack", InlineAsm::Extra_IsAlignStack)
1783 .Case("attdialect", 0)
1784 .Case("inteldialect", InlineAsm::Extra_AsmDialect)
1785 .Default(~0u);
1786 if (Flag == ~0u)
1787 return error("unknown inline asm extra info flag '" + FlagName + "'");
1788
1789 ExtraInfo |= Flag;
1790 lex();
1791 }
1792
1793 Dest = MachineOperand::CreateImm(ExtraInfo);
1794 return false;
1795 }
1796
1797 // Parse symbolic form: kind[:constraint].
1798 StringRef KindStr = Token.stringValue();
1799 constexpr auto InvalidKind = static_cast<InlineAsm::Kind>(0);
1802 .Case("regdef", InlineAsm::Kind::RegDef)
1803 .Case("reguse", InlineAsm::Kind::RegUse)
1805 .Case("clobber", InlineAsm::Kind::Clobber)
1806 .Case("imm", InlineAsm::Kind::Imm)
1807 .Case("mem", InlineAsm::Kind::Mem)
1808 .Default(InvalidKind);
1809 if (K == InvalidKind)
1810 return error("unknown inline asm operand kind '" + KindStr + "'");
1811
1812 lex();
1813
1814 // Create the flag with default of 1 operand.
1815 InlineAsm::Flag F(K, 1);
1816
1817 // Parse optional tiedto constraint: tiedto:$N.
1818 if (Token.is(MIToken::Identifier) && Token.stringValue() == "tiedto") {
1819 lex();
1820 if (Token.isNot(MIToken::colon))
1821 return error("expected ':' after 'tiedto'");
1822 lex();
1823 if (Token.isNot(MIToken::NamedRegister))
1824 return error("expected '$N' operand number after 'tiedto:'");
1825 unsigned OperandNo;
1826 if (Token.stringValue().getAsInteger(10, OperandNo))
1827 return error("invalid operand number in tiedto constraint");
1828 lex();
1829
1830 F.setMatchingOp(OperandNo);
1831
1833 return false;
1834 }
1835
1836 // Parse optional constraint after ':'.
1837 if (Token.isNot(MIToken::colon)) {
1839 return false;
1840 }
1841
1842 lex();
1843
1844 if (Token.isNot(MIToken::Identifier))
1845 return error("expected register class or memory constraint name after ':'");
1846
1847 StringRef ConstraintStr = Token.stringValue();
1848 if (K == InlineAsm::Kind::Mem) {
1881 return error("unknown memory constraint '" + ConstraintStr + "'");
1882 F.setMemConstraint(CC);
1883 } else if (K == InlineAsm::Kind::RegDef || K == InlineAsm::Kind::RegUse ||
1885 const TargetRegisterClass *RC =
1886 PFS.Target.getRegClass(ConstraintStr.lower());
1887 if (!RC)
1888 return error("unknown register class '" + ConstraintStr + "'");
1889 F.setRegClass(RC->getID());
1890 }
1891
1892 lex();
1893
1895 return false;
1896}
1897
1898bool MIParser::parseTargetImmMnemonic(const unsigned OpCode,
1899 const unsigned OpIdx,
1900 MachineOperand &Dest,
1901 const MIRFormatter &MF) {
1902 assert(Token.is(MIToken::dot));
1903 auto Loc = Token.location(); // record start position
1904 size_t Len = 1; // for "."
1905 lex();
1906
1907 // Handle the case that mnemonic starts with number.
1908 if (Token.is(MIToken::IntegerLiteral)) {
1909 Len += Token.range().size();
1910 lex();
1911 }
1912
1913 StringRef Src;
1914 if (Token.is(MIToken::comma))
1915 Src = StringRef(Loc, Len);
1916 else {
1917 assert(Token.is(MIToken::Identifier));
1918 Src = StringRef(Loc, Len + Token.stringValue().size());
1919 }
1920 int64_t Val;
1921 if (MF.parseImmMnemonic(OpCode, OpIdx, Src, Val,
1922 [this](StringRef::iterator Loc, const Twine &Msg)
1923 -> bool { return error(Loc, Msg); }))
1924 return true;
1925
1926 Dest = MachineOperand::CreateImm(Val);
1927 if (!Token.is(MIToken::comma))
1928 lex();
1929 return false;
1930}
1931
1933 PerFunctionMIParsingState &PFS, const Constant *&C,
1934 ErrorCallbackType ErrCB) {
1935 auto Source = StringValue.str(); // The source has to be null terminated.
1936 SMDiagnostic Err;
1937 C = parseConstantValue(Source, Err, *PFS.MF.getFunction().getParent(),
1938 &PFS.IRSlots);
1939 if (!C)
1940 return ErrCB(Loc + Err.getColumnNo(), Err.getMessage());
1941 return false;
1942}
1943
1944bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
1945 const Constant *&C) {
1946 return ::parseIRConstant(
1947 Loc, StringValue, PFS, C,
1948 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
1949 return error(Loc, Msg);
1950 });
1951}
1952
1953bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {
1954 if (parseIRConstant(Loc, StringRef(Loc, Token.range().end() - Loc), C))
1955 return true;
1956 lex();
1957 return false;
1958}
1959
1960// See LLT implementation for bit size limits.
1962 return Size != 0 && isUInt<16>(Size);
1963}
1964
1966 return NumElts != 0 && isUInt<16>(NumElts);
1967}
1968
1969static bool verifyAddrSpace(uint64_t AddrSpace) {
1970 return isUInt<24>(AddrSpace);
1971}
1972
1973bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
1974 StringRef TypeDigits = Token.range();
1975 if (TypeDigits.consume_front("s") || TypeDigits.consume_front("i") ||
1976 TypeDigits.consume_front("f") || TypeDigits.consume_front("p") ||
1977 TypeDigits.consume_front("bf")) {
1978 if (TypeDigits.empty() || !llvm::all_of(TypeDigits, isdigit))
1979 return error(
1980 "expected integers after 's'/'i'/'f'/'bf'/'p' type identifier");
1981 }
1982
1983 bool Scalar = Token.range().starts_with("s");
1984 if (Scalar || Token.range().starts_with("i")) {
1985 auto ScalarSize = APSInt(TypeDigits).getZExtValue();
1986 if (!ScalarSize) {
1987 Ty = LLT::token();
1988 lex();
1989 return false;
1990 }
1991
1992 if (!verifyScalarSize(ScalarSize))
1993 return error("invalid size for scalar type");
1994
1995 Ty = Scalar ? LLT::scalar(ScalarSize) : LLT::integer(ScalarSize);
1996 lex();
1997 return false;
1998 }
1999
2000 if (Token.range().starts_with("p")) {
2001 const DataLayout &DL = MF.getDataLayout();
2002 uint64_t AS = APSInt(TypeDigits).getZExtValue();
2003 if (!verifyAddrSpace(AS))
2004 return error("invalid address space number");
2005
2006 Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
2007 lex();
2008 return false;
2009 }
2010
2011 if (Token.range().starts_with("f") || Token.range().starts_with("bf")) {
2012 auto ScalarSize = APSInt(TypeDigits).getZExtValue();
2013 if (!ScalarSize || !verifyScalarSize(ScalarSize))
2014 return error("invalid size for scalar type");
2015
2016 if (Token.range().starts_with("bf") && ScalarSize != 16)
2017 return error("invalid size for bfloat");
2018
2019 Ty = Token.range().starts_with("bf") ? LLT::bfloat16()
2020 : LLT::floatIEEE(ScalarSize);
2021 lex();
2022 return false;
2023 }
2024
2025 // Now we're looking for a vector.
2026 if (Token.isNot(MIToken::less))
2027 return error(Loc, "expected tN, pA, <M x tN>, <M x pA>, <vscale x M x tN>, "
2028 "or <vscale x M x pA> for GlobalISel type, "
2029 "where t = {'s', 'i', 'f', 'bf'}");
2030 lex();
2031
2032 bool HasVScale =
2033 Token.is(MIToken::Identifier) && Token.stringValue() == "vscale";
2034 if (HasVScale) {
2035 lex();
2036 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
2037 return error(
2038 "expected <vscale x M x tN>, where t = {'s', 'i', 'f', 'bf', 'p'}");
2039 lex();
2040 }
2041
2042 auto GetError = [this, &HasVScale, Loc]() {
2043 if (HasVScale)
2044 return error(Loc, "expected <vscale x M x tN> for vector type, where t = "
2045 "{'s', 'i', 'f', 'bf', 'p'}");
2046 return error(Loc, "expected <M x tN> for vector type, where t = {'s', 'i', "
2047 "'f', 'bf', 'p'}");
2048 };
2049
2050 if (Token.isNot(MIToken::IntegerLiteral))
2051 return GetError();
2052 uint64_t NumElements = Token.integerValue().getZExtValue();
2053 if (!verifyVectorElementCount(NumElements))
2054 return error("invalid number of vector elements");
2055
2056 lex();
2057
2058 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
2059 return GetError();
2060 lex();
2061
2062 StringRef VectorTyDigits = Token.range();
2063 if (!VectorTyDigits.consume_front("s") &&
2064 !VectorTyDigits.consume_front("i") &&
2065 !VectorTyDigits.consume_front("f") &&
2066 !VectorTyDigits.consume_front("p") && !VectorTyDigits.consume_front("bf"))
2067 return GetError();
2068
2069 if (VectorTyDigits.empty() || !llvm::all_of(VectorTyDigits, isdigit))
2070 return error(
2071 "expected integers after 's'/'i'/'f'/'bf'/'p' type identifier");
2072
2073 Scalar = Token.range().starts_with("s");
2074 if (Scalar || Token.range().starts_with("i")) {
2075 auto ScalarSize = APSInt(VectorTyDigits).getZExtValue();
2076 if (!verifyScalarSize(ScalarSize))
2077 return error("invalid size for scalar element in vector");
2078 Ty = Scalar ? LLT::scalar(ScalarSize) : LLT::integer(ScalarSize);
2079 } else if (Token.range().starts_with("p")) {
2080 const DataLayout &DL = MF.getDataLayout();
2081 uint64_t AS = APSInt(VectorTyDigits).getZExtValue();
2082 if (!verifyAddrSpace(AS))
2083 return error("invalid address space number");
2084
2085 Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
2086 } else if (Token.range().starts_with("f")) {
2087 auto ScalarSize = APSInt(VectorTyDigits).getZExtValue();
2088 if (!verifyScalarSize(ScalarSize))
2089 return error("invalid size for float element in vector");
2090 Ty = LLT::floatIEEE(ScalarSize);
2091 } else if (Token.range().starts_with("bf")) {
2092 auto ScalarSize = APSInt(VectorTyDigits).getZExtValue();
2093 if (!verifyScalarSize(ScalarSize))
2094 return error("invalid size for bfloat element in vector");
2095 Ty = LLT::bfloat16();
2096 } else {
2097 return GetError();
2098 }
2099 lex();
2100
2101 if (Token.isNot(MIToken::greater))
2102 return GetError();
2103
2104 lex();
2105
2106 Ty = LLT::vector(ElementCount::get(NumElements, HasVScale), Ty);
2107 return false;
2108}
2109
2110bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {
2111 assert(Token.is(MIToken::Identifier));
2112 StringRef TypeDigits = Token.range();
2113 if (!TypeDigits.consume_front("i") && !TypeDigits.consume_front("s") &&
2114 !TypeDigits.consume_front("p") && !TypeDigits.consume_front("f") &&
2115 !TypeDigits.consume_front("bf"))
2116 return error("a typed immediate operand should start with one of 'i', "
2117 "'s', 'f', 'bf', or 'p'");
2118 if (TypeDigits.empty() || !llvm::all_of(TypeDigits, isdigit))
2119 return error(
2120 "expected integers after 'i'/'s'/'f'/'bf'/'p' type identifier");
2121
2122 auto Loc = Token.location();
2123 lex();
2124 if (Token.isNot(MIToken::IntegerLiteral)) {
2125 if (Token.isNot(MIToken::Identifier) ||
2126 !(Token.range() == "true" || Token.range() == "false"))
2127 return error("expected an integer literal");
2128 }
2129 const Constant *C = nullptr;
2130 if (parseIRConstant(Loc, C))
2131 return true;
2133 return false;
2134}
2135
2136bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
2137 auto Loc = Token.location();
2138 lex();
2139 if (Token.isNot(MIToken::FloatingPointLiteral) &&
2140 Token.isNot(MIToken::HexLiteral))
2141 return error("expected a floating point literal");
2142 const Constant *C = nullptr;
2143 if (parseIRConstant(Loc, C))
2144 return true;
2146 return false;
2147}
2148
2149static bool getHexUint(const MIToken &Token, APInt &Result) {
2151 StringRef S = Token.range();
2152 assert(S[0] == '0' && tolower(S[1]) == 'x');
2153 // This could be a floating point literal with a special prefix.
2154 if (!isxdigit(S[2]))
2155 return true;
2156 StringRef V = S.substr(2);
2157 APInt A(V.size()*4, V, 16);
2158
2159 // If A is 0, then A.getActiveBits() is 0. This isn't a valid bitwidth. Make
2160 // sure it isn't the case before constructing result.
2161 unsigned NumBits = (A == 0) ? 32 : A.getActiveBits();
2162 Result = APInt(NumBits, ArrayRef<uint64_t>(A.getRawData(), A.getNumWords()));
2163 return false;
2164}
2165
2166static bool getUnsigned(const MIToken &Token, unsigned &Result,
2167 ErrorCallbackType ErrCB) {
2168 if (Token.hasIntegerValue()) {
2169 const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1;
2170 const APSInt &SInt = Token.integerValue();
2171 if (SInt.isNegative())
2172 return ErrCB(Token.location(), "expected unsigned integer");
2173 uint64_t Val64 = SInt.getLimitedValue(Limit);
2174 if (Val64 == Limit)
2175 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
2176 Result = Val64;
2177 return false;
2178 }
2179 if (Token.is(MIToken::HexLiteral)) {
2180 APInt A;
2181 if (getHexUint(Token, A))
2182 return true;
2183 if (A.getBitWidth() > 32)
2184 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
2185 Result = A.getZExtValue();
2186 return false;
2187 }
2188 return true;
2189}
2190
2191bool MIParser::getUnsigned(unsigned &Result) {
2192 return ::getUnsigned(
2193 Token, Result, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2194 return error(Loc, Msg);
2195 });
2196}
2197
2198bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {
2201 unsigned Number;
2202 if (getUnsigned(Number))
2203 return true;
2204 auto MBBInfo = PFS.MBBSlots.find(Number);
2205 if (MBBInfo == PFS.MBBSlots.end())
2206 return error(Twine("use of undefined machine basic block #") +
2207 Twine(Number));
2208 MBB = MBBInfo->second;
2209 // TODO: Only parse the name if it's a MachineBasicBlockLabel. Deprecate once
2210 // we drop the <irname> from the bb.<id>.<irname> format.
2211 if (!Token.stringValue().empty() && Token.stringValue() != MBB->getName())
2212 return error(Twine("the name of machine basic block #") + Twine(Number) +
2213 " isn't '" + Token.stringValue() + "'");
2214 return false;
2215}
2216
2217bool MIParser::parseMBBOperand(MachineOperand &Dest) {
2220 return true;
2222 lex();
2223 return false;
2224}
2225
2226bool MIParser::parseStackFrameIndex(int &FI) {
2227 assert(Token.is(MIToken::StackObject));
2228 unsigned ID;
2229 if (getUnsigned(ID))
2230 return true;
2231 auto ObjectInfo = PFS.StackObjectSlots.find(ID);
2232 if (ObjectInfo == PFS.StackObjectSlots.end())
2233 return error(Twine("use of undefined stack object '%stack.") + Twine(ID) +
2234 "'");
2236 if (const auto *Alloca =
2237 MF.getFrameInfo().getObjectAllocation(ObjectInfo->second))
2238 Name = Alloca->getName();
2239 if (!Token.stringValue().empty() && Token.stringValue() != Name)
2240 return error(Twine("the name of the stack object '%stack.") + Twine(ID) +
2241 "' isn't '" + Token.stringValue() + "'");
2242 lex();
2243 FI = ObjectInfo->second;
2244 return false;
2245}
2246
2247bool MIParser::parseStackObjectOperand(MachineOperand &Dest) {
2248 int FI;
2249 if (parseStackFrameIndex(FI))
2250 return true;
2251 Dest = MachineOperand::CreateFI(FI);
2252 return false;
2253}
2254
2255bool MIParser::parseFixedStackFrameIndex(int &FI) {
2257 unsigned ID;
2258 if (getUnsigned(ID))
2259 return true;
2260 auto ObjectInfo = PFS.FixedStackObjectSlots.find(ID);
2261 if (ObjectInfo == PFS.FixedStackObjectSlots.end())
2262 return error(Twine("use of undefined fixed stack object '%fixed-stack.") +
2263 Twine(ID) + "'");
2264 lex();
2265 FI = ObjectInfo->second;
2266 return false;
2267}
2268
2269bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {
2270 int FI;
2271 if (parseFixedStackFrameIndex(FI))
2272 return true;
2273 Dest = MachineOperand::CreateFI(FI);
2274 return false;
2275}
2276
2277static bool parseGlobalValue(const MIToken &Token,
2279 ErrorCallbackType ErrCB) {
2280 switch (Token.kind()) {
2282 const Module *M = PFS.MF.getFunction().getParent();
2283 GV = M->getNamedValue(Token.stringValue());
2284 if (!GV)
2285 return ErrCB(Token.location(), Twine("use of undefined global value '") +
2286 Token.range() + "'");
2287 break;
2288 }
2289 case MIToken::GlobalValue: {
2290 unsigned GVIdx;
2291 if (getUnsigned(Token, GVIdx, ErrCB))
2292 return true;
2293 GV = PFS.IRSlots.GlobalValues.get(GVIdx);
2294 if (!GV)
2295 return ErrCB(Token.location(), Twine("use of undefined global value '@") +
2296 Twine(GVIdx) + "'");
2297 break;
2298 }
2299 default:
2300 llvm_unreachable("The current token should be a global value");
2301 }
2302 return false;
2303}
2304
2305bool MIParser::parseGlobalValue(GlobalValue *&GV) {
2306 return ::parseGlobalValue(
2307 Token, PFS, GV,
2308 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2309 return error(Loc, Msg);
2310 });
2311}
2312
2313bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
2314 GlobalValue *GV = nullptr;
2315 if (parseGlobalValue(GV))
2316 return true;
2317 lex();
2318 Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
2319 if (parseOperandsOffset(Dest))
2320 return true;
2321 return false;
2322}
2323
2324bool MIParser::parseConstantPoolIndexOperand(MachineOperand &Dest) {
2326 unsigned ID;
2327 if (getUnsigned(ID))
2328 return true;
2329 auto ConstantInfo = PFS.ConstantPoolSlots.find(ID);
2330 if (ConstantInfo == PFS.ConstantPoolSlots.end())
2331 return error("use of undefined constant '%const." + Twine(ID) + "'");
2332 lex();
2333 Dest = MachineOperand::CreateCPI(ID, /*Offset=*/0);
2334 if (parseOperandsOffset(Dest))
2335 return true;
2336 return false;
2337}
2338
2339bool MIParser::parseJumpTableIndexOperand(MachineOperand &Dest) {
2341 unsigned ID;
2342 if (getUnsigned(ID))
2343 return true;
2344 auto JumpTableEntryInfo = PFS.JumpTableSlots.find(ID);
2345 if (JumpTableEntryInfo == PFS.JumpTableSlots.end())
2346 return error("use of undefined jump table '%jump-table." + Twine(ID) + "'");
2347 lex();
2348 Dest = MachineOperand::CreateJTI(JumpTableEntryInfo->second);
2349 return false;
2350}
2351
2352bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) {
2354 const char *Symbol = MF.createExternalSymbolName(Token.stringValue());
2355 lex();
2356 Dest = MachineOperand::CreateES(Symbol);
2357 if (parseOperandsOffset(Dest))
2358 return true;
2359 return false;
2360}
2361
2362bool MIParser::parseMCSymbolOperand(MachineOperand &Dest) {
2363 assert(Token.is(MIToken::MCSymbol));
2364 MCSymbol *Symbol = getOrCreateMCSymbol(Token.stringValue());
2365 lex();
2366 Dest = MachineOperand::CreateMCSymbol(Symbol);
2367 if (parseOperandsOffset(Dest))
2368 return true;
2369 return false;
2370}
2371
2372bool MIParser::parseSubRegisterIndexOperand(MachineOperand &Dest) {
2374 StringRef Name = Token.stringValue();
2375 unsigned SubRegIndex = PFS.Target.getSubRegIndex(Token.stringValue());
2376 if (SubRegIndex == 0)
2377 return error(Twine("unknown subregister index '") + Name + "'");
2378 lex();
2379 Dest = MachineOperand::CreateImm(SubRegIndex);
2380 return false;
2381}
2382
2383bool MIParser::parseMDNode(MDNode *&Node) {
2384 assert(Token.is(MIToken::exclaim));
2385
2386 auto Loc = Token.location();
2387 lex();
2388 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
2389 return error("expected metadata id after '!'");
2390 unsigned ID;
2391 if (getUnsigned(ID))
2392 return true;
2393 auto NodeInfo = PFS.IRSlots.MetadataNodes.find(ID);
2394 if (NodeInfo == PFS.IRSlots.MetadataNodes.end()) {
2395 NodeInfo = PFS.MachineMetadataNodes.find(ID);
2396 if (NodeInfo == PFS.MachineMetadataNodes.end())
2397 return error(Loc, "use of undefined metadata '!" + Twine(ID) + "'");
2398 }
2399 lex();
2400 Node = NodeInfo->second.get();
2401 return false;
2402}
2403
2404bool MIParser::parseDIExpression(MDNode *&Expr) {
2405 unsigned Read;
2407 CurrentSource, Read, Error, *PFS.MF.getFunction().getParent(),
2408 &PFS.IRSlots);
2409 CurrentSource = CurrentSource.substr(Read);
2410 lex();
2411 if (!Expr)
2412 return error(Error.getMessage());
2413 return false;
2414}
2415
2416bool MIParser::parseDILocation(MDNode *&Loc) {
2417 assert(Token.is(MIToken::md_dilocation));
2418 lex();
2419
2420 bool HaveLine = false;
2421 unsigned Line = 0;
2422 unsigned Column = 0;
2423 MDNode *Scope = nullptr;
2424 MDNode *InlinedAt = nullptr;
2425 bool ImplicitCode = false;
2426 uint64_t AtomGroup = 0;
2427 uint64_t AtomRank = 0;
2428
2429 if (expectAndConsume(MIToken::lparen))
2430 return true;
2431
2432 if (Token.isNot(MIToken::rparen)) {
2433 do {
2434 if (Token.is(MIToken::Identifier)) {
2435 if (Token.stringValue() == "line") {
2436 lex();
2437 if (expectAndConsume(MIToken::colon))
2438 return true;
2439 if (Token.isNot(MIToken::IntegerLiteral) ||
2440 Token.integerValue().isSigned())
2441 return error("expected unsigned integer");
2442 Line = Token.integerValue().getZExtValue();
2443 HaveLine = true;
2444 lex();
2445 continue;
2446 }
2447 if (Token.stringValue() == "column") {
2448 lex();
2449 if (expectAndConsume(MIToken::colon))
2450 return true;
2451 if (Token.isNot(MIToken::IntegerLiteral) ||
2452 Token.integerValue().isSigned())
2453 return error("expected unsigned integer");
2454 Column = Token.integerValue().getZExtValue();
2455 lex();
2456 continue;
2457 }
2458 if (Token.stringValue() == "scope") {
2459 lex();
2460 if (expectAndConsume(MIToken::colon))
2461 return true;
2462 if (parseMDNode(Scope))
2463 return error("expected metadata node");
2464 if (!isa<DIScope>(Scope))
2465 return error("expected DIScope node");
2466 continue;
2467 }
2468 if (Token.stringValue() == "inlinedAt") {
2469 lex();
2470 if (expectAndConsume(MIToken::colon))
2471 return true;
2472 if (Token.is(MIToken::exclaim)) {
2473 if (parseMDNode(InlinedAt))
2474 return true;
2475 } else if (Token.is(MIToken::md_dilocation)) {
2476 if (parseDILocation(InlinedAt))
2477 return true;
2478 } else {
2479 return error("expected metadata node");
2480 }
2481 if (!isa<DILocation>(InlinedAt))
2482 return error("expected DILocation node");
2483 continue;
2484 }
2485 if (Token.stringValue() == "isImplicitCode") {
2486 lex();
2487 if (expectAndConsume(MIToken::colon))
2488 return true;
2489 if (!Token.is(MIToken::Identifier))
2490 return error("expected true/false");
2491 // As far as I can see, we don't have any existing need for parsing
2492 // true/false in MIR yet. Do it ad-hoc until there's something else
2493 // that needs it.
2494 if (Token.stringValue() == "true")
2495 ImplicitCode = true;
2496 else if (Token.stringValue() == "false")
2497 ImplicitCode = false;
2498 else
2499 return error("expected true/false");
2500 lex();
2501 continue;
2502 }
2503 if (Token.stringValue() == "atomGroup") {
2504 lex();
2505 if (expectAndConsume(MIToken::colon))
2506 return true;
2507 if (Token.isNot(MIToken::IntegerLiteral) ||
2508 Token.integerValue().isSigned())
2509 return error("expected unsigned integer");
2510 AtomGroup = Token.integerValue().getZExtValue();
2511 lex();
2512 continue;
2513 }
2514 if (Token.stringValue() == "atomRank") {
2515 lex();
2516 if (expectAndConsume(MIToken::colon))
2517 return true;
2518 if (Token.isNot(MIToken::IntegerLiteral) ||
2519 Token.integerValue().isSigned())
2520 return error("expected unsigned integer");
2521 AtomRank = Token.integerValue().getZExtValue();
2522 lex();
2523 continue;
2524 }
2525 }
2526 return error(Twine("invalid DILocation argument '") +
2527 Token.stringValue() + "'");
2528 } while (consumeIfPresent(MIToken::comma));
2529 }
2530
2531 if (expectAndConsume(MIToken::rparen))
2532 return true;
2533
2534 if (!HaveLine)
2535 return error("DILocation requires line number");
2536 if (!Scope)
2537 return error("DILocation requires a scope");
2538
2539 Loc = DILocation::get(MF.getFunction().getContext(), Line, Column, Scope,
2540 InlinedAt, ImplicitCode, AtomGroup, AtomRank);
2541 return false;
2542}
2543
2544bool MIParser::parseMetadataOperand(MachineOperand &Dest) {
2545 MDNode *Node = nullptr;
2546 if (Token.is(MIToken::exclaim)) {
2547 if (parseMDNode(Node))
2548 return true;
2549 } else if (Token.is(MIToken::md_diexpr)) {
2550 if (parseDIExpression(Node))
2551 return true;
2552 }
2553 Dest = MachineOperand::CreateMetadata(Node);
2554 return false;
2555}
2556
2557bool MIParser::parseCFIOffset(int &Offset) {
2558 if (Token.isNot(MIToken::IntegerLiteral))
2559 return error("expected a cfi offset");
2560 if (Token.integerValue().getSignificantBits() > 32)
2561 return error("expected a 32 bit integer (the cfi offset is too large)");
2562 Offset = (int)Token.integerValue().getExtValue();
2563 lex();
2564 return false;
2565}
2566
2567bool MIParser::parseCFIUnsigned(unsigned &Value) {
2568 if (getUnsigned(Value))
2569 return true;
2570 lex();
2571 return false;
2572}
2573
2574bool MIParser::parseCFIRegister(unsigned &Reg) {
2575 if (Token.isNot(MIToken::NamedRegister))
2576 return error("expected a cfi register");
2577 Register LLVMReg;
2578 if (parseNamedRegister(LLVMReg))
2579 return true;
2580 const auto *TRI = MF.getSubtarget().getRegisterInfo();
2581 assert(TRI && "Expected target register info");
2582 int DwarfReg = TRI->getDwarfRegNum(LLVMReg, true);
2583 if (DwarfReg < 0)
2584 return error("invalid DWARF register");
2585 Reg = (unsigned)DwarfReg;
2586 lex();
2587 return false;
2588}
2589
2590bool MIParser::parseCFIAddressSpace(unsigned &AddressSpace) {
2591 if (Token.isNot(MIToken::IntegerLiteral))
2592 return error("expected a cfi address space literal");
2593 if (Token.integerValue().isSigned())
2594 return error("expected an unsigned integer (cfi address space)");
2595 AddressSpace = Token.integerValue().getZExtValue();
2596 lex();
2597 return false;
2598}
2599
2600bool MIParser::parseCFIEscapeValues(std::string &Values) {
2601 do {
2602 if (Token.isNot(MIToken::HexLiteral))
2603 return error("expected a hexadecimal literal");
2604 unsigned Value;
2605 if (getUnsigned(Value))
2606 return true;
2607 if (Value > UINT8_MAX)
2608 return error("expected a 8-bit integer (too large)");
2609 Values.push_back(static_cast<uint8_t>(Value));
2610 lex();
2611 } while (consumeIfPresent(MIToken::comma));
2612 return false;
2613}
2614
2615bool MIParser::parseCFIOperand(MachineOperand &Dest) {
2616 auto Kind = Token.kind();
2617 lex();
2618 int Offset;
2619 unsigned Reg;
2620 unsigned AddressSpace;
2621 unsigned CFIIndex;
2622 switch (Kind) {
2624 if (parseCFIRegister(Reg))
2625 return true;
2626 CFIIndex = MF.addFrameInst(MCCFIInstruction::createSameValue(nullptr, Reg));
2627 break;
2629 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2630 parseCFIOffset(Offset))
2631 return true;
2632 CFIIndex =
2633 MF.addFrameInst(MCCFIInstruction::createOffset(nullptr, Reg, Offset));
2634 break;
2636 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2637 parseCFIOffset(Offset))
2638 return true;
2639 CFIIndex = MF.addFrameInst(
2641 break;
2643 if (parseCFIRegister(Reg))
2644 return true;
2645 CFIIndex =
2646 MF.addFrameInst(MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
2647 break;
2649 if (parseCFIOffset(Offset))
2650 return true;
2651 CFIIndex =
2652 MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, Offset));
2653 break;
2655 if (parseCFIOffset(Offset))
2656 return true;
2657 CFIIndex = MF.addFrameInst(
2659 break;
2661 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2662 parseCFIOffset(Offset))
2663 return true;
2664 CFIIndex =
2665 MF.addFrameInst(MCCFIInstruction::cfiDefCfa(nullptr, Reg, Offset));
2666 break;
2668 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2669 parseCFIOffset(Offset) || expectAndConsume(MIToken::comma) ||
2670 parseCFIAddressSpace(AddressSpace))
2671 return true;
2672 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMDefAspaceCfa(
2673 nullptr, Reg, Offset, AddressSpace, SMLoc()));
2674 break;
2676 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRememberState(nullptr));
2677 break;
2679 if (parseCFIRegister(Reg))
2680 return true;
2681 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
2682 break;
2684 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestoreState(nullptr));
2685 break;
2687 if (parseCFIRegister(Reg))
2688 return true;
2689 CFIIndex = MF.addFrameInst(MCCFIInstruction::createUndefined(nullptr, Reg));
2690 break;
2692 unsigned Reg2;
2693 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2694 parseCFIRegister(Reg2))
2695 return true;
2696
2697 CFIIndex =
2698 MF.addFrameInst(MCCFIInstruction::createRegister(nullptr, Reg, Reg2));
2699 break;
2700 }
2702 CFIIndex = MF.addFrameInst(MCCFIInstruction::createWindowSave(nullptr));
2703 break;
2705 CFIIndex = MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
2706 break;
2708 CFIIndex =
2709 MF.addFrameInst(MCCFIInstruction::createNegateRAStateWithPC(nullptr));
2710 break;
2712 unsigned State;
2713 MCSymbol *PACSym = nullptr;
2714 if (parseCFIUnsigned(State) || expectAndConsume(MIToken::comma))
2715 return true;
2716 if (Token.is(MIToken::MCSymbol)) {
2717 PACSym = getOrCreateMCSymbol(Token.stringValue());
2718 lex();
2719 CFIIndex = MF.addFrameInst(
2720 MCCFIInstruction::createSetRAState(nullptr, State, PACSym));
2721 } else if (Token.is(MIToken::IntegerLiteral)) {
2722 int Offset;
2723 if (parseCFIOffset(Offset))
2724 return true;
2725 CFIIndex = MF.addFrameInst(
2727 } else {
2728 return error("expected '<mcsymbol ...>' or integer offset for "
2729 "cfi_set_ra_state");
2730 }
2731 break;
2732 }
2734 unsigned Reg, R1, R2;
2735 unsigned R1Size, R2Size;
2736 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2737 parseCFIRegister(R1) || expectAndConsume(MIToken::comma) ||
2738 parseCFIUnsigned(R1Size) || expectAndConsume(MIToken::comma) ||
2739 parseCFIRegister(R2) || expectAndConsume(MIToken::comma) ||
2740 parseCFIUnsigned(R2Size))
2741 return true;
2742
2743 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMRegisterPair(
2744 nullptr, Reg, R1, R1Size, R2, R2Size));
2745 break;
2746 }
2748 std::vector<MCCFIInstruction::VectorRegisterWithLane> VectorRegisters;
2749 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma))
2750 return true;
2751 do {
2752 unsigned VR;
2753 unsigned Lane, Size;
2754 if (parseCFIRegister(VR) || expectAndConsume(MIToken::comma) ||
2755 parseCFIUnsigned(Lane) || expectAndConsume(MIToken::comma) ||
2756 parseCFIUnsigned(Size))
2757 return true;
2758 VectorRegisters.push_back({VR, Lane, Size});
2759 } while (consumeIfPresent(MIToken::comma));
2760
2761 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMVectorRegisters(
2762 nullptr, Reg, std::move(VectorRegisters)));
2763 break;
2764 }
2766 unsigned Reg, MaskReg;
2767 unsigned RegSize, MaskRegSize;
2768 int Offset = 0;
2769
2770 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2771 parseCFIUnsigned(RegSize) || expectAndConsume(MIToken::comma) ||
2772 parseCFIRegister(MaskReg) || expectAndConsume(MIToken::comma) ||
2773 parseCFIUnsigned(MaskRegSize) || expectAndConsume(MIToken::comma) ||
2774 parseCFIOffset(Offset))
2775 return true;
2776
2777 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMVectorOffset(
2778 nullptr, Reg, RegSize, MaskReg, MaskRegSize, Offset));
2779 break;
2780 }
2782 unsigned Reg, SpillReg, MaskReg;
2783 unsigned SpillRegLaneSize, MaskRegSize;
2784
2785 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2786 parseCFIRegister(SpillReg) || expectAndConsume(MIToken::comma) ||
2787 parseCFIUnsigned(SpillRegLaneSize) ||
2788 expectAndConsume(MIToken::comma) || parseCFIRegister(MaskReg) ||
2789 expectAndConsume(MIToken::comma) || parseCFIUnsigned(MaskRegSize))
2790 return true;
2791
2792 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMVectorRegisterMask(
2793 nullptr, Reg, SpillReg, SpillRegLaneSize, MaskReg, MaskRegSize));
2794 break;
2795 }
2797 std::string Values;
2798 if (parseCFIEscapeValues(Values))
2799 return true;
2800 CFIIndex = MF.addFrameInst(MCCFIInstruction::createEscape(nullptr, Values));
2801 break;
2802 }
2803 default:
2804 // TODO: Parse the other CFI operands.
2805 llvm_unreachable("The current token should be a cfi operand");
2806 }
2807 Dest = MachineOperand::CreateCFIIndex(CFIIndex);
2808 return false;
2809}
2810
2811bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) {
2812 switch (Token.kind()) {
2813 case MIToken::NamedIRBlock: {
2815 F.getValueSymbolTable()->lookup(Token.stringValue()));
2816 if (!BB)
2817 return error(Twine("use of undefined IR block '") + Token.range() + "'");
2818 break;
2819 }
2820 case MIToken::IRBlock: {
2821 unsigned SlotNumber = 0;
2822 if (getUnsigned(SlotNumber))
2823 return true;
2824 BB = const_cast<BasicBlock *>(getIRBlock(SlotNumber, F));
2825 if (!BB)
2826 return error(Twine("use of undefined IR block '%ir-block.") +
2827 Twine(SlotNumber) + "'");
2828 break;
2829 }
2830 default:
2831 llvm_unreachable("The current token should be an IR block reference");
2832 }
2833 return false;
2834}
2835
2836bool MIParser::parseBlockAddressOperand(MachineOperand &Dest) {
2838 lex();
2839 if (expectAndConsume(MIToken::lparen))
2840 return true;
2841 if (Token.isNot(MIToken::GlobalValue) &&
2842 Token.isNot(MIToken::NamedGlobalValue))
2843 return error("expected a global value");
2844 GlobalValue *GV = nullptr;
2845 if (parseGlobalValue(GV))
2846 return true;
2847 auto *F = dyn_cast<Function>(GV);
2848 if (!F)
2849 return error("expected an IR function reference");
2850 lex();
2851 if (expectAndConsume(MIToken::comma))
2852 return true;
2853 BasicBlock *BB = nullptr;
2854 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
2855 return error("expected an IR block reference");
2856 if (parseIRBlock(BB, *F))
2857 return true;
2858 lex();
2859 if (expectAndConsume(MIToken::rparen))
2860 return true;
2861 Dest = MachineOperand::CreateBA(BlockAddress::get(F, BB), /*Offset=*/0);
2862 if (parseOperandsOffset(Dest))
2863 return true;
2864 return false;
2865}
2866
2867bool MIParser::parseIntrinsicOperand(MachineOperand &Dest) {
2868 assert(Token.is(MIToken::kw_intrinsic));
2869 lex();
2870 if (expectAndConsume(MIToken::lparen))
2871 return error("expected syntax intrinsic(@llvm.whatever)");
2872
2873 if (Token.isNot(MIToken::NamedGlobalValue))
2874 return error("expected syntax intrinsic(@llvm.whatever)");
2875
2876 std::string Name = std::string(Token.stringValue());
2877 lex();
2878
2879 if (expectAndConsume(MIToken::rparen))
2880 return error("expected ')' to terminate intrinsic name");
2881
2882 // Find out what intrinsic we're dealing with.
2884 if (ID == Intrinsic::not_intrinsic)
2885 return error("unknown intrinsic name");
2887
2888 return false;
2889}
2890
2891bool MIParser::parsePredicateOperand(MachineOperand &Dest) {
2892 assert(Token.is(MIToken::kw_intpred) || Token.is(MIToken::kw_floatpred));
2893 bool IsFloat = Token.is(MIToken::kw_floatpred);
2894 lex();
2895
2896 if (expectAndConsume(MIToken::lparen))
2897 return error("expected syntax intpred(whatever) or floatpred(whatever");
2898
2899 if (Token.isNot(MIToken::Identifier))
2900 return error("whatever");
2901
2902 CmpInst::Predicate Pred;
2903 if (IsFloat) {
2904 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2905 .Case("false", CmpInst::FCMP_FALSE)
2906 .Case("oeq", CmpInst::FCMP_OEQ)
2907 .Case("ogt", CmpInst::FCMP_OGT)
2908 .Case("oge", CmpInst::FCMP_OGE)
2909 .Case("olt", CmpInst::FCMP_OLT)
2910 .Case("ole", CmpInst::FCMP_OLE)
2911 .Case("one", CmpInst::FCMP_ONE)
2912 .Case("ord", CmpInst::FCMP_ORD)
2913 .Case("uno", CmpInst::FCMP_UNO)
2914 .Case("ueq", CmpInst::FCMP_UEQ)
2915 .Case("ugt", CmpInst::FCMP_UGT)
2916 .Case("uge", CmpInst::FCMP_UGE)
2917 .Case("ult", CmpInst::FCMP_ULT)
2918 .Case("ule", CmpInst::FCMP_ULE)
2919 .Case("une", CmpInst::FCMP_UNE)
2920 .Case("true", CmpInst::FCMP_TRUE)
2922 if (!CmpInst::isFPPredicate(Pred))
2923 return error("invalid floating-point predicate");
2924 } else {
2925 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2926 .Case("eq", CmpInst::ICMP_EQ)
2927 .Case("ne", CmpInst::ICMP_NE)
2928 .Case("sgt", CmpInst::ICMP_SGT)
2929 .Case("sge", CmpInst::ICMP_SGE)
2930 .Case("slt", CmpInst::ICMP_SLT)
2931 .Case("sle", CmpInst::ICMP_SLE)
2932 .Case("ugt", CmpInst::ICMP_UGT)
2933 .Case("uge", CmpInst::ICMP_UGE)
2934 .Case("ult", CmpInst::ICMP_ULT)
2935 .Case("ule", CmpInst::ICMP_ULE)
2937 if (!CmpInst::isIntPredicate(Pred))
2938 return error("invalid integer predicate");
2939 }
2940
2941 lex();
2943 if (expectAndConsume(MIToken::rparen))
2944 return error("predicate should be terminated by ')'.");
2945
2946 return false;
2947}
2948
2949bool MIParser::parseShuffleMaskOperand(MachineOperand &Dest) {
2951
2952 lex();
2953 if (expectAndConsume(MIToken::lparen))
2954 return error("expected syntax shufflemask(<integer or undef>, ...)");
2955
2956 SmallVector<int, 32> ShufMask;
2957 do {
2958 if (Token.is(MIToken::kw_undef)) {
2959 ShufMask.push_back(-1);
2960 } else if (Token.is(MIToken::IntegerLiteral)) {
2961 const APSInt &Int = Token.integerValue();
2962 ShufMask.push_back(Int.getExtValue());
2963 } else {
2964 return error("expected integer constant");
2965 }
2966
2967 lex();
2968 } while (consumeIfPresent(MIToken::comma));
2969
2970 if (expectAndConsume(MIToken::rparen))
2971 return error("shufflemask should be terminated by ')'.");
2972
2973 if (ShufMask.size() < 2)
2974 return error("shufflemask should have > 1 element");
2975
2976 ArrayRef<int> MaskAlloc = MF.allocateShuffleMask(ShufMask);
2977 Dest = MachineOperand::CreateShuffleMask(MaskAlloc);
2978 return false;
2979}
2980
2981bool MIParser::parseDbgInstrRefOperand(MachineOperand &Dest) {
2983
2984 lex();
2985 if (expectAndConsume(MIToken::lparen))
2986 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
2987
2988 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isNegative())
2989 return error("expected unsigned integer for instruction index");
2990 uint64_t InstrIdx = Token.integerValue().getZExtValue();
2991 assert(InstrIdx <= std::numeric_limits<unsigned>::max() &&
2992 "Instruction reference's instruction index is too large");
2993 lex();
2994
2995 if (expectAndConsume(MIToken::comma))
2996 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
2997
2998 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isNegative())
2999 return error("expected unsigned integer for operand index");
3000 uint64_t OpIdx = Token.integerValue().getZExtValue();
3001 assert(OpIdx <= std::numeric_limits<unsigned>::max() &&
3002 "Instruction reference's operand index is too large");
3003 lex();
3004
3005 if (expectAndConsume(MIToken::rparen))
3006 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
3007
3008 Dest = MachineOperand::CreateDbgInstrRef(InstrIdx, OpIdx);
3009 return false;
3010}
3011
3012bool MIParser::parseTargetIndexOperand(MachineOperand &Dest) {
3014 lex();
3015 if (expectAndConsume(MIToken::lparen))
3016 return true;
3017 if (Token.isNot(MIToken::Identifier))
3018 return error("expected the name of the target index");
3019 int Index = 0;
3020 if (PFS.Target.getTargetIndex(Token.stringValue(), Index))
3021 return error("use of undefined target index '" + Token.stringValue() + "'");
3022 lex();
3023 if (expectAndConsume(MIToken::rparen))
3024 return true;
3025 Dest = MachineOperand::CreateTargetIndex(unsigned(Index), /*Offset=*/0);
3026 if (parseOperandsOffset(Dest))
3027 return true;
3028 return false;
3029}
3030
3031bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) {
3032 assert(Token.stringValue() == "CustomRegMask" && "Expected a custom RegMask");
3033 lex();
3034 if (expectAndConsume(MIToken::lparen))
3035 return true;
3036
3037 uint32_t *Mask = MF.allocateRegMask();
3038 do {
3039 if (Token.isNot(MIToken::rparen)) {
3040 if (Token.isNot(MIToken::NamedRegister))
3041 return error("expected a named register");
3042 Register Reg;
3043 if (parseNamedRegister(Reg))
3044 return true;
3045 lex();
3046 Mask[Reg.id() / 32] |= 1U << (Reg.id() % 32);
3047 }
3048
3049 // TODO: Report an error if the same register is used more than once.
3050 } while (consumeIfPresent(MIToken::comma));
3051
3052 if (expectAndConsume(MIToken::rparen))
3053 return true;
3054 Dest = MachineOperand::CreateRegMask(Mask);
3055 return false;
3056}
3057
3058bool MIParser::parseLaneMaskOperand(MachineOperand &Dest) {
3059 assert(Token.is(MIToken::kw_lanemask));
3060
3061 lex();
3062 if (expectAndConsume(MIToken::lparen))
3063 return true;
3064
3065 // Parse lanemask.
3066 if (Token.isNot(MIToken::IntegerLiteral) && Token.isNot(MIToken::HexLiteral))
3067 return error("expected a valid lane mask value");
3068 static_assert(sizeof(LaneBitmask::Type) == sizeof(uint64_t),
3069 "Use correct get-function for lane mask.");
3071 if (getUint64(V))
3072 return true;
3073 LaneBitmask LaneMask(V);
3074 lex();
3075
3076 if (expectAndConsume(MIToken::rparen))
3077 return true;
3078
3079 Dest = MachineOperand::CreateLaneMask(LaneMask);
3080 return false;
3081}
3082
3083bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) {
3084 assert(Token.is(MIToken::kw_liveout));
3085 uint32_t *Mask = MF.allocateRegMask();
3086 lex();
3087 if (expectAndConsume(MIToken::lparen))
3088 return true;
3089 while (true) {
3090 if (Token.isNot(MIToken::NamedRegister))
3091 return error("expected a named register");
3092 Register Reg;
3093 if (parseNamedRegister(Reg))
3094 return true;
3095 lex();
3096 Mask[Reg.id() / 32] |= 1U << (Reg.id() % 32);
3097 // TODO: Report an error if the same register is used more than once.
3098 if (Token.isNot(MIToken::comma))
3099 break;
3100 lex();
3101 }
3102 if (expectAndConsume(MIToken::rparen))
3103 return true;
3105 return false;
3106}
3107
3108bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
3109 MachineOperand &Dest,
3110 std::optional<unsigned> &TiedDefIdx) {
3111 switch (Token.kind()) {
3114 case MIToken::kw_def:
3115 case MIToken::kw_dead:
3116 case MIToken::kw_killed:
3117 case MIToken::kw_undef:
3126 return parseRegisterOperand(Dest, TiedDefIdx);
3128 // TODO: Forbid numeric operands for INLINEASM once the transition to the
3129 // symbolic form is over.
3130 return parseImmediateOperand(Dest);
3131 case MIToken::kw_half:
3132 case MIToken::kw_bfloat:
3133 case MIToken::kw_float:
3134 case MIToken::kw_double:
3136 case MIToken::kw_fp128:
3138 return parseFPImmediateOperand(Dest);
3140 return parseMBBOperand(Dest);
3142 return parseStackObjectOperand(Dest);
3144 return parseFixedStackObjectOperand(Dest);
3147 return parseGlobalAddressOperand(Dest);
3149 return parseConstantPoolIndexOperand(Dest);
3151 return parseJumpTableIndexOperand(Dest);
3153 return parseExternalSymbolOperand(Dest);
3154 case MIToken::MCSymbol:
3155 return parseMCSymbolOperand(Dest);
3157 return parseSubRegisterIndexOperand(Dest);
3158 case MIToken::md_diexpr:
3159 case MIToken::exclaim:
3160 return parseMetadataOperand(Dest);
3183 return parseCFIOperand(Dest);
3185 return parseBlockAddressOperand(Dest);
3187 return parseIntrinsicOperand(Dest);
3189 return parseTargetIndexOperand(Dest);
3191 return parseLaneMaskOperand(Dest);
3193 return parseLiveoutRegisterMaskOperand(Dest);
3196 return parsePredicateOperand(Dest);
3198 return parseShuffleMaskOperand(Dest);
3200 return parseDbgInstrRefOperand(Dest);
3201 case MIToken::Error:
3202 return true;
3203 case MIToken::Identifier: {
3204 bool IsInlineAsm = OpCode == TargetOpcode::INLINEASM ||
3205 OpCode == TargetOpcode::INLINEASM_BR;
3206 if (IsInlineAsm)
3207 return parseSymbolicInlineAsmOperand(OpIdx, Dest);
3208
3209 StringRef Id = Token.stringValue();
3210 if (const auto *RegMask = PFS.Target.getRegMask(Id)) {
3211 Dest = MachineOperand::CreateRegMask(RegMask);
3212 lex();
3213 break;
3214 } else if (Id == "CustomRegMask") {
3215 return parseCustomRegisterMaskOperand(Dest);
3216 } else {
3217 return parseTypedImmediateOperand(Dest);
3218 }
3219 }
3220 case MIToken::dot: {
3221 const auto *TII = MF.getSubtarget().getInstrInfo();
3222 if (const auto *Formatter = TII->getMIRFormatter()) {
3223 return parseTargetImmMnemonic(OpCode, OpIdx, Dest, *Formatter);
3224 }
3225 [[fallthrough]];
3226 }
3227 default:
3228 // FIXME: Parse the MCSymbol machine operand.
3229 return error("expected a machine operand");
3230 }
3231 return false;
3232}
3233
3234bool MIParser::parseMachineOperandAndTargetFlags(
3235 const unsigned OpCode, const unsigned OpIdx, MachineOperand &Dest,
3236 std::optional<unsigned> &TiedDefIdx) {
3237 unsigned TF = 0;
3238 bool HasTargetFlags = false;
3239 if (Token.is(MIToken::kw_target_flags)) {
3240 HasTargetFlags = true;
3241 lex();
3242 if (expectAndConsume(MIToken::lparen))
3243 return true;
3244 if (Token.isNot(MIToken::Identifier))
3245 return error("expected the name of the target flag");
3246 if (PFS.Target.getDirectTargetFlag(Token.stringValue(), TF)) {
3247 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), TF))
3248 return error("use of undefined target flag '" + Token.stringValue() +
3249 "'");
3250 }
3251 lex();
3252 while (Token.is(MIToken::comma)) {
3253 lex();
3254 if (Token.isNot(MIToken::Identifier))
3255 return error("expected the name of the target flag");
3256 unsigned BitFlag = 0;
3257 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), BitFlag))
3258 return error("use of undefined target flag '" + Token.stringValue() +
3259 "'");
3260 // TODO: Report an error when using a duplicate bit target flag.
3261 TF |= BitFlag;
3262 lex();
3263 }
3264 if (expectAndConsume(MIToken::rparen))
3265 return true;
3266 }
3267 auto Loc = Token.location();
3268 if (parseMachineOperand(OpCode, OpIdx, Dest, TiedDefIdx))
3269 return true;
3270 if (!HasTargetFlags)
3271 return false;
3272 if (Dest.isReg())
3273 return error(Loc, "register operands can't have target flags");
3274 Dest.setTargetFlags(TF);
3275 return false;
3276}
3277
3278bool MIParser::parseOffset(int64_t &Offset) {
3279 if (Token.isNot(MIToken::plus) && Token.isNot(MIToken::minus))
3280 return false;
3281 StringRef Sign = Token.range();
3282 bool IsNegative = Token.is(MIToken::minus);
3283 lex();
3284 if (Token.isNot(MIToken::IntegerLiteral))
3285 return error("expected an integer literal after '" + Sign + "'");
3286 if (Token.integerValue().getSignificantBits() > 64)
3287 return error("expected 64-bit integer (too large)");
3288 Offset = Token.integerValue().getExtValue();
3289 if (IsNegative)
3290 Offset = -Offset;
3291 lex();
3292 return false;
3293}
3294
3295bool MIParser::parseIRBlockAddressTaken(BasicBlock *&BB) {
3297 lex();
3298 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
3299 return error("expected basic block after 'ir_block_address_taken'");
3300
3301 if (parseIRBlock(BB, MF.getFunction()))
3302 return true;
3303
3304 lex();
3305 return false;
3306}
3307
3308bool MIParser::parseAlignment(uint64_t &Alignment) {
3309 assert(Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign));
3310 lex();
3311 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
3312 return error("expected an integer literal after 'align'");
3313 if (getUint64(Alignment))
3314 return true;
3315 lex();
3316
3317 if (!isPowerOf2_64(Alignment))
3318 return error("expected a power-of-2 literal after 'align'");
3319
3320 return false;
3321}
3322
3323bool MIParser::parseAddrspace(unsigned &Addrspace) {
3324 assert(Token.is(MIToken::kw_addrspace));
3325 lex();
3326 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
3327 return error("expected an integer literal after 'addrspace'");
3328 if (getUnsigned(Addrspace))
3329 return true;
3330 lex();
3331 return false;
3332}
3333
3334bool MIParser::parseOperandsOffset(MachineOperand &Op) {
3335 int64_t Offset = 0;
3336 if (parseOffset(Offset))
3337 return true;
3338 Op.setOffset(Offset);
3339 return false;
3340}
3341
3342static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS,
3343 const Value *&V, ErrorCallbackType ErrCB) {
3344 switch (Token.kind()) {
3345 case MIToken::NamedIRValue: {
3346 V = PFS.MF.getFunction().getValueSymbolTable()->lookup(Token.stringValue());
3347 break;
3348 }
3349 case MIToken::IRValue: {
3350 unsigned SlotNumber = 0;
3351 if (getUnsigned(Token, SlotNumber, ErrCB))
3352 return true;
3353 V = PFS.getIRValue(SlotNumber);
3354 break;
3355 }
3357 case MIToken::GlobalValue: {
3358 GlobalValue *GV = nullptr;
3359 if (parseGlobalValue(Token, PFS, GV, ErrCB))
3360 return true;
3361 V = GV;
3362 break;
3363 }
3365 const Constant *C = nullptr;
3366 if (parseIRConstant(Token.location(), Token.stringValue(), PFS, C, ErrCB))
3367 return true;
3368 V = C;
3369 break;
3370 }
3372 V = nullptr;
3373 return false;
3374 default:
3375 llvm_unreachable("The current token should be an IR block reference");
3376 }
3377 if (!V)
3378 return ErrCB(Token.location(), Twine("use of undefined IR value '") + Token.range() + "'");
3379 return false;
3380}
3381
3382bool MIParser::parseIRValue(const Value *&V) {
3383 return ::parseIRValue(
3384 Token, PFS, V, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3385 return error(Loc, Msg);
3386 });
3387}
3388
3389bool MIParser::getUint64(uint64_t &Result) {
3390 if (Token.hasIntegerValue()) {
3391 if (Token.integerValue().getActiveBits() > 64)
3392 return error("expected 64-bit integer (too large)");
3393 Result = Token.integerValue().getZExtValue();
3394 return false;
3395 }
3396 if (Token.is(MIToken::HexLiteral)) {
3397 APInt A;
3398 if (getHexUint(A))
3399 return true;
3400 if (A.getBitWidth() > 64)
3401 return error("expected 64-bit integer (too large)");
3402 Result = A.getZExtValue();
3403 return false;
3404 }
3405 return true;
3406}
3407
3408bool MIParser::getHexUint(APInt &Result) {
3409 return ::getHexUint(Token, Result);
3410}
3411
3412bool MIParser::parseMemoryOperandFlag(MachineMemOperand::Flags &Flags) {
3413 const auto OldFlags = Flags;
3414 switch (Token.kind()) {
3417 break;
3420 break;
3423 break;
3426 break;
3429 if (PFS.Target.getMMOTargetFlag(Token.stringValue(), TF))
3430 return error("use of undefined target MMO flag '" + Token.stringValue() +
3431 "'");
3432 Flags |= TF;
3433 break;
3434 }
3435 default:
3436 llvm_unreachable("The current token should be a memory operand flag");
3437 }
3438 if (OldFlags == Flags)
3439 // We know that the same flag is specified more than once when the flags
3440 // weren't modified.
3441 return error("duplicate '" + Token.stringValue() + "' memory operand flag");
3442 lex();
3443 return false;
3444}
3445
3446bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) {
3447 switch (Token.kind()) {
3448 case MIToken::kw_stack:
3449 PSV = MF.getPSVManager().getStack();
3450 break;
3451 case MIToken::kw_got:
3452 PSV = MF.getPSVManager().getGOT();
3453 break;
3455 PSV = MF.getPSVManager().getJumpTable();
3456 break;
3458 PSV = MF.getPSVManager().getConstantPool();
3459 break;
3461 int FI;
3462 if (parseFixedStackFrameIndex(FI))
3463 return true;
3464 PSV = MF.getPSVManager().getFixedStack(FI);
3465 // The token was already consumed, so use return here instead of break.
3466 return false;
3467 }
3468 case MIToken::StackObject: {
3469 int FI;
3470 if (parseStackFrameIndex(FI))
3471 return true;
3472 PSV = MF.getPSVManager().getFixedStack(FI);
3473 // The token was already consumed, so use return here instead of break.
3474 return false;
3475 }
3477 lex();
3478 switch (Token.kind()) {
3481 GlobalValue *GV = nullptr;
3482 if (parseGlobalValue(GV))
3483 return true;
3484 PSV = MF.getPSVManager().getGlobalValueCallEntry(GV);
3485 break;
3486 }
3488 PSV = MF.getPSVManager().getExternalSymbolCallEntry(
3489 MF.createExternalSymbolName(Token.stringValue()));
3490 break;
3491 default:
3492 return error(
3493 "expected a global value or an external symbol after 'call-entry'");
3494 }
3495 break;
3496 case MIToken::kw_custom: {
3497 lex();
3498 const auto *TII = MF.getSubtarget().getInstrInfo();
3499 if (const auto *Formatter = TII->getMIRFormatter()) {
3500 if (Formatter->parseCustomPseudoSourceValue(
3501 Token.stringValue(), MF, PFS, PSV,
3502 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3503 return error(Loc, Msg);
3504 }))
3505 return true;
3506 } else {
3507 return error("unable to parse target custom pseudo source value");
3508 }
3509 break;
3510 }
3511 default:
3512 llvm_unreachable("The current token should be pseudo source value");
3513 }
3514 lex();
3515 return false;
3516}
3517
3518bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) {
3519 if (Token.is(MIToken::kw_constant_pool) || Token.is(MIToken::kw_stack) ||
3520 Token.is(MIToken::kw_got) || Token.is(MIToken::kw_jump_table) ||
3521 Token.is(MIToken::FixedStackObject) || Token.is(MIToken::StackObject) ||
3522 Token.is(MIToken::kw_call_entry) || Token.is(MIToken::kw_custom)) {
3523 const PseudoSourceValue *PSV = nullptr;
3524 if (parseMemoryPseudoSourceValue(PSV))
3525 return true;
3526 int64_t Offset = 0;
3527 if (parseOffset(Offset))
3528 return true;
3529 Dest = MachinePointerInfo(PSV, Offset);
3530 return false;
3531 }
3532 if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue) &&
3533 Token.isNot(MIToken::GlobalValue) &&
3534 Token.isNot(MIToken::NamedGlobalValue) &&
3535 Token.isNot(MIToken::QuotedIRValue) &&
3536 Token.isNot(MIToken::kw_unknown_address))
3537 return error("expected an IR value reference");
3538 const Value *V = nullptr;
3539 if (parseIRValue(V))
3540 return true;
3541 if (V && !V->getType()->isPointerTy())
3542 return error("expected a pointer IR value");
3543 lex();
3544 int64_t Offset = 0;
3545 if (parseOffset(Offset))
3546 return true;
3547 Dest = MachinePointerInfo(V, Offset);
3548 return false;
3549}
3550
3551bool MIParser::parseOptionalScope(LLVMContext &Context,
3552 SyncScope::ID &SSID) {
3553 SSID = SyncScope::System;
3554 if (Token.is(MIToken::Identifier) && Token.stringValue() == "syncscope") {
3555 lex();
3556 if (expectAndConsume(MIToken::lparen))
3557 return error("expected '(' in syncscope");
3558
3559 std::string SSN;
3560 if (parseStringConstant(SSN))
3561 return true;
3562
3563 SSID = Context.getOrInsertSyncScopeID(SSN);
3564 if (expectAndConsume(MIToken::rparen))
3565 return error("expected ')' in syncscope");
3566 }
3567
3568 return false;
3569}
3570
3571bool MIParser::parseOptionalAtomicOrdering(AtomicOrdering &Order) {
3573 if (Token.isNot(MIToken::Identifier))
3574 return false;
3575
3576 Order = StringSwitch<AtomicOrdering>(Token.stringValue())
3577 .Case("unordered", AtomicOrdering::Unordered)
3578 .Case("monotonic", AtomicOrdering::Monotonic)
3579 .Case("acquire", AtomicOrdering::Acquire)
3580 .Case("release", AtomicOrdering::Release)
3584
3585 if (Order != AtomicOrdering::NotAtomic) {
3586 lex();
3587 return false;
3588 }
3589
3590 return error("expected an atomic scope, ordering or a size specification");
3591}
3592
3593bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
3594 if (expectAndConsume(MIToken::lparen))
3595 return true;
3597 while (Token.isMemoryOperandFlag()) {
3598 if (parseMemoryOperandFlag(Flags))
3599 return true;
3600 }
3601 if (Token.isNot(MIToken::Identifier) ||
3602 (Token.stringValue() != "load" && Token.stringValue() != "store"))
3603 return error("expected 'load' or 'store' memory operation");
3604 if (Token.stringValue() == "load")
3606 else
3608 lex();
3609
3610 // Optional 'store' for operands that both load and store.
3611 if (Token.is(MIToken::Identifier) && Token.stringValue() == "store") {
3613 lex();
3614 }
3615
3616 // Optional synchronization scope.
3617 SyncScope::ID SSID;
3618 if (parseOptionalScope(MF.getFunction().getContext(), SSID))
3619 return true;
3620
3621 // Up to two atomic orderings (cmpxchg provides guarantees on failure).
3622 AtomicOrdering Order, FailureOrder;
3623 if (parseOptionalAtomicOrdering(Order))
3624 return true;
3625
3626 if (parseOptionalAtomicOrdering(FailureOrder))
3627 return true;
3628
3629 if (Token.isNot(MIToken::IntegerLiteral) &&
3630 Token.isNot(MIToken::kw_unknown_size) &&
3631 Token.isNot(MIToken::lparen))
3632 return error("expected memory LLT, the size integer literal or 'unknown-size' after "
3633 "memory operation");
3634
3636 if (Token.is(MIToken::IntegerLiteral)) {
3637 uint64_t Size;
3638 if (getUint64(Size))
3639 return true;
3640
3641 // Convert from bytes to bits for storage.
3643 lex();
3644 } else if (Token.is(MIToken::kw_unknown_size)) {
3645 lex();
3646 } else {
3647 if (expectAndConsume(MIToken::lparen))
3648 return true;
3649 if (parseLowLevelType(Token.location(), MemoryType))
3650 return true;
3651 if (expectAndConsume(MIToken::rparen))
3652 return true;
3653 }
3654
3656 if (Token.is(MIToken::Identifier)) {
3657 const char *Word =
3660 ? "on"
3661 : Flags & MachineMemOperand::MOLoad ? "from" : "into";
3662 if (Token.stringValue() != Word)
3663 return error(Twine("expected '") + Word + "'");
3664 lex();
3665
3666 if (parseMachinePointerInfo(Ptr))
3667 return true;
3668 }
3669 uint64_t BaseAlignment =
3670 MemoryType.isValid()
3671 ? PowerOf2Ceil(MemoryType.getSizeInBytes().getKnownMinValue())
3672 : 1;
3673 AAMDNodes AAInfo;
3674 MDNode *Range = nullptr;
3675 MDNode *MemCacheHint = nullptr;
3676 while (consumeIfPresent(MIToken::comma)) {
3677 switch (Token.kind()) {
3678 case MIToken::kw_align: {
3679 // align is printed if it is different than size.
3681 if (parseAlignment(Alignment))
3682 return true;
3683 if (Ptr.Offset & (Alignment - 1)) {
3684 // MachineMemOperand::getAlign never returns a value greater than the
3685 // alignment of offset, so this just guards against hand-written MIR
3686 // that specifies a large "align" value when it should probably use
3687 // "basealign" instead.
3688 return error("specified alignment is more aligned than offset");
3689 }
3690 BaseAlignment = Alignment;
3691 break;
3692 }
3694 // basealign is printed if it is different than align.
3695 if (parseAlignment(BaseAlignment))
3696 return true;
3697 break;
3699 if (parseAddrspace(Ptr.AddrSpace))
3700 return true;
3701 break;
3702 case MIToken::md_tbaa:
3703 lex();
3704 if (parseMDNode(AAInfo.TBAA))
3705 return true;
3706 break;
3708 lex();
3709 if (parseMDNode(AAInfo.Scope))
3710 return true;
3711 break;
3713 lex();
3714 if (parseMDNode(AAInfo.NoAlias))
3715 return true;
3716 break;
3718 lex();
3719 if (parseMDNode(AAInfo.NoAliasAddrSpace))
3720 return true;
3721 break;
3722 case MIToken::md_range:
3723 lex();
3724 if (parseMDNode(Range))
3725 return true;
3726 break;
3728 lex();
3729 if (parseMDNode(MemCacheHint))
3730 return true;
3731 break;
3732 // TODO: Report an error on duplicate metadata nodes.
3733 default:
3734 return error("expected 'align' or '!tbaa' or '!alias.scope' or "
3735 "'!noalias' or '!range' or '!mem.cache_hint' or "
3736 "'!noalias.addrspace'");
3737 }
3738 }
3739 if (expectAndConsume(MIToken::rparen))
3740 return true;
3741 Dest = MF.getMachineMemOperand(Ptr, Flags, MemoryType, Align(BaseAlignment),
3742 MMOMetadata(AAInfo, Range, MemCacheHint), SSID,
3743 Order, FailureOrder);
3744 return false;
3745}
3746
3747bool MIParser::parsePreOrPostInstrSymbol(MCSymbol *&Symbol) {
3749 Token.is(MIToken::kw_post_instr_symbol)) &&
3750 "Invalid token for a pre- post-instruction symbol!");
3751 lex();
3752 if (Token.isNot(MIToken::MCSymbol))
3753 return error("expected a symbol after 'pre-instr-symbol'");
3754 Symbol = getOrCreateMCSymbol(Token.stringValue());
3755 lex();
3756 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3757 Token.is(MIToken::lbrace))
3758 return false;
3759 if (Token.isNot(MIToken::comma))
3760 return error("expected ',' before the next machine operand");
3761 lex();
3762 return false;
3763}
3764
3765bool MIParser::parseHeapAllocMarker(MDNode *&Node) {
3767 "Invalid token for a heap alloc marker!");
3768 lex();
3769 if (parseMDNode(Node))
3770 return true;
3771 if (!Node)
3772 return error("expected a MDNode after 'heap-alloc-marker'");
3773 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3774 Token.is(MIToken::lbrace))
3775 return false;
3776 if (Token.isNot(MIToken::comma))
3777 return error("expected ',' before the next machine operand");
3778 lex();
3779 return false;
3780}
3781
3782bool MIParser::parsePCSections(MDNode *&Node) {
3783 assert(Token.is(MIToken::kw_pcsections) &&
3784 "Invalid token for a PC sections!");
3785 lex();
3786 if (parseMDNode(Node))
3787 return true;
3788 if (!Node)
3789 return error("expected a MDNode after 'pcsections'");
3790 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3791 Token.is(MIToken::lbrace))
3792 return false;
3793 if (Token.isNot(MIToken::comma))
3794 return error("expected ',' before the next machine operand");
3795 lex();
3796 return false;
3797}
3798
3799bool MIParser::parseMMRA(MDNode *&Node) {
3800 assert(Token.is(MIToken::kw_mmra) && "Invalid token for MMRA!");
3801 lex();
3802 if (parseMDNode(Node))
3803 return true;
3804 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3805 Token.is(MIToken::lbrace))
3806 return false;
3807 if (Token.isNot(MIToken::comma))
3808 return error("expected ',' before the next machine operand");
3809 lex();
3810 return false;
3811}
3812
3814 const Function &F,
3815 DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
3816 ModuleSlotTracker MST(F.getParent());
3818 for (const auto &BB : F) {
3819 if (BB.hasName())
3820 continue;
3821 int Slot = MST.getLocalSlot(&BB);
3822 if (Slot == -1)
3823 continue;
3824 Slots2BasicBlocks.insert(std::make_pair(unsigned(Slot), &BB));
3825 }
3826}
3827
3829 unsigned Slot,
3830 const DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
3831 return Slots2BasicBlocks.lookup(Slot);
3832}
3833
3834const BasicBlock *MIParser::getIRBlock(unsigned Slot) {
3835 if (Slots2BasicBlocks.empty())
3836 initSlots2BasicBlocks(MF.getFunction(), Slots2BasicBlocks);
3837 return getIRBlockFromSlot(Slot, Slots2BasicBlocks);
3838}
3839
3840const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) {
3841 if (&F == &MF.getFunction())
3842 return getIRBlock(Slot);
3843 DenseMap<unsigned, const BasicBlock *> CustomSlots2BasicBlocks;
3844 initSlots2BasicBlocks(F, CustomSlots2BasicBlocks);
3845 return getIRBlockFromSlot(Slot, CustomSlots2BasicBlocks);
3846}
3847
3848MCSymbol *MIParser::getOrCreateMCSymbol(StringRef Name) {
3849 // FIXME: Currently we can't recognize temporary or local symbols and call all
3850 // of the appropriate forms to create them. However, this handles basic cases
3851 // well as most of the special aspects are recognized by a prefix on their
3852 // name, and the input names should already be unique. For test cases, keeping
3853 // the symbol name out of the symbol table isn't terribly important.
3854 return MF.getContext().getOrCreateSymbol(Name);
3855}
3856
3857bool MIParser::parseStringConstant(std::string &Result) {
3858 if (Token.isNot(MIToken::StringConstant))
3859 return error("expected string constant");
3860 Result = std::string(Token.stringValue());
3861 lex();
3862 return false;
3863}
3864
3866 StringRef Src,
3868 return MIParser(PFS, Error, Src).parseBasicBlockDefinitions(PFS.MBBSlots);
3869}
3870
3873 return MIParser(PFS, Error, Src).parseBasicBlocks();
3874}
3875
3879 return MIParser(PFS, Error, Src).parseStandaloneMBB(MBB);
3880}
3881
3883 Register &Reg, StringRef Src,
3885 return MIParser(PFS, Error, Src).parseStandaloneRegister(Reg);
3886}
3887
3889 Register &Reg, StringRef Src,
3891 return MIParser(PFS, Error, Src).parseStandaloneNamedRegister(Reg);
3892}
3893
3895 VRegInfo *&Info, StringRef Src,
3897 return MIParser(PFS, Error, Src).parseStandaloneVirtualRegister(Info);
3898}
3899
3902 return MIParser(PFS, Error, Src).parseStandaloneStackObject(FI);
3903}
3904
3908 return MIParser(PFS, Error, Src).parsePrefetchTarget(Target);
3909}
3912 return MIParser(PFS, Error, Src).parseStandaloneMDNode(Node);
3913}
3914
3916 PerFunctionMIParsingState &PFS, const Value *&V,
3917 ErrorCallbackType ErrorCallback) {
3918 MIToken Token;
3919 Src = lexMIToken(Src, Token, [&](StringRef::iterator Loc, const Twine &Msg) {
3920 ErrorCallback(Loc, Msg);
3921 });
3922 V = nullptr;
3923
3924 return ::parseIRValue(Token, PFS, V, ErrorCallback);
3925}
unsigned RegSize
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
unsigned uint64_t
This file implements a class to represent arbitrary precision integral constant values and operations...
This file implements the APSInt class, which is a simple class that represents an arbitrary sized int...
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
basic Basic Alias true
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static Error parseAlignment(StringRef Str, Align &Alignment, StringRef Name, bool AllowZero=false)
Attempts to parse an alignment component of a specification.
This file defines the DenseMap class.
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define RegName(no)
A common definition of LaneBitmask for use in TableGen and CodeGen.
static llvm::Error parse(GsymDataExtractor &Data, uint64_t BaseAddr, LineEntryCallback const &Callback)
Definition LineTable.cpp:54
Implement a low-level type suitable for MachineInstr level instruction selection.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static const char * printImplicitRegisterFlag(const MachineOperand &MO)
static const BasicBlock * getIRBlockFromSlot(unsigned Slot, const DenseMap< unsigned, const BasicBlock * > &Slots2BasicBlocks)
static std::string getRegisterName(const TargetRegisterInfo *TRI, Register Reg)
static bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue, PerFunctionMIParsingState &PFS, const Constant *&C, ErrorCallbackType ErrCB)
static void initSlots2Values(const Function &F, DenseMap< unsigned, const Value * > &Slots2Values)
Creates the mapping from slot numbers to function's unnamed IR values.
Definition MIParser.cpp:361
static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS, const Value *&V, ErrorCallbackType ErrCB)
static bool verifyScalarSize(uint64_t Size)
static bool getUnsigned(const MIToken &Token, unsigned &Result, ErrorCallbackType ErrCB)
static bool getHexUint(const MIToken &Token, APInt &Result)
static bool verifyVectorElementCount(uint64_t NumElts)
static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST, DenseMap< unsigned, const Value * > &Slots2Values)
Definition MIParser.cpp:352
static void initSlots2BasicBlocks(const Function &F, DenseMap< unsigned, const BasicBlock * > &Slots2BasicBlocks)
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
Definition MIParser.cpp:605
static bool isImplicitOperandIn(const MachineOperand &ImplicitOperand, ArrayRef< ParsedMachineOperand > Operands)
Return true if the parsed machine operands contain a given machine operand.
static bool parseGlobalValue(const MIToken &Token, PerFunctionMIParsingState &PFS, GlobalValue *&GV, ErrorCallbackType ErrCB)
static bool verifyAddrSpace(uint64_t AddrSpace)
Register Reg
Register const TargetRegisterInfo * TRI
#define R2(n)
Promote Memory to Register
Definition Mem2Reg.cpp:110
This file contains the declarations for metadata subclasses.
#define T
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
SI Fold Operands
const char * Msg
This file defines the SmallVector class.
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
#define error(X)
Class for arbitrary precision integers.
Definition APInt.h:78
uint64_t getZExtValue() const
Get zero extended value.
Definition APInt.h:1561
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
Definition APInt.h:472
An arbitrary precision integer that knows its signedness.
Definition APSInt.h:24
bool isNegative() const
Determine sign of this APSInt.
Definition APSInt.h:50
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
static constexpr BranchProbability getRaw(uint32_t N)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
Definition InstrTypes.h:740
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
Definition InstrTypes.h:743
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
Definition InstrTypes.h:757
@ ICMP_SLT
signed less than
Definition InstrTypes.h:769
@ ICMP_SLE
signed less or equal
Definition InstrTypes.h:770
@ FCMP_OLT
0 1 0 0 True if ordered and less than
Definition InstrTypes.h:746
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
Definition InstrTypes.h:755
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
Definition InstrTypes.h:744
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
Definition InstrTypes.h:745
@ ICMP_UGE
unsigned greater or equal
Definition InstrTypes.h:764
@ ICMP_UGT
unsigned greater than
Definition InstrTypes.h:763
@ ICMP_SGT
signed greater than
Definition InstrTypes.h:767
@ FCMP_ULT
1 1 0 0 True if unordered or less than
Definition InstrTypes.h:754
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
Definition InstrTypes.h:748
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
Definition InstrTypes.h:751
@ ICMP_ULT
unsigned less than
Definition InstrTypes.h:765
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Definition InstrTypes.h:752
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
Definition InstrTypes.h:747
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
Definition InstrTypes.h:749
@ ICMP_NE
not equal
Definition InstrTypes.h:762
@ ICMP_SGE
signed greater or equal
Definition InstrTypes.h:768
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
Definition InstrTypes.h:756
@ ICMP_ULE
unsigned less or equal
Definition InstrTypes.h:766
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
Definition InstrTypes.h:753
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
Definition InstrTypes.h:742
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
Definition InstrTypes.h:750
static bool isFPPredicate(Predicate P)
Definition InstrTypes.h:833
static bool isIntPredicate(Predicate P)
Definition InstrTypes.h:839
This is an important base class in LLVM.
Definition Constant.h:43
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
A debug info location.
Definition DebugLoc.h:126
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
Definition DenseMap.h:250
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:284
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
Definition TypeSize.h:315
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition Function.h:802
Module * getParent()
Get the module that this global value is contained inside of...
static constexpr LLT vector(ElementCount EC, unsigned ScalarSizeInBits)
Get a low-level vector of some number of elements and element width.
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
constexpr bool isValid() const
static constexpr LLT pointer(unsigned AddressSpace, unsigned SizeInBits)
Get a low-level pointer in the given address space.
static constexpr LLT token()
Get a low-level token; just a scalar with zero bits (or no size).
static constexpr LLT bfloat16()
static LLT floatIEEE(unsigned SizeInBits)
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition MCDwarf.h:635
static MCCFIInstruction createLLVMVectorOffset(MCSymbol *L, unsigned Register, unsigned RegisterSizeInBits, unsigned MaskRegister, unsigned MaskRegisterSizeInBits, int64_t Offset, SMLoc Loc={})
.cfi_llvm_vector_offset Previous value of Register is saved at Offset from CFA.
Definition MCDwarf.h:797
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_undefined From now on the previous value of Register can't be restored anymore.
Definition MCDwarf.h:732
static MCCFIInstruction createLLVMVectorRegisters(MCSymbol *L, unsigned Register, ArrayRef< VectorRegisterWithLane > VectorRegisters, SMLoc Loc={})
.cfi_llvm_vector_registers Previous value of Register is saved in lanes of vector registers.
Definition MCDwarf.h:787
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
Definition MCDwarf.h:725
static MCCFIInstruction createSetRAState(MCSymbol *L, unsigned State, MCSymbol *PACSym=nullptr, SMLoc Loc={})
.cfi_set_ra_state AArch64 set RA sign state,
Definition MCDwarf.h:708
static MCCFIInstruction createLLVMDefAspaceCfa(MCSymbol *L, unsigned Register, int64_t Offset, unsigned AddressSpace, SMLoc Loc)
.cfi_llvm_def_aspace_cfa defines the rule for computing the CFA to be the result of evaluating the DW...
Definition MCDwarf.h:660
static MCCFIInstruction createLLVMVectorRegisterMask(MCSymbol *L, unsigned Register, unsigned SpillRegister, unsigned SpillRegisterLaneSizeInBits, unsigned MaskRegister, unsigned MaskRegisterSizeInBits, SMLoc Loc={})
.cfi_llvm_vector_register_mask Previous value of Register is saved in SpillRegister,...
Definition MCDwarf.h:808
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2, SMLoc Loc={})
.cfi_register Previous value of Register1 is saved in register Register2.
Definition MCDwarf.h:685
static MCCFIInstruction cfiDefCfa(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it.
Definition MCDwarf.h:628
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition MCDwarf.h:670
static MCCFIInstruction createNegateRAStateWithPC(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state_with_pc AArch64 negate RA state with PC.
Definition MCDwarf.h:701
static MCCFIInstruction createNegateRAState(MCSymbol *L, SMLoc Loc={})
.cfi_negate_ra_state AArch64 negate RA state.
Definition MCDwarf.h:696
static MCCFIInstruction createRememberState(MCSymbol *L, SMLoc Loc={})
.cfi_remember_state Save all current rules for all registers.
Definition MCDwarf.h:745
static MCCFIInstruction createLLVMRegisterPair(MCSymbol *L, unsigned Register, unsigned R1, unsigned R1SizeInBits, unsigned R2, unsigned R2SizeInBits, SMLoc Loc={})
.cfi_llvm_register_pair Previous value of Register is saved in R1:R2.
Definition MCDwarf.h:777
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int64_t Offset, SMLoc Loc={})
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition MCDwarf.h:643
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals, SMLoc Loc={}, StringRef Comment="")
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
Definition MCDwarf.h:756
static MCCFIInstruction createWindowSave(MCSymbol *L, SMLoc Loc={})
.cfi_window_save SPARC register window is saved.
Definition MCDwarf.h:691
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int64_t Adjustment, SMLoc Loc={})
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Definition MCDwarf.h:651
static MCCFIInstruction createRestoreState(MCSymbol *L, SMLoc Loc={})
.cfi_restore_state Restore the previously saved state.
Definition MCDwarf.h:750
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register, SMLoc Loc={})
.cfi_same_value Current value of Register is the same as in the previous frame.
Definition MCDwarf.h:739
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int64_t Offset, SMLoc Loc={})
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register.
Definition MCDwarf.h:678
Describe properties that are true of each instruction in the target description file.
unsigned getID() const
getID() - Return the register class ID number.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
Metadata node.
Definition Metadata.h:1069
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Definition Metadata.h:1567
MIRFormater - Interface to format MIR operand based on target.
virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx, StringRef Src, int64_t &Imm, ErrorCallbackType ErrorCallback) const
Implement target specific parsing of immediate mnemonics.
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
static LLVM_ABI bool parseIRValue(StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS, const Value *&V, ErrorCallbackType ErrorCallback)
Helper functions to parse IR value from MIR serialization format which will be useful for target spec...
void normalizeSuccProbs()
Normalize probabilities of all successors so that the sum of them becomes one.
void setAddressTakenIRBlock(BasicBlock *BB)
Set this block to reflect that it corresponds to an IR-level basic block with a BlockAddress.
LLVM_ABI instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
void setCallFrameSize(unsigned N)
Set the call frame size on entry to this basic block.
void setAlignment(Align A)
Set alignment of the basic block.
LLVM_ABI void addSuccessor(MachineBasicBlock *Succ, BranchProbability Prob=BranchProbability::getUnknown())
Add Succ as a successor of this MachineBasicBlock.
void setSectionID(MBBSectionID V)
Sets the section ID for this basic block.
void setIsInlineAsmBrIndirectTarget(bool V=true)
Indicates if this is the indirect dest of an INLINEASM_BR.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
void setIsEHFuncletEntry(bool V=true)
Indicates if this is the entry block of an EH funclet.
LLVM_ABI bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
void setIsEHScopeEntry(bool V=true)
Indicates if this is the entry block of an EH scope, i.e., the block that that used to have a catchpa...
void setMachineBlockAddressTaken()
Set this block to indicate that its address is used as something other than the target of a terminato...
void setIsEHPad(bool V=true)
Indicates the block is a landing pad.
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
void setFlag(MIFlag Flag)
Set a MI flag.
A description of a memory reference used in the backend.
Flags
Flags values. These may be or'd together.
@ MOVolatile
The memory access is volatile.
@ MODereferenceable
The memory access is dereferenceable (i.e., doesn't trap).
@ MOLoad
The memory access reads data.
@ MONonTemporal
The memory access is non-temporal.
@ MOInvariant
The memory access always returns the same value (or traps).
@ MOStore
The memory access writes data.
MachineOperand class - Representation of each machine instruction operand.
static MachineOperand CreateMCSymbol(MCSymbol *Sym, unsigned TargetFlags=0)
static MachineOperand CreateES(const char *SymName, unsigned TargetFlags=0)
static MachineOperand CreateFPImm(const ConstantFP *CFP)
static MachineOperand CreateCFIIndex(unsigned CFIIndex)
static MachineOperand CreateRegMask(const uint32_t *Mask)
CreateRegMask - Creates a register mask operand referencing Mask.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
static MachineOperand CreateCImm(const ConstantInt *CI)
static MachineOperand CreateMetadata(const MDNode *Meta)
static MachineOperand CreatePredicate(unsigned Pred)
static MachineOperand CreateImm(int64_t Val)
static MachineOperand CreateShuffleMask(ArrayRef< int > Mask)
static MachineOperand CreateJTI(unsigned Idx, unsigned TargetFlags=0)
static MachineOperand CreateDbgInstrRef(unsigned InstrIdx, unsigned OpIdx)
static MachineOperand CreateRegLiveOut(const uint32_t *Mask)
static MachineOperand CreateGA(const GlobalValue *GV, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateBA(const BlockAddress *BA, int64_t Offset, unsigned TargetFlags=0)
void setTargetFlags(unsigned F)
static MachineOperand CreateLaneMask(LaneBitmask LaneMask)
LLVM_ABI bool isIdenticalTo(const MachineOperand &Other) const
Returns true if this operand is identical to the specified operand except for liveness related flags ...
static MachineOperand CreateCPI(unsigned Idx, int Offset, unsigned TargetFlags=0)
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static MachineOperand CreateTargetIndex(unsigned Idx, int64_t Offset, unsigned TargetFlags=0)
static MachineOperand CreateMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0)
static MachineOperand CreateIntrinsicID(Intrinsic::ID ID)
static MachineOperand CreateFI(int Idx)
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void setRegClassOrRegBank(Register Reg, const RegClassOrRegBank &RCOrRB)
LLT getType(Register Reg) const
Get the low-level type of Reg or LLT{} if Reg is not a generic (target independent) virtual register.
LLVM_ABI Register createIncompleteVirtualRegister(StringRef Name="")
Creates a new virtual register that has no register class, register bank or size assigned yet.
LLVM_ABI void setType(Register VReg, LLT Ty)
Set the low-level type of VReg to Ty.
void noteNewVirtualRegister(Register Reg)
This interface provides simple read-only access to a block of memory, and provides simple methods for...
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
const char * getBufferEnd() const
const char * getBufferStart() const
Manage lifetime of a slot tracker for printing IR.
int getLocalSlot(const Value *V)
Return the slot number of the specified local value.
void incorporateFunction(const Function &F)
Incorporate the given function.
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Special value supplied for machine level alias analysis.
const RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
unsigned getNumRegBanks() const
Get the total number of register banks.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr unsigned id() const
Definition Register.h:100
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:308
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
unsigned getMainFileID() const
Definition SourceMgr.h:151
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:144
LLVM_ABI SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
bool empty() const
Definition StringMap.h:103
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition StringMap.h:311
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:736
const char * iterator
Definition StringRef.h:60
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition StringRef.h:597
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
LLVM_ABI std::string lower() const
bool consume_front(char Prefix)
Returns true if this StringRef has the given prefix and removes that prefix.
Definition StringRef.h:661
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
TargetSubtargetInfo - Generic base class for all target subtargets.
virtual const TargetInstrInfo * getInstrInfo() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
LLVM Value Representation.
Definition Value.h:75
bool hasName() const
Definition Value.h:261
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
LLVM_ABI ID lookupIntrinsicID(StringRef Name)
This does the actual lookup of an intrinsic ID which matches the given function name.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
@ System
Synchronized with respect to all concurrently executing threads.
Definition LLVMContext.h:58
support::ulittle32_t Word
Definition IRSymtab.h:53
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
LLVM_ABI bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
RelativeUniformCounterPtr Values
Definition InstrProf.h:91
RegState
Flags to represent properties of register accesses.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
@ Dead
Unused definition.
@ Kill
The last use of a register.
@ InternalRead
Register reads a value that is defined inside the same instruction or bundle.
@ Undef
Value of the register doesn't matter.
@ EarlyClobber
Register definition happens before uses.
@ Define
Register definition.
@ Renamable
Register that may be renamed.
@ Debug
Register 'use' is for debugging purpose.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
StringRef lexMIToken(StringRef Source, MIToken &Token, function_ref< void(StringRef::iterator, const Twine &)> ErrorCallback)
Consume a single machine instruction token in the given source and return the remaining source string...
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
LLVM_ABI bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
LLVM_ABI bool parsePrefetchTarget(PerFunctionMIParsingState &PFS, CallsiteID &Target, StringRef Src, SMDiagnostic &Error)
LLVM_ABI void guessSuccessors(const MachineBasicBlock &MBB, SmallVectorImpl< MachineBasicBlock * > &Result, bool &IsFallthrough)
Determine a possible list of successors of a basic block based on the basic block machine operand bei...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
Definition MathExtras.h:380
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
LLVM_ABI DIExpression * parseDIExpressionBodyAtBeginning(StringRef Asm, unsigned &Read, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots)
Definition Parser.cpp:238
constexpr RegState getDefRegState(bool B)
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
constexpr bool hasRegState(RegState Value, RegState Test)
AtomicOrdering
Atomic ordering for LLVM's memory model.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
DWARFExpression::Operation Op
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
LLVM_ABI bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
LLVM_ABI Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
Definition Parser.cpp:197
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
Definition Metadata.h:763
MDNode * NoAliasAddrSpace
The tag specifying the noalias address spaces.
Definition Metadata.h:792
MDNode * Scope
The tag for alias scope specification (used with noalias).
Definition Metadata.h:786
MDNode * TBAA
The tag for type-based alias analysis.
Definition Metadata.h:780
MDNode * NoAlias
The tag specifying the noalias scope.
Definition Metadata.h:789
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
LLVM_ABI static const MBBSectionID ExceptionSectionID
LLVM_ABI static const MBBSectionID ColdSectionID
A token produced by the machine instruction lexer.
Definition MILexer.h:26
TokenKind kind() const
Definition MILexer.h:217
bool hasIntegerValue() const
Definition MILexer.h:257
bool is(TokenKind K) const
Definition MILexer.h:244
StringRef stringValue() const
Return the token's string value.
Definition MILexer.h:253
@ kw_pre_instr_symbol
Definition MILexer.h:141
@ kw_deactivation_symbol
Definition MILexer.h:146
@ kw_call_frame_size
Definition MILexer.h:153
@ kw_cfi_aarch64_negate_ra_sign_state
Definition MILexer.h:100
@ kw_cfi_llvm_def_aspace_cfa
Definition MILexer.h:93
@ MachineBasicBlock
Definition MILexer.h:176
@ kw_dbg_instr_ref
Definition MILexer.h:84
@ NamedVirtualRegister
Definition MILexer.h:174
@ kw_early_clobber
Definition MILexer.h:59
@ kw_unpredictable
Definition MILexer.h:77
@ FloatingPointLiteral
Definition MILexer.h:186
@ kw_cfi_window_save
Definition MILexer.h:99
@ kw_cfi_llvm_register_pair
Definition MILexer.h:103
@ kw_frame_destroy
Definition MILexer.h:64
@ kw_cfi_undefined
Definition MILexer.h:98
@ MachineBasicBlockLabel
Definition MILexer.h:175
@ kw_cfi_llvm_vector_offset
Definition MILexer.h:105
@ kw_cfi_register
Definition MILexer.h:94
@ kw_inlineasm_br_indirect_target
Definition MILexer.h:133
@ kw_cfi_rel_offset
Definition MILexer.h:87
@ kw_cfi_llvm_vector_registers
Definition MILexer.h:104
@ kw_ehfunclet_entry
Definition MILexer.h:135
@ kw_cfi_llvm_vector_register_mask
Definition MILexer.h:106
@ kw_cfi_aarch64_negate_ra_sign_state_with_pc
Definition MILexer.h:101
@ kw_cfi_def_cfa_register
Definition MILexer.h:88
@ kw_cfi_same_value
Definition MILexer.h:85
@ kw_cfi_set_ra_state
Definition MILexer.h:102
@ kw_cfi_adjust_cfa_offset
Definition MILexer.h:90
@ kw_dereferenceable
Definition MILexer.h:55
@ kw_implicit_define
Definition MILexer.h:52
@ kw_cfi_def_cfa_offset
Definition MILexer.h:89
@ md_mem_cache_hint
Definition MILexer.h:167
@ kw_machine_block_address_taken
Definition MILexer.h:152
@ kw_cfi_remember_state
Definition MILexer.h:95
@ kw_debug_instr_number
Definition MILexer.h:83
@ kw_post_instr_symbol
Definition MILexer.h:142
@ kw_cfi_restore_state
Definition MILexer.h:97
@ kw_ir_block_address_taken
Definition MILexer.h:151
@ kw_unknown_address
Definition MILexer.h:150
@ md_noalias_addrspace
Definition MILexer.h:165
@ kw_debug_location
Definition MILexer.h:82
@ kw_heap_alloc_marker
Definition MILexer.h:143
StringRef range() const
Definition MILexer.h:250
StringRef::iterator location() const
Definition MILexer.h:248
const APSInt & integerValue() const
Definition MILexer.h:255
LLVM IR metadata carried by a MachineMemOperand.
This class contains a discriminated union of information about pointers in memory operands,...
int64_t Offset
Offset - This is an offset from the base Value*.
LLVM_ABI VRegInfo & getVRegInfo(Register Num)
Definition MIParser.cpp:329
const SlotMapping & IRSlots
Definition MIParser.h:172
LLVM_ABI const Value * getIRValue(unsigned Slot)
Definition MIParser.cpp:374
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition MIParser.h:177
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:179
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition MIParser.h:186
LLVM_ABI PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM, const SlotMapping &IRSlots, PerTargetMIParsingState &Target)
Definition MIParser.cpp:324
PerTargetMIParsingState & Target
Definition MIParser.h:173
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:178
LLVM_ABI VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition MIParser.cpp:340
LLVM_ABI bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const
Definition MIParser.cpp:129
LLVM_ABI bool getDirectTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a direct target flag to the corresponding target flag.
Definition MIParser.cpp:227
LLVM_ABI const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition MIParser.cpp:317
LLVM_ABI bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition MIParser.cpp:148
LLVM_ABI unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition MIParser.cpp:188
LLVM_ABI bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition MIParser.cpp:206
LLVM_ABI void setTarget(const TargetSubtargetInfo &NewSubtarget)
Definition MIParser.cpp:81
LLVM_ABI bool getRegisterByName(StringRef RegName, Register &Reg)
Try to convert a register name to a register number.
Definition MIParser.cpp:119
LLVM_ABI bool getMMOTargetFlag(StringRef Name, MachineMemOperand::Flags &Flag)
Try to convert a name of a MachineMemOperand target flag to the corresponding target flag.
Definition MIParser.cpp:270
LLVM_ABI bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a bitmask target flag to the corresponding target flag.
Definition MIParser.cpp:249
LLVM_ABI const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition MIParser.cpp:310
LLVM_ABI const uint32_t * getRegMask(StringRef Identifier)
Check if the given identifier is a name of a register mask.
Definition MIParser.cpp:171
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition SlotMapping.h:32
NumberedValues< GlobalValue * > GlobalValues
Definition SlotMapping.h:33
const RegisterBank * RegBank
Definition MIParser.h:46
union llvm::VRegInfo::@127225073067155374133234315364317264041071000132 D
const TargetRegisterClass * RC
Definition MIParser.h:45
enum llvm::VRegInfo::@374354327266250320012227113300214031244227062232 Kind
Register VReg
Definition MIParser.h:48
bool Explicit
VReg was explicitly specified in the .mir file.
Definition MIParser.h:43