Lines Matching +full:- +full:- +full:token
1 //===- MIParser.cpp - Machine instructions parser implementation ----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
110 for (unsigned I = 0, E = TRI->getNumRegs(); I < E; ++I) {
112 Names2Regs.insert(std::make_pair(StringRef(TRI->getName(I)).lower(), I))
115 assert(WasInserted && "Expected registers to be unique case-insensitively");
125 Reg = RegInfo->getValue();
132 std::optional<uint8_t> FV = TRI->getVRegFlagValue(FlagName);
144 for (unsigned I = 0, E = TII->getNumOpcodes(); I < E; ++I)
145 Names2InstrOpCodes.insert(std::make_pair(StringRef(TII->getName(I)), I));
154 OpCode = InstrInfo->getValue();
163 ArrayRef<const uint32_t *> RegMasks = TRI->getRegMasks();
164 ArrayRef<const char *> RegMaskNames = TRI->getRegMaskNames();
176 return RegMaskInfo->getValue();
183 for (unsigned I = 1, E = TRI->getNumSubRegIndices(); I < E; ++I)
185 std::make_pair(TRI->getSubRegIndexName(I), I));
193 return SubRegInfo->getValue();
201 auto Indices = TII->getSerializableTargetIndices();
211 Index = IndexInfo->second;
221 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
233 Flag = FlagInfo->second;
243 auto Flags = TII->getSerializableBitmaskMachineOperandTargetFlags();
255 Flag = FlagInfo->second;
265 auto Flags = TII->getSerializableMachineMemOperandTargetFlags();
276 Flag = FlagInfo->second;
285 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
286 const auto *RC = TRI->getRegClass(I);
288 std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
302 for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
303 const auto &RegBank = RBI->getRegBank(I);
314 return RegClassInfo->getValue();
321 return RegBankInfo->getValue();
334 Info->VReg = MRI.createIncompleteVirtualRegister();
335 I.first->second = Info;
337 return *I.first->second;
346 Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName);
347 I.first->second = Info;
349 return *I.first->second;
355 if (Slot == -1)
405 MIToken Token;
417 /// for the next token.
531 /// Convert the integer literal in the current token into an unsigned integer.
536 /// Convert the integer literal in the current token into an uint64.
541 /// Convert the hexadecimal literal in the current token into an unsigned
547 /// If the current token is of the given kind, consume it and return false.
551 /// If the current token is of the given kind, consume it and return true.
592 CurrentSource.substr(SkipChar), Token,
596 bool MIParser::error(const Twine &Msg) { return error(Token.location(), Msg); }
610 Loc - Source.data(), SourceMgr::DK_Error, Msg.str(),
619 (Loc - Source.data()));
638 return "<unknown token>";
643 if (Token.isNot(TokenKind))
650 if (Token.isNot(TokenKind))
658 assert(Token.is(MIToken::kw_bbsections));
660 if (Token.is(MIToken::IntegerLiteral)) {
666 const StringRef &S = Token.stringValue();
680 assert(Token.is(MIToken::kw_bb_id));
687 if (Token.is(MIToken::IntegerLiteral)) {
698 assert(Token.is(MIToken::kw_call_frame_size));
710 assert(Token.is(MIToken::MachineBasicBlockLabel));
714 auto Loc = Token.location();
715 auto Name = Token.stringValue();
730 switch (Token.kind()) {
786 MF.getFunction().getValueSymbolTable()->lookup(Name));
799 MBB->setAlignment(Align(Alignment));
801 MBB->setMachineBlockAddressTaken();
803 MBB->setAddressTakenIRBlock(AddressTakenIRBlock);
804 MBB->setIsEHPad(IsLandingPad);
805 MBB->setIsInlineAsmBrIndirectTarget(IsInlineAsmBrIndirectTarget);
806 MBB->setIsEHFuncletEntry(IsEHFuncletEntry);
808 MBB->setSectionID(*SectionID);
811 MBB->setCallFrameSize(CallFrameSize);
819 while (Token.is(MIToken::Newline))
821 if (Token.isErrorOrEOF())
822 return Token.isError();
823 if (Token.isNot(MIToken::MachineBasicBlockLabel))
832 if ((Token.is(MIToken::MachineBasicBlockLabel) && IsAfterNewline) ||
833 Token.isErrorOrEOF())
835 else if (Token.is(MIToken::MachineBasicBlockLabel))
843 if (Token.is(MIToken::lbrace))
845 if (Token.is(MIToken::rbrace)) {
848 --BraceDepth;
853 if (!Token.isError() && BraceDepth)
855 } while (!Token.isErrorOrEOF());
856 return Token.isError();
860 assert(Token.is(MIToken::kw_liveins));
864 if (Token.isNewlineOrEOF()) // Allow an empty list of liveins.
867 if (Token.isNot(MIToken::NamedRegister))
876 if (Token.isNot(MIToken::IntegerLiteral) &&
877 Token.isNot(MIToken::HexLiteral))
880 "Use correct get-function for lane mask");
893 assert(Token.is(MIToken::kw_successors));
897 if (Token.isNewlineOrEOF()) // Allow an empty list of successors.
900 if (Token.isNot(MIToken::MachineBasicBlock))
908 if (Token.isNot(MIToken::IntegerLiteral) &&
909 Token.isNot(MIToken::HexLiteral))
926 assert(Token.is(MIToken::MachineBasicBlockLabel));
929 while (Token.isNot(MIToken::rparen) && !Token.isErrorOrEOF())
946 if (Token.is(MIToken::kw_successors)) {
950 } else if (Token.is(MIToken::kw_liveins)) {
957 if (!Token.isNewlineOrEOF())
965 while (!Token.is(MIToken::MachineBasicBlockLabel) &&
966 !Token.is(MIToken::Eof)) {
981 PrevMI->setFlag(MachineInstr::BundledSucc);
982 MI->setFlag(MachineInstr::BundledPred);
985 if (Token.is(MIToken::lbrace)) {
990 MI->setFlag(MachineInstr::BundledSucc);
992 if (!Token.is(MIToken::Newline))
996 assert(Token.isNewlineOrEOF() && "MI is not fully parsed");
1021 while (Token.is(MIToken::Newline))
1023 if (Token.isErrorOrEOF())
1024 return Token.isError();
1025 // The first parsing pass should have verified that this token is a MBB label
1027 assert(Token.is(MIToken::MachineBasicBlockLabel));
1034 if (!AddFalthroughFrom->isSuccessor(MBB))
1035 AddFalthroughFrom->addSuccessor(MBB);
1036 AddFalthroughFrom->normalizeSuccProbs();
1043 assert(Token.is(MIToken::MachineBasicBlockLabel) || Token.is(MIToken::Eof));
1044 } while (Token.isNot(MIToken::Eof));
1052 while (Token.isRegister() || Token.isRegisterFlag()) {
1053 auto Loc = Token.location();
1058 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1059 if (Token.isNot(MIToken::comma))
1067 if (Token.isError() || parseInstruction(OpCode, Flags))
1071 while (!Token.isNewlineOrEOF() && Token.isNot(MIToken::kw_pre_instr_symbol) &&
1072 Token.isNot(MIToken::kw_post_instr_symbol) &&
1073 Token.isNot(MIToken::kw_heap_alloc_marker) &&
1074 Token.isNot(MIToken::kw_pcsections) &&
1075 Token.isNot(MIToken::kw_cfi_type) &&
1076 Token.isNot(MIToken::kw_debug_location) &&
1077 Token.isNot(MIToken::kw_debug_instr_number) &&
1078 Token.isNot(MIToken::coloncolon) && Token.isNot(MIToken::lbrace)) {
1079 auto Loc = Token.location();
1084 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1085 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
1086 Token.is(MIToken::lbrace))
1088 if (Token.isNot(MIToken::comma))
1094 if (Token.is(MIToken::kw_pre_instr_symbol))
1098 if (Token.is(MIToken::kw_post_instr_symbol))
1102 if (Token.is(MIToken::kw_heap_alloc_marker))
1106 if (Token.is(MIToken::kw_pcsections))
1111 if (Token.is(MIToken::kw_cfi_type)) {
1113 if (Token.isNot(MIToken::IntegerLiteral))
1114 return error("expected an integer literal after 'cfi-type'");
1115 // getUnsigned is sufficient for 32-bit integers.
1120 if (Token.is(MIToken::comma))
1125 if (Token.is(MIToken::kw_debug_instr_number)) {
1127 if (Token.isNot(MIToken::IntegerLiteral))
1128 return error("expected an integer literal after 'debug-instr-number'");
1133 if (Token.is(MIToken::comma))
1138 if (Token.is(MIToken::kw_debug_location)) {
1141 if (Token.is(MIToken::exclaim)) {
1144 } else if (Token.is(MIToken::md_dilocation)) {
1148 return error("expected a metadata node after 'debug-location'");
1156 if (Token.is(MIToken::coloncolon)) {
1158 while (!Token.isNewlineOrEOF()) {
1163 if (Token.isNewlineOrEOF())
1165 if (Token.isNot(MIToken::comma))
1171 const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
1179 MI->setFlags(Flags);
1184 MI->addOperand(MF, Operand.Operand);
1189 MI->setPreInstrSymbol(MF, PreInstrSymbol);
1191 MI->setPostInstrSymbol(MF, PostInstrSymbol);
1193 MI->setHeapAllocMarker(MF, HeapAllocMarker);
1195 MI->setPCSections(MF, PCSections);
1197 MI->setCFIType(MF, CFIType);
1199 MI->setMemRefs(MF, MemOperands);
1201 MI->setDebugInstrNum(InstrNum);
1207 if (Token.isNot(MIToken::MachineBasicBlock))
1212 if (Token.isNot(MIToken::Eof))
1220 if (Token.isNot(MIToken::NamedRegister))
1225 if (Token.isNot(MIToken::Eof))
1232 if (Token.isNot(MIToken::VirtualRegister))
1237 if (Token.isNot(MIToken::Eof))
1244 if (Token.isNot(MIToken::NamedRegister) &&
1245 Token.isNot(MIToken::VirtualRegister))
1253 if (Token.isNot(MIToken::Eof))
1260 if (Token.isNot(MIToken::StackObject))
1264 if (Token.isNot(MIToken::Eof))
1271 if (Token.is(MIToken::exclaim)) {
1274 } else if (Token.is(MIToken::md_diexpr)) {
1277 } else if (Token.is(MIToken::md_dilocation)) {
1282 if (Token.isNot(MIToken::Eof))
1289 if (Token.isNot(MIToken::exclaim))
1293 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
1301 bool IsDistinct = Token.is(MIToken::kw_distinct);
1304 if (Token.isNot(MIToken::exclaim))
1314 FI->second.first->replaceAllUsesWith(MD);
1322 It->second.reset(MD);
1338 if (Token.isNot(MIToken::lbrace))
1342 if (Token.is(MIToken::rbrace)) {
1354 if (Token.isNot(MIToken::comma))
1359 if (Token.isNot(MIToken::rbrace))
1369 if (Token.isNot(MIToken::exclaim))
1373 if (Token.is(MIToken::StringConstant)) {
1381 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
1384 SMLoc Loc = mapSMLoc(Token.location());
1393 MD = NodeInfo->second.get();
1399 MD = NodeInfo->second.get();
1414 return MO.isDef() ? "implicit-def" : "implicit";
1420 return StringRef(TRI->getName(Reg)).lower();
1452 return error(Operands.empty() ? Token.location() : Operands.back().End,
1462 // clang-format off
1463 while (Token.is(MIToken::kw_frame_setup) ||
1464 Token.is(MIToken::kw_frame_destroy) ||
1465 Token.is(MIToken::kw_nnan) ||
1466 Token.is(MIToken::kw_ninf) ||
1467 Token.is(MIToken::kw_nsz) ||
1468 Token.is(MIToken::kw_arcp) ||
1469 Token.is(MIToken::kw_contract) ||
1470 Token.is(MIToken::kw_afn) ||
1471 Token.is(MIToken::kw_reassoc) ||
1472 Token.is(MIToken::kw_nuw) ||
1473 Token.is(MIToken::kw_nsw) ||
1474 Token.is(MIToken::kw_exact) ||
1475 Token.is(MIToken::kw_nofpexcept) ||
1476 Token.is(MIToken::kw_noconvergent) ||
1477 Token.is(MIToken::kw_unpredictable) ||
1478 Token.is(MIToken::kw_nneg) ||
1479 Token.is(MIToken::kw_disjoint) ||
1480 Token.is(MIToken::kw_samesign)) {
1481 // clang-format on
1483 if (Token.is(MIToken::kw_frame_setup))
1485 if (Token.is(MIToken::kw_frame_destroy))
1487 if (Token.is(MIToken::kw_nnan))
1489 if (Token.is(MIToken::kw_ninf))
1491 if (Token.is(MIToken::kw_nsz))
1493 if (Token.is(MIToken::kw_arcp))
1495 if (Token.is(MIToken::kw_contract))
1497 if (Token.is(MIToken::kw_afn))
1499 if (Token.is(MIToken::kw_reassoc))
1501 if (Token.is(MIToken::kw_nuw))
1503 if (Token.is(MIToken::kw_nsw))
1505 if (Token.is(MIToken::kw_exact))
1507 if (Token.is(MIToken::kw_nofpexcept))
1509 if (Token.is(MIToken::kw_unpredictable))
1511 if (Token.is(MIToken::kw_noconvergent))
1513 if (Token.is(MIToken::kw_nneg))
1515 if (Token.is(MIToken::kw_disjoint))
1517 if (Token.is(MIToken::kw_samesign))
1522 if (Token.isNot(MIToken::Identifier))
1524 StringRef InstrName = Token.stringValue();
1532 assert(Token.is(MIToken::NamedRegister) && "Needs NamedRegister token");
1533 StringRef Name = Token.stringValue();
1540 assert(Token.is(MIToken::NamedVirtualRegister) && "Expected NamedVReg token");
1541 StringRef Name = Token.stringValue();
1549 if (Token.is(MIToken::NamedVirtualRegister))
1551 assert(Token.is(MIToken::VirtualRegister) && "Needs VirtualRegister token");
1560 switch (Token.kind()) {
1570 Reg = Info->VReg;
1574 llvm_unreachable("The current token should be a register");
1579 if (Token.isNot(MIToken::Identifier) && Token.isNot(MIToken::underscore))
1581 StringRef::iterator Loc = Token.location();
1582 StringRef Name = Token.stringValue();
1638 switch (Token.kind()) {
1670 llvm_unreachable("The current token should be a register flag");
1675 return error("duplicate '" + Token.stringValue() + "' register flag");
1681 assert(Token.is(MIToken::dot));
1683 if (Token.isNot(MIToken::Identifier))
1685 auto Name = Token.stringValue();
1696 if (Token.isNot(MIToken::IntegerLiteral))
1697 return error("expected an integer literal after 'tied-def'");
1713 // to check the tied-def operand.
1717 Twine("use of invalid tied-def operand index '" +
1724 Twine("use of invalid tied-def operand index '") +
1727 // Check that the tied-def operand wasn't tied elsewhere.
1731 Twine("the tied-def operand #") + Twine(DefIdx) +
1747 while (Token.isRegisterFlag()) {
1751 if (!Token.isRegister())
1759 if (Token.is(MIToken::dot)) {
1765 if (Token.is(MIToken::colon)) {
1779 // Try a redundant low-level type.
1781 if (parseLowLevelType(Token.location(), Ty))
1782 return error("expected tied-def or low-level type after '('");
1801 if (parseLowLevelType(Token.location(), Ty))
1816 if (RegInfo->Kind == VRegInfo::GENERIC ||
1817 RegInfo->Kind == VRegInfo::REGBANK)
1839 assert(Token.is(MIToken::IntegerLiteral));
1840 const APSInt &Int = Token.integerValue();
1855 assert(Token.is(MIToken::dot));
1856 auto Loc = Token.location(); // record start position
1861 if (Token.is(MIToken::IntegerLiteral)) {
1862 Len += Token.range().size();
1867 if (Token.is(MIToken::comma))
1870 assert(Token.is(MIToken::Identifier));
1871 Src = StringRef(Loc, Len + Token.stringValue().size());
1876 -> bool { return error(Loc, Msg); }))
1880 if (!Token.is(MIToken::comma))
1901 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
1907 if (parseIRConstant(Loc, StringRef(Loc, Token.range().end() - Loc), C))
1927 if (Token.range().front() == 's' || Token.range().front() == 'p') {
1928 StringRef SizeStr = Token.range().drop_front();
1933 if (Token.range().front() == 's') {
1934 auto ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
1940 Ty = LLT::token();
1944 } else if (Token.range().front() == 'p') {
1946 uint64_t AS = APSInt(Token.range().drop_front()).getZExtValue();
1956 if (Token.isNot(MIToken::less))
1962 Token.is(MIToken::Identifier) && Token.stringValue() == "vscale";
1965 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1977 if (Token.isNot(MIToken::IntegerLiteral))
1979 uint64_t NumElements = Token.integerValue().getZExtValue();
1985 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1989 if (Token.range().front() != 's' && Token.range().front() != 'p')
1992 StringRef SizeStr = Token.range().drop_front();
1996 if (Token.range().front() == 's') {
1997 auto ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
2001 } else if (Token.range().front() == 'p') {
2003 uint64_t AS = APSInt(Token.range().drop_front()).getZExtValue();
2012 if (Token.isNot(MIToken::greater))
2022 assert(Token.is(MIToken::Identifier));
2023 StringRef TypeStr = Token.range();
2028 StringRef SizeStr = Token.range().drop_front();
2032 auto Loc = Token.location();
2034 if (Token.isNot(MIToken::IntegerLiteral)) {
2035 if (Token.isNot(MIToken::Identifier) ||
2036 !(Token.range() == "true" || Token.range() == "false"))
2047 auto Loc = Token.location();
2049 if (Token.isNot(MIToken::FloatingPointLiteral) &&
2050 Token.isNot(MIToken::HexLiteral))
2059 static bool getHexUint(const MIToken &Token, APInt &Result) {
2060 assert(Token.is(MIToken::HexLiteral));
2061 StringRef S = Token.range();
2076 static bool getUnsigned(const MIToken &Token, unsigned &Result,
2078 if (Token.hasIntegerValue()) {
2080 uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
2082 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
2086 if (Token.is(MIToken::HexLiteral)) {
2088 if (getHexUint(Token, A))
2091 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
2100 Token, Result, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2106 assert(Token.is(MIToken::MachineBasicBlock) ||
2107 Token.is(MIToken::MachineBasicBlockLabel));
2115 MBB = MBBInfo->second;
2118 if (!Token.stringValue().empty() && Token.stringValue() != MBB->getName())
2120 " isn't '" + Token.stringValue() + "'");
2134 assert(Token.is(MIToken::StackObject));
2144 MF.getFrameInfo().getObjectAllocation(ObjectInfo->second))
2145 Name = Alloca->getName();
2146 if (!Token.stringValue().empty() && Token.stringValue() != Name)
2148 "' isn't '" + Token.stringValue() + "'");
2150 FI = ObjectInfo->second;
2163 assert(Token.is(MIToken::FixedStackObject));
2169 return error(Twine("use of undefined fixed stack object '%fixed-stack.") +
2172 FI = ObjectInfo->second;
2184 static bool parseGlobalValue(const MIToken &Token,
2187 switch (Token.kind()) {
2190 GV = M->getNamedValue(Token.stringValue());
2192 return ErrCB(Token.location(), Twine("use of undefined global value '") +
2193 Token.range() + "'");
2198 if (getUnsigned(Token, GVIdx, ErrCB))
2202 return ErrCB(Token.location(), Twine("use of undefined global value '@") +
2207 llvm_unreachable("The current token should be a global value");
2214 Token, PFS, GV,
2215 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2232 assert(Token.is(MIToken::ConstantPoolItem));
2247 assert(Token.is(MIToken::JumpTableIndex));
2253 return error("use of undefined jump table '%jump-table." + Twine(ID) + "'");
2255 Dest = MachineOperand::CreateJTI(JumpTableEntryInfo->second);
2260 assert(Token.is(MIToken::ExternalSymbol));
2261 const char *Symbol = MF.createExternalSymbolName(Token.stringValue());
2270 assert(Token.is(MIToken::MCSymbol));
2271 MCSymbol *Symbol = getOrCreateMCSymbol(Token.stringValue());
2280 assert(Token.is(MIToken::SubRegisterIndex));
2281 StringRef Name = Token.stringValue();
2282 unsigned SubRegIndex = PFS.Target.getSubRegIndex(Token.stringValue());
2291 assert(Token.is(MIToken::exclaim));
2293 auto Loc = Token.location();
2295 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
2307 Node = NodeInfo->second.get();
2324 assert(Token.is(MIToken::md_dilocation));
2337 if (Token.isNot(MIToken::rparen)) {
2339 if (Token.is(MIToken::Identifier)) {
2340 if (Token.stringValue() == "line") {
2344 if (Token.isNot(MIToken::IntegerLiteral) ||
2345 Token.integerValue().isSigned())
2347 Line = Token.integerValue().getZExtValue();
2352 if (Token.stringValue() == "column") {
2356 if (Token.isNot(MIToken::IntegerLiteral) ||
2357 Token.integerValue().isSigned())
2359 Column = Token.integerValue().getZExtValue();
2363 if (Token.stringValue() == "scope") {
2373 if (Token.stringValue() == "inlinedAt") {
2377 if (Token.is(MIToken::exclaim)) {
2380 } else if (Token.is(MIToken::md_dilocation)) {
2389 if (Token.stringValue() == "isImplicitCode") {
2393 if (!Token.is(MIToken::Identifier))
2396 // true/false in MIR yet. Do it ad-hoc until there's something else
2398 if (Token.stringValue() == "true")
2400 else if (Token.stringValue() == "false")
2409 Token.stringValue() + "'");
2428 if (Token.is(MIToken::exclaim)) {
2431 } else if (Token.is(MIToken::md_diexpr)) {
2440 if (Token.isNot(MIToken::IntegerLiteral))
2442 if (Token.integerValue().getSignificantBits() > 32)
2444 Offset = (int)Token.integerValue().getExtValue();
2450 if (Token.isNot(MIToken::NamedRegister))
2457 int DwarfReg = TRI->getDwarfRegNum(LLVMReg, true);
2466 if (Token.isNot(MIToken::IntegerLiteral))
2468 if (Token.integerValue().isSigned())
2470 AddressSpace = Token.integerValue().getZExtValue();
2477 if (Token.isNot(MIToken::HexLiteral))
2483 return error("expected a 8-bit integer (too large)");
2491 auto Kind = Token.kind();
2595 llvm_unreachable("The current token should be a cfi operand");
2602 switch (Token.kind()) {
2605 F.getValueSymbolTable()->lookup(Token.stringValue()));
2607 return error(Twine("use of undefined IR block '") + Token.range() + "'");
2616 return error(Twine("use of undefined IR block '%ir-block.") +
2621 llvm_unreachable("The current token should be an IR block reference");
2627 assert(Token.is(MIToken::kw_blockaddress));
2631 if (Token.isNot(MIToken::GlobalValue) &&
2632 Token.isNot(MIToken::NamedGlobalValue))
2644 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
2658 assert(Token.is(MIToken::kw_intrinsic));
2663 if (Token.isNot(MIToken::NamedGlobalValue))
2666 std::string Name = std::string(Token.stringValue());
2677 ID = static_cast<Intrinsic::ID>(TII->lookupName(Name));
2687 assert(Token.is(MIToken::kw_intpred) || Token.is(MIToken::kw_floatpred));
2688 bool IsFloat = Token.is(MIToken::kw_floatpred);
2694 if (Token.isNot(MIToken::Identifier))
2699 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2718 return error("invalid floating-point predicate");
2720 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2745 assert(Token.is(MIToken::kw_shufflemask));
2753 if (Token.is(MIToken::kw_undef)) {
2754 ShufMask.push_back(-1);
2755 } else if (Token.is(MIToken::IntegerLiteral)) {
2756 const APSInt &Int = Token.integerValue();
2773 assert(Token.is(MIToken::kw_dbg_instr_ref));
2777 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
2779 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isNegative())
2781 uint64_t InstrIdx = Token.integerValue().getZExtValue();
2787 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
2789 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isNegative())
2791 uint64_t OpIdx = Token.integerValue().getZExtValue();
2797 return error("expected syntax dbg-instr-ref(<unsigned>, <unsigned>)");
2804 assert(Token.is(MIToken::kw_target_index));
2808 if (Token.isNot(MIToken::Identifier))
2811 if (PFS.Target.getTargetIndex(Token.stringValue(), Index))
2812 return error("use of undefined target index '" + Token.stringValue() + "'");
2823 assert(Token.stringValue() == "CustomRegMask" && "Expected a custom RegMask");
2830 if (Token.isNot(MIToken::rparen)) {
2831 if (Token.isNot(MIToken::NamedRegister))
2850 assert(Token.is(MIToken::kw_liveout));
2856 if (Token.isNot(MIToken::NamedRegister))
2864 if (Token.isNot(MIToken::comma))
2877 switch (Token.kind()) {
2961 if (const auto *RegMask = PFS.Target.getRegMask(Token.stringValue())) {
2965 } else if (Token.stringValue() == "CustomRegMask") {
2971 if (const auto *Formatter = TII->getMIRFormatter()) {
2988 if (Token.is(MIToken::kw_target_flags)) {
2993 if (Token.isNot(MIToken::Identifier))
2995 if (PFS.Target.getDirectTargetFlag(Token.stringValue(), TF)) {
2996 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), TF))
2997 return error("use of undefined target flag '" + Token.stringValue() +
3001 while (Token.is(MIToken::comma)) {
3003 if (Token.isNot(MIToken::Identifier))
3006 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), BitFlag))
3007 return error("use of undefined target flag '" + Token.stringValue() +
3016 auto Loc = Token.location();
3028 if (Token.isNot(MIToken::plus) && Token.isNot(MIToken::minus))
3030 StringRef Sign = Token.range();
3031 bool IsNegative = Token.is(MIToken::minus);
3033 if (Token.isNot(MIToken::IntegerLiteral))
3035 if (Token.integerValue().getSignificantBits() > 64)
3036 return error("expected 64-bit integer (too large)");
3037 Offset = Token.integerValue().getExtValue();
3039 Offset = -Offset;
3045 assert(Token.is(MIToken::kw_ir_block_address_taken));
3047 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
3058 assert(Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign));
3060 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
3067 return error("expected a power-of-2 literal after 'align'");
3073 assert(Token.is(MIToken::kw_addrspace));
3075 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
3091 static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS,
3093 switch (Token.kind()) {
3095 V = PFS.MF.getFunction().getValueSymbolTable()->lookup(Token.stringValue());
3100 if (getUnsigned(Token, SlotNumber, ErrCB))
3108 if (parseGlobalValue(Token, PFS, GV, ErrCB))
3115 if (parseIRConstant(Token.location(), Token.stringValue(), PFS, C, ErrCB))
3124 llvm_unreachable("The current token should be an IR block reference");
3127 return ErrCB(Token.location(), Twine("use of undefined IR value '") + Token.range() + "'");
3133 Token, PFS, V, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3139 if (Token.hasIntegerValue()) {
3140 if (Token.integerValue().getActiveBits() > 64)
3141 return error("expected 64-bit integer (too large)");
3142 Result = Token.integerValue().getZExtValue();
3145 if (Token.is(MIToken::HexLiteral)) {
3150 return error("expected 64-bit integer (too large)");
3158 return ::getHexUint(Token, Result);
3163 switch (Token.kind()) {
3178 if (PFS.Target.getMMOTargetFlag(Token.stringValue(), TF))
3179 return error("use of undefined target MMO flag '" + Token.stringValue() +
3185 llvm_unreachable("The current token should be a memory operand flag");
3190 return error("duplicate '" + Token.stringValue() + "' memory operand flag");
3196 switch (Token.kind()) {
3214 // The token was already consumed, so use return here instead of break.
3222 // The token was already consumed, so use return here instead of break.
3227 switch (Token.kind()) {
3238 MF.createExternalSymbolName(Token.stringValue()));
3242 "expected a global value or an external symbol after 'call-entry'");
3248 if (const auto *Formatter = TII->getMIRFormatter()) {
3249 if (Formatter->parseCustomPseudoSourceValue(
3250 Token.stringValue(), MF, PFS, PSV,
3251 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3260 llvm_unreachable("The current token should be pseudo source value");
3267 if (Token.is(MIToken::kw_constant_pool) || Token.is(MIToken::kw_stack) ||
3268 Token.is(MIToken::kw_got) || Token.is(MIToken::kw_jump_table) ||
3269 Token.is(MIToken::FixedStackObject) || Token.is(MIToken::StackObject) ||
3270 Token.is(MIToken::kw_call_entry) || Token.is(MIToken::kw_custom)) {
3280 if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue) &&
3281 Token.isNot(MIToken::GlobalValue) &&
3282 Token.isNot(MIToken::NamedGlobalValue) &&
3283 Token.isNot(MIToken::QuotedIRValue) &&
3284 Token.isNot(MIToken::kw_unknown_address))
3289 if (V && !V->getType()->isPointerTy())
3302 if (Token.is(MIToken::Identifier) && Token.stringValue() == "syncscope") {
3321 if (Token.isNot(MIToken::Identifier))
3324 Order = StringSwitch<AtomicOrdering>(Token.stringValue())
3345 while (Token.isMemoryOperandFlag()) {
3349 if (Token.isNot(MIToken::Identifier) ||
3350 (Token.stringValue() != "load" && Token.stringValue() != "store"))
3352 if (Token.stringValue() == "load")
3359 if (Token.is(MIToken::Identifier) && Token.stringValue() == "store") {
3377 if (Token.isNot(MIToken::IntegerLiteral) &&
3378 Token.isNot(MIToken::kw_unknown_size) &&
3379 Token.isNot(MIToken::lparen))
3380 return error("expected memory LLT, the size integer literal or 'unknown-size' after "
3384 if (Token.is(MIToken::IntegerLiteral)) {
3392 } else if (Token.is(MIToken::kw_unknown_size)) {
3397 if (parseLowLevelType(Token.location(), MemoryType))
3404 if (Token.is(MIToken::Identifier)) {
3410 if (Token.stringValue() != Word)
3424 switch (Token.kind()) {
3430 if (Ptr.Offset & (Alignment - 1)) {
3432 // alignment of offset, so this just guards against hand-written MIR
3483 assert((Token.is(MIToken::kw_pre_instr_symbol) ||
3484 Token.is(MIToken::kw_post_instr_symbol)) &&
3485 "Invalid token for a pre- post-instruction symbol!");
3487 if (Token.isNot(MIToken::MCSymbol))
3488 return error("expected a symbol after 'pre-instr-symbol'");
3489 Symbol = getOrCreateMCSymbol(Token.stringValue());
3491 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3492 Token.is(MIToken::lbrace))
3494 if (Token.isNot(MIToken::comma))
3501 assert(Token.is(MIToken::kw_heap_alloc_marker) &&
3502 "Invalid token for a heap alloc marker!");
3507 return error("expected a MDNode after 'heap-alloc-marker'");
3508 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3509 Token.is(MIToken::lbrace))
3511 if (Token.isNot(MIToken::comma))
3518 assert(Token.is(MIToken::kw_pcsections) &&
3519 "Invalid token for a PC sections!");
3525 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3526 Token.is(MIToken::lbrace))
3528 if (Token.isNot(MIToken::comma))
3543 if (Slot == -1)
3579 if (Token.isNot(MIToken::StringConstant))
3581 Result = std::string(Token.stringValue());
3640 MIToken Token;
3641 Src = lexMIToken(Src, Token, [&](StringRef::iterator Loc, const Twine &Msg) {
3646 return ::parseIRValue(Token, PFS, V, ErrorCallback);