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(MachineFunction &MF, yaml::MachineInstrLoc MILoc,
197 MachineInstr const *&MI);
198};
199
200} // end namespace llvm
201
202static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
203 reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
204}
205
206MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
207 StringRef Filename, LLVMContext &Context,
208 std::function<void(Function &)> Callback)
209 : Context(Context),
210 In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
211 ->getBuffer(),
212 nullptr, handleYAMLDiag, this),
213 Filename(Filename), ProcessIRFunction(Callback) {
214 In.setContext(&In);
215}
216
217bool MIRParserImpl::error(const Twine &Message) {
218 Context.diagnose(DiagnosticInfoMIRParser(
219 DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
220 return true;
221}
222
223bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
224 Context.diagnose(DiagnosticInfoMIRParser(
225 DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
226 return true;
227}
228
230 assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
231 reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
232 return true;
233}
234
237 switch (Diag.getKind()) {
239 Kind = DS_Error;
240 break;
242 Kind = DS_Warning;
243 break;
245 Kind = DS_Note;
246 break;
248 llvm_unreachable("remark unexpected");
249 break;
250 }
251 Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
252}
253
254std::unique_ptr<Module>
256 if (!In.setCurrentDocument()) {
257 if (In.error())
258 return nullptr;
259 // Create an empty module when the MIR file is empty.
260 NoMIRDocuments = true;
261 auto M = std::make_unique<Module>(Filename, Context);
262 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
263 M->getDataLayoutStr()))
264 M->setDataLayout(*LayoutOverride);
265 return M;
266 }
267
268 std::unique_ptr<Module> M;
269 // Parse the block scalar manually so that we can return unique pointer
270 // without having to go trough YAML traits.
271 if (const auto *BSN =
272 dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
274 M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
275 Context, &IRSlots, DataLayoutCallback);
276 if (!M) {
277 reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
278 return nullptr;
279 }
280 In.nextDocument();
281 if (!In.setCurrentDocument())
282 NoMIRDocuments = true;
283 } else {
284 // Create an new, empty module.
285 M = std::make_unique<Module>(Filename, Context);
286 if (auto LayoutOverride = DataLayoutCallback(M->getTargetTriple().str(),
287 M->getDataLayoutStr()))
288 M->setDataLayout(*LayoutOverride);
289 NoLLVMIR = true;
290 }
291 return M;
292}
293
296 if (NoMIRDocuments)
297 return false;
298
299 // Parse the machine functions.
300 auto FirstUnvisitedFunction = M.begin();
301 do {
302 if (parseMachineFunction(M, MMI, MAM, FirstUnvisitedFunction))
303 return true;
304 In.nextDocument();
305 } while (In.setCurrentDocument());
306
307 return false;
308}
309
311 auto &Context = M.getContext();
312 Function *F =
315 BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
316 new UnreachableInst(Context, BB);
317
318 if (ProcessIRFunction)
319 ProcessIRFunction(*F);
320
321 return F;
322}
323
324static Function *
326 Module::iterator &FirstUnvisitedFunction) {
327 for (; FirstUnvisitedFunction != M.end(); ++FirstUnvisitedFunction)
328 if (!FirstUnvisitedFunction->hasName())
329 return &*FirstUnvisitedFunction++;
330
331 return nullptr;
332}
333
336 Module::iterator &FirstUnvisitedFunction) {
337 // Parse the yaml.
340
341 const TargetMachine &TM = MMI.getTarget();
342 YamlMF.MachineFuncInfo = std::unique_ptr<yaml::MachineFunctionInfo>(
344
345 yaml::yamlize(In, YamlMF, false, Ctx);
346 if (In.error())
347 return true;
348
349 // Search for the corresponding IR function.
350 StringRef FunctionName = YamlMF.Name;
351 Function *F = M.getFunction(FunctionName);
352 if (!F) {
353 if (NoLLVMIR) {
354 F = createDummyFunction(FunctionName, M);
355 } else if (!FunctionName.empty() ||
356 !(F = getNextUnusedUnnamedFunction(M, FirstUnvisitedFunction))) {
357 return error(Twine("function '") + FunctionName +
358 "' isn't defined in the provided LLVM IR");
359 }
360 }
361
362 if (!MAM) {
363 if (MMI.getMachineFunction(*F) != nullptr)
364 return error(Twine("redefinition of machine function '") + FunctionName +
365 "'");
366
367 // Create the MachineFunction.
369 if (initializeMachineFunction(YamlMF, MF))
370 return true;
371 } else {
372 auto &FAM =
373 MAM->getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
374 if (FAM.getCachedResult<MachineFunctionAnalysis>(*F))
375 return error(Twine("redefinition of machine function '") + FunctionName +
376 "'");
377
378 // Create the MachineFunction.
379 MachineFunction &MF = FAM.getResult<MachineFunctionAnalysis>(*F).getMF();
380 if (initializeMachineFunction(YamlMF, MF))
381 return true;
382 }
383
384 return false;
385}
386
387static bool isSSA(const MachineFunction &MF) {
388 const MachineRegisterInfo &MRI = MF.getRegInfo();
389 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
391 if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
392 return false;
393
394 // Subregister defs are invalid in SSA.
395 const MachineOperand *RegDef = MRI.getOneDef(Reg);
396 if (RegDef && RegDef->getSubReg() != 0)
397 return false;
398 }
399 return true;
400}
401
402bool MIRParserImpl::computeFunctionProperties(
403 MachineFunction &MF, const yaml::MachineFunction &YamlMF) {
404 MachineFunctionProperties &Properties = MF.getProperties();
405
406 bool HasPHI = false;
407 bool HasInlineAsm = false;
408 bool HasFakeUses = false;
409 bool AllTiedOpsRewritten = true, HasTiedOps = false;
410 for (const MachineBasicBlock &MBB : MF) {
411 for (const MachineInstr &MI : MBB) {
412 if (MI.isPHI())
413 HasPHI = true;
414 if (MI.isInlineAsm())
415 HasInlineAsm = true;
416 if (MI.isFakeUse())
417 HasFakeUses = true;
418 for (unsigned I = 0; I < MI.getNumOperands(); ++I) {
419 const MachineOperand &MO = MI.getOperand(I);
420 if (!MO.isReg() || !MO.getReg())
421 continue;
422 unsigned DefIdx;
423 if (MO.isUse() && MI.isRegTiedToDefOperand(I, &DefIdx)) {
424 HasTiedOps = true;
425 if (MO.getReg() != MI.getOperand(DefIdx).getReg())
426 AllTiedOpsRewritten = false;
427 }
428 }
429 }
430 }
431
432 // Helper function to sanity-check and set properties that are computed, but
433 // may be explicitly set from the input MIR
434 auto ComputedPropertyHelper =
435 [&Properties](std::optional<bool> ExplicitProp, bool ComputedProp,
437 // Prefer explicitly given values over the computed properties
438 if (ExplicitProp.value_or(ComputedProp))
440 else
442
443 // Check for conflict between the explicit values and the computed ones
444 return ExplicitProp && *ExplicitProp && !ComputedProp;
445 };
446
447 if (ComputedPropertyHelper(YamlMF.NoPHIs, !HasPHI,
449 return error(MF.getName() +
450 " has explicit property NoPhi, but contains at least one PHI");
451 }
452
453 MF.setHasInlineAsm(HasInlineAsm);
454
455 if (HasTiedOps && AllTiedOpsRewritten)
456 Properties.setTiedOpsRewritten();
457
458 if (ComputedPropertyHelper(YamlMF.IsSSA, isSSA(MF),
460 return error(MF.getName() +
461 " has explicit property IsSSA, but is not valid SSA");
462 }
463
464 const MachineRegisterInfo &MRI = MF.getRegInfo();
465 if (ComputedPropertyHelper(YamlMF.NoVRegs, MRI.getNumVirtRegs() == 0,
467 return error(
468 MF.getName() +
469 " has explicit property NoVRegs, but contains virtual registers");
470 }
471
472 // For hasFakeUses we follow similar logic to the ComputedPropertyHelper,
473 // except for caring about the inverse case only, i.e. when the property is
474 // explicitly set to false and Fake Uses are present; having HasFakeUses=true
475 // on a function without fake uses is harmless.
476 if (YamlMF.HasFakeUses && !*YamlMF.HasFakeUses && HasFakeUses)
477 return error(
478 MF.getName() +
479 " has explicit property hasFakeUses=false, but contains fake uses");
480 MF.setHasFakeUses(YamlMF.HasFakeUses.value_or(HasFakeUses));
481
482 return false;
483}
484
485bool MIRParserImpl::parseMachineInst(MachineFunction &MF,
487 MachineInstr const *&MI) {
488 if (MILoc.BlockNum >= MF.size()) {
489 return error(Twine(MF.getName()) +
490 Twine(" instruction block out of range.") +
491 " Unable to reference bb:" + Twine(MILoc.BlockNum));
492 }
493 auto BB = std::next(MF.begin(), MILoc.BlockNum);
494 if (MILoc.Offset >= BB->size())
495 return error(
496 Twine(MF.getName()) + Twine(" instruction offset out of range.") +
497 " Unable to reference instruction at bb: " + Twine(MILoc.BlockNum) +
498 " at offset:" + Twine(MILoc.Offset));
499 MI = &*std::next(BB->instr_begin(), MILoc.Offset);
500 return false;
501}
502
505 MachineFunction &MF = PFS.MF;
507 const TargetMachine &TM = MF.getTarget();
508 for (auto &YamlCSInfo : YamlMF.CallSitesInfo) {
509 yaml::MachineInstrLoc MILoc = YamlCSInfo.CallLocation;
510 const MachineInstr *CallI;
511 if (parseMachineInst(MF, MILoc, CallI))
512 return true;
514 return error(Twine(MF.getName()) +
515 Twine(" call site info should reference call "
516 "instruction. Instruction at bb:") +
517 Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset) +
518 " is not a call instruction");
520 for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
521 Register Reg;
522 if (parseNamedRegisterReference(PFS, Reg, ArgRegPair.Reg.Value, Error))
523 return error(Error, ArgRegPair.Reg.SourceRange);
524 CSInfo.ArgRegPairs.emplace_back(Reg, ArgRegPair.ArgNo);
525 }
526 if (!YamlCSInfo.CalleeTypeIds.empty()) {
527 for (auto CalleeTypeId : YamlCSInfo.CalleeTypeIds) {
528 IntegerType *Int64Ty = Type::getInt64Ty(Context);
529 CSInfo.CalleeTypeIds.push_back(ConstantInt::get(Int64Ty, CalleeTypeId,
530 /*isSigned=*/false));
531 }
532 }
533
535 MF.addCallSiteInfo(&*CallI, std::move(CSInfo));
536 }
537
538 if (!YamlMF.CallSitesInfo.empty() &&
540 return error("call site info provided but not used");
541 return false;
542}
543
544void MIRParserImpl::setupDebugValueTracking(
546 const yaml::MachineFunction &YamlMF) {
547 // Compute the value of the "next instruction number" field.
548 unsigned MaxInstrNum = 0;
549 for (auto &MBB : MF)
550 for (auto &MI : MBB)
551 MaxInstrNum = std::max(MI.peekDebugInstrNum(), MaxInstrNum);
552 MF.setDebugInstrNumberingCount(MaxInstrNum);
553
554 // Load any substitutions.
555 for (const auto &Sub : YamlMF.DebugValueSubstitutions) {
556 MF.makeDebugValueSubstitution({Sub.SrcInst, Sub.SrcOp},
557 {Sub.DstInst, Sub.DstOp}, Sub.Subreg);
558 }
559
560 // Flag for whether we're supposed to be using DBG_INSTR_REF.
561 MF.setUseDebugInstrRef(YamlMF.UseDebugInstrRef);
562}
563
564bool
566 MachineFunction &MF) {
567 // TODO: Recreate the machine function.
568 if (Target) {
569 // Avoid clearing state if we're using the same subtarget again.
570 Target->setTarget(MF.getSubtarget());
571 } else {
572 Target.reset(new PerTargetMIParsingState(MF.getSubtarget()));
573 }
574
575 MF.setAlignment(YamlMF.Alignment.valueOrOne());
577 MF.setHasWinCFI(YamlMF.HasWinCFI);
578
582 MF.setHasEHScopes(YamlMF.HasEHScopes);
584 MF.setIsOutlined(YamlMF.IsOutlined);
585
587 if (YamlMF.Legalized)
588 Props.setLegalized();
589 if (YamlMF.RegBankSelected)
590 Props.setRegBankSelected();
591 if (YamlMF.Selected)
592 Props.setSelected();
593 if (YamlMF.FailedISel)
594 Props.setFailedISel();
595 if (YamlMF.FailsVerification)
596 Props.setFailsVerification();
597 if (YamlMF.TracksDebugUserValues)
598 Props.setTracksDebugUserValues();
599
600 PerFunctionMIParsingState PFS(MF, SM, IRSlots, *Target);
601 if (parseRegisterInfo(PFS, YamlMF))
602 return true;
603 if (initializePrefetchTargets(PFS, YamlMF))
604 return true;
605 if (!YamlMF.Constants.empty()) {
606 auto *ConstantPool = MF.getConstantPool();
607 assert(ConstantPool && "Constant pool must be created");
608 if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
609 return true;
610 }
611 if (!YamlMF.MachineMetadataNodes.empty() &&
612 parseMachineMetadataNodes(PFS, MF, YamlMF))
613 return true;
614
615 StringRef BlockStr = YamlMF.Body.Value.Value;
617 SourceMgr BlockSM;
618 BlockSM.AddNewSourceBuffer(
619 MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
620 SMLoc());
621 PFS.SM = &BlockSM;
622 if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
624 diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
625 return true;
626 }
627 // Check Basic Block Section Flags.
628 if (MF.hasBBSections()) {
630 }
631 PFS.SM = &SM;
632
633 // Initialize the frame information after creating all the MBBs so that the
634 // MBB references in the frame information can be resolved.
635 if (initializeFrameInfo(PFS, YamlMF))
636 return true;
637 // Initialize the jump table after creating all the MBBs so that the MBB
638 // references can be resolved.
639 if (!YamlMF.JumpTableInfo.Entries.empty() &&
641 return true;
642 // Parse the machine instructions after creating all of the MBBs so that the
643 // parser can resolve the MBB references.
644 StringRef InsnStr = YamlMF.Body.Value.Value;
645 SourceMgr InsnSM;
646 InsnSM.AddNewSourceBuffer(
647 MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
648 SMLoc());
649 PFS.SM = &InsnSM;
650 if (parseMachineInstructions(PFS, InsnStr, Error)) {
652 diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
653 return true;
654 }
655 PFS.SM = &SM;
656
657 if (setupRegisterInfo(PFS, YamlMF))
658 return true;
659
660 if (YamlMF.MachineFuncInfo) {
661 const TargetMachine &TM = MF.getTarget();
662 // Note this is called after the initial constructor of the
663 // MachineFunctionInfo based on the MachineFunction, which may depend on the
664 // IR.
665
666 SMRange SrcRange;
668 SrcRange)) {
669 return error(Error, SrcRange);
670 }
671 }
672
673 // Set the reserved registers after parsing MachineFuncInfo. The target may
674 // have been recording information used to select the reserved registers
675 // there.
676 // FIXME: This is a temporary workaround until the reserved registers can be
677 // serialized.
679 MRI.freezeReservedRegs();
680
681 if (computeFunctionProperties(MF, YamlMF))
682 return true;
683
684 if (initializeCallSiteInfo(PFS, YamlMF))
685 return true;
686
687 if (parseCalledGlobals(PFS, MF, YamlMF))
688 return true;
689
690 if (initializePrefetchTargets(PFS, YamlMF))
691 return true;
692
693 setupDebugValueTracking(MF, PFS, YamlMF);
694
696
697 MF.verify(nullptr, nullptr, &errs());
698 return false;
699}
700
703 MachineFunction &MF = PFS.MF;
706 for (const auto &YamlTarget : YamlMF.PrefetchTargets) {
707 CallsiteID Target;
708 if (llvm::parsePrefetchTarget(PFS, Target, YamlTarget.Value, Error))
709 return error(Error, YamlTarget.SourceRange);
710 Targets[Target.BBID].push_back(Target.CallsiteIndex);
711 }
712 MF.setPrefetchTargets(Targets);
713 return false;
714}
715
717 const yaml::MachineFunction &YamlMF) {
718 MachineFunction &MF = PFS.MF;
719 MachineRegisterInfo &RegInfo = MF.getRegInfo();
720 assert(RegInfo.tracksLiveness());
721 if (!YamlMF.TracksRegLiveness)
722 RegInfo.invalidateLiveness();
723
725 // Parse the virtual register information.
726 for (const auto &VReg : YamlMF.VirtualRegisters) {
727 VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
728 if (Info.Explicit)
729 return error(VReg.ID.SourceRange.Start,
730 Twine("redefinition of virtual register '%") +
731 Twine(VReg.ID.Value) + "'");
732 Info.Explicit = true;
733
734 if (VReg.Class.Value == "_") {
735 Info.Kind = VRegInfo::GENERIC;
736 Info.D.RegBank = nullptr;
737 } else {
738 const auto *RC = Target->getRegClass(VReg.Class.Value);
739 if (RC) {
740 Info.Kind = VRegInfo::NORMAL;
741 Info.D.RC = RC;
742 } else {
743 const RegisterBank *RegBank = Target->getRegBank(VReg.Class.Value);
744 if (!RegBank)
745 return error(
746 VReg.Class.SourceRange.Start,
747 Twine("use of undefined register class or register bank '") +
748 VReg.Class.Value + "'");
749 Info.Kind = VRegInfo::REGBANK;
750 Info.D.RegBank = RegBank;
751 }
752 }
753
754 if (!VReg.PreferredRegister.Value.empty()) {
755 if (Info.Kind != VRegInfo::NORMAL)
756 return error(VReg.Class.SourceRange.Start,
757 Twine("preferred register can only be set for normal vregs"));
758
759 if (parseRegisterReference(PFS, Info.PreferredReg,
760 VReg.PreferredRegister.Value, Error))
761 return error(Error, VReg.PreferredRegister.SourceRange);
762 }
763
764 for (const auto &FlagStringValue : VReg.RegisterFlags) {
765 uint8_t FlagValue;
766 if (Target->getVRegFlagValue(FlagStringValue.Value, FlagValue))
767 return error(FlagStringValue.SourceRange.Start,
768 Twine("use of undefined register flag '") +
769 FlagStringValue.Value + "'");
770 Info.Flags |= FlagValue;
771 }
772 RegInfo.noteNewVirtualRegister(Info.VReg);
773 }
774
775 // Parse the liveins.
776 for (const auto &LiveIn : YamlMF.LiveIns) {
777 Register Reg;
778 if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
779 return error(Error, LiveIn.Register.SourceRange);
780 Register VReg;
781 if (!LiveIn.VirtualRegister.Value.empty()) {
782 VRegInfo *Info;
783 if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
784 Error))
785 return error(Error, LiveIn.VirtualRegister.SourceRange);
786 VReg = Info->VReg;
787 }
788 RegInfo.addLiveIn(Reg, VReg);
789 }
790
791 // Parse the callee saved registers (Registers that will
792 // be saved for the caller).
793 if (YamlMF.CalleeSavedRegisters) {
794 SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
795 for (const auto &RegSource : *YamlMF.CalleeSavedRegisters) {
796 Register Reg;
797 if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
798 return error(Error, RegSource.SourceRange);
799 CalleeSavedRegisters.push_back(Reg.id());
800 }
801 RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
802 }
803
804 // Stash any VirtRegMap state on MRI.
805 // VirtRegMap::init() will use that information to get pre-populated
806 // on the first analysis run.
807 for (const auto &VReg : YamlMF.VirtualRegisters) {
808 if (VReg.SplitFrom.Value.empty() && VReg.AssignedPhys.Value.empty())
809 continue;
810
811 auto It = PFS.VRegInfos.find(VReg.ID.Value);
812 if (It == PFS.VRegInfos.end())
813 continue;
814 Register ChildReg = It->second->VReg;
815
817 Pending.VReg = ChildReg;
818
819 if (!VReg.SplitFrom.Value.empty()) {
820 VRegInfo *Parent = nullptr;
821 if (parseVirtualRegisterReference(PFS, Parent, VReg.SplitFrom.Value,
822 Error))
823 return error(Error, VReg.SplitFrom.SourceRange);
824 if (Parent->VReg == ChildReg)
825 return error(VReg.SplitFrom.SourceRange.Start,
826 Twine("'split-from' references the same vreg as 'id' (%") +
827 Twine(VReg.ID.Value) + ")");
828 Pending.SplitFrom = Parent->VReg;
829 }
830 if (!VReg.AssignedPhys.Value.empty()) {
831 Register Phys;
832 if (parseRegisterReference(PFS, Phys, VReg.AssignedPhys.Value, Error))
833 return error(Error, VReg.AssignedPhys.SourceRange);
834 if (!Phys.isPhysical())
835 return error(
836 VReg.AssignedPhys.SourceRange.Start,
837 Twine("'assigned-phys' must be a physical register, got '") +
838 VReg.AssignedPhys.Value + "'");
839 Pending.AssignedPhys = Phys.asMCReg();
840 }
841 RegInfo.addPendingVirtRegMapEntry(Pending);
842 }
843
844 return false;
845}
846
848 const yaml::MachineFunction &YamlMF) {
849 MachineFunction &MF = PFS.MF;
852
854
855 // Create VRegs
856 auto populateVRegInfo = [&](const VRegInfo &Info, const Twine &Name) {
857 Register Reg = Info.VReg;
858 switch (Info.Kind) {
860 Errors.push_back(
861 (Twine("Cannot determine class/bank of virtual register ") + Name +
862 " in function '" + MF.getName() + "'")
863 .str());
864 break;
865 case VRegInfo::NORMAL:
866 if (!Info.D.RC->isAllocatable()) {
867 Errors.push_back((Twine("Cannot use non-allocatable class '") +
868 TRI->getRegClassName(Info.D.RC) +
869 "' for virtual register " + Name + " in function '" +
870 MF.getName() + "'")
871 .str());
872 break;
873 }
874
875 MRI.setRegClass(Reg, Info.D.RC);
876 if (Info.PreferredReg != 0)
877 MRI.setSimpleHint(Reg, Info.PreferredReg);
878 break;
880 break;
882 MRI.setRegBank(Reg, *Info.D.RegBank);
883 break;
884 }
885 };
886
887 for (const auto &P : PFS.VRegInfosNamed) {
888 const VRegInfo &Info = *P.second;
889 populateVRegInfo(Info, Twine(P.first()));
890 }
891
892 for (auto P : PFS.VRegInfos) {
893 const VRegInfo &Info = *P.second;
894 populateVRegInfo(Info, Twine(P.first.id()));
895 }
896
897 // Compute MachineRegisterInfo::UsedPhysRegMask
898 for (const MachineBasicBlock &MBB : MF) {
899 // Make sure MRI knows about registers clobbered by unwinder.
900 if (MBB.isEHPad())
901 if (auto *RegMask = TRI->getCustomEHPadPreservedMask(MF))
902 MRI.addPhysRegsUsedFromRegMask(RegMask);
903
904 for (const MachineInstr &MI : MBB) {
905 for (const MachineOperand &MO : MI.operands()) {
906 if (!MO.isRegMask())
907 continue;
909 }
910 }
911 }
912
913 if (Errors.empty())
914 return false;
915
916 // Report errors in a deterministic order.
917 sort(Errors);
918 for (auto &E : Errors)
919 error(E);
920 return true;
921}
922
924 const yaml::MachineFunction &YamlMF) {
925 MachineFunction &MF = PFS.MF;
926 MachineFrameInfo &MFI = MF.getFrameInfo();
928 const Function &F = MF.getFunction();
929 const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
932 MFI.setHasStackMap(YamlMFI.HasStackMap);
933 MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
934 MFI.setStackSize(YamlMFI.StackSize);
936 if (YamlMFI.MaxAlignment)
938 MFI.setAdjustsStack(YamlMFI.AdjustsStack);
939 MFI.setHasCalls(YamlMFI.HasCalls);
942 if (YamlMFI.MaxCallFrameSize != ~0u)
946 MFI.setHasVAStart(YamlMFI.HasVAStart);
948 MFI.setHasTailCall(YamlMFI.HasTailCall);
951 llvm::SaveRestorePoints SavePoints;
952 if (initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, SavePoints))
953 return true;
954 MFI.setSavePoints(SavePoints);
955 llvm::SaveRestorePoints RestorePoints;
956 if (initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints, RestorePoints))
957 return true;
958 MFI.setRestorePoints(RestorePoints);
959
960 std::vector<CalleeSavedInfo> CSIInfo;
961 // Initialize the fixed frame objects.
962 for (const auto &Object : YamlMF.FixedStackObjects) {
963 int ObjectIdx;
965 ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
966 Object.IsImmutable, Object.IsAliased);
967 else
968 ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
969
970 if (!TFI->isSupportedStackID(Object.StackID))
971 return error(Object.ID.SourceRange.Start,
972 Twine("StackID is not supported by target"));
973 MFI.setStackID(ObjectIdx, Object.StackID);
974 MFI.setObjectAlignment(ObjectIdx, Object.Alignment.valueOrOne());
975 if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
976 ObjectIdx))
977 .second)
978 return error(Object.ID.SourceRange.Start,
979 Twine("redefinition of fixed stack object '%fixed-stack.") +
980 Twine(Object.ID.Value) + "'");
981 if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
982 Object.CalleeSavedRestored, ObjectIdx))
983 return true;
984 if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
985 return true;
986 }
987
988 for (const auto &Object : YamlMF.EntryValueObjects) {
990 Register Reg;
991 if (parseNamedRegisterReference(PFS, Reg, Object.EntryValueRegister.Value,
992 Error))
993 return error(Error, Object.EntryValueRegister.SourceRange);
994 if (!Reg.isPhysical())
995 return error(Object.EntryValueRegister.SourceRange.Start,
996 "Expected physical register for entry value field");
997 std::optional<VarExprLoc> MaybeInfo = parseVarExprLoc(
998 PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
999 if (!MaybeInfo)
1000 return true;
1001 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1002 PFS.MF.setVariableDbgInfo(MaybeInfo->DIVar, MaybeInfo->DIExpr,
1003 Reg.asMCReg(), MaybeInfo->DILoc);
1004 }
1005
1006 // Initialize the ordinary frame objects.
1007 for (const auto &Object : YamlMF.StackObjects) {
1008 int ObjectIdx;
1009 const AllocaInst *Alloca = nullptr;
1010 const yaml::StringValue &Name = Object.Name;
1011 if (!Name.Value.empty()) {
1013 F.getValueSymbolTable()->lookup(Name.Value));
1014 if (!Alloca)
1015 return error(Name.SourceRange.Start,
1016 "alloca instruction named '" + Name.Value +
1017 "' isn't defined in the function '" + F.getName() +
1018 "'");
1019 }
1020 if (!TFI->isSupportedStackID(Object.StackID))
1021 return error(Object.ID.SourceRange.Start,
1022 Twine("StackID is not supported by target"));
1023 if (Object.Type == yaml::MachineStackObject::VariableSized)
1024 ObjectIdx =
1025 MFI.CreateVariableSizedObject(Object.Alignment.valueOrOne(), Alloca);
1026 else
1027 ObjectIdx = MFI.CreateStackObject(
1028 Object.Size, Object.Alignment.valueOrOne(),
1029 Object.Type == yaml::MachineStackObject::SpillSlot, Alloca,
1030 Object.StackID);
1031 MFI.setObjectOffset(ObjectIdx, Object.Offset);
1032
1033 if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
1034 .second)
1035 return error(Object.ID.SourceRange.Start,
1036 Twine("redefinition of stack object '%stack.") +
1037 Twine(Object.ID.Value) + "'");
1038 if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
1039 Object.CalleeSavedRestored, ObjectIdx))
1040 return true;
1041 if (Object.LocalOffset)
1042 MFI.mapLocalFrameObject(ObjectIdx, *Object.LocalOffset);
1043 if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
1044 return true;
1045 }
1046 MFI.setCalleeSavedInfo(CSIInfo);
1047 if (!CSIInfo.empty())
1048 MFI.setCalleeSavedInfoValid(true);
1049
1050 // Initialize the various stack object references after initializing the
1051 // stack objects.
1052 if (!YamlMFI.StackProtector.Value.empty()) {
1054 int FI;
1055 if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
1056 return error(Error, YamlMFI.StackProtector.SourceRange);
1057 MFI.setStackProtectorIndex(FI);
1058 }
1059
1060 if (!YamlMFI.FunctionContext.Value.empty()) {
1062 int FI;
1064 return error(Error, YamlMFI.FunctionContext.SourceRange);
1066 }
1067
1068 return false;
1069}
1070
1072 std::vector<CalleeSavedInfo> &CSIInfo,
1073 const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
1074 if (RegisterSource.Value.empty())
1075 return false;
1076 Register Reg;
1078 if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
1079 return error(Error, RegisterSource.SourceRange);
1080 CalleeSavedInfo CSI(Reg, FrameIdx);
1081 CSI.setRestored(IsRestored);
1082 CSIInfo.push_back(CSI);
1083 return false;
1084}
1085
1086/// Verify that given node is of a certain type. Return true on error.
1087template <typename T>
1088static bool typecheckMDNode(T *&Result, MDNode *Node,
1089 const yaml::StringValue &Source,
1090 StringRef TypeString, MIRParserImpl &Parser) {
1091 if (!Node)
1092 return false;
1093 Result = dyn_cast<T>(Node);
1094 if (!Result)
1095 return Parser.error(Source.SourceRange.Start,
1096 "expected a reference to a '" + TypeString +
1097 "' metadata node");
1098 return false;
1099}
1100
1101std::optional<MIRParserImpl::VarExprLoc> MIRParserImpl::parseVarExprLoc(
1102 PerFunctionMIParsingState &PFS, const yaml::StringValue &VarStr,
1103 const yaml::StringValue &ExprStr, const yaml::StringValue &LocStr) {
1104 MDNode *Var = nullptr;
1105 MDNode *Expr = nullptr;
1106 MDNode *Loc = nullptr;
1107 if (parseMDNode(PFS, Var, VarStr) || parseMDNode(PFS, Expr, ExprStr) ||
1108 parseMDNode(PFS, Loc, LocStr))
1109 return std::nullopt;
1110 DILocalVariable *DIVar = nullptr;
1111 DIExpression *DIExpr = nullptr;
1112 DILocation *DILoc = nullptr;
1113 if (typecheckMDNode(DIVar, Var, VarStr, "DILocalVariable", *this) ||
1114 typecheckMDNode(DIExpr, Expr, ExprStr, "DIExpression", *this) ||
1115 typecheckMDNode(DILoc, Loc, LocStr, "DILocation", *this))
1116 return std::nullopt;
1117 return VarExprLoc{DIVar, DIExpr, DILoc};
1118}
1119
1120template <typename T>
1122 const T &Object, int FrameIdx) {
1123 std::optional<VarExprLoc> MaybeInfo =
1124 parseVarExprLoc(PFS, Object.DebugVar, Object.DebugExpr, Object.DebugLoc);
1125 if (!MaybeInfo)
1126 return true;
1127 // Debug information can only be attached to stack objects; Fixed stack
1128 // objects aren't supported.
1129 if (MaybeInfo->DIVar || MaybeInfo->DIExpr || MaybeInfo->DILoc)
1130 PFS.MF.setVariableDbgInfo(MaybeInfo->DIVar, MaybeInfo->DIExpr, FrameIdx,
1131 MaybeInfo->DILoc);
1132 return false;
1133}
1134
1135bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
1136 MDNode *&Node, const yaml::StringValue &Source) {
1137 if (Source.Value.empty())
1138 return false;
1140 if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
1141 return error(Error, Source.SourceRange);
1142 return false;
1143}
1144
1147 DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
1148 const MachineFunction &MF = PFS.MF;
1149 const auto &M = *MF.getFunction().getParent();
1151 for (const auto &YamlConstant : YamlMF.Constants) {
1152 if (YamlConstant.IsTargetSpecific)
1153 // FIXME: Support target-specific constant pools
1154 return error(YamlConstant.Value.SourceRange.Start,
1155 "Can't parse target-specific constant pool entries yet");
1157 parseConstantValue(YamlConstant.Value.Value, Error, M));
1158 if (!Value)
1159 return error(Error, YamlConstant.Value.SourceRange);
1160 const Align PrefTypeAlign =
1161 M.getDataLayout().getPrefTypeAlign(Value->getType());
1162 const Align Alignment = YamlConstant.Alignment.value_or(PrefTypeAlign);
1163 unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
1164 if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
1165 .second)
1166 return error(YamlConstant.ID.SourceRange.Start,
1167 Twine("redefinition of constant pool item '%const.") +
1168 Twine(YamlConstant.ID.Value) + "'");
1169 }
1170 return false;
1171}
1172
1173// Return true if basic block was incorrectly specified in MIR
1176 const std::vector<yaml::SaveRestorePointEntry> &YamlSRPoints,
1179 MachineBasicBlock *MBB = nullptr;
1180 for (const yaml::SaveRestorePointEntry &Entry : YamlSRPoints) {
1181 if (parseMBBReference(PFS, MBB, Entry.Point.Value))
1182 return true;
1183
1184 std::vector<CalleeSavedInfo> Registers;
1185 for (auto &RegStr : Entry.Registers) {
1186 Register Reg;
1187 if (parseNamedRegisterReference(PFS, Reg, RegStr.Value, Error))
1188 return error(Error, RegStr.SourceRange);
1189 Registers.push_back(CalleeSavedInfo(Reg));
1190 }
1191 SaveRestorePoints.try_emplace(MBB, std::move(Registers));
1192 }
1193 return false;
1194}
1195
1197 const yaml::MachineJumpTable &YamlJTI) {
1199 for (const auto &Entry : YamlJTI.Entries) {
1200 std::vector<MachineBasicBlock *> Blocks;
1201 for (const auto &MBBSource : Entry.Blocks) {
1202 MachineBasicBlock *MBB = nullptr;
1203 if (parseMBBReference(PFS, MBB, MBBSource.Value))
1204 return true;
1205 Blocks.push_back(MBB);
1206 }
1207 unsigned Index = JTI->createJumpTableIndex(Blocks);
1208 if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
1209 .second)
1210 return error(Entry.ID.SourceRange.Start,
1211 Twine("redefinition of jump table entry '%jump-table.") +
1212 Twine(Entry.ID.Value) + "'");
1213 }
1214 return false;
1215}
1216
1217bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
1219 const yaml::StringValue &Source) {
1221 if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
1222 return error(Error, Source.SourceRange);
1223 return false;
1224}
1225
1228 const yaml::MachineFunction &YMF) {
1229 SmallVector<StringRef> Definitions;
1230 for (const auto &MDS : YMF.MachineMetadataNodes)
1231 Definitions.push_back(MDS.Value);
1232
1233 SlotMapping Slots = PFS.IRSlots;
1235 unsigned ErrorDefinitionIndex = 0;
1236 if (parseMetadataDefinitions(Definitions, Error,
1237 *MF.getFunction().getParent(), Slots,
1238 ErrorDefinitionIndex)) {
1239 const yaml::StringValue &Source =
1240 YMF.MachineMetadataNodes[ErrorDefinitionIndex];
1241 if (StringRef(Source.Value).contains('\n')) {
1242 reportDiagnostic(diagFromBlockStringDiag(Error, Source.SourceRange));
1243 return true;
1244 }
1245 return error(Error, Source.SourceRange);
1246 }
1247
1248 for (auto &[ID, MD] : Slots.MetadataNodes)
1249 if (PFS.IRSlots.MetadataNodes.find(ID) == PFS.IRSlots.MetadataNodes.end())
1250 PFS.MachineMetadataNodes.try_emplace(ID, MD);
1251 return false;
1252}
1253
1255 MachineFunction &MF,
1256 const yaml::MachineFunction &YMF) {
1257 Function &F = MF.getFunction();
1258 for (const auto &YamlCG : YMF.CalledGlobals) {
1259 yaml::MachineInstrLoc MILoc = YamlCG.CallSite;
1260 const MachineInstr *CallI;
1261 if (parseMachineInst(MF, MILoc, CallI))
1262 return true;
1264 return error(Twine(MF.getName()) +
1265 Twine(" called global should reference call "
1266 "instruction. Instruction at bb:") +
1267 Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset) +
1268 " is not a call instruction");
1269
1270 auto Callee =
1271 F.getParent()->getValueSymbolTable().lookup(YamlCG.Callee.Value);
1272 if (!Callee)
1273 return error(YamlCG.Callee.SourceRange.Start,
1274 "use of undefined global '" + YamlCG.Callee.Value + "'");
1275 if (!isa<GlobalValue>(Callee))
1276 return error(YamlCG.Callee.SourceRange.Start,
1277 "use of non-global value '" + YamlCG.Callee.Value + "'");
1278
1279 MF.addCalledGlobal(CallI, {cast<GlobalValue>(Callee), YamlCG.Flags});
1280 }
1281
1282 return false;
1283}
1284
1285SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
1286 SMRange SourceRange) {
1287 assert(SourceRange.isValid() && "Invalid source range");
1288 SMLoc Loc = SourceRange.Start;
1289 bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
1290 *Loc.getPointer() == '\'';
1291 // Translate the location of the error from the location in the MI string to
1292 // the corresponding location in the MIR file.
1293 Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
1294 (HasQuote ? 1 : 0));
1295
1296 // TODO: Translate any source ranges as well.
1297 return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), {},
1298 Error.getFixIts());
1299}
1300
1301SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
1302 SMRange SourceRange) {
1303 assert(SourceRange.isValid());
1304
1305 // Translate the location of the error from the location in the llvm IR string
1306 // to the corresponding location in the MIR file.
1307 auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
1308 unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
1309 unsigned Column = Error.getColumnNo();
1310 StringRef LineStr = Error.getLineContents();
1311 SMLoc Loc = Error.getLoc();
1312
1313 // Get the full line and adjust the column number by taking the indentation of
1314 // LLVM IR into account.
1315 for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
1316 L != E; ++L) {
1317 if (L.line_number() == Line) {
1318 LineStr = *L;
1319 Loc = SMLoc::getFromPointer(LineStr.data());
1320 auto Indent = LineStr.find(Error.getLineContents());
1321 if (Indent != StringRef::npos)
1322 Column += Indent;
1323 break;
1324 }
1325 }
1326
1327 return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
1328 Error.getMessage(), LineStr, Error.getRanges(),
1329 Error.getFixIts());
1330}
1331
1332MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
1333 : Impl(std::move(Impl)) {}
1334
1335MIRParser::~MIRParser() = default;
1336
1337std::unique_ptr<Module>
1339 return Impl->parseIRModule(DataLayoutCallback);
1340}
1341
1343 return Impl->parseMachineFunctions(M, MMI);
1344}
1345
1347 auto &MMI = MAM.getResult<MachineModuleAnalysis>(M).getMMI();
1348 return Impl->parseMachineFunctions(M, MMI, &MAM);
1349}
1350
1351std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(
1353 std::function<void(Function &)> ProcessIRFunction) {
1354 auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
1355 if (std::error_code EC = FileOrErr.getError()) {
1357 "could not open input file: " + EC.message());
1358 return nullptr;
1359 }
1360 return createMIRParser(std::move(FileOrErr.get()), Context,
1361 ProcessIRFunction);
1362}
1363
1364std::unique_ptr<MIRParser>
1365llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
1366 LLVMContext &Context,
1367 std::function<void(Function &)> ProcessIRFunction) {
1368 auto Filename = Contents->getBufferIdentifier();
1369 if (Context.shouldDiscardValueNames()) {
1370 Context.diagnose(DiagnosticInfoMIRParser(
1371 DS_Error,
1374 "cannot read MIR with a Context that discards named Values")));
1375 return nullptr;
1376 }
1377 return std::make_unique<MIRParser>(std::make_unique<MIRParserImpl>(
1378 std::move(Contents), Filename, Context, ProcessIRFunction));
1379}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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
SI Pre allocate WWM Registers
#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:284
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:168
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Definition Function.cpp:353
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:68
Metadata node.
Definition Metadata.h:1069
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 ...
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:67
FunctionListType::iterator iterator
The Function iterators.
Definition Module.h:92
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 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:308
SourceMgr::DiagKind getKind() const
Definition SourceMgr.h:338
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:37
unsigned getMainFileID() const
Definition SourceMgr.h:151
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:144
LLVM_ABI SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition SourceMgr.h:163
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:310
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:282
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:255
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, Property_enumSize > 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:1636
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:1917
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:130
DenseMap< unsigned, unsigned > JumpTableSlots
Definition MIParser.h:183
LLVM_ABI VRegInfo & getVRegInfo(Register Num)
Definition MIParser.cpp:329
DenseMap< unsigned, int > FixedStackObjectSlots
Definition MIParser.h:180
const SlotMapping & IRSlots
Definition MIParser.h:172
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition MIParser.h:182
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:179
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition MIParser.h:175
DenseMap< unsigned, int > StackObjectSlots
Definition MIParser.h:181
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:178
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:107
constexpr EnumSet & reset(Enum E)
Definition OMP.h:103
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.