LLVM 24.0.0git
MIRParser.cpp
Go to the documentation of this file.
1//===- MIRParser.cpp - MIR serialization format 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 class that parses the optional LLVM IR and machine
10// functions that are stored in MIR files.
11//
12//===----------------------------------------------------------------------===//
13
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/StringRef.h"
28#include "llvm/IR/BasicBlock.h"
32#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Module.h"
37#include "llvm/Support/SMLoc.h"
41#include <memory>
42
43using namespace llvm;
44
45namespace llvm {
46class MDNode;
47class RegisterBank;
48
49/// This class implements the parsing of LLVM IR that's embedded inside a MIR
50/// file.
52 SourceMgr SM;
53 LLVMContext &Context;
54 yaml::Input In;
55 StringRef Filename;
56 SlotMapping IRSlots;
57 std::unique_ptr<PerTargetMIParsingState> Target;
58
59 /// True when the MIR file doesn't have LLVM IR. Dummy IR functions are
60 /// created and inserted into the given module when this is true.
61 bool NoLLVMIR = false;
62 /// True when a well formed MIR file does not contain any MIR/machine function
63 /// parts.
64 bool NoMIRDocuments = false;
65
66 std::function<void(Function &)> ProcessIRFunction;
67
68public:
69 MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
70 LLVMContext &Context,
71 std::function<void(Function &)> ProcessIRFunction);
72
73 void reportDiagnostic(const SMDiagnostic &Diag);
74
75 /// Report an error with the given message at unknown location.
76 ///
77 /// Always returns true.
78 bool error(const Twine &Message);
79
80 /// Report an error with the given message at the given location.
81 ///
82 /// Always returns true.
83 bool error(SMLoc Loc, const Twine &Message);
84
85 /// Report a given error with the location translated from the location in an
86 /// embedded string literal to a location in the MIR file.
87 ///
88 /// Always returns true.
89 bool error(const SMDiagnostic &Error, SMRange SourceRange);
90
91 /// Try to parse the optional LLVM module and the machine functions in the MIR
92 /// file.
93 ///
94 /// Return null if an error occurred.
95 std::unique_ptr<Module>
96 parseIRModule(DataLayoutCallbackTy DataLayoutCallback);
97
98 /// Create an empty function with the given name.
100
102 ModuleAnalysisManager *FAM = nullptr);
103
104 /// Parse the machine function in the current YAML document.
105 ///
106 ///
107 /// Return true if an error occurred.
110 Module::iterator &FirstUnvisitedFunction);
111
112 /// Initialize the machine function to the state that's described in the MIR
113 /// file.
114 ///
115 /// Return true if error occurred.
117 MachineFunction &MF);
118
120 const yaml::MachineFunction &YamlMF);
121
123 const yaml::MachineFunction &YamlMF);
124
126 const yaml::MachineFunction &YamlMF);
127
129 const yaml::MachineFunction &YamlMF);
130
132 const yaml::MachineFunction &YamlMF);
133
136 const std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
138
140 std::vector<CalleeSavedInfo> &CSIInfo,
141 const yaml::StringValue &RegisterSource,
142 bool IsRestored, int FrameIdx);
143
144 struct VarExprLoc {
147 DILocation *DILoc = nullptr;
148 };
149
150 std::optional<VarExprLoc> parseVarExprLoc(PerFunctionMIParsingState &PFS,
151 const yaml::StringValue &VarStr,
152 const yaml::StringValue &ExprStr,
153 const yaml::StringValue &LocStr);
154 template <typename T>
156 const T &Object,
157 int FrameIdx);
158
161 const yaml::MachineFunction &YamlMF);
162
164 const yaml::MachineJumpTable &YamlJTI);
165
167 MachineFunction &MF,
168 const yaml::MachineFunction &YMF);
169
171 const yaml::MachineFunction &YMF);
172
173private:
174 bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node,
175 const yaml::StringValue &Source);
176
177 bool parseMBBReference(PerFunctionMIParsingState &PFS,
179 const yaml::StringValue &Source);
180
181 /// Return a MIR diagnostic converted from an MI string diagnostic.
182 SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
183 SMRange SourceRange);
184
185 /// Return a MIR diagnostic converted from a diagnostic located in a YAML
186 /// block scalar string.
187 SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
188 SMRange SourceRange);
189
190 bool computeFunctionProperties(MachineFunction &MF,
191 const yaml::MachineFunction &YamlMF);
192
193 void setupDebugValueTracking(MachineFunction &MF,
195
196 bool parseMachineInst(PerFunctionMIParsingState &PFS,
197 const yaml::MachineInstrLoc &MILoc,
198 MachineInstr const *&MI);
199};
200
201} // end namespace llvm
202
203static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
204 reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
205}
206
207MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
208 StringRef Filename, LLVMContext &Context,
209 std::function<void(Function &)> Callback)
210 : Context(Context),
211 In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
212 ->getBuffer(),
213 nullptr, handleYAMLDiag, this),
214 Filename(Filename), ProcessIRFunction(Callback) {
215 In.setContext(&In);
216}
217
218bool MIRParserImpl::error(const Twine &Message) {
219 Context.diagnose(DiagnosticInfoMIRParser(
220 DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
221 return true;
222}
223
224bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
225 Context.diagnose(DiagnosticInfoMIRParser(
226 DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
227 return true;
228}
229
231 assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
232 reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
233 return true;
234}
235
238 switch (Diag.getKind()) {
240 Kind = DS_Error;
241 break;
243 Kind = DS_Warning;
244 break;
246 Kind = DS_Note;
247 break;
249 llvm_unreachable("remark unexpected");
250 break;
251 }
252 Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
253}
254
255std::unique_ptr<Module>
257 if (!In.setCurrentDocument()) {
258 if (In.error())
259 return nullptr;
260 // Create an empty module when the MIR file is empty.
261 NoMIRDocuments = true;
262 auto M = std::make_unique<Module>(Filename, Context);
263 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
264 M->getDataLayoutStr()))
265 M->setDataLayout(*LayoutOverride);
266 return M;
267 }
268
269 std::unique_ptr<Module> M;
270 // Parse the block scalar manually so that we can return unique pointer
271 // without having to go trough YAML traits.
272 if (const auto *BSN =
273 dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
275 M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
276 Context, &IRSlots, DataLayoutCallback);
277 if (!M) {
278 reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
279 return nullptr;
280 }
281 In.nextDocument();
282 if (!In.setCurrentDocument())
283 NoMIRDocuments = true;
284 } else {
285 // Create an new, empty module.
286 M = std::make_unique<Module>(Filename, Context);
287 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
288 M->getDataLayoutStr()))
289 M->setDataLayout(*LayoutOverride);
290 NoLLVMIR = true;
291 }
292 return M;
293}
294
297 if (NoMIRDocuments)
298 return false;
299
300 // Parse the machine functions.
301 auto FirstUnvisitedFunction = M.begin();
302 do {
303 if (parseMachineFunction(M, MMI, MAM, FirstUnvisitedFunction))
304 return true;
305 In.nextDocument();
306 } while (In.setCurrentDocument());
307
308 return false;
309}
310
312 auto &Context = M.getContext();
313 Function *F =
316 BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
317 new UnreachableInst(Context, BB);
318
319 if (ProcessIRFunction)
320 ProcessIRFunction(*F);
321
322 return F;
323}
324
325static Function *
327 Module::iterator &FirstUnvisitedFunction) {
328 for (; FirstUnvisitedFunction != M.end(); ++FirstUnvisitedFunction)
329 if (!FirstUnvisitedFunction->hasName())
330 return &*FirstUnvisitedFunction++;
331
332 return nullptr;
333}
334
337 Module::iterator &FirstUnvisitedFunction) {
338 // Parse the yaml.
341
342 const TargetMachine &TM = MMI.getTarget();
343 YamlMF.MachineFuncInfo = std::unique_ptr<yaml::MachineFunctionInfo>(
345
346 yaml::yamlize(In, YamlMF, false, Ctx);
347 if (In.error())
348 return true;
349
350 // Search for the corresponding IR function.
351 StringRef FunctionName = YamlMF.Name;
352 Function *F = M.getFunction(FunctionName);
353 if (!F) {
354 if (NoLLVMIR) {
355 F = createDummyFunction(FunctionName, M);
356 } else if (!FunctionName.empty() ||
357 !(F = getNextUnusedUnnamedFunction(M, FirstUnvisitedFunction))) {
358 return error(Twine("function '") + FunctionName +
359 "' isn't defined in the provided LLVM IR");
360 }
361 }
362
363 if (!MAM) {
364 if (MMI.getMachineFunction(*F) != nullptr)
365 return error(Twine("redefinition of machine function '") + FunctionName +
366 "'");
367
368 // Create the MachineFunction.
370 if (initializeMachineFunction(YamlMF, MF))
371 return true;
372 } else {
373 auto &FAM =
374 MAM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
375 if (FAM.getCachedResult<MachineFunctionAnalysis>(*F))
376 return error(Twine("redefinition of machine function '") + FunctionName +
377 "'");
378
379 // Create the MachineFunction.
380 MachineFunction &MF = FAM.getResult<MachineFunctionAnalysis>(*F).getMF();
381 if (initializeMachineFunction(YamlMF, MF))
382 return true;
383 }
384
385 return false;
386}
387
388static bool isSSA(const MachineFunction &MF) {
389 const MachineRegisterInfo &MRI = MF.getRegInfo();
390 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
392 if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
393 return false;
394
395 // Subregister defs are invalid in SSA.
396 const MachineOperand *RegDef = MRI.getOneDef(Reg);
397 if (RegDef && RegDef->getSubReg() != 0)
398 return false;
399 }
400 return true;
401}
402
403bool MIRParserImpl::computeFunctionProperties(
404 MachineFunction &MF, const yaml::MachineFunction &YamlMF) {
405 MachineFunctionProperties &Properties = MF.getProperties();
406
407 bool HasPHI = false;
408 bool HasInlineAsm = false;
409 bool HasFakeUses = false;
410 bool AllTiedOpsRewritten = true, HasTiedOps = false;
411 for (const MachineBasicBlock &MBB : MF) {
412 for (const MachineInstr &MI : MBB) {
413 if (MI.isPHI())
414 HasPHI = true;
415 if (MI.isInlineAsm())
416 HasInlineAsm = true;
417 if (MI.isFakeUse())
418 HasFakeUses = true;
419 for (unsigned I = 0; I < MI.getNumOperands(); ++I) {
420 const MachineOperand &MO = MI.getOperand(I);
421 if (!MO.isReg() || !MO.getReg())
422 continue;
423 unsigned DefIdx;
424 if (MO.isUse() && MI.isRegTiedToDefOperand(I, &DefIdx)) {
425 HasTiedOps = true;
426 if (MO.getReg() != MI.getOperand(DefIdx).getReg())
427 AllTiedOpsRewritten = false;
428 }
429 }
430 }
431 }
432
433 // Helper function to sanity-check and set properties that are computed, but
434 // may be explicitly set from the input MIR
435 auto ComputedPropertyHelper =
436 [&Properties](std::optional<bool> ExplicitProp, bool ComputedProp,
438 // Prefer explicitly given values over the computed properties
439 if (ExplicitProp.value_or(ComputedProp))
441 else
443
444 // Check for conflict between the explicit values and the computed ones
445 return ExplicitProp && *ExplicitProp && !ComputedProp;
446 };
447
448 if (ComputedPropertyHelper(YamlMF.NoPHIs, !HasPHI,
450 return error(MF.getName() +
451 " has explicit property NoPhi, but contains at least one PHI");
452 }
453
454 MF.setHasInlineAsm(HasInlineAsm);
455
456 if (HasTiedOps && AllTiedOpsRewritten)
457 Properties.setTiedOpsRewritten();
458
459 if (ComputedPropertyHelper(YamlMF.IsSSA, isSSA(MF),
461 return error(MF.getName() +
462 " has explicit property IsSSA, but is not valid SSA");
463 }
464
465 const MachineRegisterInfo &MRI = MF.getRegInfo();
466 if (ComputedPropertyHelper(YamlMF.NoVRegs, MRI.getNumVirtRegs() == 0,
468 return error(
469 MF.getName() +
470 " has explicit property NoVRegs, but contains virtual registers");
471 }
472
473 // For hasFakeUses we follow similar logic to the ComputedPropertyHelper,
474 // except for caring about the inverse case only, i.e. when the property is
475 // explicitly set to false and Fake Uses are present; having HasFakeUses=true
476 // on a function without fake uses is harmless.
477 if (YamlMF.HasFakeUses && !*YamlMF.HasFakeUses && HasFakeUses)
478 return error(
479 MF.getName() +
480 " has explicit property hasFakeUses=false, but contains fake uses");
481 MF.setHasFakeUses(YamlMF.HasFakeUses.value_or(HasFakeUses));
482
483 return false;
484}
485
486bool MIRParserImpl::parseMachineInst(PerFunctionMIParsingState &PFS,
487 const yaml::MachineInstrLoc &MILoc,
488 MachineInstr const *&MI) {
489 MachineFunction &MF = PFS.MF;
490 MachineBasicBlock *BB;
491 if (parseMBBReference(PFS, BB, MILoc.Block))
492 return true;
493 if (MILoc.Offset >= BB->size())
494 return error(Twine(MF.getName()) +
495 Twine(" instruction offset out of range.") +
496 " Unable to reference instruction at " + MILoc.Block.Value +
497 " at offset:" + Twine(MILoc.Offset));
498 MI = &*std::next(BB->instr_begin(), MILoc.Offset);
499 return false;
500}
501
504 MachineFunction &MF = PFS.MF;
506 const TargetMachine &TM = MF.getTarget();
507 for (auto &YamlCSInfo : YamlMF.CallSitesInfo) {
508 const yaml::MachineInstrLoc &MILoc = YamlCSInfo.CallLocation;
509 const MachineInstr *CallI;
510 if (parseMachineInst(PFS, MILoc, CallI))
511 return true;
513 return error(Twine(MF.getName()) +
514 Twine(" call site info should reference call "
515 "instruction. Instruction at ") +
516 MILoc.Block.Value + " at offset:" + Twine(MILoc.Offset) +
517 " is not a call instruction");
519 for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
520 Register Reg;
521 if (parseNamedRegisterReference(PFS, Reg, ArgRegPair.Reg.Value, Error))
522 return error(Error, ArgRegPair.Reg.SourceRange);
523 CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
524 }
525 if (!YamlCSInfo.CalleeTypeIds.empty()) {
526 for (auto CalleeTypeId : YamlCSInfo.CalleeTypeIds) {
527 IntegerType *Int64Ty = Type::getInt64Ty(Context);
528 CSInfo.CalleeTypeIds.push_back(ConstantInt::get(Int64Ty, CalleeTypeId,
529 /*isSigned=*/false));
530 }
531 }
532
534 MF.addCallSiteInfo(&*CallI, std::move(CSInfo));
535 }
536
537 if (!YamlMF.CallSitesInfo.empty() &&
539 return error("call site info provided but not used");
540 return false;
541}
542
543void MIRParserImpl::setupDebugValueTracking(
545 const yaml::MachineFunction &YamlMF) {
546 // Compute the value of the "next instruction number" field.
547 unsigned MaxInstrNum = 0;
548 for (auto &MBB : MF)
549 for (auto &MI : MBB)
550 MaxInstrNum = std::max(MI.peekDebugInstrNum(), MaxInstrNum);
551 MF.setDebugInstrNumberingCount(MaxInstrNum);
552
553 // Load any substitutions.
554 for (const auto &Sub : YamlMF.DebugValueSubstitutions) {
555 MF.makeDebugValueSubstitution({Sub.SrcInst, Sub.SrcOp},
556 {Sub.DstInst, Sub.DstOp}, Sub.Subreg);
557 }
558
559 // Flag for whether we're supposed to be using DBG_INSTR_REF.
560 MF.setUseDebugInstrRef(YamlMF.UseDebugInstrRef);
561}
562
563bool
565 MachineFunction &MF) {
566 // TODO: Recreate the machine function.
567 if (Target) {
568 // Avoid clearing state if we're using the same subtarget again.
569 Target->setTarget(MF.getSubtarget());
570 } else {
571 Target.reset(new PerTargetMIParsingState(MF.getSubtarget()));
572 }
573
574 MF.setAlignment(YamlMF.Alignment.valueOrOne());
576 MF.setHasWinCFI(YamlMF.HasWinCFI);
577
581 MF.setHasEHScopes(YamlMF.HasEHScopes);
583 MF.setIsOutlined(YamlMF.IsOutlined);
584
586 if (YamlMF.Legalized)
587 Props.setLegalized();
588 if (YamlMF.RegBankSelected)
589 Props.setRegBankSelected();
590 if (YamlMF.Selected)
591 Props.setSelected();
592 if (YamlMF.FailedISel)
593 Props.setFailedISel();
594 if (YamlMF.FailsVerification)
595 Props.setFailsVerification();
596 if (YamlMF.TracksDebugUserValues)
597 Props.setTracksDebugUserValues();
598
599 PerFunctionMIParsingState PFS(MF, SM, IRSlots, *Target);
600 if (parseRegisterInfo(PFS, YamlMF))
601 return true;
602 if (initializePrefetchTargets(PFS, YamlMF))
603 return true;
604 if (!YamlMF.Constants.empty()) {
605 auto *ConstantPool = MF.getConstantPool();
606 assert(ConstantPool && "Constant pool must be created");
607 if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
608 return true;
609 }
610 if (!YamlMF.MachineMetadataNodes.empty() &&
611 parseMachineMetadataNodes(PFS, MF, YamlMF))
612 return true;
613
614 StringRef BlockStr = YamlMF.Body.Value.Value;
616 SourceMgr BlockSM;
617 BlockSM.AddNewSourceBuffer(
618 MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
619 SMLoc());
620 PFS.SM = &BlockSM;
621 if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
623 diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
624 return true;
625 }
626 // Check Basic Block Section Flags.
627 if (MF.hasBBSections()) {
629 }
630 PFS.SM = &SM;
631
632 // Initialize the frame information after creating all the MBBs so that the
633 // MBB references in the frame information can be resolved.
634 if (initializeFrameInfo(PFS, YamlMF))
635 return true;
636 // Initialize the jump table after creating all the MBBs so that the MBB
637 // references can be resolved.
638 if (!YamlMF.JumpTableInfo.Entries.empty() &&
640 return true;
641 // Parse the machine instructions after creating all of the MBBs so that the
642 // parser can resolve the MBB references.
643 StringRef InsnStr = YamlMF.Body.Value.Value;
644 SourceMgr InsnSM;
645 InsnSM.AddNewSourceBuffer(
646 MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
647 SMLoc());
648 PFS.SM = &InsnSM;
649 if (parseMachineInstructions(PFS, InsnStr, Error)) {
651 diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
652 return true;
653 }
654 PFS.SM = &SM;
655
656 if (setupRegisterInfo(PFS, YamlMF))
657 return true;
658
659 if (YamlMF.MachineFuncInfo) {
660 const TargetMachine &TM = MF.getTarget();
661 // Note this is called after the initial constructor of the
662 // MachineFunctionInfo based on the MachineFunction, which may depend on the
663 // IR.
664
665 SMRange SrcRange;
667 SrcRange)) {
668 return error(Error, SrcRange);
669 }
670 }
671
672 // Set the reserved registers after parsing MachineFuncInfo. The target may
673 // have been recording information used to select the reserved registers
674 // there.
675 // FIXME: This is a temporary workaround until the reserved registers can be
676 // serialized.
678 MRI.freezeReservedRegs();
679
680 if (computeFunctionProperties(MF, YamlMF))
681 return true;
682
683 if (initializeCallSiteInfo(PFS, YamlMF))
684 return true;
685
686 if (parseCalledGlobals(PFS, MF, YamlMF))
687 return true;
688
689 if (initializePrefetchTargets(PFS, YamlMF))
690 return true;
691
692 setupDebugValueTracking(MF, PFS, YamlMF);
693
695
696 MF.verify(nullptr, nullptr, &errs());
697 return false;
698}
699
702 MachineFunction &MF = PFS.MF;
705 for (const auto &YamlTarget : YamlMF.PrefetchTargets) {
706 CallsiteID Target;
707 if (llvm::parsePrefetchTarget(PFS, Target, YamlTarget.Value, Error))
708 return error(Error, YamlTarget.SourceRange);
709 Targets[Target.BBID].push_back(Target.CallsiteIndex);
710 }
711 MF.setPrefetchTargets(Targets);
712 return false;
713}
714
716 const yaml::MachineFunction &YamlMF) {
717 MachineFunction &MF = PFS.MF;
718 MachineRegisterInfo &RegInfo = MF.getRegInfo();
719 assert(RegInfo.tracksLiveness());
720 if (!YamlMF.TracksRegLiveness)
721 RegInfo.invalidateLiveness();
722
724 // Parse the virtual register information.
725 for (const auto &VReg : YamlMF.VirtualRegisters) {
726 VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
727 if (Info.Explicit)
728 return error(VReg.ID.SourceRange.Start,
729 Twine("redefinition of virtual register '%") +
730 Twine(VReg.ID.Value) + "'");
731 Info.Explicit = true;
732
733 if (VReg.Class.Value == "_") {
734 Info.Kind = VRegInfo::GENERIC;
735 Info.D.RegBank = nullptr;
736 } else {
737 const auto *RC = Target->getRegClass(VReg.Class.Value);
738 if (RC) {
739 Info.Kind = VRegInfo::NORMAL;
740 Info.D.RC = RC;
741 } else {
742 const RegisterBank *RegBank = Target->getRegBank(VReg.Class.Value);
743 if (!RegBank)
744 return error(
745 VReg.Class.SourceRange.Start,
746 Twine("use of undefined register class or register bank '") +
747 VReg.Class.Value + "'");
748 Info.Kind = VRegInfo::REGBANK;
749 Info.D.RegBank = RegBank;
750 }
751 }
752
753 if (!VReg.PreferredRegister.Value.empty()) {
754 if (Info.Kind != VRegInfo::NORMAL)
755 return error(VReg.Class.SourceRange.Start,
756 Twine("preferred register can only be set for normal vregs"));
757
758 if (parseRegisterReference(PFS, Info.PreferredReg,
759 VReg.PreferredRegister.Value, Error))
760 return error(Error, VReg.PreferredRegister.SourceRange);
761 }
762
763 for (const auto &FlagStringValue : VReg.RegisterFlags) {
764 uint8_t FlagValue;
765 if (Target->getVRegFlagValue(FlagStringValue.Value, FlagValue))
766 return error(FlagStringValue.SourceRange.Start,
767 Twine("use of undefined register flag '") +
768 FlagStringValue.Value + "'");
769 Info.Flags |= FlagValue;
770 }
771 if (!VReg.AntiHints.empty() && Info.Kind != VRegInfo::NORMAL)
772 return error(VReg.AntiHints.front().SourceRange.Start,
773 "anti-hints can only be set for normal vregs");
774
775 for (const auto &AntiHintValue : VReg.AntiHints) {
776 Register AntiHintReg;
777 if (parseRegisterReference(PFS, AntiHintReg, AntiHintValue.Value, Error))
778 return error(Error, AntiHintValue.SourceRange);
779
780 if (!AntiHintReg.isVirtual()) {
781 return error(AntiHintValue.SourceRange.Start,
782 "anti-hint '" + Twine(AntiHintValue.Value) +
783 "' must be a virtual register");
784 }
785
786 Info.AntiHints.push_back(AntiHintReg);
787 }
788 RegInfo.noteNewVirtualRegister(Info.VReg);
789 }
790
791 // Parse the liveins.
792 for (const auto &LiveIn : YamlMF.LiveIns) {
793 Register Reg;
794 if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
795 return error(Error, LiveIn.Register.SourceRange);
796 Register VReg;
797 if (!LiveIn.VirtualRegister.Value.empty()) {
798 VRegInfo *Info;
799 if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
800 Error))
801 return error(Error, LiveIn.VirtualRegister.SourceRange);
802 VReg = Info->VReg;
803 }
804 RegInfo.addLiveIn(Reg, VReg);
805 }
806
807 // Parse the callee saved registers (Registers that will
808 // be saved for the caller).
809 if (YamlMF.CalleeSavedRegisters) {
810 SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
811 for (const auto &RegSource : *YamlMF.CalleeSavedRegisters) {
812 Register Reg;
813 if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
814 return error(Error, RegSource.SourceRange);
815 CalleeSavedRegisters.push_back(Reg.id());
816 }
817 RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
818 }
819
820 // Stash any VirtRegMap state on MRI.
821 // VirtRegMap::init() will use that information to get pre-populated
822 // on the first analysis run.
823 for (const auto &VReg : YamlMF.VirtualRegisters) {
824 if (VReg.SplitFrom.Value.empty() && VReg.AssignedPhys.Value.empty())
825 continue;
826
827 auto It = PFS.VRegInfos.find(VReg.ID.Value);
828 if (It == PFS.VRegInfos.end())
829 continue;
830 Register ChildReg = It->second->VReg;
831
833 Pending.VReg = ChildReg;
834
835 if (!VReg.SplitFrom.Value.empty()) {
836 VRegInfo *Parent = nullptr;
837 if (parseVirtualRegisterReference(PFS, Parent, VReg.SplitFrom.Value,
838 Error))
839 return error(Error, VReg.SplitFrom.SourceRange);
840 if (Parent->VReg == ChildReg)
841 return error(VReg.SplitFrom.SourceRange.Start,
842 Twine("'split-from' references the same vreg as 'id' (%") +
843 Twine(VReg.ID.Value) + ")");
844 Pending.SplitFrom = Parent->VReg;
845 }
846 if (!VReg.AssignedPhys.Value.empty()) {
847 Register Phys;
848 if (parseRegisterReference(PFS, Phys, VReg.AssignedPhys.Value, Error))
849 return error(Error, VReg.AssignedPhys.SourceRange);
850 if (!Phys.isPhysical())
851 return error(
852 VReg.AssignedPhys.SourceRange.Start,
853 Twine("'assigned-phys' must be a physical register, got '") +
854 VReg.AssignedPhys.Value + "'");
855 Pending.AssignedPhys = Phys.asMCReg();
856 }
857 RegInfo.addPendingVirtRegMapEntry(Pending);
858 }
859
860 return false;
861}
862
864 const yaml::MachineFunction &YamlMF) {
865 MachineFunction &MF = PFS.MF;
868
870
871 // Create VRegs
872 auto populateVRegInfo = [&](const VRegInfo &Info, const Twine &Name) {
873 Register Reg = Info.VReg;
874 switch (Info.Kind) {
876 Errors.push_back(
877 (Twine("Cannot determine class/bank of virtual register ") + Name +
878 " in function '" + MF.getName() + "'")
879 .str());
880 break;
881 case VRegInfo::NORMAL:
882 if (!Info.D.RC->isAllocatable()) {
883 Errors.push_back((Twine("Cannot use non-allocatable class '") +
884 TRI->getRegClassName(Info.D.RC) +
885 "' for virtual register " + Name + " in function '" +
886 MF.getName() + "'")
887 .str());
888 break;
889 }
890
891 MRI.setRegClass(Reg, Info.D.RC);
892 if (Info.PreferredReg != 0)
893 MRI.setSimpleHint(Reg, Info.PreferredReg);
894 if (!Info.AntiHints.empty())
895 MRI.addRegAllocationAntiHints(Reg, Info.AntiHints);
896 break;
898 break;
900 MRI.setRegBank(Reg, *Info.D.RegBank);
901 break;
902 }
903 };
904
905 for (const auto &P : PFS.VRegInfosNamed) {
906 const VRegInfo &Info = *P.second;
907 populateVRegInfo(Info, Twine(P.first()));
908 }
909
910 for (auto P : PFS.VRegInfos) {
911 const VRegInfo &Info = *P.second;
912 populateVRegInfo(Info, Twine(P.first.id()));
913 }
914
915 // Compute MachineRegisterInfo::UsedPhysRegMask
916 for (const MachineBasicBlock &MBB : MF) {
917 // Make sure MRI knows about registers clobbered by unwinder.
918 if (MBB.isEHPad())
919 if (auto *RegMask = TRI->getCustomEHPadPreservedMask(MF))
920 MRI.addPhysRegsUsedFromRegMask(RegMask);
921
922 for (const MachineInstr &MI : MBB) {
923 for (const MachineOperand &MO : MI.operands()) {
924 if (!MO.isRegMask())
925 continue;
927 }
928 }
929 }
930
931 if (Errors.empty())
932 return false;
933
934 // Report errors in a deterministic order.
935 sort(Errors);
936 for (auto &E : Errors)
937 error(E);
938 return true;
939}
940
942 const yaml::MachineFunction &YamlMF) {
943 MachineFunction &MF = PFS.MF;
944 MachineFrameInfo &MFI = MF.getFrameInfo();
946 const Function &F = MF.getFunction();
947 const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
950 MFI.setHasStackMap(YamlMFI.HasStackMap);
951 MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
952 MFI.setStackSize(YamlMFI.StackSize);
954 if (YamlMFI.MaxAlignment)
956 MFI.setAdjustsStack(YamlMFI.AdjustsStack);
957 MFI.setHasCalls(YamlMFI.HasCalls);
960 if (YamlMFI.MaxCallFrameSize != ~0u)
964 MFI.setHasVAStart(YamlMFI.HasVAStart);
966 MFI.setHasTailCall(YamlMFI.HasTailCall);
969 llvm::SaveRestorePoints SavePoints;
970 if (initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, SavePoints))
971 return true;
972 MFI.setSavePoints(SavePoints);
973 llvm::SaveRestorePoints RestorePoints;
974 if (initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints, RestorePoints))
975 return true;
976 MFI.setRestorePoints(RestorePoints);
977
978 std::vector<CalleeSavedInfo> CSIInfo;
979 // Initialize the fixed frame objects.
980 for (const auto &Object : YamlMF.FixedStackObjects) {
981 int ObjectIdx;
983 ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
984 Object.IsImmutable, Object.IsAliased);
985 else
986 ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
987
988 if (!TFI->isSupportedStackID(Object.StackID))
989 return error(Object.ID.SourceRange.Start,
990 Twine("StackID is not supported by target"));
991 MFI.setStackID(ObjectIdx, Object.StackID);
992 MFI.setObjectAlignment(ObjectIdx, Object.Alignment.valueOrOne());
993 if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
994 ObjectIdx))
995 .second)
996 return error(Object.ID.SourceRange.Start,
997 Twine("redefinition of fixed stack object '%fixed-stack.") +
998 Twine(Object.ID.Value) + "'");
999 if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
1000 Object.CalleeSavedRestored, ObjectIdx))
1001 return true;
1002 if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
1003 return true;
1004 }
1005
1006 for (const auto &Object : YamlMF.EntryValueObjects) {
1008 Register Reg;
1009 if (parseNamedRegisterReference(PFS, Reg, Object.EntryValueRegister.Value,
1010 Error))
1011 return error(Error, Object.EntryValueRegister.SourceRange);
1012 if (!Reg.isPhysical())
1013 return error(Object.EntryValueRegister.SourceRange.Start,
1014 "Expected physical register for entry value field");
1015 std::optional<VarExprLoc> MaybeInfo = parseVarExprLoc(
1016 PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
1017 if (!MaybeInfo)
1018 return true;
1019 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1020 PFS.MF.setVariableDbgInfo(MaybeInfo->DIVar, MaybeInfo->DIExpr,
1021 Reg.asMCReg(), MaybeInfo->DILoc);
1022 }
1023
1024 // Initialize the ordinary frame objects.
1025 for (const auto &Object : YamlMF.StackObjects) {
1026 int ObjectIdx;
1027 const AllocaInst *Alloca = nullptr;
1028 const yaml::StringValue &Name = Object.Name;
1029 if (!Name.Value.empty()) {
1031 F.getValueSymbolTable()->lookup(Name.Value));
1032 if (!Alloca)
1033 return error(Name.SourceRange.Start,
1034 "alloca instruction named '" + Name.Value +
1035 "' isn't defined in the function '" + F.getName() +
1036 "'");
1037 }
1038 if (!TFI->isSupportedStackID(Object.StackID))
1039 return error(Object.ID.SourceRange.Start,
1040 Twine("StackID is not supported by target"));
1041 if (Object.Type == yaml::MachineStackObject::VariableSized)
1042 ObjectIdx =
1043 MFI.CreateVariableSizedObject(Object.Alignment.valueOrOne(), Alloca);
1044 else
1045 ObjectIdx = MFI.CreateStackObject(
1046 Object.Size, Object.Alignment.valueOrOne(),
1047 Object.Type == yaml::MachineStackObject::SpillSlot, Alloca,
1048 Object.StackID);
1049 MFI.setObjectOffset(ObjectIdx, Object.Offset);
1050
1051 if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
1052 .second)
1053 return error(Object.ID.SourceRange.Start,
1054 Twine("redefinition of stack object '%stack.") +
1055 Twine(Object.ID.Value) + "'");
1056 if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
1057 Object.CalleeSavedRestored, ObjectIdx))
1058 return true;
1059 if (Object.LocalOffset)
1060 MFI.mapLocalFrameObject(ObjectIdx, *Object.LocalOffset);
1061 if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
1062 return true;
1063 }
1064 MFI.setCalleeSavedInfo(CSIInfo);
1065 if (!CSIInfo.empty())
1066 MFI.setCalleeSavedInfoValid(true);
1067
1068 // Initialize the various stack object references after initializing the
1069 // stack objects.
1070 if (!YamlMFI.StackProtector.Value.empty()) {
1072 int FI;
1073 if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
1074 return error(Error, YamlMFI.StackProtector.SourceRange);
1075 MFI.setStackProtectorIndex(FI);
1076 }
1077
1078 if (!YamlMFI.FunctionContext.Value.empty()) {
1080 int FI;
1082 return error(Error, YamlMFI.FunctionContext.SourceRange);
1084 }
1085
1086 return false;
1087}
1088
1090 std::vector<CalleeSavedInfo> &CSIInfo,
1091 const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
1092 if (RegisterSource.Value.empty())
1093 return false;
1094 Register Reg;
1096 if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
1097 return error(Error, RegisterSource.SourceRange);
1098 CalleeSavedInfo CSI(Reg, FrameIdx);
1099 CSI.setRestored(IsRestored);
1100 CSIInfo.push_back(CSI);
1101 return false;
1102}
1103
1104/// Verify that given node is of a certain type. Return true on error.
1105template <typename T>
1106static bool typecheckMDNode(T *&Result, MDNode *Node,
1107 const yaml::StringValue &Source,
1108 StringRef TypeString, MIRParserImpl &Parser) {
1109 if (!Node)
1110 return false;
1111 Result = dyn_cast<T>(Node);
1112 if (!Result)
1113 return Parser.error(Source.SourceRange.Start,
1114 "expected a reference to a '" + TypeString +
1115 "' metadata node");
1116 return false;
1117}
1118
1119std::optional<MIRParserImpl::VarExprLoc> MIRParserImpl::parseVarExprLoc(
1120 PerFunctionMIParsingState &PFS, const yaml::StringValue &VarStr,
1121 const yaml::StringValue &ExprStr, const yaml::StringValue &LocStr) {
1122 MDNode *Var = nullptr;
1123 MDNode *Expr = nullptr;
1124 MDNode *Loc = nullptr;
1125 if (parseMDNode(PFS, Var, VarStr) || parseMDNode(PFS, Expr, ExprStr) ||
1126 parseMDNode(PFS, Loc, LocStr))
1127 return std::nullopt;
1128 DILocalVariable *DIVar = nullptr;
1129 DIExpression *DIExpr = nullptr;
1130 DILocation *DILoc = nullptr;
1131 if (typecheckMDNode(DIVar, Var, VarStr, "DILocalVariable", *this) ||
1132 typecheckMDNode(DIExpr, Expr, ExprStr, "DIExpression", *this) ||
1133 typecheckMDNode(DILoc, Loc, LocStr, "DILocation", *this))
1134 return std::nullopt;
1135 return VarExprLoc{DIVar, DIExpr, DILoc};
1136}
1137
1138template <typename T>
1140 const T &Object, int FrameIdx) {
1141 std::optional<VarExprLoc> MaybeInfo =
1142 parseVarExprLoc(PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
1143 if (!MaybeInfo)
1144 return true;
1145 // Debug information can only be attached to stack objects; Fixed stack
1146 // objects aren't supported.
1147 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1148 PFS.MF.setVariableDbgInfo(MaybeInfo->DIVar, MaybeInfo->DIExpr, FrameIdx,
1149 MaybeInfo->DILoc);
1150 return false;
1151}
1152
1153bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
1154 MDNode *&Node, const yaml::StringValue &Source) {
1155 if (Source.Value.empty())
1156 return false;
1158 if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
1159 return error(Error, Source.SourceRange);
1160 return false;
1161}
1162
1165 DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
1166 const MachineFunction &MF = PFS.MF;
1167 const auto &M = *MF.getFunction().getParent();
1169 for (const auto &YamlConstant : YamlMF.Constants) {
1170 if (YamlConstant.IsTargetSpecific)
1171 // FIXME: Support target-specific constant pools
1172 return error(YamlConstant.Value.SourceRange.Start,
1173 "Can't parse target-specific constant pool entries yet");
1175 parseConstantValue(YamlConstant.Value.Value, Error, M));
1176 if (!Value)
1177 return error(Error, YamlConstant.Value.SourceRange);
1178 const Align PrefTypeAlign =
1179 M.getDataLayout().getPrefTypeAlign(Value->getType());
1180 const Align Alignment = YamlConstant.Alignment.value_or(PrefTypeAlign);
1181 unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
1182 if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
1183 .second)
1184 return error(YamlConstant.ID.SourceRange.Start,
1185 Twine("redefinition of constant pool item '%const.") +
1186 Twine(YamlConstant.ID.Value) + "'");
1187 }
1188 return false;
1189}
1190
1191// Return true if basic block was incorrectly specified in MIR
1194 const std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
1197 MachineBasicBlock *MBB = nullptr;
1198 for (const yaml::SaveRestorePointEntry &Entry : YamlSRPoints) {
1199 if (parseMBBReference(PFS, MBB, Entry.Point.Value))
1200 return true;
1201
1202 std::vector<CalleeSavedInfo> Registers;
1203 for (auto &RegStr : Entry.Registers) {
1204 Register Reg;
1205 if (parseNamedRegisterReference(PFS, Reg, RegStr.Value, Error))
1206 return error(Error, RegStr.SourceRange);
1207 Registers.push_back(CalleeSavedInfo(Reg));
1208 }
1209 SaveRestorePoints.try_emplace(MBB, std::move(Registers));
1210 }
1211 return false;
1212}
1213
1215 const yaml::MachineJumpTable &YamlJTI) {
1217 for (const auto &Entry : YamlJTI.Entries) {
1218 std::vector<MachineBasicBlock *> Blocks;
1219 for (const auto &MBBSource : Entry.Blocks) {
1220 MachineBasicBlock *MBB = nullptr;
1221 if (parseMBBReference(PFS, MBB, MBBSource.Value))
1222 return true;
1223 Blocks.push_back(MBB);
1224 }
1225 unsigned Index = JTI->createJumpTableIndex(Blocks);
1226 if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
1227 .second)
1228 return error(Entry.ID.SourceRange.Start,
1229 Twine("redefinition of jump table entry '%jump-table.") +
1230 Twine(Entry.ID.Value) + "'");
1231 }
1232 return false;
1233}
1234
1235bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
1237 const yaml::StringValue &Source) {
1239 if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
1240 return error(Error, Source.SourceRange);
1241 return false;
1242}
1243
1246 const yaml::MachineFunction &YMF) {
1247 SmallVector<StringRef> Definitions;
1248 for (const auto &MDS : YMF.MachineMetadataNodes)
1249 Definitions.push_back(MDS.Value);
1250
1251 SlotMapping Slots = PFS.IRSlots;
1253 unsigned ErrorDefinitionIndex = 0;
1254 if (parseMetadataDefinitions(Definitions, Error,
1255 *MF.getFunction().getParent(), Slots,
1256 ErrorDefinitionIndex)) {
1257 const yaml::StringValue &Source =
1258 YMF.MachineMetadataNodes[ErrorDefinitionIndex];
1259 if (StringRef(Source.Value).contains('\n')) {
1260 reportDiagnostic(diagFromBlockStringDiag(Error, Source.SourceRange));
1261 return true;
1262 }
1263 return error(Error, Source.SourceRange);
1264 }
1265
1266 for (auto &[ID, MD] : Slots.MetadataNodes)
1267 if (PFS.IRSlots.MetadataNodes.find(ID) == PFS.IRSlots.MetadataNodes.end())
1268 PFS.MachineMetadataNodes.try_emplace(ID, MD);
1269 return false;
1270}
1271
1273 MachineFunction &MF,
1274 const yaml::MachineFunction &YMF) {
1275 Function &F = MF.getFunction();
1276 for (const auto &YamlCG : YMF.CalledGlobals) {
1277 const yaml::MachineInstrLoc &MILoc = YamlCG.CallSite;
1278 const MachineInstr *CallI;
1279 if (parseMachineInst(PFS, MILoc, CallI))
1280 return true;
1282 return error(Twine(MF.getName()) +
1283 Twine(" called global should reference call "
1284 "instruction. Instruction at ") +
1285 MILoc.Block.Value + " at offset:" + Twine(MILoc.Offset) +
1286 " is not a call instruction");
1287
1288 auto Callee =
1289 F.getParent()->getValueSymbolTable().lookup(YamlCG.Callee.Value);
1290 if (!Callee)
1291 return error(YamlCG.Callee.SourceRange.Start,
1292 "use of undefined global '" + YamlCG.Callee.Value + "'");
1293 if (!isa<GlobalValue>(Callee))
1294 return error(YamlCG.Callee.SourceRange.Start,
1295 "use of non-global value '" + YamlCG.Callee.Value + "'");
1296
1297 MF.addCalledGlobal(CallI, {cast<GlobalValue>(Callee), YamlCG.Flags});
1298 }
1299
1300 return false;
1301}
1302
1303SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
1304 SMRange SourceRange) {
1305 assert(SourceRange.isValid() && "Invalid source range");
1306 SMLoc Loc = SourceRange.Start;
1307 bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
1308 *Loc.getPointer() == '\'';
1309 // Translate the location of the error from the location in the MI string to
1310 // the corresponding location in the MIR file.
1311 Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
1312 (HasQuote ? 1 : 0));
1313
1314 // TODO: Translate any source ranges as well.
1315 return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), {},
1316 Error.getFixIts());
1317}
1318
1319SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
1320 SMRange SourceRange) {
1321 assert(SourceRange.isValid());
1322
1323 // Translate the location of the error from the location in the llvm IR string
1324 // to the corresponding location in the MIR file.
1325 auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
1326 unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
1327 unsigned Column = Error.getColumnNo();
1328 StringRef LineStr = Error.getLineContents();
1329 SMLoc Loc = Error.getLoc();
1330
1331 // Get the full line and adjust the column number by taking the indentation of
1332 // LLVM IR into account.
1333 for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
1334 L != E; ++L) {
1335 if (L.line_number() == Line) {
1336 LineStr = *L;
1337 Loc = SMLoc::getFromPointer(LineStr.data());
1338 auto Indent = LineStr.find(Error.getLineContents());
1339 if (Indent != StringRef::npos)
1340 Column += Indent;
1341 break;
1342 }
1343 }
1344
1345 return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
1346 Error.getMessage(), LineStr, Error.getRanges(),
1347 Error.getFixIts());
1348}
1349
1350MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
1351 : Impl(std::move(Impl)) {}
1352
1353MIRParser::~MIRParser() = default;
1354
1355std::unique_ptr<Module>
1357 return Impl->parseIRModule(DataLayoutCallback);
1358}
1359
1361 return Impl->parseMachineFunctions(M, MMI);
1362}
1363
1365 auto &MMI = MAM.getResult<MachineModuleAnalysis>(M).getMMI();
1366 return Impl->parseMachineFunctions(M, MMI, &MAM);
1367}
1368
1369std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(
1371 std::function<void(Function &)> ProcessIRFunction) {
1372 auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
1373 if (std::error_code EC = FileOrErr.getError()) {
1375 "could not open input file: " + EC.message());
1376 return nullptr;
1377 }
1378 return createMIRParser(std::move(FileOrErr.get()), Context,
1379 ProcessIRFunction);
1380}
1381
1382std::unique_ptr<MIRParser>
1383llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
1384 LLVMContext &Context,
1385 std::function<void(Function &)> ProcessIRFunction) {
1386 auto Filename = Contents->getBufferIdentifier();
1387 if (Context.shouldDiscardValueNames()) {
1388 Context.diagnose(DiagnosticInfoMIRParser(
1389 DS_Error,
1392 "cannot read MIR with a Context that discards named Values")));
1393 return nullptr;
1394 }
1395 return std::make_unique<MIRParser>(std::make_unique<MIRParserImpl>(
1396 std::move(Contents), Filename, Context, ProcessIRFunction));
1397}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Reserve WWM Registers
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
IRTranslator LLVM IR MI
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
static bool isSSA(const MachineFunction &MF)
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
static bool typecheckMDNode(T *&Result, MDNode *Node, const yaml::StringValue &Source, StringRef TypeString, MIRParserImpl &Parser)
Verify that given node is of a certain type. Return true on error.
static Function * getNextUnusedUnnamedFunction(const Module &M, Module::iterator &FirstUnvisitedFunction)
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Register Reg
Register const TargetRegisterInfo * TRI
#define T
static constexpr StringLiteral Filename
#define P(N)
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
#define error(X)
an instruction to allocate memory on the stack
LLVM Basic Block Representation.
Definition BasicBlock.h:62
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
This is an important base class in LLVM.
Definition Constant.h:43
DWARF expression.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.h:827
Diagnostic information for machine IR parser.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition Function.h:169
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:352
Module * getParent()
Get the module that this global value is contained inside of...
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
Metadata node.
Definition Metadata.h:1081
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
Definition MIRParser.cpp:51
bool error(const Twine &Message)
Report an error with the given message at unknown location.
void reportDiagnostic(const SMDiagnostic &Diag)
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM, Module::iterator &FirstUnvisitedFunction)
Parse the machine function in the current YAML document.
Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const T &Object, int FrameIdx)
bool initializeMachineFunction(const yaml::MachineFunction &YamlMF, MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback)
Try to parse the optional LLVM module and the machine functions in the MIR file.
bool initializePrefetchTargets(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction)
std::optional< VarExprLoc > parseVarExprLoc(PerFunctionMIParsingState &PFS, const yaml::StringValue &VarStr, const yaml::StringValue &ExprStr, const yaml::StringValue &LocStr)
bool parseCalledGlobals(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx)
bool parseMachineMetadataNodes(PerFunctionMIParsingState &PFS, MachineFunction &MF, const yaml::MachineFunction &YMF)
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS, const std::vector< yaml::SaveRestorePointEntry > &YamlSRPoints, llvm::SaveRestorePoints &SaveRestorePoints)
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI, ModuleAnalysisManager *FAM=nullptr)
LLVM_ABI MIRParser(std::unique_ptr< MIRParserImpl > Impl)
LLVM_ABI std::unique_ptr< Module > parseIRModule(DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;})
Parses the optional LLVM IR module in the MIR file.
LLVM_ABI bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI.
LLVM_ABI ~MIRParser()
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
void setMaxCallFrameSize(uint64_t S)
LLVM_ABI int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
LLVM_ABI void ensureMaxAlignment(Align Alignment)
Make sure the function's frame is at least Align bytes aligned.
void setHasPatchPoint(bool s=true)
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
void setFrameAddressIsTaken(bool T)
void setHasStackMap(bool s=true)
void setSavePoints(SaveRestorePoints NewSavePoints)
void setFramePointerPolicy(FramePointerKind Kind)
void setCVBytesOfCalleeSavedRegisters(unsigned S)
void setStackID(int ObjectIdx, uint8_t ID)
void setHasTailCall(bool V=true)
void setCalleeSavedInfoValid(bool v)
void setReturnAddressIsTaken(bool s)
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
void setHasOpaqueSPAdjustment(bool B)
void setCalleeSavedInfo(std::vector< CalleeSavedInfo > CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
LLVM_ABI int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created.
void setRestorePoints(SaveRestorePoints NewRestorePoints)
LLVM_ABI int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
void setStackSize(uint64_t Size)
Set the size of the stack.
void setHasMustTailInVarArgFunc(bool B)
void setObjectAlignment(int ObjectIdx, Align Alignment)
setObjectAlignment - Change the alignment of the specified stack object.
void setOffsetAdjustment(int64_t Adj)
Set the correction for frame offsets.
void setFunctionContextIndex(int I)
This analysis create MachineFunction for given Function.
Properties which a MachineFunction may have at a given point in time.
void setCallsUnwindInit(bool b)
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist,...
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
void setAlignment(Align A)
setAlignment - Set the alignment of the function.
void setPrefetchTargets(const DenseMap< UniqueBBID, SmallVector< unsigned > > &V)
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
bool hasBBSections() const
Returns true if this function has basic block sections enabled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, raw_ostream *OS=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use.
Function & getFunction()
Return the LLVM function that this machine code represents.
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
void addCallSiteInfo(const MachineInstr *CallI, CallSiteInfo &&CallInfo)
Start tracking the arguments passed to the call CallI.
const MachineFunctionProperties & getProperties() const
Get the function properties.
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable in a stack slot.
void setHasEHContTarget(bool V)
void addCalledGlobal(const MachineInstr *MI, CalledGlobalInfo Details)
Notes the global and target flags for a call site.
void assignBeginEndSections()
Assign IsBeginSection IsEndSection fields for basic blocks in this function.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
bool isCall(QueryType Type=AnyInBundle) const
LLVM_ABI unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
An analysis that produces MachineModuleInfo for a module.
This class contains meta information specific to a module.
LLVM_ABI MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
const TargetMachine & getTarget() const
LLVM_ABI MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
Register getReg() const
getReg - Returns the register number.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI void freezeReservedRegs()
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
void addRegAllocationAntiHints(Register VReg, ArrayRef< Register > AntiHintVRegs)
Add multiple anti-hints at once.
MachineOperand * getOneDef(Register Reg) const
Returns the defining operand if there is exactly one operand defining the specified register,...
bool def_empty(Register RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_ABI void setRegBank(Register Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
void setSimpleHint(Register VReg, Register PrefReg)
Specify the preferred (target independent) register allocation hint for the specified virtual registe...
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
FunctionListType::iterator iterator
The Function iterators.
Definition Module.h:93
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
Definition Register.h:107
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:307
SourceMgr::DiagKind getKind() const
Definition SourceMgr.h:337
Represents a location in source code.
Definition SMLoc.h:22
static SMLoc getFromPointer(const char *Ptr)
Definition SMLoc.h:35
constexpr const char * getPointer() const
Definition SMLoc.h:33
Represents a range in source code.
Definition SMLoc.h:47
bool isValid() const
Definition SMLoc.h:57
SMLoc Start
Definition SMLoc.h:49
SMLoc End
Definition SMLoc.h:49
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:34
unsigned getMainFileID() const
Definition SourceMgr.h:150
LLVM_ABI std::pair< unsigned, unsigned > getLineAndColumn(SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition SourceMgr.h:141
LLVM_ABI SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition SourceMgr.h:162
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
static constexpr size_t npos
Definition StringRef.h:58
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
constexpr const char * data() const
Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:138
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Definition StringRef.h:446
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition StringRef.h:290
Information about stack frame layout on the target.
virtual bool isSupportedStackID(TargetStackID::Value ID) const
Primary interface to the complete machine description for the target machine.
TargetOptions Options
virtual yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
virtual bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
unsigned EmitCallSiteInfo
The flag enables call site info production.
unsigned EmitCallGraphSection
Emit section containing call graph metadata.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual void mirFileLoaded(MachineFunction &MF) const
This is called after a .mir file was loaded.
virtual const TargetFrameLowering * getFrameLowering() const
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:300
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:272
This function has undefined behavior.
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:257
A forward iterator which reads text lines from a buffer.
The Input class is used to parse a yaml document into in-memory structs and vectors.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
EnumSet< Property > Properties
std::enable_if_t< has_ScalarEnumerationTraits< T >::value, void > yamlize(IO &io, T &Val, bool, EmptyContext &Ctx)
Definition YAMLTraits.h:888
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
LLVM_ABI std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, DataLayoutCallbackTy DataLayoutCallback=[](StringRef, StringRef) { return std::nullopt;}, AsmParserContext *ParserContext=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition Parser.cpp:53
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
LLVM_ABI bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
LLVM_ABI bool parsePrefetchTarget(PerFunctionMIParsingState &PFS, CallsiteID &Target, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMetadataDefinitions(ArrayRef< StringRef > Definitions, SMDiagnostic &Err, const Module &M, SlotMapping &Slots, unsigned &ErrorDefinitionIndex)
Parse standalone metadata definitions using and updating the supplied slot mapping.
Definition Parser.cpp:253
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
DenseMap< MachineBasicBlock *, std::vector< CalleeSavedInfo > > SaveRestorePoints
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1652
LLVM_ABI std::unique_ptr< MIRParser > createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is the main interface to the MIR serialization format parser.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction=nullptr)
This function is another interface to the MIR serialization format parser.
llvm::function_ref< std::optional< std::string >(StringRef, StringRef)> DataLayoutCallbackTy
Definition Parser.h:37
@ Sub
Subtraction of integers.
LLVM_ABI bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
LLVM_ABI bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
LLVM_ABI Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
Definition Parser.cpp:197
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
LLVM_ABI bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
SmallVector< ConstantInt *, 4 > CalleeTypeIds
Callee type ids.
SmallVector< ArgRegPair, 1 > ArgRegPairs
Vector of call argument and its forwarding register.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:135
DenseMap< unsigned, unsigned > JumpTableSlots
Definition MIParser.h:184
LLVM_ABI VRegInfo & getVRegInfo(Register Num)
Definition MIParser.cpp:329
DenseMap< unsigned, int > FixedStackObjectSlots
Definition MIParser.h:181
const SlotMapping & IRSlots
Definition MIParser.h:173
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition MIParser.h:183
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:180
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition MIParser.h:176
DenseMap< unsigned, int > StackObjectSlots
Definition MIParser.h:182
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:179
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition SlotMapping.h:32
std::map< unsigned, TrackingMDNodeRef > MetadataNodes
Definition SlotMapping.h:34
Register VReg
Definition MIParser.h:48
constexpr EnumSet & set(Enum E)
Definition OMP.h:115
constexpr EnumSet & reset(Enum E)
Definition OMP.h:111
Serializable representation of MachineFrameInfo.
std::vector< SaveRestorePointEntry > RestorePoints
unsigned MaxCallFrameSize
~0u means: not computed yet.
FramePointerKind FramePointerPolicy
std::vector< SaveRestorePointEntry > SavePoints
std::vector< MachineStackObject > StackObjects
std::vector< StringValue > MachineMetadataNodes
std::optional< std::vector< FlowStringValue > > CalleeSavedRegisters
std::vector< CalledGlobal > CalledGlobals
std::optional< bool > HasFakeUses
std::vector< EntryValueObject > EntryValueObjects
std::optional< bool > NoPHIs
std::vector< FlowStringValue > PrefetchTargets
std::vector< MachineConstantPoolValue > Constants
std::optional< bool > NoVRegs
std::vector< CallSiteInfo > CallSitesInfo
std::vector< MachineFunctionLiveIn > LiveIns
std::vector< VirtualRegisterDefinition > VirtualRegisters
std::vector< FixedMachineStackObject > FixedStackObjects
std::optional< bool > IsSSA
std::vector< DebugValueSubstitution > DebugValueSubstitutions
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
Identifies call instruction location in machine function.
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
A wrapper around std::string which contains a source range that's being set during parsing.