Bug Summary

File:build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/CodeGen/MIRParser/MIParser.cpp
Warning:line 2108, column 15
The left operand of '>=' is a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name MIParser.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-16/lib/clang/16.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I lib/CodeGen/MIRParser -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/CodeGen/MIRParser -I include -I /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-09-04-125545-48738-1 -x c++ /build/llvm-toolchain-snapshot-16~++20220904122748+c444af1c20b3/llvm/lib/CodeGen/MIRParser/MIParser.cpp
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
13#include "llvm/CodeGen/MIRParser/MIParser.h"
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"
19#include "llvm/ADT/None.h"
20#include "llvm/ADT/Optional.h"
21#include "llvm/ADT/SmallVector.h"
22#include "llvm/ADT/StringMap.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/StringSwitch.h"
25#include "llvm/ADT/Twine.h"
26#include "llvm/Analysis/MemoryLocation.h"
27#include "llvm/AsmParser/Parser.h"
28#include "llvm/AsmParser/SlotMapping.h"
29#include "llvm/CodeGen/MIRFormatter.h"
30#include "llvm/CodeGen/MIRPrinter.h"
31#include "llvm/CodeGen/MachineBasicBlock.h"
32#include "llvm/CodeGen/MachineFrameInfo.h"
33#include "llvm/CodeGen/MachineFunction.h"
34#include "llvm/CodeGen/MachineInstr.h"
35#include "llvm/CodeGen/MachineInstrBuilder.h"
36#include "llvm/CodeGen/MachineMemOperand.h"
37#include "llvm/CodeGen/MachineOperand.h"
38#include "llvm/CodeGen/MachineRegisterInfo.h"
39#include "llvm/CodeGen/RegisterBank.h"
40#include "llvm/CodeGen/RegisterBankInfo.h"
41#include "llvm/CodeGen/TargetInstrInfo.h"
42#include "llvm/CodeGen/TargetRegisterInfo.h"
43#include "llvm/CodeGen/TargetSubtargetInfo.h"
44#include "llvm/IR/BasicBlock.h"
45#include "llvm/IR/Constants.h"
46#include "llvm/IR/DataLayout.h"
47#include "llvm/IR/DebugInfoMetadata.h"
48#include "llvm/IR/DebugLoc.h"
49#include "llvm/IR/Function.h"
50#include "llvm/IR/InstrTypes.h"
51#include "llvm/IR/Instructions.h"
52#include "llvm/IR/Intrinsics.h"
53#include "llvm/IR/Metadata.h"
54#include "llvm/IR/Module.h"
55#include "llvm/IR/ModuleSlotTracker.h"
56#include "llvm/IR/Type.h"
57#include "llvm/IR/Value.h"
58#include "llvm/IR/ValueSymbolTable.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"
63#include "llvm/Support/AtomicOrdering.h"
64#include "llvm/Support/BranchProbability.h"
65#include "llvm/Support/Casting.h"
66#include "llvm/Support/ErrorHandling.h"
67#include "llvm/Support/LowLevelTypeImpl.h"
68#include "llvm/Support/MemoryBuffer.h"
69#include "llvm/Support/SMLoc.h"
70#include "llvm/Support/SourceMgr.h"
71#include "llvm/Target/TargetIntrinsicInfo.h"
72#include "llvm/Target/TargetMachine.h"
73#include <cassert>
74#include <cctype>
75#include <cstddef>
76#include <cstdint>
77#include <limits>
78#include <string>
79#include <utility>
80
81using namespace llvm;
82
83void PerTargetMIParsingState::setTarget(
84 const TargetSubtargetInfo &NewSubtarget) {
85
86 // If the subtarget changed, over conservatively assume everything is invalid.
87 if (&Subtarget == &NewSubtarget)
88 return;
89
90 Names2InstrOpCodes.clear();
91 Names2Regs.clear();
92 Names2RegMasks.clear();
93 Names2SubRegIndices.clear();
94 Names2TargetIndices.clear();
95 Names2DirectTargetFlags.clear();
96 Names2BitmaskTargetFlags.clear();
97 Names2MMOTargetFlags.clear();
98
99 initNames2RegClasses();
100 initNames2RegBanks();
101}
102
103void PerTargetMIParsingState::initNames2Regs() {
104 if (!Names2Regs.empty())
105 return;
106
107 // The '%noreg' register is the register 0.
108 Names2Regs.insert(std::make_pair("noreg", 0));
109 const auto *TRI = Subtarget.getRegisterInfo();
110 assert(TRI && "Expected target register info")(static_cast <bool> (TRI && "Expected target register info"
) ? void (0) : __assert_fail ("TRI && \"Expected target register info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 110, __extension__
__PRETTY_FUNCTION__))
;
111
112 for (unsigned I = 0, E = TRI->getNumRegs(); I < E; ++I) {
113 bool WasInserted =
114 Names2Regs.insert(std::make_pair(StringRef(TRI->getName(I)).lower(), I))
115 .second;
116 (void)WasInserted;
117 assert(WasInserted && "Expected registers to be unique case-insensitively")(static_cast <bool> (WasInserted && "Expected registers to be unique case-insensitively"
) ? void (0) : __assert_fail ("WasInserted && \"Expected registers to be unique case-insensitively\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 117, __extension__
__PRETTY_FUNCTION__))
;
118 }
119}
120
121bool PerTargetMIParsingState::getRegisterByName(StringRef RegName,
122 Register &Reg) {
123 initNames2Regs();
124 auto RegInfo = Names2Regs.find(RegName);
125 if (RegInfo == Names2Regs.end())
126 return true;
127 Reg = RegInfo->getValue();
128 return false;
129}
130
131void PerTargetMIParsingState::initNames2InstrOpCodes() {
132 if (!Names2InstrOpCodes.empty())
133 return;
134 const auto *TII = Subtarget.getInstrInfo();
135 assert(TII && "Expected target instruction info")(static_cast <bool> (TII && "Expected target instruction info"
) ? void (0) : __assert_fail ("TII && \"Expected target instruction info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 135, __extension__
__PRETTY_FUNCTION__))
;
136 for (unsigned I = 0, E = TII->getNumOpcodes(); I < E; ++I)
137 Names2InstrOpCodes.insert(std::make_pair(StringRef(TII->getName(I)), I));
138}
139
140bool PerTargetMIParsingState::parseInstrName(StringRef InstrName,
141 unsigned &OpCode) {
142 initNames2InstrOpCodes();
143 auto InstrInfo = Names2InstrOpCodes.find(InstrName);
144 if (InstrInfo == Names2InstrOpCodes.end())
145 return true;
146 OpCode = InstrInfo->getValue();
147 return false;
148}
149
150void PerTargetMIParsingState::initNames2RegMasks() {
151 if (!Names2RegMasks.empty())
152 return;
153 const auto *TRI = Subtarget.getRegisterInfo();
154 assert(TRI && "Expected target register info")(static_cast <bool> (TRI && "Expected target register info"
) ? void (0) : __assert_fail ("TRI && \"Expected target register info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 154, __extension__
__PRETTY_FUNCTION__))
;
155 ArrayRef<const uint32_t *> RegMasks = TRI->getRegMasks();
156 ArrayRef<const char *> RegMaskNames = TRI->getRegMaskNames();
157 assert(RegMasks.size() == RegMaskNames.size())(static_cast <bool> (RegMasks.size() == RegMaskNames.size
()) ? void (0) : __assert_fail ("RegMasks.size() == RegMaskNames.size()"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 157, __extension__
__PRETTY_FUNCTION__))
;
158 for (size_t I = 0, E = RegMasks.size(); I < E; ++I)
159 Names2RegMasks.insert(
160 std::make_pair(StringRef(RegMaskNames[I]).lower(), RegMasks[I]));
161}
162
163const uint32_t *PerTargetMIParsingState::getRegMask(StringRef Identifier) {
164 initNames2RegMasks();
165 auto RegMaskInfo = Names2RegMasks.find(Identifier);
166 if (RegMaskInfo == Names2RegMasks.end())
167 return nullptr;
168 return RegMaskInfo->getValue();
169}
170
171void PerTargetMIParsingState::initNames2SubRegIndices() {
172 if (!Names2SubRegIndices.empty())
173 return;
174 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
175 for (unsigned I = 1, E = TRI->getNumSubRegIndices(); I < E; ++I)
176 Names2SubRegIndices.insert(
177 std::make_pair(TRI->getSubRegIndexName(I), I));
178}
179
180unsigned PerTargetMIParsingState::getSubRegIndex(StringRef Name) {
181 initNames2SubRegIndices();
182 auto SubRegInfo = Names2SubRegIndices.find(Name);
183 if (SubRegInfo == Names2SubRegIndices.end())
184 return 0;
185 return SubRegInfo->getValue();
186}
187
188void PerTargetMIParsingState::initNames2TargetIndices() {
189 if (!Names2TargetIndices.empty())
190 return;
191 const auto *TII = Subtarget.getInstrInfo();
192 assert(TII && "Expected target instruction info")(static_cast <bool> (TII && "Expected target instruction info"
) ? void (0) : __assert_fail ("TII && \"Expected target instruction info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 192, __extension__
__PRETTY_FUNCTION__))
;
193 auto Indices = TII->getSerializableTargetIndices();
194 for (const auto &I : Indices)
195 Names2TargetIndices.insert(std::make_pair(StringRef(I.second), I.first));
196}
197
198bool PerTargetMIParsingState::getTargetIndex(StringRef Name, int &Index) {
199 initNames2TargetIndices();
200 auto IndexInfo = Names2TargetIndices.find(Name);
201 if (IndexInfo == Names2TargetIndices.end())
202 return true;
203 Index = IndexInfo->second;
204 return false;
205}
206
207void PerTargetMIParsingState::initNames2DirectTargetFlags() {
208 if (!Names2DirectTargetFlags.empty())
209 return;
210
211 const auto *TII = Subtarget.getInstrInfo();
212 assert(TII && "Expected target instruction info")(static_cast <bool> (TII && "Expected target instruction info"
) ? void (0) : __assert_fail ("TII && \"Expected target instruction info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 212, __extension__
__PRETTY_FUNCTION__))
;
213 auto Flags = TII->getSerializableDirectMachineOperandTargetFlags();
214 for (const auto &I : Flags)
215 Names2DirectTargetFlags.insert(
216 std::make_pair(StringRef(I.second), I.first));
217}
218
219bool PerTargetMIParsingState::getDirectTargetFlag(StringRef Name,
220 unsigned &Flag) {
221 initNames2DirectTargetFlags();
222 auto FlagInfo = Names2DirectTargetFlags.find(Name);
223 if (FlagInfo == Names2DirectTargetFlags.end())
224 return true;
225 Flag = FlagInfo->second;
226 return false;
227}
228
229void PerTargetMIParsingState::initNames2BitmaskTargetFlags() {
230 if (!Names2BitmaskTargetFlags.empty())
231 return;
232
233 const auto *TII = Subtarget.getInstrInfo();
234 assert(TII && "Expected target instruction info")(static_cast <bool> (TII && "Expected target instruction info"
) ? void (0) : __assert_fail ("TII && \"Expected target instruction info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 234, __extension__
__PRETTY_FUNCTION__))
;
235 auto Flags = TII->getSerializableBitmaskMachineOperandTargetFlags();
236 for (const auto &I : Flags)
237 Names2BitmaskTargetFlags.insert(
238 std::make_pair(StringRef(I.second), I.first));
239}
240
241bool PerTargetMIParsingState::getBitmaskTargetFlag(StringRef Name,
242 unsigned &Flag) {
243 initNames2BitmaskTargetFlags();
244 auto FlagInfo = Names2BitmaskTargetFlags.find(Name);
245 if (FlagInfo == Names2BitmaskTargetFlags.end())
246 return true;
247 Flag = FlagInfo->second;
248 return false;
249}
250
251void PerTargetMIParsingState::initNames2MMOTargetFlags() {
252 if (!Names2MMOTargetFlags.empty())
253 return;
254
255 const auto *TII = Subtarget.getInstrInfo();
256 assert(TII && "Expected target instruction info")(static_cast <bool> (TII && "Expected target instruction info"
) ? void (0) : __assert_fail ("TII && \"Expected target instruction info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 256, __extension__
__PRETTY_FUNCTION__))
;
257 auto Flags = TII->getSerializableMachineMemOperandTargetFlags();
258 for (const auto &I : Flags)
259 Names2MMOTargetFlags.insert(std::make_pair(StringRef(I.second), I.first));
260}
261
262bool PerTargetMIParsingState::getMMOTargetFlag(StringRef Name,
263 MachineMemOperand::Flags &Flag) {
264 initNames2MMOTargetFlags();
265 auto FlagInfo = Names2MMOTargetFlags.find(Name);
266 if (FlagInfo == Names2MMOTargetFlags.end())
267 return true;
268 Flag = FlagInfo->second;
269 return false;
270}
271
272void PerTargetMIParsingState::initNames2RegClasses() {
273 if (!Names2RegClasses.empty())
274 return;
275
276 const TargetRegisterInfo *TRI = Subtarget.getRegisterInfo();
277 for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
278 const auto *RC = TRI->getRegClass(I);
279 Names2RegClasses.insert(
280 std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
281 }
282}
283
284void PerTargetMIParsingState::initNames2RegBanks() {
285 if (!Names2RegBanks.empty())
286 return;
287
288 const RegisterBankInfo *RBI = Subtarget.getRegBankInfo();
289 // If the target does not support GlobalISel, we may not have a
290 // register bank info.
291 if (!RBI)
292 return;
293
294 for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
295 const auto &RegBank = RBI->getRegBank(I);
296 Names2RegBanks.insert(
297 std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
298 }
299}
300
301const TargetRegisterClass *
302PerTargetMIParsingState::getRegClass(StringRef Name) {
303 auto RegClassInfo = Names2RegClasses.find(Name);
304 if (RegClassInfo == Names2RegClasses.end())
305 return nullptr;
306 return RegClassInfo->getValue();
307}
308
309const RegisterBank *PerTargetMIParsingState::getRegBank(StringRef Name) {
310 auto RegBankInfo = Names2RegBanks.find(Name);
311 if (RegBankInfo == Names2RegBanks.end())
312 return nullptr;
313 return RegBankInfo->getValue();
314}
315
316PerFunctionMIParsingState::PerFunctionMIParsingState(MachineFunction &MF,
317 SourceMgr &SM, const SlotMapping &IRSlots, PerTargetMIParsingState &T)
318 : MF(MF), SM(&SM), IRSlots(IRSlots), Target(T) {
319}
320
321VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {
322 auto I = VRegInfos.insert(std::make_pair(Num, nullptr));
323 if (I.second) {
324 MachineRegisterInfo &MRI = MF.getRegInfo();
325 VRegInfo *Info = new (Allocator) VRegInfo;
326 Info->VReg = MRI.createIncompleteVirtualRegister();
327 I.first->second = Info;
328 }
329 return *I.first->second;
330}
331
332VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) {
333 assert(RegName != "" && "Expected named reg.")(static_cast <bool> (RegName != "" && "Expected named reg."
) ? void (0) : __assert_fail ("RegName != \"\" && \"Expected named reg.\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 333, __extension__
__PRETTY_FUNCTION__))
;
334
335 auto I = VRegInfosNamed.insert(std::make_pair(RegName.str(), nullptr));
336 if (I.second) {
337 VRegInfo *Info = new (Allocator) VRegInfo;
338 Info->VReg = MF.getRegInfo().createIncompleteVirtualRegister(RegName);
339 I.first->second = Info;
340 }
341 return *I.first->second;
342}
343
344static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST,
345 DenseMap<unsigned, const Value *> &Slots2Values) {
346 int Slot = MST.getLocalSlot(V);
347 if (Slot == -1)
348 return;
349 Slots2Values.insert(std::make_pair(unsigned(Slot), V));
350}
351
352/// Creates the mapping from slot numbers to function's unnamed IR values.
353static void initSlots2Values(const Function &F,
354 DenseMap<unsigned, const Value *> &Slots2Values) {
355 ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
356 MST.incorporateFunction(F);
357 for (const auto &Arg : F.args())
358 mapValueToSlot(&Arg, MST, Slots2Values);
359 for (const auto &BB : F) {
360 mapValueToSlot(&BB, MST, Slots2Values);
361 for (const auto &I : BB)
362 mapValueToSlot(&I, MST, Slots2Values);
363 }
364}
365
366const Value* PerFunctionMIParsingState::getIRValue(unsigned Slot) {
367 if (Slots2Values.empty())
368 initSlots2Values(MF.getFunction(), Slots2Values);
369 return Slots2Values.lookup(Slot);
370}
371
372namespace {
373
374/// A wrapper struct around the 'MachineOperand' struct that includes a source
375/// range and other attributes.
376struct ParsedMachineOperand {
377 MachineOperand Operand;
378 StringRef::iterator Begin;
379 StringRef::iterator End;
380 Optional<unsigned> TiedDefIdx;
381
382 ParsedMachineOperand(const MachineOperand &Operand, StringRef::iterator Begin,
383 StringRef::iterator End, Optional<unsigned> &TiedDefIdx)
384 : Operand(Operand), Begin(Begin), End(End), TiedDefIdx(TiedDefIdx) {
385 if (TiedDefIdx)
386 assert(Operand.isReg() && Operand.isUse() &&(static_cast <bool> (Operand.isReg() && Operand
.isUse() && "Only used register operands can be tied"
) ? void (0) : __assert_fail ("Operand.isReg() && Operand.isUse() && \"Only used register operands can be tied\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 387, __extension__
__PRETTY_FUNCTION__))
387 "Only used register operands can be tied")(static_cast <bool> (Operand.isReg() && Operand
.isUse() && "Only used register operands can be tied"
) ? void (0) : __assert_fail ("Operand.isReg() && Operand.isUse() && \"Only used register operands can be tied\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 387, __extension__
__PRETTY_FUNCTION__))
;
388 }
389};
390
391class MIParser {
392 MachineFunction &MF;
393 SMDiagnostic &Error;
394 StringRef Source, CurrentSource;
395 SMRange SourceRange;
396 MIToken Token;
397 PerFunctionMIParsingState &PFS;
398 /// Maps from slot numbers to function's unnamed basic blocks.
399 DenseMap<unsigned, const BasicBlock *> Slots2BasicBlocks;
400
401public:
402 MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
403 StringRef Source);
404 MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
405 StringRef Source, SMRange SourceRange);
406
407 /// \p SkipChar gives the number of characters to skip before looking
408 /// for the next token.
409 void lex(unsigned SkipChar = 0);
410
411 /// Report an error at the current location with the given message.
412 ///
413 /// This function always return true.
414 bool error(const Twine &Msg);
415
416 /// Report an error at the given location with the given message.
417 ///
418 /// This function always return true.
419 bool error(StringRef::iterator Loc, const Twine &Msg);
420
421 bool
422 parseBasicBlockDefinitions(DenseMap<unsigned, MachineBasicBlock *> &MBBSlots);
423 bool parseBasicBlocks();
424 bool parse(MachineInstr *&MI);
425 bool parseStandaloneMBB(MachineBasicBlock *&MBB);
426 bool parseStandaloneNamedRegister(Register &Reg);
427 bool parseStandaloneVirtualRegister(VRegInfo *&Info);
428 bool parseStandaloneRegister(Register &Reg);
429 bool parseStandaloneStackObject(int &FI);
430 bool parseStandaloneMDNode(MDNode *&Node);
431 bool parseMachineMetadata();
432 bool parseMDTuple(MDNode *&MD, bool IsDistinct);
433 bool parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts);
434 bool parseMetadata(Metadata *&MD);
435
436 bool
437 parseBasicBlockDefinition(DenseMap<unsigned, MachineBasicBlock *> &MBBSlots);
438 bool parseBasicBlock(MachineBasicBlock &MBB,
439 MachineBasicBlock *&AddFalthroughFrom);
440 bool parseBasicBlockLiveins(MachineBasicBlock &MBB);
441 bool parseBasicBlockSuccessors(MachineBasicBlock &MBB);
442
443 bool parseNamedRegister(Register &Reg);
444 bool parseVirtualRegister(VRegInfo *&Info);
445 bool parseNamedVirtualRegister(VRegInfo *&Info);
446 bool parseRegister(Register &Reg, VRegInfo *&VRegInfo);
447 bool parseRegisterFlag(unsigned &Flags);
448 bool parseRegisterClassOrBank(VRegInfo &RegInfo);
449 bool parseSubRegisterIndex(unsigned &SubReg);
450 bool parseRegisterTiedDefIndex(unsigned &TiedDefIdx);
451 bool parseRegisterOperand(MachineOperand &Dest,
452 Optional<unsigned> &TiedDefIdx, bool IsDef = false);
453 bool parseImmediateOperand(MachineOperand &Dest);
454 bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
455 const Constant *&C);
456 bool parseIRConstant(StringRef::iterator Loc, const Constant *&C);
457 bool parseLowLevelType(StringRef::iterator Loc, LLT &Ty);
458 bool parseTypedImmediateOperand(MachineOperand &Dest);
459 bool parseFPImmediateOperand(MachineOperand &Dest);
460 bool parseMBBReference(MachineBasicBlock *&MBB);
461 bool parseMBBOperand(MachineOperand &Dest);
462 bool parseStackFrameIndex(int &FI);
463 bool parseStackObjectOperand(MachineOperand &Dest);
464 bool parseFixedStackFrameIndex(int &FI);
465 bool parseFixedStackObjectOperand(MachineOperand &Dest);
466 bool parseGlobalValue(GlobalValue *&GV);
467 bool parseGlobalAddressOperand(MachineOperand &Dest);
468 bool parseConstantPoolIndexOperand(MachineOperand &Dest);
469 bool parseSubRegisterIndexOperand(MachineOperand &Dest);
470 bool parseJumpTableIndexOperand(MachineOperand &Dest);
471 bool parseExternalSymbolOperand(MachineOperand &Dest);
472 bool parseMCSymbolOperand(MachineOperand &Dest);
473 bool parseMDNode(MDNode *&Node);
474 bool parseDIExpression(MDNode *&Expr);
475 bool parseDILocation(MDNode *&Expr);
476 bool parseMetadataOperand(MachineOperand &Dest);
477 bool parseCFIOffset(int &Offset);
478 bool parseCFIRegister(Register &Reg);
479 bool parseCFIAddressSpace(unsigned &AddressSpace);
480 bool parseCFIEscapeValues(std::string& Values);
481 bool parseCFIOperand(MachineOperand &Dest);
482 bool parseIRBlock(BasicBlock *&BB, const Function &F);
483 bool parseBlockAddressOperand(MachineOperand &Dest);
484 bool parseIntrinsicOperand(MachineOperand &Dest);
485 bool parsePredicateOperand(MachineOperand &Dest);
486 bool parseShuffleMaskOperand(MachineOperand &Dest);
487 bool parseTargetIndexOperand(MachineOperand &Dest);
488 bool parseCustomRegisterMaskOperand(MachineOperand &Dest);
489 bool parseLiveoutRegisterMaskOperand(MachineOperand &Dest);
490 bool parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
491 MachineOperand &Dest,
492 Optional<unsigned> &TiedDefIdx);
493 bool parseMachineOperandAndTargetFlags(const unsigned OpCode,
494 const unsigned OpIdx,
495 MachineOperand &Dest,
496 Optional<unsigned> &TiedDefIdx);
497 bool parseOffset(int64_t &Offset);
498 bool parseIRBlockAddressTaken(BasicBlock *&BB);
499 bool parseAlignment(uint64_t &Alignment);
500 bool parseAddrspace(unsigned &Addrspace);
501 bool parseSectionID(Optional<MBBSectionID> &SID);
502 bool parseOperandsOffset(MachineOperand &Op);
503 bool parseIRValue(const Value *&V);
504 bool parseMemoryOperandFlag(MachineMemOperand::Flags &Flags);
505 bool parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV);
506 bool parseMachinePointerInfo(MachinePointerInfo &Dest);
507 bool parseOptionalScope(LLVMContext &Context, SyncScope::ID &SSID);
508 bool parseOptionalAtomicOrdering(AtomicOrdering &Order);
509 bool parseMachineMemoryOperand(MachineMemOperand *&Dest);
510 bool parsePreOrPostInstrSymbol(MCSymbol *&Symbol);
511 bool parseHeapAllocMarker(MDNode *&Node);
512
513 bool parseTargetImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
514 MachineOperand &Dest, const MIRFormatter &MF);
515
516private:
517 /// Convert the integer literal in the current token into an unsigned integer.
518 ///
519 /// Return true if an error occurred.
520 bool getUnsigned(unsigned &Result);
521
522 /// Convert the integer literal in the current token into an uint64.
523 ///
524 /// Return true if an error occurred.
525 bool getUint64(uint64_t &Result);
526
527 /// Convert the hexadecimal literal in the current token into an unsigned
528 /// APInt with a minimum bitwidth required to represent the value.
529 ///
530 /// Return true if the literal does not represent an integer value.
531 bool getHexUint(APInt &Result);
532
533 /// If the current token is of the given kind, consume it and return false.
534 /// Otherwise report an error and return true.
535 bool expectAndConsume(MIToken::TokenKind TokenKind);
536
537 /// If the current token is of the given kind, consume it and return true.
538 /// Otherwise return false.
539 bool consumeIfPresent(MIToken::TokenKind TokenKind);
540
541 bool parseInstruction(unsigned &OpCode, unsigned &Flags);
542
543 bool assignRegisterTies(MachineInstr &MI,
544 ArrayRef<ParsedMachineOperand> Operands);
545
546 bool verifyImplicitOperands(ArrayRef<ParsedMachineOperand> Operands,
547 const MCInstrDesc &MCID);
548
549 const BasicBlock *getIRBlock(unsigned Slot);
550 const BasicBlock *getIRBlock(unsigned Slot, const Function &F);
551
552 /// Get or create an MCSymbol for a given name.
553 MCSymbol *getOrCreateMCSymbol(StringRef Name);
554
555 /// parseStringConstant
556 /// ::= StringConstant
557 bool parseStringConstant(std::string &Result);
558
559 /// Map the location in the MI string to the corresponding location specified
560 /// in `SourceRange`.
561 SMLoc mapSMLoc(StringRef::iterator Loc);
562};
563
564} // end anonymous namespace
565
566MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
567 StringRef Source)
568 : MF(PFS.MF), Error(Error), Source(Source), CurrentSource(Source), PFS(PFS)
569{}
570
571MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
572 StringRef Source, SMRange SourceRange)
573 : MF(PFS.MF), Error(Error), Source(Source), CurrentSource(Source),
574 SourceRange(SourceRange), PFS(PFS) {}
575
576void MIParser::lex(unsigned SkipChar) {
577 CurrentSource = lexMIToken(
578 CurrentSource.slice(SkipChar, StringRef::npos), Token,
579 [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); });
580}
581
582bool MIParser::error(const Twine &Msg) { return error(Token.location(), Msg); }
583
584bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) {
585 const SourceMgr &SM = *PFS.SM;
586 assert(Loc >= Source.data() && Loc <= (Source.data() + Source.size()))(static_cast <bool> (Loc >= Source.data() &&
Loc <= (Source.data() + Source.size())) ? void (0) : __assert_fail
("Loc >= Source.data() && Loc <= (Source.data() + Source.size())"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 586, __extension__
__PRETTY_FUNCTION__))
;
587 const MemoryBuffer &Buffer = *SM.getMemoryBuffer(SM.getMainFileID());
588 if (Loc >= Buffer.getBufferStart() && Loc <= Buffer.getBufferEnd()) {
589 // Create an ordinary diagnostic when the source manager's buffer is the
590 // source string.
591 Error = SM.GetMessage(SMLoc::getFromPointer(Loc), SourceMgr::DK_Error, Msg);
592 return true;
593 }
594 // Create a diagnostic for a YAML string literal.
595 Error = SMDiagnostic(SM, SMLoc(), Buffer.getBufferIdentifier(), 1,
596 Loc - Source.data(), SourceMgr::DK_Error, Msg.str(),
597 Source, None, None);
598 return true;
599}
600
601SMLoc MIParser::mapSMLoc(StringRef::iterator Loc) {
602 assert(SourceRange.isValid() && "Invalid source range")(static_cast <bool> (SourceRange.isValid() && "Invalid source range"
) ? void (0) : __assert_fail ("SourceRange.isValid() && \"Invalid source range\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 602, __extension__
__PRETTY_FUNCTION__))
;
603 assert(Loc >= Source.data() && Loc <= (Source.data() + Source.size()))(static_cast <bool> (Loc >= Source.data() &&
Loc <= (Source.data() + Source.size())) ? void (0) : __assert_fail
("Loc >= Source.data() && Loc <= (Source.data() + Source.size())"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 603, __extension__
__PRETTY_FUNCTION__))
;
604 return SMLoc::getFromPointer(SourceRange.Start.getPointer() +
605 (Loc - Source.data()));
606}
607
608typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
609 ErrorCallbackType;
610
611static const char *toString(MIToken::TokenKind TokenKind) {
612 switch (TokenKind) {
613 case MIToken::comma:
614 return "','";
615 case MIToken::equal:
616 return "'='";
617 case MIToken::colon:
618 return "':'";
619 case MIToken::lparen:
620 return "'('";
621 case MIToken::rparen:
622 return "')'";
623 default:
624 return "<unknown token>";
625 }
626}
627
628bool MIParser::expectAndConsume(MIToken::TokenKind TokenKind) {
629 if (Token.isNot(TokenKind))
630 return error(Twine("expected ") + toString(TokenKind));
631 lex();
632 return false;
633}
634
635bool MIParser::consumeIfPresent(MIToken::TokenKind TokenKind) {
636 if (Token.isNot(TokenKind))
637 return false;
638 lex();
639 return true;
640}
641
642// Parse Machine Basic Block Section ID.
643bool MIParser::parseSectionID(Optional<MBBSectionID> &SID) {
644 assert(Token.is(MIToken::kw_bbsections))(static_cast <bool> (Token.is(MIToken::kw_bbsections)) ?
void (0) : __assert_fail ("Token.is(MIToken::kw_bbsections)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 644, __extension__
__PRETTY_FUNCTION__))
;
645 lex();
646 if (Token.is(MIToken::IntegerLiteral)) {
647 unsigned Value = 0;
648 if (getUnsigned(Value))
649 return error("Unknown Section ID");
650 SID = MBBSectionID{Value};
651 } else {
652 const StringRef &S = Token.stringValue();
653 if (S == "Exception")
654 SID = MBBSectionID::ExceptionSectionID;
655 else if (S == "Cold")
656 SID = MBBSectionID::ColdSectionID;
657 else
658 return error("Unknown Section ID");
659 }
660 lex();
661 return false;
662}
663
664bool MIParser::parseBasicBlockDefinition(
665 DenseMap<unsigned, MachineBasicBlock *> &MBBSlots) {
666 assert(Token.is(MIToken::MachineBasicBlockLabel))(static_cast <bool> (Token.is(MIToken::MachineBasicBlockLabel
)) ? void (0) : __assert_fail ("Token.is(MIToken::MachineBasicBlockLabel)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 666, __extension__
__PRETTY_FUNCTION__))
;
667 unsigned ID = 0;
668 if (getUnsigned(ID))
669 return true;
670 auto Loc = Token.location();
671 auto Name = Token.stringValue();
672 lex();
673 bool MachineBlockAddressTaken = false;
674 BasicBlock *AddressTakenIRBlock = nullptr;
675 bool IsLandingPad = false;
676 bool IsInlineAsmBrIndirectTarget = false;
677 bool IsEHFuncletEntry = false;
678 Optional<MBBSectionID> SectionID;
679 uint64_t Alignment = 0;
680 BasicBlock *BB = nullptr;
681 if (consumeIfPresent(MIToken::lparen)) {
682 do {
683 // TODO: Report an error when multiple same attributes are specified.
684 switch (Token.kind()) {
685 case MIToken::kw_machine_block_address_taken:
686 MachineBlockAddressTaken = true;
687 lex();
688 break;
689 case MIToken::kw_ir_block_address_taken:
690 if (parseIRBlockAddressTaken(AddressTakenIRBlock))
691 return true;
692 break;
693 case MIToken::kw_landing_pad:
694 IsLandingPad = true;
695 lex();
696 break;
697 case MIToken::kw_inlineasm_br_indirect_target:
698 IsInlineAsmBrIndirectTarget = true;
699 lex();
700 break;
701 case MIToken::kw_ehfunclet_entry:
702 IsEHFuncletEntry = true;
703 lex();
704 break;
705 case MIToken::kw_align:
706 if (parseAlignment(Alignment))
707 return true;
708 break;
709 case MIToken::IRBlock:
710 case MIToken::NamedIRBlock:
711 // TODO: Report an error when both name and ir block are specified.
712 if (parseIRBlock(BB, MF.getFunction()))
713 return true;
714 lex();
715 break;
716 case MIToken::kw_bbsections:
717 if (parseSectionID(SectionID))
718 return true;
719 break;
720 default:
721 break;
722 }
723 } while (consumeIfPresent(MIToken::comma));
724 if (expectAndConsume(MIToken::rparen))
725 return true;
726 }
727 if (expectAndConsume(MIToken::colon))
728 return true;
729
730 if (!Name.empty()) {
731 BB = dyn_cast_or_null<BasicBlock>(
732 MF.getFunction().getValueSymbolTable()->lookup(Name));
733 if (!BB)
734 return error(Loc, Twine("basic block '") + Name +
735 "' is not defined in the function '" +
736 MF.getName() + "'");
737 }
738 auto *MBB = MF.CreateMachineBasicBlock(BB);
739 MF.insert(MF.end(), MBB);
740 bool WasInserted = MBBSlots.insert(std::make_pair(ID, MBB)).second;
741 if (!WasInserted)
742 return error(Loc, Twine("redefinition of machine basic block with id #") +
743 Twine(ID));
744 if (Alignment)
745 MBB->setAlignment(Align(Alignment));
746 if (MachineBlockAddressTaken)
747 MBB->setMachineBlockAddressTaken();
748 if (AddressTakenIRBlock)
749 MBB->setAddressTakenIRBlock(AddressTakenIRBlock);
750 MBB->setIsEHPad(IsLandingPad);
751 MBB->setIsInlineAsmBrIndirectTarget(IsInlineAsmBrIndirectTarget);
752 MBB->setIsEHFuncletEntry(IsEHFuncletEntry);
753 if (SectionID) {
754 MBB->setSectionID(SectionID.value());
755 MF.setBBSectionsType(BasicBlockSection::List);
756 }
757 return false;
758}
759
760bool MIParser::parseBasicBlockDefinitions(
761 DenseMap<unsigned, MachineBasicBlock *> &MBBSlots) {
762 lex();
763 // Skip until the first machine basic block.
764 while (Token.is(MIToken::Newline))
765 lex();
766 if (Token.isErrorOrEOF())
767 return Token.isError();
768 if (Token.isNot(MIToken::MachineBasicBlockLabel))
769 return error("expected a basic block definition before instructions");
770 unsigned BraceDepth = 0;
771 do {
772 if (parseBasicBlockDefinition(MBBSlots))
773 return true;
774 bool IsAfterNewline = false;
775 // Skip until the next machine basic block.
776 while (true) {
777 if ((Token.is(MIToken::MachineBasicBlockLabel) && IsAfterNewline) ||
778 Token.isErrorOrEOF())
779 break;
780 else if (Token.is(MIToken::MachineBasicBlockLabel))
781 return error("basic block definition should be located at the start of "
782 "the line");
783 else if (consumeIfPresent(MIToken::Newline)) {
784 IsAfterNewline = true;
785 continue;
786 }
787 IsAfterNewline = false;
788 if (Token.is(MIToken::lbrace))
789 ++BraceDepth;
790 if (Token.is(MIToken::rbrace)) {
791 if (!BraceDepth)
792 return error("extraneous closing brace ('}')");
793 --BraceDepth;
794 }
795 lex();
796 }
797 // Verify that we closed all of the '{' at the end of a file or a block.
798 if (!Token.isError() && BraceDepth)
799 return error("expected '}'"); // FIXME: Report a note that shows '{'.
800 } while (!Token.isErrorOrEOF());
801 return Token.isError();
802}
803
804bool MIParser::parseBasicBlockLiveins(MachineBasicBlock &MBB) {
805 assert(Token.is(MIToken::kw_liveins))(static_cast <bool> (Token.is(MIToken::kw_liveins)) ? void
(0) : __assert_fail ("Token.is(MIToken::kw_liveins)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 805, __extension__ __PRETTY_FUNCTION__))
;
806 lex();
807 if (expectAndConsume(MIToken::colon))
808 return true;
809 if (Token.isNewlineOrEOF()) // Allow an empty list of liveins.
810 return false;
811 do {
812 if (Token.isNot(MIToken::NamedRegister))
813 return error("expected a named register");
814 Register Reg;
815 if (parseNamedRegister(Reg))
816 return true;
817 lex();
818 LaneBitmask Mask = LaneBitmask::getAll();
819 if (consumeIfPresent(MIToken::colon)) {
820 // Parse lane mask.
821 if (Token.isNot(MIToken::IntegerLiteral) &&
822 Token.isNot(MIToken::HexLiteral))
823 return error("expected a lane mask");
824 static_assert(sizeof(LaneBitmask::Type) == sizeof(uint64_t),
825 "Use correct get-function for lane mask");
826 LaneBitmask::Type V;
827 if (getUint64(V))
828 return error("invalid lane mask value");
829 Mask = LaneBitmask(V);
830 lex();
831 }
832 MBB.addLiveIn(Reg, Mask);
833 } while (consumeIfPresent(MIToken::comma));
834 return false;
835}
836
837bool MIParser::parseBasicBlockSuccessors(MachineBasicBlock &MBB) {
838 assert(Token.is(MIToken::kw_successors))(static_cast <bool> (Token.is(MIToken::kw_successors)) ?
void (0) : __assert_fail ("Token.is(MIToken::kw_successors)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 838, __extension__
__PRETTY_FUNCTION__))
;
839 lex();
840 if (expectAndConsume(MIToken::colon))
841 return true;
842 if (Token.isNewlineOrEOF()) // Allow an empty list of successors.
843 return false;
844 do {
845 if (Token.isNot(MIToken::MachineBasicBlock))
846 return error("expected a machine basic block reference");
847 MachineBasicBlock *SuccMBB = nullptr;
848 if (parseMBBReference(SuccMBB))
849 return true;
850 lex();
851 unsigned Weight = 0;
852 if (consumeIfPresent(MIToken::lparen)) {
853 if (Token.isNot(MIToken::IntegerLiteral) &&
854 Token.isNot(MIToken::HexLiteral))
855 return error("expected an integer literal after '('");
856 if (getUnsigned(Weight))
857 return true;
858 lex();
859 if (expectAndConsume(MIToken::rparen))
860 return true;
861 }
862 MBB.addSuccessor(SuccMBB, BranchProbability::getRaw(Weight));
863 } while (consumeIfPresent(MIToken::comma));
864 MBB.normalizeSuccProbs();
865 return false;
866}
867
868bool MIParser::parseBasicBlock(MachineBasicBlock &MBB,
869 MachineBasicBlock *&AddFalthroughFrom) {
870 // Skip the definition.
871 assert(Token.is(MIToken::MachineBasicBlockLabel))(static_cast <bool> (Token.is(MIToken::MachineBasicBlockLabel
)) ? void (0) : __assert_fail ("Token.is(MIToken::MachineBasicBlockLabel)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 871, __extension__
__PRETTY_FUNCTION__))
;
872 lex();
873 if (consumeIfPresent(MIToken::lparen)) {
874 while (Token.isNot(MIToken::rparen) && !Token.isErrorOrEOF())
875 lex();
876 consumeIfPresent(MIToken::rparen);
877 }
878 consumeIfPresent(MIToken::colon);
879
880 // Parse the liveins and successors.
881 // N.B: Multiple lists of successors and liveins are allowed and they're
882 // merged into one.
883 // Example:
884 // liveins: $edi
885 // liveins: $esi
886 //
887 // is equivalent to
888 // liveins: $edi, $esi
889 bool ExplicitSuccessors = false;
890 while (true) {
891 if (Token.is(MIToken::kw_successors)) {
892 if (parseBasicBlockSuccessors(MBB))
893 return true;
894 ExplicitSuccessors = true;
895 } else if (Token.is(MIToken::kw_liveins)) {
896 if (parseBasicBlockLiveins(MBB))
897 return true;
898 } else if (consumeIfPresent(MIToken::Newline)) {
899 continue;
900 } else
901 break;
902 if (!Token.isNewlineOrEOF())
903 return error("expected line break at the end of a list");
904 lex();
905 }
906
907 // Parse the instructions.
908 bool IsInBundle = false;
909 MachineInstr *PrevMI = nullptr;
910 while (!Token.is(MIToken::MachineBasicBlockLabel) &&
911 !Token.is(MIToken::Eof)) {
912 if (consumeIfPresent(MIToken::Newline))
913 continue;
914 if (consumeIfPresent(MIToken::rbrace)) {
915 // The first parsing pass should verify that all closing '}' have an
916 // opening '{'.
917 assert(IsInBundle)(static_cast <bool> (IsInBundle) ? void (0) : __assert_fail
("IsInBundle", "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 917
, __extension__ __PRETTY_FUNCTION__))
;
918 IsInBundle = false;
919 continue;
920 }
921 MachineInstr *MI = nullptr;
922 if (parse(MI))
923 return true;
924 MBB.insert(MBB.end(), MI);
925 if (IsInBundle) {
926 PrevMI->setFlag(MachineInstr::BundledSucc);
927 MI->setFlag(MachineInstr::BundledPred);
928 }
929 PrevMI = MI;
930 if (Token.is(MIToken::lbrace)) {
931 if (IsInBundle)
932 return error("nested instruction bundles are not allowed");
933 lex();
934 // This instruction is the start of the bundle.
935 MI->setFlag(MachineInstr::BundledSucc);
936 IsInBundle = true;
937 if (!Token.is(MIToken::Newline))
938 // The next instruction can be on the same line.
939 continue;
940 }
941 assert(Token.isNewlineOrEOF() && "MI is not fully parsed")(static_cast <bool> (Token.isNewlineOrEOF() && "MI is not fully parsed"
) ? void (0) : __assert_fail ("Token.isNewlineOrEOF() && \"MI is not fully parsed\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 941, __extension__
__PRETTY_FUNCTION__))
;
942 lex();
943 }
944
945 // Construct successor list by searching for basic block machine operands.
946 if (!ExplicitSuccessors) {
947 SmallVector<MachineBasicBlock*,4> Successors;
948 bool IsFallthrough;
949 guessSuccessors(MBB, Successors, IsFallthrough);
950 for (MachineBasicBlock *Succ : Successors)
951 MBB.addSuccessor(Succ);
952
953 if (IsFallthrough) {
954 AddFalthroughFrom = &MBB;
955 } else {
956 MBB.normalizeSuccProbs();
957 }
958 }
959
960 return false;
961}
962
963bool MIParser::parseBasicBlocks() {
964 lex();
965 // Skip until the first machine basic block.
966 while (Token.is(MIToken::Newline))
967 lex();
968 if (Token.isErrorOrEOF())
969 return Token.isError();
970 // The first parsing pass should have verified that this token is a MBB label
971 // in the 'parseBasicBlockDefinitions' method.
972 assert(Token.is(MIToken::MachineBasicBlockLabel))(static_cast <bool> (Token.is(MIToken::MachineBasicBlockLabel
)) ? void (0) : __assert_fail ("Token.is(MIToken::MachineBasicBlockLabel)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 972, __extension__
__PRETTY_FUNCTION__))
;
973 MachineBasicBlock *AddFalthroughFrom = nullptr;
974 do {
975 MachineBasicBlock *MBB = nullptr;
976 if (parseMBBReference(MBB))
977 return true;
978 if (AddFalthroughFrom) {
979 if (!AddFalthroughFrom->isSuccessor(MBB))
980 AddFalthroughFrom->addSuccessor(MBB);
981 AddFalthroughFrom->normalizeSuccProbs();
982 AddFalthroughFrom = nullptr;
983 }
984 if (parseBasicBlock(*MBB, AddFalthroughFrom))
985 return true;
986 // The method 'parseBasicBlock' should parse the whole block until the next
987 // block or the end of file.
988 assert(Token.is(MIToken::MachineBasicBlockLabel) || Token.is(MIToken::Eof))(static_cast <bool> (Token.is(MIToken::MachineBasicBlockLabel
) || Token.is(MIToken::Eof)) ? void (0) : __assert_fail ("Token.is(MIToken::MachineBasicBlockLabel) || Token.is(MIToken::Eof)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 988, __extension__
__PRETTY_FUNCTION__))
;
989 } while (Token.isNot(MIToken::Eof));
990 return false;
991}
992
993bool MIParser::parse(MachineInstr *&MI) {
994 // Parse any register operands before '='
995 MachineOperand MO = MachineOperand::CreateImm(0);
996 SmallVector<ParsedMachineOperand, 8> Operands;
997 while (Token.isRegister() || Token.isRegisterFlag()) {
998 auto Loc = Token.location();
999 Optional<unsigned> TiedDefIdx;
1000 if (parseRegisterOperand(MO, TiedDefIdx, /*IsDef=*/true))
1001 return true;
1002 Operands.push_back(
1003 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1004 if (Token.isNot(MIToken::comma))
1005 break;
1006 lex();
1007 }
1008 if (!Operands.empty() && expectAndConsume(MIToken::equal))
1009 return true;
1010
1011 unsigned OpCode, Flags = 0;
1012 if (Token.isError() || parseInstruction(OpCode, Flags))
1013 return true;
1014
1015 // Parse the remaining machine operands.
1016 while (!Token.isNewlineOrEOF() && Token.isNot(MIToken::kw_pre_instr_symbol) &&
1017 Token.isNot(MIToken::kw_post_instr_symbol) &&
1018 Token.isNot(MIToken::kw_heap_alloc_marker) &&
1019 Token.isNot(MIToken::kw_cfi_type) &&
1020 Token.isNot(MIToken::kw_debug_location) &&
1021 Token.isNot(MIToken::kw_debug_instr_number) &&
1022 Token.isNot(MIToken::coloncolon) && Token.isNot(MIToken::lbrace)) {
1023 auto Loc = Token.location();
1024 Optional<unsigned> TiedDefIdx;
1025 if (parseMachineOperandAndTargetFlags(OpCode, Operands.size(), MO, TiedDefIdx))
1026 return true;
1027 Operands.push_back(
1028 ParsedMachineOperand(MO, Loc, Token.location(), TiedDefIdx));
1029 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
1030 Token.is(MIToken::lbrace))
1031 break;
1032 if (Token.isNot(MIToken::comma))
1033 return error("expected ',' before the next machine operand");
1034 lex();
1035 }
1036
1037 MCSymbol *PreInstrSymbol = nullptr;
1038 if (Token.is(MIToken::kw_pre_instr_symbol))
1039 if (parsePreOrPostInstrSymbol(PreInstrSymbol))
1040 return true;
1041 MCSymbol *PostInstrSymbol = nullptr;
1042 if (Token.is(MIToken::kw_post_instr_symbol))
1043 if (parsePreOrPostInstrSymbol(PostInstrSymbol))
1044 return true;
1045 MDNode *HeapAllocMarker = nullptr;
1046 if (Token.is(MIToken::kw_heap_alloc_marker))
1047 if (parseHeapAllocMarker(HeapAllocMarker))
1048 return true;
1049
1050 unsigned CFIType = 0;
1051 if (Token.is(MIToken::kw_cfi_type)) {
1052 lex();
1053 if (Token.isNot(MIToken::IntegerLiteral))
1054 return error("expected an integer literal after 'cfi-type'");
1055 // getUnsigned is sufficient for 32-bit integers.
1056 if (getUnsigned(CFIType))
1057 return true;
1058 lex();
1059 // Lex past trailing comma if present.
1060 if (Token.is(MIToken::comma))
1061 lex();
1062 }
1063
1064 unsigned InstrNum = 0;
1065 if (Token.is(MIToken::kw_debug_instr_number)) {
1066 lex();
1067 if (Token.isNot(MIToken::IntegerLiteral))
1068 return error("expected an integer literal after 'debug-instr-number'");
1069 if (getUnsigned(InstrNum))
1070 return true;
1071 lex();
1072 // Lex past trailing comma if present.
1073 if (Token.is(MIToken::comma))
1074 lex();
1075 }
1076
1077 DebugLoc DebugLocation;
1078 if (Token.is(MIToken::kw_debug_location)) {
1079 lex();
1080 MDNode *Node = nullptr;
1081 if (Token.is(MIToken::exclaim)) {
1082 if (parseMDNode(Node))
1083 return true;
1084 } else if (Token.is(MIToken::md_dilocation)) {
1085 if (parseDILocation(Node))
1086 return true;
1087 } else
1088 return error("expected a metadata node after 'debug-location'");
1089 if (!isa<DILocation>(Node))
1090 return error("referenced metadata is not a DILocation");
1091 DebugLocation = DebugLoc(Node);
1092 }
1093
1094 // Parse the machine memory operands.
1095 SmallVector<MachineMemOperand *, 2> MemOperands;
1096 if (Token.is(MIToken::coloncolon)) {
1097 lex();
1098 while (!Token.isNewlineOrEOF()) {
1099 MachineMemOperand *MemOp = nullptr;
1100 if (parseMachineMemoryOperand(MemOp))
1101 return true;
1102 MemOperands.push_back(MemOp);
1103 if (Token.isNewlineOrEOF())
1104 break;
1105 if (Token.isNot(MIToken::comma))
1106 return error("expected ',' before the next machine memory operand");
1107 lex();
1108 }
1109 }
1110
1111 const auto &MCID = MF.getSubtarget().getInstrInfo()->get(OpCode);
1112 if (!MCID.isVariadic()) {
1113 // FIXME: Move the implicit operand verification to the machine verifier.
1114 if (verifyImplicitOperands(Operands, MCID))
1115 return true;
1116 }
1117
1118 MI = MF.CreateMachineInstr(MCID, DebugLocation, /*NoImplicit=*/true);
1119 MI->setFlags(Flags);
1120
1121 unsigned NumExplicitOps = 0;
1122 for (const auto &Operand : Operands) {
1123 bool IsImplicitOp = Operand.Operand.isReg() && Operand.Operand.isImplicit();
1124 if (!IsImplicitOp) {
1125 if (!MCID.isVariadic() && NumExplicitOps >= MCID.getNumOperands() &&
1126 !Operand.Operand.isValidExcessOperand())
1127 return error(Operand.Begin, "too many operands for instruction");
1128
1129 ++NumExplicitOps;
1130 }
1131
1132 MI->addOperand(MF, Operand.Operand);
1133 }
1134
1135 if (assignRegisterTies(*MI, Operands))
1136 return true;
1137 if (PreInstrSymbol)
1138 MI->setPreInstrSymbol(MF, PreInstrSymbol);
1139 if (PostInstrSymbol)
1140 MI->setPostInstrSymbol(MF, PostInstrSymbol);
1141 if (HeapAllocMarker)
1142 MI->setHeapAllocMarker(MF, HeapAllocMarker);
1143 if (CFIType)
1144 MI->setCFIType(MF, CFIType);
1145 if (!MemOperands.empty())
1146 MI->setMemRefs(MF, MemOperands);
1147 if (InstrNum)
1148 MI->setDebugInstrNum(InstrNum);
1149 return false;
1150}
1151
1152bool MIParser::parseStandaloneMBB(MachineBasicBlock *&MBB) {
1153 lex();
1154 if (Token.isNot(MIToken::MachineBasicBlock))
1155 return error("expected a machine basic block reference");
1156 if (parseMBBReference(MBB))
1157 return true;
1158 lex();
1159 if (Token.isNot(MIToken::Eof))
1160 return error(
1161 "expected end of string after the machine basic block reference");
1162 return false;
1163}
1164
1165bool MIParser::parseStandaloneNamedRegister(Register &Reg) {
1166 lex();
1167 if (Token.isNot(MIToken::NamedRegister))
1168 return error("expected a named register");
1169 if (parseNamedRegister(Reg))
1170 return true;
1171 lex();
1172 if (Token.isNot(MIToken::Eof))
1173 return error("expected end of string after the register reference");
1174 return false;
1175}
1176
1177bool MIParser::parseStandaloneVirtualRegister(VRegInfo *&Info) {
1178 lex();
1179 if (Token.isNot(MIToken::VirtualRegister))
1180 return error("expected a virtual register");
1181 if (parseVirtualRegister(Info))
1182 return true;
1183 lex();
1184 if (Token.isNot(MIToken::Eof))
1185 return error("expected end of string after the register reference");
1186 return false;
1187}
1188
1189bool MIParser::parseStandaloneRegister(Register &Reg) {
1190 lex();
1191 if (Token.isNot(MIToken::NamedRegister) &&
1192 Token.isNot(MIToken::VirtualRegister))
1193 return error("expected either a named or virtual register");
1194
1195 VRegInfo *Info;
1196 if (parseRegister(Reg, Info))
1197 return true;
1198
1199 lex();
1200 if (Token.isNot(MIToken::Eof))
1201 return error("expected end of string after the register reference");
1202 return false;
1203}
1204
1205bool MIParser::parseStandaloneStackObject(int &FI) {
1206 lex();
1207 if (Token.isNot(MIToken::StackObject))
1208 return error("expected a stack object");
1209 if (parseStackFrameIndex(FI))
1210 return true;
1211 if (Token.isNot(MIToken::Eof))
1212 return error("expected end of string after the stack object reference");
1213 return false;
1214}
1215
1216bool MIParser::parseStandaloneMDNode(MDNode *&Node) {
1217 lex();
1218 if (Token.is(MIToken::exclaim)) {
1219 if (parseMDNode(Node))
1220 return true;
1221 } else if (Token.is(MIToken::md_diexpr)) {
1222 if (parseDIExpression(Node))
1223 return true;
1224 } else if (Token.is(MIToken::md_dilocation)) {
1225 if (parseDILocation(Node))
1226 return true;
1227 } else
1228 return error("expected a metadata node");
1229 if (Token.isNot(MIToken::Eof))
1230 return error("expected end of string after the metadata node");
1231 return false;
1232}
1233
1234bool MIParser::parseMachineMetadata() {
1235 lex();
1236 if (Token.isNot(MIToken::exclaim))
1237 return error("expected a metadata node");
1238
1239 lex();
1240 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
1241 return error("expected metadata id after '!'");
1242 unsigned ID = 0;
1243 if (getUnsigned(ID))
1244 return true;
1245 lex();
1246 if (expectAndConsume(MIToken::equal))
1247 return true;
1248 bool IsDistinct = Token.is(MIToken::kw_distinct);
1249 if (IsDistinct)
1250 lex();
1251 if (Token.isNot(MIToken::exclaim))
1252 return error("expected a metadata node");
1253 lex();
1254
1255 MDNode *MD;
1256 if (parseMDTuple(MD, IsDistinct))
1257 return true;
1258
1259 auto FI = PFS.MachineForwardRefMDNodes.find(ID);
1260 if (FI != PFS.MachineForwardRefMDNodes.end()) {
1261 FI->second.first->replaceAllUsesWith(MD);
1262 PFS.MachineForwardRefMDNodes.erase(FI);
1263
1264 assert(PFS.MachineMetadataNodes[ID] == MD && "Tracking VH didn't work")(static_cast <bool> (PFS.MachineMetadataNodes[ID] == MD
&& "Tracking VH didn't work") ? void (0) : __assert_fail
("PFS.MachineMetadataNodes[ID] == MD && \"Tracking VH didn't work\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1264, __extension__
__PRETTY_FUNCTION__))
;
1265 } else {
1266 if (PFS.MachineMetadataNodes.count(ID))
1267 return error("Metadata id is already used");
1268 PFS.MachineMetadataNodes[ID].reset(MD);
1269 }
1270
1271 return false;
1272}
1273
1274bool MIParser::parseMDTuple(MDNode *&MD, bool IsDistinct) {
1275 SmallVector<Metadata *, 16> Elts;
1276 if (parseMDNodeVector(Elts))
1277 return true;
1278 MD = (IsDistinct ? MDTuple::getDistinct
1279 : MDTuple::get)(MF.getFunction().getContext(), Elts);
1280 return false;
1281}
1282
1283bool MIParser::parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts) {
1284 if (Token.isNot(MIToken::lbrace))
1285 return error("expected '{' here");
1286 lex();
1287
1288 if (Token.is(MIToken::rbrace)) {
1289 lex();
1290 return false;
1291 }
1292
1293 do {
1294 Metadata *MD;
1295 if (parseMetadata(MD))
1296 return true;
1297
1298 Elts.push_back(MD);
1299
1300 if (Token.isNot(MIToken::comma))
1301 break;
1302 lex();
1303 } while (true);
1304
1305 if (Token.isNot(MIToken::rbrace))
1306 return error("expected end of metadata node");
1307 lex();
1308
1309 return false;
1310}
1311
1312// ::= !42
1313// ::= !"string"
1314bool MIParser::parseMetadata(Metadata *&MD) {
1315 if (Token.isNot(MIToken::exclaim))
1316 return error("expected '!' here");
1317 lex();
1318
1319 if (Token.is(MIToken::StringConstant)) {
1320 std::string Str;
1321 if (parseStringConstant(Str))
1322 return true;
1323 MD = MDString::get(MF.getFunction().getContext(), Str);
1324 return false;
1325 }
1326
1327 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
1328 return error("expected metadata id after '!'");
1329
1330 SMLoc Loc = mapSMLoc(Token.location());
1331
1332 unsigned ID = 0;
1333 if (getUnsigned(ID))
1334 return true;
1335 lex();
1336
1337 auto NodeInfo = PFS.IRSlots.MetadataNodes.find(ID);
1338 if (NodeInfo != PFS.IRSlots.MetadataNodes.end()) {
1339 MD = NodeInfo->second.get();
1340 return false;
1341 }
1342 // Check machine metadata.
1343 NodeInfo = PFS.MachineMetadataNodes.find(ID);
1344 if (NodeInfo != PFS.MachineMetadataNodes.end()) {
1345 MD = NodeInfo->second.get();
1346 return false;
1347 }
1348 // Forward reference.
1349 auto &FwdRef = PFS.MachineForwardRefMDNodes[ID];
1350 FwdRef = std::make_pair(
1351 MDTuple::getTemporary(MF.getFunction().getContext(), None), Loc);
1352 PFS.MachineMetadataNodes[ID].reset(FwdRef.first.get());
1353 MD = FwdRef.first.get();
1354
1355 return false;
1356}
1357
1358static const char *printImplicitRegisterFlag(const MachineOperand &MO) {
1359 assert(MO.isImplicit())(static_cast <bool> (MO.isImplicit()) ? void (0) : __assert_fail
("MO.isImplicit()", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1359, __extension__ __PRETTY_FUNCTION__))
;
1360 return MO.isDef() ? "implicit-def" : "implicit";
1361}
1362
1363static std::string getRegisterName(const TargetRegisterInfo *TRI,
1364 Register Reg) {
1365 assert(Register::isPhysicalRegister(Reg) && "expected phys reg")(static_cast <bool> (Register::isPhysicalRegister(Reg) &&
"expected phys reg") ? void (0) : __assert_fail ("Register::isPhysicalRegister(Reg) && \"expected phys reg\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1365, __extension__
__PRETTY_FUNCTION__))
;
1366 return StringRef(TRI->getName(Reg)).lower();
1367}
1368
1369/// Return true if the parsed machine operands contain a given machine operand.
1370static bool isImplicitOperandIn(const MachineOperand &ImplicitOperand,
1371 ArrayRef<ParsedMachineOperand> Operands) {
1372 for (const auto &I : Operands) {
1373 if (ImplicitOperand.isIdenticalTo(I.Operand))
1374 return true;
1375 }
1376 return false;
1377}
1378
1379bool MIParser::verifyImplicitOperands(ArrayRef<ParsedMachineOperand> Operands,
1380 const MCInstrDesc &MCID) {
1381 if (MCID.isCall())
1382 // We can't verify call instructions as they can contain arbitrary implicit
1383 // register and register mask operands.
1384 return false;
1385
1386 // Gather all the expected implicit operands.
1387 SmallVector<MachineOperand, 4> ImplicitOperands;
1388 if (MCID.ImplicitDefs)
1389 for (const MCPhysReg *ImpDefs = MCID.getImplicitDefs(); *ImpDefs; ++ImpDefs)
1390 ImplicitOperands.push_back(
1391 MachineOperand::CreateReg(*ImpDefs, true, true));
1392 if (MCID.ImplicitUses)
1393 for (const MCPhysReg *ImpUses = MCID.getImplicitUses(); *ImpUses; ++ImpUses)
1394 ImplicitOperands.push_back(
1395 MachineOperand::CreateReg(*ImpUses, false, true));
1396
1397 const auto *TRI = MF.getSubtarget().getRegisterInfo();
1398 assert(TRI && "Expected target register info")(static_cast <bool> (TRI && "Expected target register info"
) ? void (0) : __assert_fail ("TRI && \"Expected target register info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1398, __extension__
__PRETTY_FUNCTION__))
;
1399 for (const auto &I : ImplicitOperands) {
1400 if (isImplicitOperandIn(I, Operands))
1401 continue;
1402 return error(Operands.empty() ? Token.location() : Operands.back().End,
1403 Twine("missing implicit register operand '") +
1404 printImplicitRegisterFlag(I) + " $" +
1405 getRegisterName(TRI, I.getReg()) + "'");
1406 }
1407 return false;
1408}
1409
1410bool MIParser::parseInstruction(unsigned &OpCode, unsigned &Flags) {
1411 // Allow frame and fast math flags for OPCODE
1412 while (Token.is(MIToken::kw_frame_setup) ||
1413 Token.is(MIToken::kw_frame_destroy) ||
1414 Token.is(MIToken::kw_nnan) ||
1415 Token.is(MIToken::kw_ninf) ||
1416 Token.is(MIToken::kw_nsz) ||
1417 Token.is(MIToken::kw_arcp) ||
1418 Token.is(MIToken::kw_contract) ||
1419 Token.is(MIToken::kw_afn) ||
1420 Token.is(MIToken::kw_reassoc) ||
1421 Token.is(MIToken::kw_nuw) ||
1422 Token.is(MIToken::kw_nsw) ||
1423 Token.is(MIToken::kw_exact) ||
1424 Token.is(MIToken::kw_nofpexcept)) {
1425 // Mine frame and fast math flags
1426 if (Token.is(MIToken::kw_frame_setup))
1427 Flags |= MachineInstr::FrameSetup;
1428 if (Token.is(MIToken::kw_frame_destroy))
1429 Flags |= MachineInstr::FrameDestroy;
1430 if (Token.is(MIToken::kw_nnan))
1431 Flags |= MachineInstr::FmNoNans;
1432 if (Token.is(MIToken::kw_ninf))
1433 Flags |= MachineInstr::FmNoInfs;
1434 if (Token.is(MIToken::kw_nsz))
1435 Flags |= MachineInstr::FmNsz;
1436 if (Token.is(MIToken::kw_arcp))
1437 Flags |= MachineInstr::FmArcp;
1438 if (Token.is(MIToken::kw_contract))
1439 Flags |= MachineInstr::FmContract;
1440 if (Token.is(MIToken::kw_afn))
1441 Flags |= MachineInstr::FmAfn;
1442 if (Token.is(MIToken::kw_reassoc))
1443 Flags |= MachineInstr::FmReassoc;
1444 if (Token.is(MIToken::kw_nuw))
1445 Flags |= MachineInstr::NoUWrap;
1446 if (Token.is(MIToken::kw_nsw))
1447 Flags |= MachineInstr::NoSWrap;
1448 if (Token.is(MIToken::kw_exact))
1449 Flags |= MachineInstr::IsExact;
1450 if (Token.is(MIToken::kw_nofpexcept))
1451 Flags |= MachineInstr::NoFPExcept;
1452
1453 lex();
1454 }
1455 if (Token.isNot(MIToken::Identifier))
1456 return error("expected a machine instruction");
1457 StringRef InstrName = Token.stringValue();
1458 if (PFS.Target.parseInstrName(InstrName, OpCode))
1459 return error(Twine("unknown machine instruction name '") + InstrName + "'");
1460 lex();
1461 return false;
1462}
1463
1464bool MIParser::parseNamedRegister(Register &Reg) {
1465 assert(Token.is(MIToken::NamedRegister) && "Needs NamedRegister token")(static_cast <bool> (Token.is(MIToken::NamedRegister) &&
"Needs NamedRegister token") ? void (0) : __assert_fail ("Token.is(MIToken::NamedRegister) && \"Needs NamedRegister token\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1465, __extension__
__PRETTY_FUNCTION__))
;
1466 StringRef Name = Token.stringValue();
1467 if (PFS.Target.getRegisterByName(Name, Reg))
1468 return error(Twine("unknown register name '") + Name + "'");
1469 return false;
1470}
1471
1472bool MIParser::parseNamedVirtualRegister(VRegInfo *&Info) {
1473 assert(Token.is(MIToken::NamedVirtualRegister) && "Expected NamedVReg token")(static_cast <bool> (Token.is(MIToken::NamedVirtualRegister
) && "Expected NamedVReg token") ? void (0) : __assert_fail
("Token.is(MIToken::NamedVirtualRegister) && \"Expected NamedVReg token\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1473, __extension__
__PRETTY_FUNCTION__))
;
1474 StringRef Name = Token.stringValue();
1475 // TODO: Check that the VReg name is not the same as a physical register name.
1476 // If it is, then print a warning (when warnings are implemented).
1477 Info = &PFS.getVRegInfoNamed(Name);
1478 return false;
1479}
1480
1481bool MIParser::parseVirtualRegister(VRegInfo *&Info) {
1482 if (Token.is(MIToken::NamedVirtualRegister))
1483 return parseNamedVirtualRegister(Info);
1484 assert(Token.is(MIToken::VirtualRegister) && "Needs VirtualRegister token")(static_cast <bool> (Token.is(MIToken::VirtualRegister)
&& "Needs VirtualRegister token") ? void (0) : __assert_fail
("Token.is(MIToken::VirtualRegister) && \"Needs VirtualRegister token\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1484, __extension__
__PRETTY_FUNCTION__))
;
1485 unsigned ID;
1486 if (getUnsigned(ID))
1487 return true;
1488 Info = &PFS.getVRegInfo(ID);
1489 return false;
1490}
1491
1492bool MIParser::parseRegister(Register &Reg, VRegInfo *&Info) {
1493 switch (Token.kind()) {
1494 case MIToken::underscore:
1495 Reg = 0;
1496 return false;
1497 case MIToken::NamedRegister:
1498 return parseNamedRegister(Reg);
1499 case MIToken::NamedVirtualRegister:
1500 case MIToken::VirtualRegister:
1501 if (parseVirtualRegister(Info))
1502 return true;
1503 Reg = Info->VReg;
1504 return false;
1505 // TODO: Parse other register kinds.
1506 default:
1507 llvm_unreachable("The current token should be a register")::llvm::llvm_unreachable_internal("The current token should be a register"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1507)
;
1508 }
1509}
1510
1511bool MIParser::parseRegisterClassOrBank(VRegInfo &RegInfo) {
1512 if (Token.isNot(MIToken::Identifier) && Token.isNot(MIToken::underscore))
1513 return error("expected '_', register class, or register bank name");
1514 StringRef::iterator Loc = Token.location();
1515 StringRef Name = Token.stringValue();
1516
1517 // Was it a register class?
1518 const TargetRegisterClass *RC = PFS.Target.getRegClass(Name);
1519 if (RC) {
1520 lex();
1521
1522 switch (RegInfo.Kind) {
1523 case VRegInfo::UNKNOWN:
1524 case VRegInfo::NORMAL:
1525 RegInfo.Kind = VRegInfo::NORMAL;
1526 if (RegInfo.Explicit && RegInfo.D.RC != RC) {
1527 const TargetRegisterInfo &TRI = *MF.getSubtarget().getRegisterInfo();
1528 return error(Loc, Twine("conflicting register classes, previously: ") +
1529 Twine(TRI.getRegClassName(RegInfo.D.RC)));
1530 }
1531 RegInfo.D.RC = RC;
1532 RegInfo.Explicit = true;
1533 return false;
1534
1535 case VRegInfo::GENERIC:
1536 case VRegInfo::REGBANK:
1537 return error(Loc, "register class specification on generic register");
1538 }
1539 llvm_unreachable("Unexpected register kind")::llvm::llvm_unreachable_internal("Unexpected register kind",
"llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1539)
;
1540 }
1541
1542 // Should be a register bank or a generic register.
1543 const RegisterBank *RegBank = nullptr;
1544 if (Name != "_") {
1545 RegBank = PFS.Target.getRegBank(Name);
1546 if (!RegBank)
1547 return error(Loc, "expected '_', register class, or register bank name");
1548 }
1549
1550 lex();
1551
1552 switch (RegInfo.Kind) {
1553 case VRegInfo::UNKNOWN:
1554 case VRegInfo::GENERIC:
1555 case VRegInfo::REGBANK:
1556 RegInfo.Kind = RegBank ? VRegInfo::REGBANK : VRegInfo::GENERIC;
1557 if (RegInfo.Explicit && RegInfo.D.RegBank != RegBank)
1558 return error(Loc, "conflicting generic register banks");
1559 RegInfo.D.RegBank = RegBank;
1560 RegInfo.Explicit = true;
1561 return false;
1562
1563 case VRegInfo::NORMAL:
1564 return error(Loc, "register bank specification on normal register");
1565 }
1566 llvm_unreachable("Unexpected register kind")::llvm::llvm_unreachable_internal("Unexpected register kind",
"llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1566)
;
1567}
1568
1569bool MIParser::parseRegisterFlag(unsigned &Flags) {
1570 const unsigned OldFlags = Flags;
1571 switch (Token.kind()) {
1572 case MIToken::kw_implicit:
1573 Flags |= RegState::Implicit;
1574 break;
1575 case MIToken::kw_implicit_define:
1576 Flags |= RegState::ImplicitDefine;
1577 break;
1578 case MIToken::kw_def:
1579 Flags |= RegState::Define;
1580 break;
1581 case MIToken::kw_dead:
1582 Flags |= RegState::Dead;
1583 break;
1584 case MIToken::kw_killed:
1585 Flags |= RegState::Kill;
1586 break;
1587 case MIToken::kw_undef:
1588 Flags |= RegState::Undef;
1589 break;
1590 case MIToken::kw_internal:
1591 Flags |= RegState::InternalRead;
1592 break;
1593 case MIToken::kw_early_clobber:
1594 Flags |= RegState::EarlyClobber;
1595 break;
1596 case MIToken::kw_debug_use:
1597 Flags |= RegState::Debug;
1598 break;
1599 case MIToken::kw_renamable:
1600 Flags |= RegState::Renamable;
1601 break;
1602 default:
1603 llvm_unreachable("The current token should be a register flag")::llvm::llvm_unreachable_internal("The current token should be a register flag"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1603)
;
1604 }
1605 if (OldFlags == Flags)
1606 // We know that the same flag is specified more than once when the flags
1607 // weren't modified.
1608 return error("duplicate '" + Token.stringValue() + "' register flag");
1609 lex();
1610 return false;
1611}
1612
1613bool MIParser::parseSubRegisterIndex(unsigned &SubReg) {
1614 assert(Token.is(MIToken::dot))(static_cast <bool> (Token.is(MIToken::dot)) ? void (0)
: __assert_fail ("Token.is(MIToken::dot)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1614, __extension__ __PRETTY_FUNCTION__))
;
1615 lex();
1616 if (Token.isNot(MIToken::Identifier))
1617 return error("expected a subregister index after '.'");
1618 auto Name = Token.stringValue();
1619 SubReg = PFS.Target.getSubRegIndex(Name);
1620 if (!SubReg)
1621 return error(Twine("use of unknown subregister index '") + Name + "'");
1622 lex();
1623 return false;
1624}
1625
1626bool MIParser::parseRegisterTiedDefIndex(unsigned &TiedDefIdx) {
1627 if (!consumeIfPresent(MIToken::kw_tied_def))
1628 return true;
1629 if (Token.isNot(MIToken::IntegerLiteral))
1630 return error("expected an integer literal after 'tied-def'");
1631 if (getUnsigned(TiedDefIdx))
1632 return true;
1633 lex();
1634 if (expectAndConsume(MIToken::rparen))
1635 return true;
1636 return false;
1637}
1638
1639bool MIParser::assignRegisterTies(MachineInstr &MI,
1640 ArrayRef<ParsedMachineOperand> Operands) {
1641 SmallVector<std::pair<unsigned, unsigned>, 4> TiedRegisterPairs;
1642 for (unsigned I = 0, E = Operands.size(); I != E; ++I) {
1643 if (!Operands[I].TiedDefIdx)
1644 continue;
1645 // The parser ensures that this operand is a register use, so we just have
1646 // to check the tied-def operand.
1647 unsigned DefIdx = *Operands[I].TiedDefIdx;
1648 if (DefIdx >= E)
1649 return error(Operands[I].Begin,
1650 Twine("use of invalid tied-def operand index '" +
1651 Twine(DefIdx) + "'; instruction has only ") +
1652 Twine(E) + " operands");
1653 const auto &DefOperand = Operands[DefIdx].Operand;
1654 if (!DefOperand.isReg() || !DefOperand.isDef())
1655 // FIXME: add note with the def operand.
1656 return error(Operands[I].Begin,
1657 Twine("use of invalid tied-def operand index '") +
1658 Twine(DefIdx) + "'; the operand #" + Twine(DefIdx) +
1659 " isn't a defined register");
1660 // Check that the tied-def operand wasn't tied elsewhere.
1661 for (const auto &TiedPair : TiedRegisterPairs) {
1662 if (TiedPair.first == DefIdx)
1663 return error(Operands[I].Begin,
1664 Twine("the tied-def operand #") + Twine(DefIdx) +
1665 " is already tied with another register operand");
1666 }
1667 TiedRegisterPairs.push_back(std::make_pair(DefIdx, I));
1668 }
1669 // FIXME: Verify that for non INLINEASM instructions, the def and use tied
1670 // indices must be less than tied max.
1671 for (const auto &TiedPair : TiedRegisterPairs)
1672 MI.tieOperands(TiedPair.first, TiedPair.second);
1673 return false;
1674}
1675
1676bool MIParser::parseRegisterOperand(MachineOperand &Dest,
1677 Optional<unsigned> &TiedDefIdx,
1678 bool IsDef) {
1679 unsigned Flags = IsDef ? RegState::Define : 0;
1680 while (Token.isRegisterFlag()) {
1681 if (parseRegisterFlag(Flags))
1682 return true;
1683 }
1684 if (!Token.isRegister())
1685 return error("expected a register after register flags");
1686 Register Reg;
1687 VRegInfo *RegInfo;
1688 if (parseRegister(Reg, RegInfo))
1689 return true;
1690 lex();
1691 unsigned SubReg = 0;
1692 if (Token.is(MIToken::dot)) {
1693 if (parseSubRegisterIndex(SubReg))
1694 return true;
1695 if (!Register::isVirtualRegister(Reg))
1696 return error("subregister index expects a virtual register");
1697 }
1698 if (Token.is(MIToken::colon)) {
1699 if (!Register::isVirtualRegister(Reg))
1700 return error("register class specification expects a virtual register");
1701 lex();
1702 if (parseRegisterClassOrBank(*RegInfo))
1703 return true;
1704 }
1705 MachineRegisterInfo &MRI = MF.getRegInfo();
1706 if ((Flags & RegState::Define) == 0) {
1707 if (consumeIfPresent(MIToken::lparen)) {
1708 unsigned Idx;
1709 if (!parseRegisterTiedDefIndex(Idx))
1710 TiedDefIdx = Idx;
1711 else {
1712 // Try a redundant low-level type.
1713 LLT Ty;
1714 if (parseLowLevelType(Token.location(), Ty))
1715 return error("expected tied-def or low-level type after '('");
1716
1717 if (expectAndConsume(MIToken::rparen))
1718 return true;
1719
1720 if (MRI.getType(Reg).isValid() && MRI.getType(Reg) != Ty)
1721 return error("inconsistent type for generic virtual register");
1722
1723 MRI.setRegClassOrRegBank(Reg, static_cast<RegisterBank *>(nullptr));
1724 MRI.setType(Reg, Ty);
1725 }
1726 }
1727 } else if (consumeIfPresent(MIToken::lparen)) {
1728 // Virtual registers may have a tpe with GlobalISel.
1729 if (!Register::isVirtualRegister(Reg))
1730 return error("unexpected type on physical register");
1731
1732 LLT Ty;
1733 if (parseLowLevelType(Token.location(), Ty))
1734 return true;
1735
1736 if (expectAndConsume(MIToken::rparen))
1737 return true;
1738
1739 if (MRI.getType(Reg).isValid() && MRI.getType(Reg) != Ty)
1740 return error("inconsistent type for generic virtual register");
1741
1742 MRI.setRegClassOrRegBank(Reg, static_cast<RegisterBank *>(nullptr));
1743 MRI.setType(Reg, Ty);
1744 } else if (Register::isVirtualRegister(Reg)) {
1745 // Generic virtual registers must have a type.
1746 // If we end up here this means the type hasn't been specified and
1747 // this is bad!
1748 if (RegInfo->Kind == VRegInfo::GENERIC ||
1749 RegInfo->Kind == VRegInfo::REGBANK)
1750 return error("generic virtual registers must have a type");
1751 }
1752
1753 if (Flags & RegState::Define) {
1754 if (Flags & RegState::Kill)
1755 return error("cannot have a killed def operand");
1756 } else {
1757 if (Flags & RegState::Dead)
1758 return error("cannot have a dead use operand");
1759 }
1760
1761 Dest = MachineOperand::CreateReg(
1762 Reg, Flags & RegState::Define, Flags & RegState::Implicit,
1763 Flags & RegState::Kill, Flags & RegState::Dead, Flags & RegState::Undef,
1764 Flags & RegState::EarlyClobber, SubReg, Flags & RegState::Debug,
1765 Flags & RegState::InternalRead, Flags & RegState::Renamable);
1766
1767 return false;
1768}
1769
1770bool MIParser::parseImmediateOperand(MachineOperand &Dest) {
1771 assert(Token.is(MIToken::IntegerLiteral))(static_cast <bool> (Token.is(MIToken::IntegerLiteral))
? void (0) : __assert_fail ("Token.is(MIToken::IntegerLiteral)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1771, __extension__
__PRETTY_FUNCTION__))
;
1772 const APSInt &Int = Token.integerValue();
1773 if (Int.getMinSignedBits() > 64)
1774 return error("integer literal is too large to be an immediate operand");
1775 Dest = MachineOperand::CreateImm(Int.getExtValue());
1776 lex();
1777 return false;
1778}
1779
1780bool MIParser::parseTargetImmMnemonic(const unsigned OpCode,
1781 const unsigned OpIdx,
1782 MachineOperand &Dest,
1783 const MIRFormatter &MF) {
1784 assert(Token.is(MIToken::dot))(static_cast <bool> (Token.is(MIToken::dot)) ? void (0)
: __assert_fail ("Token.is(MIToken::dot)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1784, __extension__ __PRETTY_FUNCTION__))
;
1785 auto Loc = Token.location(); // record start position
1786 size_t Len = 1; // for "."
1787 lex();
1788
1789 // Handle the case that mnemonic starts with number.
1790 if (Token.is(MIToken::IntegerLiteral)) {
1791 Len += Token.range().size();
1792 lex();
1793 }
1794
1795 StringRef Src;
1796 if (Token.is(MIToken::comma))
1797 Src = StringRef(Loc, Len);
1798 else {
1799 assert(Token.is(MIToken::Identifier))(static_cast <bool> (Token.is(MIToken::Identifier)) ? void
(0) : __assert_fail ("Token.is(MIToken::Identifier)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1799, __extension__ __PRETTY_FUNCTION__))
;
1800 Src = StringRef(Loc, Len + Token.stringValue().size());
1801 }
1802 int64_t Val;
1803 if (MF.parseImmMnemonic(OpCode, OpIdx, Src, Val,
1804 [this](StringRef::iterator Loc, const Twine &Msg)
1805 -> bool { return error(Loc, Msg); }))
1806 return true;
1807
1808 Dest = MachineOperand::CreateImm(Val);
1809 if (!Token.is(MIToken::comma))
1810 lex();
1811 return false;
1812}
1813
1814static bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
1815 PerFunctionMIParsingState &PFS, const Constant *&C,
1816 ErrorCallbackType ErrCB) {
1817 auto Source = StringValue.str(); // The source has to be null terminated.
1818 SMDiagnostic Err;
1819 C = parseConstantValue(Source, Err, *PFS.MF.getFunction().getParent(),
1820 &PFS.IRSlots);
1821 if (!C)
1822 return ErrCB(Loc + Err.getColumnNo(), Err.getMessage());
1823 return false;
1824}
1825
1826bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
1827 const Constant *&C) {
1828 return ::parseIRConstant(
1829 Loc, StringValue, PFS, C,
1830 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
1831 return error(Loc, Msg);
1832 });
1833}
1834
1835bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {
1836 if (parseIRConstant(Loc, StringRef(Loc, Token.range().end() - Loc), C))
1837 return true;
1838 lex();
1839 return false;
1840}
1841
1842// See LLT implemntation for bit size limits.
1843static bool verifyScalarSize(uint64_t Size) {
1844 return Size != 0 && isUInt<16>(Size);
1845}
1846
1847static bool verifyVectorElementCount(uint64_t NumElts) {
1848 return NumElts != 0 && isUInt<16>(NumElts);
1849}
1850
1851static bool verifyAddrSpace(uint64_t AddrSpace) {
1852 return isUInt<24>(AddrSpace);
1853}
1854
1855bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {
1856 if (Token.range().front() == 's' || Token.range().front() == 'p') {
1857 StringRef SizeStr = Token.range().drop_front();
1858 if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
1859 return error("expected integers after 's'/'p' type character");
1860 }
1861
1862 if (Token.range().front() == 's') {
1863 auto ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
1864 if (!verifyScalarSize(ScalarSize))
1865 return error("invalid size for scalar type");
1866
1867 Ty = LLT::scalar(ScalarSize);
1868 lex();
1869 return false;
1870 } else if (Token.range().front() == 'p') {
1871 const DataLayout &DL = MF.getDataLayout();
1872 uint64_t AS = APSInt(Token.range().drop_front()).getZExtValue();
1873 if (!verifyAddrSpace(AS))
1874 return error("invalid address space number");
1875
1876 Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
1877 lex();
1878 return false;
1879 }
1880
1881 // Now we're looking for a vector.
1882 if (Token.isNot(MIToken::less))
1883 return error(Loc,
1884 "expected sN, pA, <M x sN>, or <M x pA> for GlobalISel type");
1885 lex();
1886
1887 if (Token.isNot(MIToken::IntegerLiteral))
1888 return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1889 uint64_t NumElements = Token.integerValue().getZExtValue();
1890 if (!verifyVectorElementCount(NumElements))
1891 return error("invalid number of vector elements");
1892
1893 lex();
1894
1895 if (Token.isNot(MIToken::Identifier) || Token.stringValue() != "x")
1896 return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1897 lex();
1898
1899 if (Token.range().front() != 's' && Token.range().front() != 'p')
1900 return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1901 StringRef SizeStr = Token.range().drop_front();
1902 if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
1903 return error("expected integers after 's'/'p' type character");
1904
1905 if (Token.range().front() == 's') {
1906 auto ScalarSize = APSInt(Token.range().drop_front()).getZExtValue();
1907 if (!verifyScalarSize(ScalarSize))
1908 return error("invalid size for scalar type");
1909 Ty = LLT::scalar(ScalarSize);
1910 } else if (Token.range().front() == 'p') {
1911 const DataLayout &DL = MF.getDataLayout();
1912 uint64_t AS = APSInt(Token.range().drop_front()).getZExtValue();
1913 if (!verifyAddrSpace(AS))
1914 return error("invalid address space number");
1915
1916 Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
1917 } else
1918 return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1919 lex();
1920
1921 if (Token.isNot(MIToken::greater))
1922 return error(Loc, "expected <M x sN> or <M x pA> for vector type");
1923 lex();
1924
1925 Ty = LLT::fixed_vector(NumElements, Ty);
1926 return false;
1927}
1928
1929bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {
1930 assert(Token.is(MIToken::Identifier))(static_cast <bool> (Token.is(MIToken::Identifier)) ? void
(0) : __assert_fail ("Token.is(MIToken::Identifier)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1930, __extension__ __PRETTY_FUNCTION__))
;
1931 StringRef TypeStr = Token.range();
1932 if (TypeStr.front() != 'i' && TypeStr.front() != 's' &&
1933 TypeStr.front() != 'p')
1934 return error(
1935 "a typed immediate operand should start with one of 'i', 's', or 'p'");
1936 StringRef SizeStr = Token.range().drop_front();
1937 if (SizeStr.size() == 0 || !llvm::all_of(SizeStr, isdigit))
1938 return error("expected integers after 'i'/'s'/'p' type character");
1939
1940 auto Loc = Token.location();
1941 lex();
1942 if (Token.isNot(MIToken::IntegerLiteral)) {
1943 if (Token.isNot(MIToken::Identifier) ||
1944 !(Token.range() == "true" || Token.range() == "false"))
1945 return error("expected an integer literal");
1946 }
1947 const Constant *C = nullptr;
1948 if (parseIRConstant(Loc, C))
1949 return true;
1950 Dest = MachineOperand::CreateCImm(cast<ConstantInt>(C));
1951 return false;
1952}
1953
1954bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {
1955 auto Loc = Token.location();
1956 lex();
1957 if (Token.isNot(MIToken::FloatingPointLiteral) &&
1958 Token.isNot(MIToken::HexLiteral))
1959 return error("expected a floating point literal");
1960 const Constant *C = nullptr;
1961 if (parseIRConstant(Loc, C))
1962 return true;
1963 Dest = MachineOperand::CreateFPImm(cast<ConstantFP>(C));
1964 return false;
1965}
1966
1967static bool getHexUint(const MIToken &Token, APInt &Result) {
1968 assert(Token.is(MIToken::HexLiteral))(static_cast <bool> (Token.is(MIToken::HexLiteral)) ? void
(0) : __assert_fail ("Token.is(MIToken::HexLiteral)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 1968, __extension__ __PRETTY_FUNCTION__))
;
1969 StringRef S = Token.range();
1970 assert(S[0] == '0' && tolower(S[1]) == 'x')(static_cast <bool> (S[0] == '0' && tolower(S[1
]) == 'x') ? void (0) : __assert_fail ("S[0] == '0' && tolower(S[1]) == 'x'"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 1970, __extension__
__PRETTY_FUNCTION__))
;
1971 // This could be a floating point literal with a special prefix.
1972 if (!isxdigit(S[2]))
1973 return true;
1974 StringRef V = S.substr(2);
1975 APInt A(V.size()*4, V, 16);
1976
1977 // If A is 0, then A.getActiveBits() is 0. This isn't a valid bitwidth. Make
1978 // sure it isn't the case before constructing result.
1979 unsigned NumBits = (A == 0) ? 32 : A.getActiveBits();
1980 Result = APInt(NumBits, ArrayRef<uint64_t>(A.getRawData(), A.getNumWords()));
1981 return false;
1982}
1983
1984static bool getUnsigned(const MIToken &Token, unsigned &Result,
1985 ErrorCallbackType ErrCB) {
1986 if (Token.hasIntegerValue()) {
7
Taking true branch
1987 const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1;
1988 uint64_t Val64 = Token.integerValue().getLimitedValue(Limit);
1989 if (Val64
7.1
'Val64' is equal to 'Limit'
== Limit)
8
Taking true branch
1990 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
9
Returning without writing to 'Result'
1991 Result = Val64;
1992 return false;
1993 }
1994 if (Token.is(MIToken::HexLiteral)) {
1995 APInt A;
1996 if (getHexUint(Token, A))
1997 return true;
1998 if (A.getBitWidth() > 32)
1999 return ErrCB(Token.location(), "expected 32-bit integer (too large)");
2000 Result = A.getZExtValue();
2001 return false;
2002 }
2003 return true;
2004}
2005
2006bool MIParser::getUnsigned(unsigned &Result) {
2007 return ::getUnsigned(
2008 Token, Result, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2009 return error(Loc, Msg);
2010 });
2011}
2012
2013bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {
2014 assert(Token.is(MIToken::MachineBasicBlock) ||(static_cast <bool> (Token.is(MIToken::MachineBasicBlock
) || Token.is(MIToken::MachineBasicBlockLabel)) ? void (0) : __assert_fail
("Token.is(MIToken::MachineBasicBlock) || Token.is(MIToken::MachineBasicBlockLabel)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2015, __extension__
__PRETTY_FUNCTION__))
2015 Token.is(MIToken::MachineBasicBlockLabel))(static_cast <bool> (Token.is(MIToken::MachineBasicBlock
) || Token.is(MIToken::MachineBasicBlockLabel)) ? void (0) : __assert_fail
("Token.is(MIToken::MachineBasicBlock) || Token.is(MIToken::MachineBasicBlockLabel)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2015, __extension__
__PRETTY_FUNCTION__))
;
2016 unsigned Number;
2017 if (getUnsigned(Number))
2018 return true;
2019 auto MBBInfo = PFS.MBBSlots.find(Number);
2020 if (MBBInfo == PFS.MBBSlots.end())
2021 return error(Twine("use of undefined machine basic block #") +
2022 Twine(Number));
2023 MBB = MBBInfo->second;
2024 // TODO: Only parse the name if it's a MachineBasicBlockLabel. Deprecate once
2025 // we drop the <irname> from the bb.<id>.<irname> format.
2026 if (!Token.stringValue().empty() && Token.stringValue() != MBB->getName())
2027 return error(Twine("the name of machine basic block #") + Twine(Number) +
2028 " isn't '" + Token.stringValue() + "'");
2029 return false;
2030}
2031
2032bool MIParser::parseMBBOperand(MachineOperand &Dest) {
2033 MachineBasicBlock *MBB;
2034 if (parseMBBReference(MBB))
2035 return true;
2036 Dest = MachineOperand::CreateMBB(MBB);
2037 lex();
2038 return false;
2039}
2040
2041bool MIParser::parseStackFrameIndex(int &FI) {
2042 assert(Token.is(MIToken::StackObject))(static_cast <bool> (Token.is(MIToken::StackObject)) ? void
(0) : __assert_fail ("Token.is(MIToken::StackObject)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 2042, __extension__ __PRETTY_FUNCTION__))
;
2043 unsigned ID;
2044 if (getUnsigned(ID))
2045 return true;
2046 auto ObjectInfo = PFS.StackObjectSlots.find(ID);
2047 if (ObjectInfo == PFS.StackObjectSlots.end())
2048 return error(Twine("use of undefined stack object '%stack.") + Twine(ID) +
2049 "'");
2050 StringRef Name;
2051 if (const auto *Alloca =
2052 MF.getFrameInfo().getObjectAllocation(ObjectInfo->second))
2053 Name = Alloca->getName();
2054 if (!Token.stringValue().empty() && Token.stringValue() != Name)
2055 return error(Twine("the name of the stack object '%stack.") + Twine(ID) +
2056 "' isn't '" + Token.stringValue() + "'");
2057 lex();
2058 FI = ObjectInfo->second;
2059 return false;
2060}
2061
2062bool MIParser::parseStackObjectOperand(MachineOperand &Dest) {
2063 int FI;
2064 if (parseStackFrameIndex(FI))
2065 return true;
2066 Dest = MachineOperand::CreateFI(FI);
2067 return false;
2068}
2069
2070bool MIParser::parseFixedStackFrameIndex(int &FI) {
2071 assert(Token.is(MIToken::FixedStackObject))(static_cast <bool> (Token.is(MIToken::FixedStackObject
)) ? void (0) : __assert_fail ("Token.is(MIToken::FixedStackObject)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2071, __extension__
__PRETTY_FUNCTION__))
;
2072 unsigned ID;
2073 if (getUnsigned(ID))
2074 return true;
2075 auto ObjectInfo = PFS.FixedStackObjectSlots.find(ID);
2076 if (ObjectInfo == PFS.FixedStackObjectSlots.end())
2077 return error(Twine("use of undefined fixed stack object '%fixed-stack.") +
2078 Twine(ID) + "'");
2079 lex();
2080 FI = ObjectInfo->second;
2081 return false;
2082}
2083
2084bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {
2085 int FI;
2086 if (parseFixedStackFrameIndex(FI))
2087 return true;
2088 Dest = MachineOperand::CreateFI(FI);
2089 return false;
2090}
2091
2092static bool parseGlobalValue(const MIToken &Token,
2093 PerFunctionMIParsingState &PFS, GlobalValue *&GV,
2094 ErrorCallbackType ErrCB) {
2095 switch (Token.kind()) {
4
Control jumps to 'case GlobalValue:' at line 2104
2096 case MIToken::NamedGlobalValue: {
2097 const Module *M = PFS.MF.getFunction().getParent();
2098 GV = M->getNamedValue(Token.stringValue());
2099 if (!GV)
2100 return ErrCB(Token.location(), Twine("use of undefined global value '") +
2101 Token.range() + "'");
2102 break;
2103 }
2104 case MIToken::GlobalValue: {
2105 unsigned GVIdx;
5
'GVIdx' declared without an initial value
2106 if (getUnsigned(Token, GVIdx, ErrCB))
6
Calling 'getUnsigned'
10
Returning from 'getUnsigned'
11
Assuming the condition is false
12
Taking false branch
2107 return true;
2108 if (GVIdx >= PFS.IRSlots.GlobalValues.size())
13
The left operand of '>=' is a garbage value
2109 return ErrCB(Token.location(), Twine("use of undefined global value '@") +
2110 Twine(GVIdx) + "'");
2111 GV = PFS.IRSlots.GlobalValues[GVIdx];
2112 break;
2113 }
2114 default:
2115 llvm_unreachable("The current token should be a global value")::llvm::llvm_unreachable_internal("The current token should be a global value"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2115)
;
2116 }
2117 return false;
2118}
2119
2120bool MIParser::parseGlobalValue(GlobalValue *&GV) {
2121 return ::parseGlobalValue(
2122 Token, PFS, GV,
2123 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
2124 return error(Loc, Msg);
2125 });
2126}
2127
2128bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {
2129 GlobalValue *GV = nullptr;
2130 if (parseGlobalValue(GV))
2131 return true;
2132 lex();
2133 Dest = MachineOperand::CreateGA(GV, /*Offset=*/0);
2134 if (parseOperandsOffset(Dest))
2135 return true;
2136 return false;
2137}
2138
2139bool MIParser::parseConstantPoolIndexOperand(MachineOperand &Dest) {
2140 assert(Token.is(MIToken::ConstantPoolItem))(static_cast <bool> (Token.is(MIToken::ConstantPoolItem
)) ? void (0) : __assert_fail ("Token.is(MIToken::ConstantPoolItem)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2140, __extension__
__PRETTY_FUNCTION__))
;
2141 unsigned ID;
2142 if (getUnsigned(ID))
2143 return true;
2144 auto ConstantInfo = PFS.ConstantPoolSlots.find(ID);
2145 if (ConstantInfo == PFS.ConstantPoolSlots.end())
2146 return error("use of undefined constant '%const." + Twine(ID) + "'");
2147 lex();
2148 Dest = MachineOperand::CreateCPI(ID, /*Offset=*/0);
2149 if (parseOperandsOffset(Dest))
2150 return true;
2151 return false;
2152}
2153
2154bool MIParser::parseJumpTableIndexOperand(MachineOperand &Dest) {
2155 assert(Token.is(MIToken::JumpTableIndex))(static_cast <bool> (Token.is(MIToken::JumpTableIndex))
? void (0) : __assert_fail ("Token.is(MIToken::JumpTableIndex)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2155, __extension__
__PRETTY_FUNCTION__))
;
2156 unsigned ID;
2157 if (getUnsigned(ID))
2158 return true;
2159 auto JumpTableEntryInfo = PFS.JumpTableSlots.find(ID);
2160 if (JumpTableEntryInfo == PFS.JumpTableSlots.end())
2161 return error("use of undefined jump table '%jump-table." + Twine(ID) + "'");
2162 lex();
2163 Dest = MachineOperand::CreateJTI(JumpTableEntryInfo->second);
2164 return false;
2165}
2166
2167bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) {
2168 assert(Token.is(MIToken::ExternalSymbol))(static_cast <bool> (Token.is(MIToken::ExternalSymbol))
? void (0) : __assert_fail ("Token.is(MIToken::ExternalSymbol)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2168, __extension__
__PRETTY_FUNCTION__))
;
2169 const char *Symbol = MF.createExternalSymbolName(Token.stringValue());
2170 lex();
2171 Dest = MachineOperand::CreateES(Symbol);
2172 if (parseOperandsOffset(Dest))
2173 return true;
2174 return false;
2175}
2176
2177bool MIParser::parseMCSymbolOperand(MachineOperand &Dest) {
2178 assert(Token.is(MIToken::MCSymbol))(static_cast <bool> (Token.is(MIToken::MCSymbol)) ? void
(0) : __assert_fail ("Token.is(MIToken::MCSymbol)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 2178, __extension__ __PRETTY_FUNCTION__))
;
2179 MCSymbol *Symbol = getOrCreateMCSymbol(Token.stringValue());
2180 lex();
2181 Dest = MachineOperand::CreateMCSymbol(Symbol);
2182 if (parseOperandsOffset(Dest))
2183 return true;
2184 return false;
2185}
2186
2187bool MIParser::parseSubRegisterIndexOperand(MachineOperand &Dest) {
2188 assert(Token.is(MIToken::SubRegisterIndex))(static_cast <bool> (Token.is(MIToken::SubRegisterIndex
)) ? void (0) : __assert_fail ("Token.is(MIToken::SubRegisterIndex)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2188, __extension__
__PRETTY_FUNCTION__))
;
2189 StringRef Name = Token.stringValue();
2190 unsigned SubRegIndex = PFS.Target.getSubRegIndex(Token.stringValue());
2191 if (SubRegIndex == 0)
2192 return error(Twine("unknown subregister index '") + Name + "'");
2193 lex();
2194 Dest = MachineOperand::CreateImm(SubRegIndex);
2195 return false;
2196}
2197
2198bool MIParser::parseMDNode(MDNode *&Node) {
2199 assert(Token.is(MIToken::exclaim))(static_cast <bool> (Token.is(MIToken::exclaim)) ? void
(0) : __assert_fail ("Token.is(MIToken::exclaim)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 2199, __extension__ __PRETTY_FUNCTION__))
;
2200
2201 auto Loc = Token.location();
2202 lex();
2203 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
2204 return error("expected metadata id after '!'");
2205 unsigned ID;
2206 if (getUnsigned(ID))
2207 return true;
2208 auto NodeInfo = PFS.IRSlots.MetadataNodes.find(ID);
2209 if (NodeInfo == PFS.IRSlots.MetadataNodes.end()) {
2210 NodeInfo = PFS.MachineMetadataNodes.find(ID);
2211 if (NodeInfo == PFS.MachineMetadataNodes.end())
2212 return error(Loc, "use of undefined metadata '!" + Twine(ID) + "'");
2213 }
2214 lex();
2215 Node = NodeInfo->second.get();
2216 return false;
2217}
2218
2219bool MIParser::parseDIExpression(MDNode *&Expr) {
2220 assert(Token.is(MIToken::md_diexpr))(static_cast <bool> (Token.is(MIToken::md_diexpr)) ? void
(0) : __assert_fail ("Token.is(MIToken::md_diexpr)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 2220, __extension__ __PRETTY_FUNCTION__))
;
2221 lex();
2222
2223 // FIXME: Share this parsing with the IL parser.
2224 SmallVector<uint64_t, 8> Elements;
2225
2226 if (expectAndConsume(MIToken::lparen))
2227 return true;
2228
2229 if (Token.isNot(MIToken::rparen)) {
2230 do {
2231 if (Token.is(MIToken::Identifier)) {
2232 if (unsigned Op = dwarf::getOperationEncoding(Token.stringValue())) {
2233 lex();
2234 Elements.push_back(Op);
2235 continue;
2236 }
2237 if (unsigned Enc = dwarf::getAttributeEncoding(Token.stringValue())) {
2238 lex();
2239 Elements.push_back(Enc);
2240 continue;
2241 }
2242 return error(Twine("invalid DWARF op '") + Token.stringValue() + "'");
2243 }
2244
2245 if (Token.isNot(MIToken::IntegerLiteral) ||
2246 Token.integerValue().isSigned())
2247 return error("expected unsigned integer");
2248
2249 auto &U = Token.integerValue();
2250 if (U.ugt(UINT64_MAX(18446744073709551615UL)))
2251 return error("element too large, limit is " + Twine(UINT64_MAX(18446744073709551615UL)));
2252 Elements.push_back(U.getZExtValue());
2253 lex();
2254
2255 } while (consumeIfPresent(MIToken::comma));
2256 }
2257
2258 if (expectAndConsume(MIToken::rparen))
2259 return true;
2260
2261 Expr = DIExpression::get(MF.getFunction().getContext(), Elements);
2262 return false;
2263}
2264
2265bool MIParser::parseDILocation(MDNode *&Loc) {
2266 assert(Token.is(MIToken::md_dilocation))(static_cast <bool> (Token.is(MIToken::md_dilocation)) ?
void (0) : __assert_fail ("Token.is(MIToken::md_dilocation)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2266, __extension__
__PRETTY_FUNCTION__))
;
2267 lex();
2268
2269 bool HaveLine = false;
2270 unsigned Line = 0;
2271 unsigned Column = 0;
2272 MDNode *Scope = nullptr;
2273 MDNode *InlinedAt = nullptr;
2274 bool ImplicitCode = false;
2275
2276 if (expectAndConsume(MIToken::lparen))
2277 return true;
2278
2279 if (Token.isNot(MIToken::rparen)) {
2280 do {
2281 if (Token.is(MIToken::Identifier)) {
2282 if (Token.stringValue() == "line") {
2283 lex();
2284 if (expectAndConsume(MIToken::colon))
2285 return true;
2286 if (Token.isNot(MIToken::IntegerLiteral) ||
2287 Token.integerValue().isSigned())
2288 return error("expected unsigned integer");
2289 Line = Token.integerValue().getZExtValue();
2290 HaveLine = true;
2291 lex();
2292 continue;
2293 }
2294 if (Token.stringValue() == "column") {
2295 lex();
2296 if (expectAndConsume(MIToken::colon))
2297 return true;
2298 if (Token.isNot(MIToken::IntegerLiteral) ||
2299 Token.integerValue().isSigned())
2300 return error("expected unsigned integer");
2301 Column = Token.integerValue().getZExtValue();
2302 lex();
2303 continue;
2304 }
2305 if (Token.stringValue() == "scope") {
2306 lex();
2307 if (expectAndConsume(MIToken::colon))
2308 return true;
2309 if (parseMDNode(Scope))
2310 return error("expected metadata node");
2311 if (!isa<DIScope>(Scope))
2312 return error("expected DIScope node");
2313 continue;
2314 }
2315 if (Token.stringValue() == "inlinedAt") {
2316 lex();
2317 if (expectAndConsume(MIToken::colon))
2318 return true;
2319 if (Token.is(MIToken::exclaim)) {
2320 if (parseMDNode(InlinedAt))
2321 return true;
2322 } else if (Token.is(MIToken::md_dilocation)) {
2323 if (parseDILocation(InlinedAt))
2324 return true;
2325 } else
2326 return error("expected metadata node");
2327 if (!isa<DILocation>(InlinedAt))
2328 return error("expected DILocation node");
2329 continue;
2330 }
2331 if (Token.stringValue() == "isImplicitCode") {
2332 lex();
2333 if (expectAndConsume(MIToken::colon))
2334 return true;
2335 if (!Token.is(MIToken::Identifier))
2336 return error("expected true/false");
2337 // As far as I can see, we don't have any existing need for parsing
2338 // true/false in MIR yet. Do it ad-hoc until there's something else
2339 // that needs it.
2340 if (Token.stringValue() == "true")
2341 ImplicitCode = true;
2342 else if (Token.stringValue() == "false")
2343 ImplicitCode = false;
2344 else
2345 return error("expected true/false");
2346 lex();
2347 continue;
2348 }
2349 }
2350 return error(Twine("invalid DILocation argument '") +
2351 Token.stringValue() + "'");
2352 } while (consumeIfPresent(MIToken::comma));
2353 }
2354
2355 if (expectAndConsume(MIToken::rparen))
2356 return true;
2357
2358 if (!HaveLine)
2359 return error("DILocation requires line number");
2360 if (!Scope)
2361 return error("DILocation requires a scope");
2362
2363 Loc = DILocation::get(MF.getFunction().getContext(), Line, Column, Scope,
2364 InlinedAt, ImplicitCode);
2365 return false;
2366}
2367
2368bool MIParser::parseMetadataOperand(MachineOperand &Dest) {
2369 MDNode *Node = nullptr;
2370 if (Token.is(MIToken::exclaim)) {
2371 if (parseMDNode(Node))
2372 return true;
2373 } else if (Token.is(MIToken::md_diexpr)) {
2374 if (parseDIExpression(Node))
2375 return true;
2376 }
2377 Dest = MachineOperand::CreateMetadata(Node);
2378 return false;
2379}
2380
2381bool MIParser::parseCFIOffset(int &Offset) {
2382 if (Token.isNot(MIToken::IntegerLiteral))
2383 return error("expected a cfi offset");
2384 if (Token.integerValue().getMinSignedBits() > 32)
2385 return error("expected a 32 bit integer (the cfi offset is too large)");
2386 Offset = (int)Token.integerValue().getExtValue();
2387 lex();
2388 return false;
2389}
2390
2391bool MIParser::parseCFIRegister(Register &Reg) {
2392 if (Token.isNot(MIToken::NamedRegister))
2393 return error("expected a cfi register");
2394 Register LLVMReg;
2395 if (parseNamedRegister(LLVMReg))
2396 return true;
2397 const auto *TRI = MF.getSubtarget().getRegisterInfo();
2398 assert(TRI && "Expected target register info")(static_cast <bool> (TRI && "Expected target register info"
) ? void (0) : __assert_fail ("TRI && \"Expected target register info\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2398, __extension__
__PRETTY_FUNCTION__))
;
2399 int DwarfReg = TRI->getDwarfRegNum(LLVMReg, true);
2400 if (DwarfReg < 0)
2401 return error("invalid DWARF register");
2402 Reg = (unsigned)DwarfReg;
2403 lex();
2404 return false;
2405}
2406
2407bool MIParser::parseCFIAddressSpace(unsigned &AddressSpace) {
2408 if (Token.isNot(MIToken::IntegerLiteral))
2409 return error("expected a cfi address space literal");
2410 if (Token.integerValue().isSigned())
2411 return error("expected an unsigned integer (cfi address space)");
2412 AddressSpace = Token.integerValue().getZExtValue();
2413 lex();
2414 return false;
2415}
2416
2417bool MIParser::parseCFIEscapeValues(std::string &Values) {
2418 do {
2419 if (Token.isNot(MIToken::HexLiteral))
2420 return error("expected a hexadecimal literal");
2421 unsigned Value;
2422 if (getUnsigned(Value))
2423 return true;
2424 if (Value > UINT8_MAX(255))
2425 return error("expected a 8-bit integer (too large)");
2426 Values.push_back(static_cast<uint8_t>(Value));
2427 lex();
2428 } while (consumeIfPresent(MIToken::comma));
2429 return false;
2430}
2431
2432bool MIParser::parseCFIOperand(MachineOperand &Dest) {
2433 auto Kind = Token.kind();
2434 lex();
2435 int Offset;
2436 Register Reg;
2437 unsigned AddressSpace;
2438 unsigned CFIIndex;
2439 switch (Kind) {
2440 case MIToken::kw_cfi_same_value:
2441 if (parseCFIRegister(Reg))
2442 return true;
2443 CFIIndex = MF.addFrameInst(MCCFIInstruction::createSameValue(nullptr, Reg));
2444 break;
2445 case MIToken::kw_cfi_offset:
2446 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2447 parseCFIOffset(Offset))
2448 return true;
2449 CFIIndex =
2450 MF.addFrameInst(MCCFIInstruction::createOffset(nullptr, Reg, Offset));
2451 break;
2452 case MIToken::kw_cfi_rel_offset:
2453 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2454 parseCFIOffset(Offset))
2455 return true;
2456 CFIIndex = MF.addFrameInst(
2457 MCCFIInstruction::createRelOffset(nullptr, Reg, Offset));
2458 break;
2459 case MIToken::kw_cfi_def_cfa_register:
2460 if (parseCFIRegister(Reg))
2461 return true;
2462 CFIIndex =
2463 MF.addFrameInst(MCCFIInstruction::createDefCfaRegister(nullptr, Reg));
2464 break;
2465 case MIToken::kw_cfi_def_cfa_offset:
2466 if (parseCFIOffset(Offset))
2467 return true;
2468 CFIIndex =
2469 MF.addFrameInst(MCCFIInstruction::cfiDefCfaOffset(nullptr, Offset));
2470 break;
2471 case MIToken::kw_cfi_adjust_cfa_offset:
2472 if (parseCFIOffset(Offset))
2473 return true;
2474 CFIIndex = MF.addFrameInst(
2475 MCCFIInstruction::createAdjustCfaOffset(nullptr, Offset));
2476 break;
2477 case MIToken::kw_cfi_def_cfa:
2478 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2479 parseCFIOffset(Offset))
2480 return true;
2481 CFIIndex =
2482 MF.addFrameInst(MCCFIInstruction::cfiDefCfa(nullptr, Reg, Offset));
2483 break;
2484 case MIToken::kw_cfi_llvm_def_aspace_cfa:
2485 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2486 parseCFIOffset(Offset) || expectAndConsume(MIToken::comma) ||
2487 parseCFIAddressSpace(AddressSpace))
2488 return true;
2489 CFIIndex = MF.addFrameInst(MCCFIInstruction::createLLVMDefAspaceCfa(
2490 nullptr, Reg, Offset, AddressSpace));
2491 break;
2492 case MIToken::kw_cfi_remember_state:
2493 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRememberState(nullptr));
2494 break;
2495 case MIToken::kw_cfi_restore:
2496 if (parseCFIRegister(Reg))
2497 return true;
2498 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, Reg));
2499 break;
2500 case MIToken::kw_cfi_restore_state:
2501 CFIIndex = MF.addFrameInst(MCCFIInstruction::createRestoreState(nullptr));
2502 break;
2503 case MIToken::kw_cfi_undefined:
2504 if (parseCFIRegister(Reg))
2505 return true;
2506 CFIIndex = MF.addFrameInst(MCCFIInstruction::createUndefined(nullptr, Reg));
2507 break;
2508 case MIToken::kw_cfi_register: {
2509 Register Reg2;
2510 if (parseCFIRegister(Reg) || expectAndConsume(MIToken::comma) ||
2511 parseCFIRegister(Reg2))
2512 return true;
2513
2514 CFIIndex =
2515 MF.addFrameInst(MCCFIInstruction::createRegister(nullptr, Reg, Reg2));
2516 break;
2517 }
2518 case MIToken::kw_cfi_window_save:
2519 CFIIndex = MF.addFrameInst(MCCFIInstruction::createWindowSave(nullptr));
2520 break;
2521 case MIToken::kw_cfi_aarch64_negate_ra_sign_state:
2522 CFIIndex = MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
2523 break;
2524 case MIToken::kw_cfi_escape: {
2525 std::string Values;
2526 if (parseCFIEscapeValues(Values))
2527 return true;
2528 CFIIndex = MF.addFrameInst(MCCFIInstruction::createEscape(nullptr, Values));
2529 break;
2530 }
2531 default:
2532 // TODO: Parse the other CFI operands.
2533 llvm_unreachable("The current token should be a cfi operand")::llvm::llvm_unreachable_internal("The current token should be a cfi operand"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2533)
;
2534 }
2535 Dest = MachineOperand::CreateCFIIndex(CFIIndex);
2536 return false;
2537}
2538
2539bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) {
2540 switch (Token.kind()) {
2541 case MIToken::NamedIRBlock: {
2542 BB = dyn_cast_or_null<BasicBlock>(
2543 F.getValueSymbolTable()->lookup(Token.stringValue()));
2544 if (!BB)
2545 return error(Twine("use of undefined IR block '") + Token.range() + "'");
2546 break;
2547 }
2548 case MIToken::IRBlock: {
2549 unsigned SlotNumber = 0;
2550 if (getUnsigned(SlotNumber))
2551 return true;
2552 BB = const_cast<BasicBlock *>(getIRBlock(SlotNumber, F));
2553 if (!BB)
2554 return error(Twine("use of undefined IR block '%ir-block.") +
2555 Twine(SlotNumber) + "'");
2556 break;
2557 }
2558 default:
2559 llvm_unreachable("The current token should be an IR block reference")::llvm::llvm_unreachable_internal("The current token should be an IR block reference"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2559)
;
2560 }
2561 return false;
2562}
2563
2564bool MIParser::parseBlockAddressOperand(MachineOperand &Dest) {
2565 assert(Token.is(MIToken::kw_blockaddress))(static_cast <bool> (Token.is(MIToken::kw_blockaddress)
) ? void (0) : __assert_fail ("Token.is(MIToken::kw_blockaddress)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2565, __extension__
__PRETTY_FUNCTION__))
;
2566 lex();
2567 if (expectAndConsume(MIToken::lparen))
2568 return true;
2569 if (Token.isNot(MIToken::GlobalValue) &&
2570 Token.isNot(MIToken::NamedGlobalValue))
2571 return error("expected a global value");
2572 GlobalValue *GV = nullptr;
2573 if (parseGlobalValue(GV))
2574 return true;
2575 auto *F = dyn_cast<Function>(GV);
2576 if (!F)
2577 return error("expected an IR function reference");
2578 lex();
2579 if (expectAndConsume(MIToken::comma))
2580 return true;
2581 BasicBlock *BB = nullptr;
2582 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
2583 return error("expected an IR block reference");
2584 if (parseIRBlock(BB, *F))
2585 return true;
2586 lex();
2587 if (expectAndConsume(MIToken::rparen))
2588 return true;
2589 Dest = MachineOperand::CreateBA(BlockAddress::get(F, BB), /*Offset=*/0);
2590 if (parseOperandsOffset(Dest))
2591 return true;
2592 return false;
2593}
2594
2595bool MIParser::parseIntrinsicOperand(MachineOperand &Dest) {
2596 assert(Token.is(MIToken::kw_intrinsic))(static_cast <bool> (Token.is(MIToken::kw_intrinsic)) ?
void (0) : __assert_fail ("Token.is(MIToken::kw_intrinsic)",
"llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2596, __extension__
__PRETTY_FUNCTION__))
;
2597 lex();
2598 if (expectAndConsume(MIToken::lparen))
2599 return error("expected syntax intrinsic(@llvm.whatever)");
2600
2601 if (Token.isNot(MIToken::NamedGlobalValue))
2602 return error("expected syntax intrinsic(@llvm.whatever)");
2603
2604 std::string Name = std::string(Token.stringValue());
2605 lex();
2606
2607 if (expectAndConsume(MIToken::rparen))
2608 return error("expected ')' to terminate intrinsic name");
2609
2610 // Find out what intrinsic we're dealing with, first try the global namespace
2611 // and then the target's private intrinsics if that fails.
2612 const TargetIntrinsicInfo *TII = MF.getTarget().getIntrinsicInfo();
2613 Intrinsic::ID ID = Function::lookupIntrinsicID(Name);
2614 if (ID == Intrinsic::not_intrinsic && TII)
2615 ID = static_cast<Intrinsic::ID>(TII->lookupName(Name));
2616
2617 if (ID == Intrinsic::not_intrinsic)
2618 return error("unknown intrinsic name");
2619 Dest = MachineOperand::CreateIntrinsicID(ID);
2620
2621 return false;
2622}
2623
2624bool MIParser::parsePredicateOperand(MachineOperand &Dest) {
2625 assert(Token.is(MIToken::kw_intpred) || Token.is(MIToken::kw_floatpred))(static_cast <bool> (Token.is(MIToken::kw_intpred) || Token
.is(MIToken::kw_floatpred)) ? void (0) : __assert_fail ("Token.is(MIToken::kw_intpred) || Token.is(MIToken::kw_floatpred)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2625, __extension__
__PRETTY_FUNCTION__))
;
2626 bool IsFloat = Token.is(MIToken::kw_floatpred);
2627 lex();
2628
2629 if (expectAndConsume(MIToken::lparen))
2630 return error("expected syntax intpred(whatever) or floatpred(whatever");
2631
2632 if (Token.isNot(MIToken::Identifier))
2633 return error("whatever");
2634
2635 CmpInst::Predicate Pred;
2636 if (IsFloat) {
2637 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2638 .Case("false", CmpInst::FCMP_FALSE)
2639 .Case("oeq", CmpInst::FCMP_OEQ)
2640 .Case("ogt", CmpInst::FCMP_OGT)
2641 .Case("oge", CmpInst::FCMP_OGE)
2642 .Case("olt", CmpInst::FCMP_OLT)
2643 .Case("ole", CmpInst::FCMP_OLE)
2644 .Case("one", CmpInst::FCMP_ONE)
2645 .Case("ord", CmpInst::FCMP_ORD)
2646 .Case("uno", CmpInst::FCMP_UNO)
2647 .Case("ueq", CmpInst::FCMP_UEQ)
2648 .Case("ugt", CmpInst::FCMP_UGT)
2649 .Case("uge", CmpInst::FCMP_UGE)
2650 .Case("ult", CmpInst::FCMP_ULT)
2651 .Case("ule", CmpInst::FCMP_ULE)
2652 .Case("une", CmpInst::FCMP_UNE)
2653 .Case("true", CmpInst::FCMP_TRUE)
2654 .Default(CmpInst::BAD_FCMP_PREDICATE);
2655 if (!CmpInst::isFPPredicate(Pred))
2656 return error("invalid floating-point predicate");
2657 } else {
2658 Pred = StringSwitch<CmpInst::Predicate>(Token.stringValue())
2659 .Case("eq", CmpInst::ICMP_EQ)
2660 .Case("ne", CmpInst::ICMP_NE)
2661 .Case("sgt", CmpInst::ICMP_SGT)
2662 .Case("sge", CmpInst::ICMP_SGE)
2663 .Case("slt", CmpInst::ICMP_SLT)
2664 .Case("sle", CmpInst::ICMP_SLE)
2665 .Case("ugt", CmpInst::ICMP_UGT)
2666 .Case("uge", CmpInst::ICMP_UGE)
2667 .Case("ult", CmpInst::ICMP_ULT)
2668 .Case("ule", CmpInst::ICMP_ULE)
2669 .Default(CmpInst::BAD_ICMP_PREDICATE);
2670 if (!CmpInst::isIntPredicate(Pred))
2671 return error("invalid integer predicate");
2672 }
2673
2674 lex();
2675 Dest = MachineOperand::CreatePredicate(Pred);
2676 if (expectAndConsume(MIToken::rparen))
2677 return error("predicate should be terminated by ')'.");
2678
2679 return false;
2680}
2681
2682bool MIParser::parseShuffleMaskOperand(MachineOperand &Dest) {
2683 assert(Token.is(MIToken::kw_shufflemask))(static_cast <bool> (Token.is(MIToken::kw_shufflemask))
? void (0) : __assert_fail ("Token.is(MIToken::kw_shufflemask)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2683, __extension__
__PRETTY_FUNCTION__))
;
2684
2685 lex();
2686 if (expectAndConsume(MIToken::lparen))
2687 return error("expected syntax shufflemask(<integer or undef>, ...)");
2688
2689 SmallVector<int, 32> ShufMask;
2690 do {
2691 if (Token.is(MIToken::kw_undef)) {
2692 ShufMask.push_back(-1);
2693 } else if (Token.is(MIToken::IntegerLiteral)) {
2694 const APSInt &Int = Token.integerValue();
2695 ShufMask.push_back(Int.getExtValue());
2696 } else
2697 return error("expected integer constant");
2698
2699 lex();
2700 } while (consumeIfPresent(MIToken::comma));
2701
2702 if (expectAndConsume(MIToken::rparen))
2703 return error("shufflemask should be terminated by ')'.");
2704
2705 ArrayRef<int> MaskAlloc = MF.allocateShuffleMask(ShufMask);
2706 Dest = MachineOperand::CreateShuffleMask(MaskAlloc);
2707 return false;
2708}
2709
2710bool MIParser::parseTargetIndexOperand(MachineOperand &Dest) {
2711 assert(Token.is(MIToken::kw_target_index))(static_cast <bool> (Token.is(MIToken::kw_target_index)
) ? void (0) : __assert_fail ("Token.is(MIToken::kw_target_index)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2711, __extension__
__PRETTY_FUNCTION__))
;
2712 lex();
2713 if (expectAndConsume(MIToken::lparen))
2714 return true;
2715 if (Token.isNot(MIToken::Identifier))
2716 return error("expected the name of the target index");
2717 int Index = 0;
2718 if (PFS.Target.getTargetIndex(Token.stringValue(), Index))
2719 return error("use of undefined target index '" + Token.stringValue() + "'");
2720 lex();
2721 if (expectAndConsume(MIToken::rparen))
2722 return true;
2723 Dest = MachineOperand::CreateTargetIndex(unsigned(Index), /*Offset=*/0);
2724 if (parseOperandsOffset(Dest))
2725 return true;
2726 return false;
2727}
2728
2729bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) {
2730 assert(Token.stringValue() == "CustomRegMask" && "Expected a custom RegMask")(static_cast <bool> (Token.stringValue() == "CustomRegMask"
&& "Expected a custom RegMask") ? void (0) : __assert_fail
("Token.stringValue() == \"CustomRegMask\" && \"Expected a custom RegMask\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2730, __extension__
__PRETTY_FUNCTION__))
;
2731 lex();
2732 if (expectAndConsume(MIToken::lparen))
2733 return true;
2734
2735 uint32_t *Mask = MF.allocateRegMask();
2736 do {
2737 if (Token.isNot(MIToken::rparen)) {
2738 if (Token.isNot(MIToken::NamedRegister))
2739 return error("expected a named register");
2740 Register Reg;
2741 if (parseNamedRegister(Reg))
2742 return true;
2743 lex();
2744 Mask[Reg / 32] |= 1U << (Reg % 32);
2745 }
2746
2747 // TODO: Report an error if the same register is used more than once.
2748 } while (consumeIfPresent(MIToken::comma));
2749
2750 if (expectAndConsume(MIToken::rparen))
2751 return true;
2752 Dest = MachineOperand::CreateRegMask(Mask);
2753 return false;
2754}
2755
2756bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) {
2757 assert(Token.is(MIToken::kw_liveout))(static_cast <bool> (Token.is(MIToken::kw_liveout)) ? void
(0) : __assert_fail ("Token.is(MIToken::kw_liveout)", "llvm/lib/CodeGen/MIRParser/MIParser.cpp"
, 2757, __extension__ __PRETTY_FUNCTION__))
;
2758 uint32_t *Mask = MF.allocateRegMask();
2759 lex();
2760 if (expectAndConsume(MIToken::lparen))
2761 return true;
2762 while (true) {
2763 if (Token.isNot(MIToken::NamedRegister))
2764 return error("expected a named register");
2765 Register Reg;
2766 if (parseNamedRegister(Reg))
2767 return true;
2768 lex();
2769 Mask[Reg / 32] |= 1U << (Reg % 32);
2770 // TODO: Report an error if the same register is used more than once.
2771 if (Token.isNot(MIToken::comma))
2772 break;
2773 lex();
2774 }
2775 if (expectAndConsume(MIToken::rparen))
2776 return true;
2777 Dest = MachineOperand::CreateRegLiveOut(Mask);
2778 return false;
2779}
2780
2781bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
2782 MachineOperand &Dest,
2783 Optional<unsigned> &TiedDefIdx) {
2784 switch (Token.kind()) {
2785 case MIToken::kw_implicit:
2786 case MIToken::kw_implicit_define:
2787 case MIToken::kw_def:
2788 case MIToken::kw_dead:
2789 case MIToken::kw_killed:
2790 case MIToken::kw_undef:
2791 case MIToken::kw_internal:
2792 case MIToken::kw_early_clobber:
2793 case MIToken::kw_debug_use:
2794 case MIToken::kw_renamable:
2795 case MIToken::underscore:
2796 case MIToken::NamedRegister:
2797 case MIToken::VirtualRegister:
2798 case MIToken::NamedVirtualRegister:
2799 return parseRegisterOperand(Dest, TiedDefIdx);
2800 case MIToken::IntegerLiteral:
2801 return parseImmediateOperand(Dest);
2802 case MIToken::kw_half:
2803 case MIToken::kw_float:
2804 case MIToken::kw_double:
2805 case MIToken::kw_x86_fp80:
2806 case MIToken::kw_fp128:
2807 case MIToken::kw_ppc_fp128:
2808 return parseFPImmediateOperand(Dest);
2809 case MIToken::MachineBasicBlock:
2810 return parseMBBOperand(Dest);
2811 case MIToken::StackObject:
2812 return parseStackObjectOperand(Dest);
2813 case MIToken::FixedStackObject:
2814 return parseFixedStackObjectOperand(Dest);
2815 case MIToken::GlobalValue:
2816 case MIToken::NamedGlobalValue:
2817 return parseGlobalAddressOperand(Dest);
2818 case MIToken::ConstantPoolItem:
2819 return parseConstantPoolIndexOperand(Dest);
2820 case MIToken::JumpTableIndex:
2821 return parseJumpTableIndexOperand(Dest);
2822 case MIToken::ExternalSymbol:
2823 return parseExternalSymbolOperand(Dest);
2824 case MIToken::MCSymbol:
2825 return parseMCSymbolOperand(Dest);
2826 case MIToken::SubRegisterIndex:
2827 return parseSubRegisterIndexOperand(Dest);
2828 case MIToken::md_diexpr:
2829 case MIToken::exclaim:
2830 return parseMetadataOperand(Dest);
2831 case MIToken::kw_cfi_same_value:
2832 case MIToken::kw_cfi_offset:
2833 case MIToken::kw_cfi_rel_offset:
2834 case MIToken::kw_cfi_def_cfa_register:
2835 case MIToken::kw_cfi_def_cfa_offset:
2836 case MIToken::kw_cfi_adjust_cfa_offset:
2837 case MIToken::kw_cfi_escape:
2838 case MIToken::kw_cfi_def_cfa:
2839 case MIToken::kw_cfi_llvm_def_aspace_cfa:
2840 case MIToken::kw_cfi_register:
2841 case MIToken::kw_cfi_remember_state:
2842 case MIToken::kw_cfi_restore:
2843 case MIToken::kw_cfi_restore_state:
2844 case MIToken::kw_cfi_undefined:
2845 case MIToken::kw_cfi_window_save:
2846 case MIToken::kw_cfi_aarch64_negate_ra_sign_state:
2847 return parseCFIOperand(Dest);
2848 case MIToken::kw_blockaddress:
2849 return parseBlockAddressOperand(Dest);
2850 case MIToken::kw_intrinsic:
2851 return parseIntrinsicOperand(Dest);
2852 case MIToken::kw_target_index:
2853 return parseTargetIndexOperand(Dest);
2854 case MIToken::kw_liveout:
2855 return parseLiveoutRegisterMaskOperand(Dest);
2856 case MIToken::kw_floatpred:
2857 case MIToken::kw_intpred:
2858 return parsePredicateOperand(Dest);
2859 case MIToken::kw_shufflemask:
2860 return parseShuffleMaskOperand(Dest);
2861 case MIToken::Error:
2862 return true;
2863 case MIToken::Identifier:
2864 if (const auto *RegMask = PFS.Target.getRegMask(Token.stringValue())) {
2865 Dest = MachineOperand::CreateRegMask(RegMask);
2866 lex();
2867 break;
2868 } else if (Token.stringValue() == "CustomRegMask") {
2869 return parseCustomRegisterMaskOperand(Dest);
2870 } else
2871 return parseTypedImmediateOperand(Dest);
2872 case MIToken::dot: {
2873 const auto *TII = MF.getSubtarget().getInstrInfo();
2874 if (const auto *Formatter = TII->getMIRFormatter()) {
2875 return parseTargetImmMnemonic(OpCode, OpIdx, Dest, *Formatter);
2876 }
2877 [[fallthrough]];
2878 }
2879 default:
2880 // FIXME: Parse the MCSymbol machine operand.
2881 return error("expected a machine operand");
2882 }
2883 return false;
2884}
2885
2886bool MIParser::parseMachineOperandAndTargetFlags(
2887 const unsigned OpCode, const unsigned OpIdx, MachineOperand &Dest,
2888 Optional<unsigned> &TiedDefIdx) {
2889 unsigned TF = 0;
2890 bool HasTargetFlags = false;
2891 if (Token.is(MIToken::kw_target_flags)) {
2892 HasTargetFlags = true;
2893 lex();
2894 if (expectAndConsume(MIToken::lparen))
2895 return true;
2896 if (Token.isNot(MIToken::Identifier))
2897 return error("expected the name of the target flag");
2898 if (PFS.Target.getDirectTargetFlag(Token.stringValue(), TF)) {
2899 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), TF))
2900 return error("use of undefined target flag '" + Token.stringValue() +
2901 "'");
2902 }
2903 lex();
2904 while (Token.is(MIToken::comma)) {
2905 lex();
2906 if (Token.isNot(MIToken::Identifier))
2907 return error("expected the name of the target flag");
2908 unsigned BitFlag = 0;
2909 if (PFS.Target.getBitmaskTargetFlag(Token.stringValue(), BitFlag))
2910 return error("use of undefined target flag '" + Token.stringValue() +
2911 "'");
2912 // TODO: Report an error when using a duplicate bit target flag.
2913 TF |= BitFlag;
2914 lex();
2915 }
2916 if (expectAndConsume(MIToken::rparen))
2917 return true;
2918 }
2919 auto Loc = Token.location();
2920 if (parseMachineOperand(OpCode, OpIdx, Dest, TiedDefIdx))
2921 return true;
2922 if (!HasTargetFlags)
2923 return false;
2924 if (Dest.isReg())
2925 return error(Loc, "register operands can't have target flags");
2926 Dest.setTargetFlags(TF);
2927 return false;
2928}
2929
2930bool MIParser::parseOffset(int64_t &Offset) {
2931 if (Token.isNot(MIToken::plus) && Token.isNot(MIToken::minus))
2932 return false;
2933 StringRef Sign = Token.range();
2934 bool IsNegative = Token.is(MIToken::minus);
2935 lex();
2936 if (Token.isNot(MIToken::IntegerLiteral))
2937 return error("expected an integer literal after '" + Sign + "'");
2938 if (Token.integerValue().getMinSignedBits() > 64)
2939 return error("expected 64-bit integer (too large)");
2940 Offset = Token.integerValue().getExtValue();
2941 if (IsNegative)
2942 Offset = -Offset;
2943 lex();
2944 return false;
2945}
2946
2947bool MIParser::parseIRBlockAddressTaken(BasicBlock *&BB) {
2948 assert(Token.is(MIToken::kw_ir_block_address_taken))(static_cast <bool> (Token.is(MIToken::kw_ir_block_address_taken
)) ? void (0) : __assert_fail ("Token.is(MIToken::kw_ir_block_address_taken)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2948, __extension__
__PRETTY_FUNCTION__))
;
2949 lex();
2950 if (Token.isNot(MIToken::IRBlock) && Token.isNot(MIToken::NamedIRBlock))
2951 return error("expected basic block after 'ir_block_address_taken'");
2952
2953 if (parseIRBlock(BB, MF.getFunction()))
2954 return true;
2955
2956 lex();
2957 return false;
2958}
2959
2960bool MIParser::parseAlignment(uint64_t &Alignment) {
2961 assert(Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign))(static_cast <bool> (Token.is(MIToken::kw_align) || Token
.is(MIToken::kw_basealign)) ? void (0) : __assert_fail ("Token.is(MIToken::kw_align) || Token.is(MIToken::kw_basealign)"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2961, __extension__
__PRETTY_FUNCTION__))
;
2962 lex();
2963 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
2964 return error("expected an integer literal after 'align'");
2965 if (getUint64(Alignment))
2966 return true;
2967 lex();
2968
2969 if (!isPowerOf2_64(Alignment))
2970 return error("expected a power-of-2 literal after 'align'");
2971
2972 return false;
2973}
2974
2975bool MIParser::parseAddrspace(unsigned &Addrspace) {
2976 assert(Token.is(MIToken::kw_addrspace))(static_cast <bool> (Token.is(MIToken::kw_addrspace)) ?
void (0) : __assert_fail ("Token.is(MIToken::kw_addrspace)",
"llvm/lib/CodeGen/MIRParser/MIParser.cpp", 2976, __extension__
__PRETTY_FUNCTION__))
;
2977 lex();
2978 if (Token.isNot(MIToken::IntegerLiteral) || Token.integerValue().isSigned())
2979 return error("expected an integer literal after 'addrspace'");
2980 if (getUnsigned(Addrspace))
2981 return true;
2982 lex();
2983 return false;
2984}
2985
2986bool MIParser::parseOperandsOffset(MachineOperand &Op) {
2987 int64_t Offset = 0;
2988 if (parseOffset(Offset))
2989 return true;
2990 Op.setOffset(Offset);
2991 return false;
2992}
2993
2994static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS,
2995 const Value *&V, ErrorCallbackType ErrCB) {
2996 switch (Token.kind()) {
2
Control jumps to 'case GlobalValue:' at line 3009
2997 case MIToken::NamedIRValue: {
2998 V = PFS.MF.getFunction().getValueSymbolTable()->lookup(Token.stringValue());
2999 break;
3000 }
3001 case MIToken::IRValue: {
3002 unsigned SlotNumber = 0;
3003 if (getUnsigned(Token, SlotNumber, ErrCB))
3004 return true;
3005 V = PFS.getIRValue(SlotNumber);
3006 break;
3007 }
3008 case MIToken::NamedGlobalValue:
3009 case MIToken::GlobalValue: {
3010 GlobalValue *GV = nullptr;
3011 if (parseGlobalValue(Token, PFS, GV, ErrCB))
3
Calling 'parseGlobalValue'
3012 return true;
3013 V = GV;
3014 break;
3015 }
3016 case MIToken::QuotedIRValue: {
3017 const Constant *C = nullptr;
3018 if (parseIRConstant(Token.location(), Token.stringValue(), PFS, C, ErrCB))
3019 return true;
3020 V = C;
3021 break;
3022 }
3023 case MIToken::kw_unknown_address:
3024 V = nullptr;
3025 return false;
3026 default:
3027 llvm_unreachable("The current token should be an IR block reference")::llvm::llvm_unreachable_internal("The current token should be an IR block reference"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3027)
;
3028 }
3029 if (!V)
3030 return ErrCB(Token.location(), Twine("use of undefined IR value '") + Token.range() + "'");
3031 return false;
3032}
3033
3034bool MIParser::parseIRValue(const Value *&V) {
3035 return ::parseIRValue(
3036 Token, PFS, V, [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3037 return error(Loc, Msg);
3038 });
3039}
3040
3041bool MIParser::getUint64(uint64_t &Result) {
3042 if (Token.hasIntegerValue()) {
3043 if (Token.integerValue().getActiveBits() > 64)
3044 return error("expected 64-bit integer (too large)");
3045 Result = Token.integerValue().getZExtValue();
3046 return false;
3047 }
3048 if (Token.is(MIToken::HexLiteral)) {
3049 APInt A;
3050 if (getHexUint(A))
3051 return true;
3052 if (A.getBitWidth() > 64)
3053 return error("expected 64-bit integer (too large)");
3054 Result = A.getZExtValue();
3055 return false;
3056 }
3057 return true;
3058}
3059
3060bool MIParser::getHexUint(APInt &Result) {
3061 return ::getHexUint(Token, Result);
3062}
3063
3064bool MIParser::parseMemoryOperandFlag(MachineMemOperand::Flags &Flags) {
3065 const auto OldFlags = Flags;
3066 switch (Token.kind()) {
3067 case MIToken::kw_volatile:
3068 Flags |= MachineMemOperand::MOVolatile;
3069 break;
3070 case MIToken::kw_non_temporal:
3071 Flags |= MachineMemOperand::MONonTemporal;
3072 break;
3073 case MIToken::kw_dereferenceable:
3074 Flags |= MachineMemOperand::MODereferenceable;
3075 break;
3076 case MIToken::kw_invariant:
3077 Flags |= MachineMemOperand::MOInvariant;
3078 break;
3079 case MIToken::StringConstant: {
3080 MachineMemOperand::Flags TF;
3081 if (PFS.Target.getMMOTargetFlag(Token.stringValue(), TF))
3082 return error("use of undefined target MMO flag '" + Token.stringValue() +
3083 "'");
3084 Flags |= TF;
3085 break;
3086 }
3087 default:
3088 llvm_unreachable("The current token should be a memory operand flag")::llvm::llvm_unreachable_internal("The current token should be a memory operand flag"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3088)
;
3089 }
3090 if (OldFlags == Flags)
3091 // We know that the same flag is specified more than once when the flags
3092 // weren't modified.
3093 return error("duplicate '" + Token.stringValue() + "' memory operand flag");
3094 lex();
3095 return false;
3096}
3097
3098bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) {
3099 switch (Token.kind()) {
3100 case MIToken::kw_stack:
3101 PSV = MF.getPSVManager().getStack();
3102 break;
3103 case MIToken::kw_got:
3104 PSV = MF.getPSVManager().getGOT();
3105 break;
3106 case MIToken::kw_jump_table:
3107 PSV = MF.getPSVManager().getJumpTable();
3108 break;
3109 case MIToken::kw_constant_pool:
3110 PSV = MF.getPSVManager().getConstantPool();
3111 break;
3112 case MIToken::FixedStackObject: {
3113 int FI;
3114 if (parseFixedStackFrameIndex(FI))
3115 return true;
3116 PSV = MF.getPSVManager().getFixedStack(FI);
3117 // The token was already consumed, so use return here instead of break.
3118 return false;
3119 }
3120 case MIToken::StackObject: {
3121 int FI;
3122 if (parseStackFrameIndex(FI))
3123 return true;
3124 PSV = MF.getPSVManager().getFixedStack(FI);
3125 // The token was already consumed, so use return here instead of break.
3126 return false;
3127 }
3128 case MIToken::kw_call_entry:
3129 lex();
3130 switch (Token.kind()) {
3131 case MIToken::GlobalValue:
3132 case MIToken::NamedGlobalValue: {
3133 GlobalValue *GV = nullptr;
3134 if (parseGlobalValue(GV))
3135 return true;
3136 PSV = MF.getPSVManager().getGlobalValueCallEntry(GV);
3137 break;
3138 }
3139 case MIToken::ExternalSymbol:
3140 PSV = MF.getPSVManager().getExternalSymbolCallEntry(
3141 MF.createExternalSymbolName(Token.stringValue()));
3142 break;
3143 default:
3144 return error(
3145 "expected a global value or an external symbol after 'call-entry'");
3146 }
3147 break;
3148 case MIToken::kw_custom: {
3149 lex();
3150 const auto *TII = MF.getSubtarget().getInstrInfo();
3151 if (const auto *Formatter = TII->getMIRFormatter()) {
3152 if (Formatter->parseCustomPseudoSourceValue(
3153 Token.stringValue(), MF, PFS, PSV,
3154 [this](StringRef::iterator Loc, const Twine &Msg) -> bool {
3155 return error(Loc, Msg);
3156 }))
3157 return true;
3158 } else
3159 return error("unable to parse target custom pseudo source value");
3160 break;
3161 }
3162 default:
3163 llvm_unreachable("The current token should be pseudo source value")::llvm::llvm_unreachable_internal("The current token should be pseudo source value"
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3163)
;
3164 }
3165 lex();
3166 return false;
3167}
3168
3169bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) {
3170 if (Token.is(MIToken::kw_constant_pool) || Token.is(MIToken::kw_stack) ||
3171 Token.is(MIToken::kw_got) || Token.is(MIToken::kw_jump_table) ||
3172 Token.is(MIToken::FixedStackObject) || Token.is(MIToken::StackObject) ||
3173 Token.is(MIToken::kw_call_entry) || Token.is(MIToken::kw_custom)) {
3174 const PseudoSourceValue *PSV = nullptr;
3175 if (parseMemoryPseudoSourceValue(PSV))
3176 return true;
3177 int64_t Offset = 0;
3178 if (parseOffset(Offset))
3179 return true;
3180 Dest = MachinePointerInfo(PSV, Offset);
3181 return false;
3182 }
3183 if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue) &&
3184 Token.isNot(MIToken::GlobalValue) &&
3185 Token.isNot(MIToken::NamedGlobalValue) &&
3186 Token.isNot(MIToken::QuotedIRValue) &&
3187 Token.isNot(MIToken::kw_unknown_address))
3188 return error("expected an IR value reference");
3189 const Value *V = nullptr;
3190 if (parseIRValue(V))
3191 return true;
3192 if (V && !V->getType()->isPointerTy())
3193 return error("expected a pointer IR value");
3194 lex();
3195 int64_t Offset = 0;
3196 if (parseOffset(Offset))
3197 return true;
3198 Dest = MachinePointerInfo(V, Offset);
3199 return false;
3200}
3201
3202bool MIParser::parseOptionalScope(LLVMContext &Context,
3203 SyncScope::ID &SSID) {
3204 SSID = SyncScope::System;
3205 if (Token.is(MIToken::Identifier) && Token.stringValue() == "syncscope") {
3206 lex();
3207 if (expectAndConsume(MIToken::lparen))
3208 return error("expected '(' in syncscope");
3209
3210 std::string SSN;
3211 if (parseStringConstant(SSN))
3212 return true;
3213
3214 SSID = Context.getOrInsertSyncScopeID(SSN);
3215 if (expectAndConsume(MIToken::rparen))
3216 return error("expected ')' in syncscope");
3217 }
3218
3219 return false;
3220}
3221
3222bool MIParser::parseOptionalAtomicOrdering(AtomicOrdering &Order) {
3223 Order = AtomicOrdering::NotAtomic;
3224 if (Token.isNot(MIToken::Identifier))
3225 return false;
3226
3227 Order = StringSwitch<AtomicOrdering>(Token.stringValue())
3228 .Case("unordered", AtomicOrdering::Unordered)
3229 .Case("monotonic", AtomicOrdering::Monotonic)
3230 .Case("acquire", AtomicOrdering::Acquire)
3231 .Case("release", AtomicOrdering::Release)
3232 .Case("acq_rel", AtomicOrdering::AcquireRelease)
3233 .Case("seq_cst", AtomicOrdering::SequentiallyConsistent)
3234 .Default(AtomicOrdering::NotAtomic);
3235
3236 if (Order != AtomicOrdering::NotAtomic) {
3237 lex();
3238 return false;
3239 }
3240
3241 return error("expected an atomic scope, ordering or a size specification");
3242}
3243
3244bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {
3245 if (expectAndConsume(MIToken::lparen))
3246 return true;
3247 MachineMemOperand::Flags Flags = MachineMemOperand::MONone;
3248 while (Token.isMemoryOperandFlag()) {
3249 if (parseMemoryOperandFlag(Flags))
3250 return true;
3251 }
3252 if (Token.isNot(MIToken::Identifier) ||
3253 (Token.stringValue() != "load" && Token.stringValue() != "store"))
3254 return error("expected 'load' or 'store' memory operation");
3255 if (Token.stringValue() == "load")
3256 Flags |= MachineMemOperand::MOLoad;
3257 else
3258 Flags |= MachineMemOperand::MOStore;
3259 lex();
3260
3261 // Optional 'store' for operands that both load and store.
3262 if (Token.is(MIToken::Identifier) && Token.stringValue() == "store") {
3263 Flags |= MachineMemOperand::MOStore;
3264 lex();
3265 }
3266
3267 // Optional synchronization scope.
3268 SyncScope::ID SSID;
3269 if (parseOptionalScope(MF.getFunction().getContext(), SSID))
3270 return true;
3271
3272 // Up to two atomic orderings (cmpxchg provides guarantees on failure).
3273 AtomicOrdering Order, FailureOrder;
3274 if (parseOptionalAtomicOrdering(Order))
3275 return true;
3276
3277 if (parseOptionalAtomicOrdering(FailureOrder))
3278 return true;
3279
3280 LLT MemoryType;
3281 if (Token.isNot(MIToken::IntegerLiteral) &&
3282 Token.isNot(MIToken::kw_unknown_size) &&
3283 Token.isNot(MIToken::lparen))
3284 return error("expected memory LLT, the size integer literal or 'unknown-size' after "
3285 "memory operation");
3286
3287 uint64_t Size = MemoryLocation::UnknownSize;
3288 if (Token.is(MIToken::IntegerLiteral)) {
3289 if (getUint64(Size))
3290 return true;
3291
3292 // Convert from bytes to bits for storage.
3293 MemoryType = LLT::scalar(8 * Size);
3294 lex();
3295 } else if (Token.is(MIToken::kw_unknown_size)) {
3296 Size = MemoryLocation::UnknownSize;
3297 lex();
3298 } else {
3299 if (expectAndConsume(MIToken::lparen))
3300 return true;
3301 if (parseLowLevelType(Token.location(), MemoryType))
3302 return true;
3303 if (expectAndConsume(MIToken::rparen))
3304 return true;
3305
3306 Size = MemoryType.getSizeInBytes();
3307 }
3308
3309 MachinePointerInfo Ptr = MachinePointerInfo();
3310 if (Token.is(MIToken::Identifier)) {
3311 const char *Word =
3312 ((Flags & MachineMemOperand::MOLoad) &&
3313 (Flags & MachineMemOperand::MOStore))
3314 ? "on"
3315 : Flags & MachineMemOperand::MOLoad ? "from" : "into";
3316 if (Token.stringValue() != Word)
3317 return error(Twine("expected '") + Word + "'");
3318 lex();
3319
3320 if (parseMachinePointerInfo(Ptr))
3321 return true;
3322 }
3323 uint64_t BaseAlignment =
3324 (Size != MemoryLocation::UnknownSize ? PowerOf2Ceil(Size) : 1);
3325 AAMDNodes AAInfo;
3326 MDNode *Range = nullptr;
3327 while (consumeIfPresent(MIToken::comma)) {
3328 switch (Token.kind()) {
3329 case MIToken::kw_align: {
3330 // align is printed if it is different than size.
3331 uint64_t Alignment;
3332 if (parseAlignment(Alignment))
3333 return true;
3334 if (Ptr.Offset & (Alignment - 1)) {
3335 // MachineMemOperand::getAlign never returns a value greater than the
3336 // alignment of offset, so this just guards against hand-written MIR
3337 // that specifies a large "align" value when it should probably use
3338 // "basealign" instead.
3339 return error("specified alignment is more aligned than offset");
3340 }
3341 BaseAlignment = Alignment;
3342 break;
3343 }
3344 case MIToken::kw_basealign:
3345 // basealign is printed if it is different than align.
3346 if (parseAlignment(BaseAlignment))
3347 return true;
3348 break;
3349 case MIToken::kw_addrspace:
3350 if (parseAddrspace(Ptr.AddrSpace))
3351 return true;
3352 break;
3353 case MIToken::md_tbaa:
3354 lex();
3355 if (parseMDNode(AAInfo.TBAA))
3356 return true;
3357 break;
3358 case MIToken::md_alias_scope:
3359 lex();
3360 if (parseMDNode(AAInfo.Scope))
3361 return true;
3362 break;
3363 case MIToken::md_noalias:
3364 lex();
3365 if (parseMDNode(AAInfo.NoAlias))
3366 return true;
3367 break;
3368 case MIToken::md_range:
3369 lex();
3370 if (parseMDNode(Range))
3371 return true;
3372 break;
3373 // TODO: Report an error on duplicate metadata nodes.
3374 default:
3375 return error("expected 'align' or '!tbaa' or '!alias.scope' or "
3376 "'!noalias' or '!range'");
3377 }
3378 }
3379 if (expectAndConsume(MIToken::rparen))
3380 return true;
3381 Dest = MF.getMachineMemOperand(Ptr, Flags, MemoryType, Align(BaseAlignment),
3382 AAInfo, Range, SSID, Order, FailureOrder);
3383 return false;
3384}
3385
3386bool MIParser::parsePreOrPostInstrSymbol(MCSymbol *&Symbol) {
3387 assert((Token.is(MIToken::kw_pre_instr_symbol) ||(static_cast <bool> ((Token.is(MIToken::kw_pre_instr_symbol
) || Token.is(MIToken::kw_post_instr_symbol)) && "Invalid token for a pre- post-instruction symbol!"
) ? void (0) : __assert_fail ("(Token.is(MIToken::kw_pre_instr_symbol) || Token.is(MIToken::kw_post_instr_symbol)) && \"Invalid token for a pre- post-instruction symbol!\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3389, __extension__
__PRETTY_FUNCTION__))
3388 Token.is(MIToken::kw_post_instr_symbol)) &&(static_cast <bool> ((Token.is(MIToken::kw_pre_instr_symbol
) || Token.is(MIToken::kw_post_instr_symbol)) && "Invalid token for a pre- post-instruction symbol!"
) ? void (0) : __assert_fail ("(Token.is(MIToken::kw_pre_instr_symbol) || Token.is(MIToken::kw_post_instr_symbol)) && \"Invalid token for a pre- post-instruction symbol!\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3389, __extension__
__PRETTY_FUNCTION__))
3389 "Invalid token for a pre- post-instruction symbol!")(static_cast <bool> ((Token.is(MIToken::kw_pre_instr_symbol
) || Token.is(MIToken::kw_post_instr_symbol)) && "Invalid token for a pre- post-instruction symbol!"
) ? void (0) : __assert_fail ("(Token.is(MIToken::kw_pre_instr_symbol) || Token.is(MIToken::kw_post_instr_symbol)) && \"Invalid token for a pre- post-instruction symbol!\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3389, __extension__
__PRETTY_FUNCTION__))
;
3390 lex();
3391 if (Token.isNot(MIToken::MCSymbol))
3392 return error("expected a symbol after 'pre-instr-symbol'");
3393 Symbol = getOrCreateMCSymbol(Token.stringValue());
3394 lex();
3395 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3396 Token.is(MIToken::lbrace))
3397 return false;
3398 if (Token.isNot(MIToken::comma))
3399 return error("expected ',' before the next machine operand");
3400 lex();
3401 return false;
3402}
3403
3404bool MIParser::parseHeapAllocMarker(MDNode *&Node) {
3405 assert(Token.is(MIToken::kw_heap_alloc_marker) &&(static_cast <bool> (Token.is(MIToken::kw_heap_alloc_marker
) && "Invalid token for a heap alloc marker!") ? void
(0) : __assert_fail ("Token.is(MIToken::kw_heap_alloc_marker) && \"Invalid token for a heap alloc marker!\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3406, __extension__
__PRETTY_FUNCTION__))
3406 "Invalid token for a heap alloc marker!")(static_cast <bool> (Token.is(MIToken::kw_heap_alloc_marker
) && "Invalid token for a heap alloc marker!") ? void
(0) : __assert_fail ("Token.is(MIToken::kw_heap_alloc_marker) && \"Invalid token for a heap alloc marker!\""
, "llvm/lib/CodeGen/MIRParser/MIParser.cpp", 3406, __extension__
__PRETTY_FUNCTION__))
;
3407 lex();
3408 parseMDNode(Node);
3409 if (!Node)
3410 return error("expected a MDNode after 'heap-alloc-marker'");
3411 if (Token.isNewlineOrEOF() || Token.is(MIToken::coloncolon) ||
3412 Token.is(MIToken::lbrace))
3413 return false;
3414 if (Token.isNot(MIToken::comma))
3415 return error("expected ',' before the next machine operand");
3416 lex();
3417 return false;
3418}
3419
3420static void initSlots2BasicBlocks(
3421 const Function &F,
3422 DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
3423 ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false);
3424 MST.incorporateFunction(F);
3425 for (const auto &BB : F) {
3426 if (BB.hasName())
3427 continue;
3428 int Slot = MST.getLocalSlot(&BB);
3429 if (Slot == -1)
3430 continue;
3431 Slots2BasicBlocks.insert(std::make_pair(unsigned(Slot), &BB));
3432 }
3433}
3434
3435static const BasicBlock *getIRBlockFromSlot(
3436 unsigned Slot,
3437 const DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {
3438 return Slots2BasicBlocks.lookup(Slot);
3439}
3440
3441const BasicBlock *MIParser::getIRBlock(unsigned Slot) {
3442 if (Slots2BasicBlocks.empty())
3443 initSlots2BasicBlocks(MF.getFunction(), Slots2BasicBlocks);
3444 return getIRBlockFromSlot(Slot, Slots2BasicBlocks);
3445}
3446
3447const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) {
3448 if (&F == &MF.getFunction())
3449 return getIRBlock(Slot);
3450 DenseMap<unsigned, const BasicBlock *> CustomSlots2BasicBlocks;
3451 initSlots2BasicBlocks(F, CustomSlots2BasicBlocks);
3452 return getIRBlockFromSlot(Slot, CustomSlots2BasicBlocks);
3453}
3454
3455MCSymbol *MIParser::getOrCreateMCSymbol(StringRef Name) {
3456 // FIXME: Currently we can't recognize temporary or local symbols and call all
3457 // of the appropriate forms to create them. However, this handles basic cases
3458 // well as most of the special aspects are recognized by a prefix on their
3459 // name, and the input names should already be unique. For test cases, keeping
3460 // the symbol name out of the symbol table isn't terribly important.
3461 return MF.getContext().getOrCreateSymbol(Name);
3462}
3463
3464bool MIParser::parseStringConstant(std::string &Result) {
3465 if (Token.isNot(MIToken::StringConstant))
3466 return error("expected string constant");
3467 Result = std::string(Token.stringValue());
3468 lex();
3469 return false;
3470}
3471
3472bool llvm::parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
3473 StringRef Src,
3474 SMDiagnostic &Error) {
3475 return MIParser(PFS, Error, Src).parseBasicBlockDefinitions(PFS.MBBSlots);
3476}
3477
3478bool llvm::parseMachineInstructions(PerFunctionMIParsingState &PFS,
3479 StringRef Src, SMDiagnostic &Error) {
3480 return MIParser(PFS, Error, Src).parseBasicBlocks();
3481}
3482
3483bool llvm::parseMBBReference(PerFunctionMIParsingState &PFS,
3484 MachineBasicBlock *&MBB, StringRef Src,
3485 SMDiagnostic &Error) {
3486 return MIParser(PFS, Error, Src).parseStandaloneMBB(MBB);
3487}
3488
3489bool llvm::parseRegisterReference(PerFunctionMIParsingState &PFS,
3490 Register &Reg, StringRef Src,
3491 SMDiagnostic &Error) {
3492 return MIParser(PFS, Error, Src).parseStandaloneRegister(Reg);
3493}
3494
3495bool llvm::parseNamedRegisterReference(PerFunctionMIParsingState &PFS,
3496 Register &Reg, StringRef Src,
3497 SMDiagnostic &Error) {
3498 return MIParser(PFS, Error, Src).parseStandaloneNamedRegister(Reg);
3499}
3500
3501bool llvm::parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
3502 VRegInfo *&Info, StringRef Src,
3503 SMDiagnostic &Error) {
3504 return MIParser(PFS, Error, Src).parseStandaloneVirtualRegister(Info);
3505}
3506
3507bool llvm::parseStackObjectReference(PerFunctionMIParsingState &PFS,
3508 int &FI, StringRef Src,
3509 SMDiagnostic &Error) {
3510 return MIParser(PFS, Error, Src).parseStandaloneStackObject(FI);
3511}
3512
3513bool llvm::parseMDNode(PerFunctionMIParsingState &PFS,
3514 MDNode *&Node, StringRef Src, SMDiagnostic &Error) {
3515 return MIParser(PFS, Error, Src).parseStandaloneMDNode(Node);
3516}
3517
3518bool llvm::parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src,
3519 SMRange SrcRange, SMDiagnostic &Error) {
3520 return MIParser(PFS, Error, Src, SrcRange).parseMachineMetadata();
3521}
3522
3523bool MIRFormatter::parseIRValue(StringRef Src, MachineFunction &MF,
3524 PerFunctionMIParsingState &PFS, const Value *&V,
3525 ErrorCallbackType ErrorCallback) {
3526 MIToken Token;
3527 Src = lexMIToken(Src, Token, [&](StringRef::iterator Loc, const Twine &Msg) {
3528 ErrorCallback(Loc, Msg);
3529 });
3530 V = nullptr;
3531
3532 return ::parseIRValue(Token, PFS, V, ErrorCallback);
1
Calling 'parseIRValue'
3533}