LLVM  10.0.0
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/STLExtras.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/AsmParser/Parser.h"
31 #include "llvm/IR/BasicBlock.h"
32 #include "llvm/IR/DebugInfo.h"
33 #include "llvm/IR/DiagnosticInfo.h"
34 #include "llvm/IR/Instructions.h"
35 #include "llvm/IR/LLVMContext.h"
36 #include "llvm/IR/Module.h"
40 #include "llvm/Support/SMLoc.h"
41 #include "llvm/Support/SourceMgr.h"
44 #include <memory>
45 
46 using namespace llvm;
47 
48 namespace llvm {
49 
50 /// This class implements the parsing of LLVM IR that's embedded inside a MIR
51 /// file.
53  SourceMgr SM;
54  yaml::Input In;
55  StringRef Filename;
56  LLVMContext &Context;
57  SlotMapping IRSlots;
58  std::unique_ptr<PerTargetMIParsingState> Target;
59 
60  /// True when the MIR file doesn't have LLVM IR. Dummy IR functions are
61  /// created and inserted into the given module when this is true.
62  bool NoLLVMIR = false;
63  /// True when a well formed MIR file does not contain any MIR/machine function
64  /// parts.
65  bool NoMIRDocuments = false;
66 
67  std::function<void(Function &)> ProcessIRFunction;
68 
69 public:
70  MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
71  LLVMContext &Context,
72  std::function<void(Function &)> ProcessIRFunction);
73 
74  void reportDiagnostic(const SMDiagnostic &Diag);
75 
76  /// Report an error with the given message at unknown location.
77  ///
78  /// Always returns true.
79  bool error(const Twine &Message);
80 
81  /// Report an error with the given message at the given location.
82  ///
83  /// Always returns true.
84  bool error(SMLoc Loc, const Twine &Message);
85 
86  /// Report a given error with the location translated from the location in an
87  /// embedded string literal to a location in the MIR file.
88  ///
89  /// Always returns true.
90  bool error(const SMDiagnostic &Error, SMRange SourceRange);
91 
92  /// Try to parse the optional LLVM module and the machine functions in the MIR
93  /// file.
94  ///
95  /// Return null if an error occurred.
96  std::unique_ptr<Module> parseIRModule();
97 
98  /// Create an empty function with the given name.
100 
102 
103  /// Parse the machine function in the current YAML document.
104  ///
105  ///
106  /// Return true if an error occurred.
108 
109  /// Initialize the machine function to the state that's described in the MIR
110  /// file.
111  ///
112  /// Return true if error occurred.
114  MachineFunction &MF);
115 
117  const yaml::MachineFunction &YamlMF);
118 
120  const yaml::MachineFunction &YamlMF);
121 
123  const yaml::MachineFunction &YamlMF);
124 
126  const yaml::MachineFunction &YamlMF);
127 
129  std::vector<CalleeSavedInfo> &CSIInfo,
130  const yaml::StringValue &RegisterSource,
131  bool IsRestored, int FrameIdx);
132 
133  template <typename T>
135  const T &Object,
136  int FrameIdx);
137 
140  const yaml::MachineFunction &YamlMF);
141 
143  const yaml::MachineJumpTable &YamlJTI);
144 
145 private:
146  bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node,
147  const yaml::StringValue &Source);
148 
149  bool parseMBBReference(PerFunctionMIParsingState &PFS,
150  MachineBasicBlock *&MBB,
151  const yaml::StringValue &Source);
152 
153  /// Return a MIR diagnostic converted from an MI string diagnostic.
154  SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
155  SMRange SourceRange);
156 
157  /// Return a MIR diagnostic converted from a diagnostic located in a YAML
158  /// block scalar string.
159  SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
160  SMRange SourceRange);
161 
162  void computeFunctionProperties(MachineFunction &MF);
163 };
164 
165 } // end namespace llvm
166 
167 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
168  reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
169 }
170 
171 MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
172  StringRef Filename, LLVMContext &Context,
173  std::function<void(Function &)> Callback)
174  : SM(),
175  In(SM.getMemoryBuffer(SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))
176  ->getBuffer(),
177  nullptr, handleYAMLDiag, this),
178  Filename(Filename), Context(Context), ProcessIRFunction(Callback) {
179  In.setContext(&In);
180 }
181 
182 bool MIRParserImpl::error(const Twine &Message) {
184  DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
185  return true;
186 }
187 
188 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
190  DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
191  return true;
192 }
193 
194 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
195  assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
196  reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
197  return true;
198 }
199 
202  switch (Diag.getKind()) {
203  case SourceMgr::DK_Error:
204  Kind = DS_Error;
205  break;
207  Kind = DS_Warning;
208  break;
209  case SourceMgr::DK_Note:
210  Kind = DS_Note;
211  break;
213  llvm_unreachable("remark unexpected");
214  break;
215  }
216  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
217 }
218 
219 std::unique_ptr<Module> MIRParserImpl::parseIRModule() {
220  if (!In.setCurrentDocument()) {
221  if (In.error())
222  return nullptr;
223  // Create an empty module when the MIR file is empty.
224  NoMIRDocuments = true;
225  return std::make_unique<Module>(Filename, Context);
226  }
227 
228  std::unique_ptr<Module> M;
229  // Parse the block scalar manually so that we can return unique pointer
230  // without having to go trough YAML traits.
231  if (const auto *BSN =
232  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
234  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
235  Context, &IRSlots, /*UpgradeDebugInfo=*/false);
236  if (!M) {
237  reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
238  return nullptr;
239  }
240  In.nextDocument();
241  if (!In.setCurrentDocument())
242  NoMIRDocuments = true;
243  } else {
244  // Create an new, empty module.
245  M = std::make_unique<Module>(Filename, Context);
246  NoLLVMIR = true;
247  }
248  return M;
249 }
250 
252  if (NoMIRDocuments)
253  return false;
254 
255  // Parse the machine functions.
256  do {
257  if (parseMachineFunction(M, MMI))
258  return true;
259  In.nextDocument();
260  } while (In.setCurrentDocument());
261 
262  return false;
263 }
264 
266  auto &Context = M.getContext();
267  Function *F =
269  Function::ExternalLinkage, Name, M);
270  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
271  new UnreachableInst(Context, BB);
272 
273  if (ProcessIRFunction)
274  ProcessIRFunction(*F);
275 
276  return F;
277 }
278 
280  // Parse the yaml.
281  yaml::MachineFunction YamlMF;
282  yaml::EmptyContext Ctx;
283 
284  const LLVMTargetMachine &TM = MMI.getTarget();
285  YamlMF.MachineFuncInfo = std::unique_ptr<yaml::MachineFunctionInfo>(
287 
288  yaml::yamlize(In, YamlMF, false, Ctx);
289  if (In.error())
290  return true;
291 
292  // Search for the corresponding IR function.
293  StringRef FunctionName = YamlMF.Name;
294  Function *F = M.getFunction(FunctionName);
295  if (!F) {
296  if (NoLLVMIR) {
297  F = createDummyFunction(FunctionName, M);
298  } else {
299  return error(Twine("function '") + FunctionName +
300  "' isn't defined in the provided LLVM IR");
301  }
302  }
303  if (MMI.getMachineFunction(*F) != nullptr)
304  return error(Twine("redefinition of machine function '") + FunctionName +
305  "'");
306 
307  // Create the MachineFunction.
309  if (initializeMachineFunction(YamlMF, MF))
310  return true;
311 
312  return false;
313 }
314 
315 static bool isSSA(const MachineFunction &MF) {
316  const MachineRegisterInfo &MRI = MF.getRegInfo();
317  for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
318  unsigned Reg = Register::index2VirtReg(I);
319  if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
320  return false;
321  }
322  return true;
323 }
324 
325 void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
326  MachineFunctionProperties &Properties = MF.getProperties();
327 
328  bool HasPHI = false;
329  bool HasInlineAsm = false;
330  for (const MachineBasicBlock &MBB : MF) {
331  for (const MachineInstr &MI : MBB) {
332  if (MI.isPHI())
333  HasPHI = true;
334  if (MI.isInlineAsm())
335  HasInlineAsm = true;
336  }
337  }
338  if (!HasPHI)
340  MF.setHasInlineAsm(HasInlineAsm);
341 
342  if (isSSA(MF))
344  else
346 
347  const MachineRegisterInfo &MRI = MF.getRegInfo();
348  if (MRI.getNumVirtRegs() == 0)
350 }
351 
353  PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF) {
354  MachineFunction &MF = PFS.MF;
356  const LLVMTargetMachine &TM = MF.getTarget();
357  for (auto YamlCSInfo : YamlMF.CallSitesInfo) {
358  yaml::CallSiteInfo::MachineInstrLoc MILoc = YamlCSInfo.CallLocation;
359  if (MILoc.BlockNum >= MF.size())
360  return error(Twine(MF.getName()) +
361  Twine(" call instruction block out of range.") +
362  " Unable to reference bb:" + Twine(MILoc.BlockNum));
363  auto CallB = std::next(MF.begin(), MILoc.BlockNum);
364  if (MILoc.Offset >= CallB->size())
365  return error(Twine(MF.getName()) +
366  Twine(" call instruction offset out of range.") +
367  " Unable to reference instruction at bb: " +
368  Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset));
369  auto CallI = std::next(CallB->instr_begin(), MILoc.Offset);
370  if (!CallI->isCall(MachineInstr::IgnoreBundle))
371  return error(Twine(MF.getName()) +
372  Twine(" call site info should reference call "
373  "instruction. Instruction at bb:") +
374  Twine(MILoc.BlockNum) + " at offset:" + Twine(MILoc.Offset) +
375  " is not a call instruction");
377  for (auto ArgRegPair : YamlCSInfo.ArgForwardingRegs) {
378  unsigned Reg = 0;
379  if (parseNamedRegisterReference(PFS, Reg, ArgRegPair.Reg.Value, Error))
380  return error(Error, ArgRegPair.Reg.SourceRange);
381  CSInfo.emplace_back(Reg, ArgRegPair.ArgNo);
382  }
383 
385  MF.addCallArgsForwardingRegs(&*CallI, std::move(CSInfo));
386  }
387 
388  if (YamlMF.CallSitesInfo.size() && !TM.Options.EnableDebugEntryValues)
389  return error(Twine("Call site info provided but not used"));
390  return false;
391 }
392 
393 bool
395  MachineFunction &MF) {
396  // TODO: Recreate the machine function.
397  if (Target) {
398  // Avoid clearing state if we're using the same subtarget again.
399  Target->setTarget(MF.getSubtarget());
400  } else {
402  }
403 
404  if (YamlMF.Alignment)
405  MF.setAlignment(Align(YamlMF.Alignment));
407  MF.setHasWinCFI(YamlMF.HasWinCFI);
408 
409  if (YamlMF.Legalized)
411  if (YamlMF.RegBankSelected)
412  MF.getProperties().set(
414  if (YamlMF.Selected)
416  if (YamlMF.FailedISel)
418 
419  PerFunctionMIParsingState PFS(MF, SM, IRSlots, *Target);
420  if (parseRegisterInfo(PFS, YamlMF))
421  return true;
422  if (!YamlMF.Constants.empty()) {
423  auto *ConstantPool = MF.getConstantPool();
424  assert(ConstantPool && "Constant pool must be created");
425  if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
426  return true;
427  }
428 
429  StringRef BlockStr = YamlMF.Body.Value.Value;
431  SourceMgr BlockSM;
432  BlockSM.AddNewSourceBuffer(
433  MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
434  SMLoc());
435  PFS.SM = &BlockSM;
436  if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
438  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
439  return true;
440  }
441  PFS.SM = &SM;
442 
443  // Initialize the frame information after creating all the MBBs so that the
444  // MBB references in the frame information can be resolved.
445  if (initializeFrameInfo(PFS, YamlMF))
446  return true;
447  // Initialize the jump table after creating all the MBBs so that the MBB
448  // references can be resolved.
449  if (!YamlMF.JumpTableInfo.Entries.empty() &&
451  return true;
452  // Parse the machine instructions after creating all of the MBBs so that the
453  // parser can resolve the MBB references.
454  StringRef InsnStr = YamlMF.Body.Value.Value;
455  SourceMgr InsnSM;
456  InsnSM.AddNewSourceBuffer(
457  MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
458  SMLoc());
459  PFS.SM = &InsnSM;
460  if (parseMachineInstructions(PFS, InsnStr, Error)) {
462  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
463  return true;
464  }
465  PFS.SM = &SM;
466 
467  if (setupRegisterInfo(PFS, YamlMF))
468  return true;
469 
470  if (YamlMF.MachineFuncInfo) {
471  const LLVMTargetMachine &TM = MF.getTarget();
472  // Note this is called after the initial constructor of the
473  // MachineFunctionInfo based on the MachineFunction, which may depend on the
474  // IR.
475 
476  SMRange SrcRange;
477  if (TM.parseMachineFunctionInfo(*YamlMF.MachineFuncInfo, PFS, Error,
478  SrcRange)) {
479  return error(Error, SrcRange);
480  }
481  }
482 
483  // Set the reserved registers after parsing MachineFuncInfo. The target may
484  // have been recording information used to select the reserved registers
485  // there.
486  // FIXME: This is a temporary workaround until the reserved registers can be
487  // serialized.
489  MRI.freezeReservedRegs(MF);
490 
491  computeFunctionProperties(MF);
492 
493  if (initializeCallSiteInfo(PFS, YamlMF))
494  return false;
495 
496  MF.getSubtarget().mirFileLoaded(MF);
497 
498  MF.verify();
499  return false;
500 }
501 
503  const yaml::MachineFunction &YamlMF) {
504  MachineFunction &MF = PFS.MF;
505  MachineRegisterInfo &RegInfo = MF.getRegInfo();
506  assert(RegInfo.tracksLiveness());
507  if (!YamlMF.TracksRegLiveness)
508  RegInfo.invalidateLiveness();
509 
511  // Parse the virtual register information.
512  for (const auto &VReg : YamlMF.VirtualRegisters) {
513  VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
514  if (Info.Explicit)
515  return error(VReg.ID.SourceRange.Start,
516  Twine("redefinition of virtual register '%") +
517  Twine(VReg.ID.Value) + "'");
518  Info.Explicit = true;
519 
520  if (StringRef(VReg.Class.Value).equals("_")) {
521  Info.Kind = VRegInfo::GENERIC;
522  Info.D.RegBank = nullptr;
523  } else {
524  const auto *RC = Target->getRegClass(VReg.Class.Value);
525  if (RC) {
526  Info.Kind = VRegInfo::NORMAL;
527  Info.D.RC = RC;
528  } else {
529  const RegisterBank *RegBank = Target->getRegBank(VReg.Class.Value);
530  if (!RegBank)
531  return error(
532  VReg.Class.SourceRange.Start,
533  Twine("use of undefined register class or register bank '") +
534  VReg.Class.Value + "'");
535  Info.Kind = VRegInfo::REGBANK;
536  Info.D.RegBank = RegBank;
537  }
538  }
539 
540  if (!VReg.PreferredRegister.Value.empty()) {
541  if (Info.Kind != VRegInfo::NORMAL)
542  return error(VReg.Class.SourceRange.Start,
543  Twine("preferred register can only be set for normal vregs"));
544 
545  if (parseRegisterReference(PFS, Info.PreferredReg,
546  VReg.PreferredRegister.Value, Error))
547  return error(Error, VReg.PreferredRegister.SourceRange);
548  }
549  }
550 
551  // Parse the liveins.
552  for (const auto &LiveIn : YamlMF.LiveIns) {
553  unsigned Reg = 0;
554  if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
555  return error(Error, LiveIn.Register.SourceRange);
556  unsigned VReg = 0;
557  if (!LiveIn.VirtualRegister.Value.empty()) {
558  VRegInfo *Info;
559  if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
560  Error))
561  return error(Error, LiveIn.VirtualRegister.SourceRange);
562  VReg = Info->VReg;
563  }
564  RegInfo.addLiveIn(Reg, VReg);
565  }
566 
567  // Parse the callee saved registers (Registers that will
568  // be saved for the caller).
569  if (YamlMF.CalleeSavedRegisters) {
570  SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
571  for (const auto &RegSource : YamlMF.CalleeSavedRegisters.getValue()) {
572  unsigned Reg = 0;
573  if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
574  return error(Error, RegSource.SourceRange);
575  CalleeSavedRegisters.push_back(Reg);
576  }
577  RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
578  }
579 
580  return false;
581 }
582 
584  const yaml::MachineFunction &YamlMF) {
585  MachineFunction &MF = PFS.MF;
587  bool Error = false;
588  // Create VRegs
589  auto populateVRegInfo = [&] (const VRegInfo &Info, Twine Name) {
590  unsigned Reg = Info.VReg;
591  switch (Info.Kind) {
592  case VRegInfo::UNKNOWN:
593  error(Twine("Cannot determine class/bank of virtual register ") +
594  Name + " in function '" + MF.getName() + "'");
595  Error = true;
596  break;
597  case VRegInfo::NORMAL:
598  MRI.setRegClass(Reg, Info.D.RC);
599  if (Info.PreferredReg != 0)
600  MRI.setSimpleHint(Reg, Info.PreferredReg);
601  break;
602  case VRegInfo::GENERIC:
603  break;
604  case VRegInfo::REGBANK:
605  MRI.setRegBank(Reg, *Info.D.RegBank);
606  break;
607  }
608  };
609 
610  for (auto I = PFS.VRegInfosNamed.begin(), E = PFS.VRegInfosNamed.end();
611  I != E; I++) {
612  const VRegInfo &Info = *I->second;
613  populateVRegInfo(Info, Twine(I->first()));
614  }
615 
616  for (auto P : PFS.VRegInfos) {
617  const VRegInfo &Info = *P.second;
618  populateVRegInfo(Info, Twine(P.first));
619  }
620 
621  // Compute MachineRegisterInfo::UsedPhysRegMask
622  for (const MachineBasicBlock &MBB : MF) {
623  for (const MachineInstr &MI : MBB) {
624  for (const MachineOperand &MO : MI.operands()) {
625  if (!MO.isRegMask())
626  continue;
627  MRI.addPhysRegsUsedFromRegMask(MO.getRegMask());
628  }
629  }
630  }
631 
632  return Error;
633 }
634 
636  const yaml::MachineFunction &YamlMF) {
637  MachineFunction &MF = PFS.MF;
638  MachineFrameInfo &MFI = MF.getFrameInfo();
640  const Function &F = MF.getFunction();
641  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
644  MFI.setHasStackMap(YamlMFI.HasStackMap);
645  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
646  MFI.setStackSize(YamlMFI.StackSize);
648  if (YamlMFI.MaxAlignment)
649  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
650  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
651  MFI.setHasCalls(YamlMFI.HasCalls);
652  if (YamlMFI.MaxCallFrameSize != ~0u)
656  MFI.setHasVAStart(YamlMFI.HasVAStart);
658  MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
659  if (!YamlMFI.SavePoint.Value.empty()) {
660  MachineBasicBlock *MBB = nullptr;
661  if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
662  return true;
663  MFI.setSavePoint(MBB);
664  }
665  if (!YamlMFI.RestorePoint.Value.empty()) {
666  MachineBasicBlock *MBB = nullptr;
667  if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
668  return true;
669  MFI.setRestorePoint(MBB);
670  }
671 
672  std::vector<CalleeSavedInfo> CSIInfo;
673  // Initialize the fixed frame objects.
674  for (const auto &Object : YamlMF.FixedStackObjects) {
675  int ObjectIdx;
676  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
677  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
678  Object.IsImmutable, Object.IsAliased);
679  else
680  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
681 
682  if (!TFI->isSupportedStackID(Object.StackID))
683  return error(Object.ID.SourceRange.Start,
684  Twine("StackID is not supported by target"));
685  MFI.setStackID(ObjectIdx, Object.StackID);
686  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
687  if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
688  ObjectIdx))
689  .second)
690  return error(Object.ID.SourceRange.Start,
691  Twine("redefinition of fixed stack object '%fixed-stack.") +
692  Twine(Object.ID.Value) + "'");
693  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
694  Object.CalleeSavedRestored, ObjectIdx))
695  return true;
696  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
697  return true;
698  }
699 
700  // Initialize the ordinary frame objects.
701  for (const auto &Object : YamlMF.StackObjects) {
702  int ObjectIdx;
703  const AllocaInst *Alloca = nullptr;
704  const yaml::StringValue &Name = Object.Name;
705  if (!Name.Value.empty()) {
706  Alloca = dyn_cast_or_null<AllocaInst>(
707  F.getValueSymbolTable()->lookup(Name.Value));
708  if (!Alloca)
709  return error(Name.SourceRange.Start,
710  "alloca instruction named '" + Name.Value +
711  "' isn't defined in the function '" + F.getName() +
712  "'");
713  }
714  if (!TFI->isSupportedStackID(Object.StackID))
715  return error(Object.ID.SourceRange.Start,
716  Twine("StackID is not supported by target"));
717  if (Object.Type == yaml::MachineStackObject::VariableSized)
718  ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
719  else
720  ObjectIdx = MFI.CreateStackObject(
721  Object.Size, Object.Alignment,
722  Object.Type == yaml::MachineStackObject::SpillSlot, Alloca,
723  Object.StackID);
724  MFI.setObjectOffset(ObjectIdx, Object.Offset);
725 
726  if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
727  .second)
728  return error(Object.ID.SourceRange.Start,
729  Twine("redefinition of stack object '%stack.") +
730  Twine(Object.ID.Value) + "'");
731  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
732  Object.CalleeSavedRestored, ObjectIdx))
733  return true;
734  if (Object.LocalOffset)
735  MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
736  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
737  return true;
738  }
739  MFI.setCalleeSavedInfo(CSIInfo);
740  if (!CSIInfo.empty())
741  MFI.setCalleeSavedInfoValid(true);
742 
743  // Initialize the various stack object references after initializing the
744  // stack objects.
745  if (!YamlMFI.StackProtector.Value.empty()) {
747  int FI;
748  if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
749  return error(Error, YamlMFI.StackProtector.SourceRange);
750  MFI.setStackProtectorIndex(FI);
751  }
752  return false;
753 }
754 
756  std::vector<CalleeSavedInfo> &CSIInfo,
757  const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
758  if (RegisterSource.Value.empty())
759  return false;
760  unsigned Reg = 0;
762  if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
763  return error(Error, RegisterSource.SourceRange);
764  CalleeSavedInfo CSI(Reg, FrameIdx);
765  CSI.setRestored(IsRestored);
766  CSIInfo.push_back(CSI);
767  return false;
768 }
769 
770 /// Verify that given node is of a certain type. Return true on error.
771 template <typename T>
772 static bool typecheckMDNode(T *&Result, MDNode *Node,
773  const yaml::StringValue &Source,
774  StringRef TypeString, MIRParserImpl &Parser) {
775  if (!Node)
776  return false;
777  Result = dyn_cast<T>(Node);
778  if (!Result)
779  return Parser.error(Source.SourceRange.Start,
780  "expected a reference to a '" + TypeString +
781  "' metadata node");
782  return false;
783 }
784 
785 template <typename T>
787  const T &Object, int FrameIdx) {
788  // Debug information can only be attached to stack objects; Fixed stack
789  // objects aren't supported.
790  MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
791  if (parseMDNode(PFS, Var, Object.DebugVar) ||
792  parseMDNode(PFS, Expr, Object.DebugExpr) ||
793  parseMDNode(PFS, Loc, Object.DebugLoc))
794  return true;
795  if (!Var && !Expr && !Loc)
796  return false;
797  DILocalVariable *DIVar = nullptr;
798  DIExpression *DIExpr = nullptr;
799  DILocation *DILoc = nullptr;
800  if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
801  typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
802  typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
803  return true;
804  PFS.MF.setVariableDbgInfo(DIVar, DIExpr, FrameIdx, DILoc);
805  return false;
806 }
807 
808 bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
809  MDNode *&Node, const yaml::StringValue &Source) {
810  if (Source.Value.empty())
811  return false;
813  if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
814  return error(Error, Source.SourceRange);
815  return false;
816 }
817 
820  DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
821  const MachineFunction &MF = PFS.MF;
822  const auto &M = *MF.getFunction().getParent();
824  for (const auto &YamlConstant : YamlMF.Constants) {
825  if (YamlConstant.IsTargetSpecific)
826  // FIXME: Support target-specific constant pools
827  return error(YamlConstant.Value.SourceRange.Start,
828  "Can't parse target-specific constant pool entries yet");
829  const Constant *Value = dyn_cast_or_null<Constant>(
830  parseConstantValue(YamlConstant.Value.Value, Error, M));
831  if (!Value)
832  return error(Error, YamlConstant.Value.SourceRange);
833  unsigned Alignment =
834  YamlConstant.Alignment
835  ? YamlConstant.Alignment
836  : M.getDataLayout().getPrefTypeAlignment(Value->getType());
837  unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
838  if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
839  .second)
840  return error(YamlConstant.ID.SourceRange.Start,
841  Twine("redefinition of constant pool item '%const.") +
842  Twine(YamlConstant.ID.Value) + "'");
843  }
844  return false;
845 }
846 
848  const yaml::MachineJumpTable &YamlJTI) {
850  for (const auto &Entry : YamlJTI.Entries) {
851  std::vector<MachineBasicBlock *> Blocks;
852  for (const auto &MBBSource : Entry.Blocks) {
853  MachineBasicBlock *MBB = nullptr;
854  if (parseMBBReference(PFS, MBB, MBBSource.Value))
855  return true;
856  Blocks.push_back(MBB);
857  }
858  unsigned Index = JTI->createJumpTableIndex(Blocks);
859  if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
860  .second)
861  return error(Entry.ID.SourceRange.Start,
862  Twine("redefinition of jump table entry '%jump-table.") +
863  Twine(Entry.ID.Value) + "'");
864  }
865  return false;
866 }
867 
868 bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
869  MachineBasicBlock *&MBB,
870  const yaml::StringValue &Source) {
872  if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
873  return error(Error, Source.SourceRange);
874  return false;
875 }
876 
877 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
878  SMRange SourceRange) {
879  assert(SourceRange.isValid() && "Invalid source range");
880  SMLoc Loc = SourceRange.Start;
881  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
882  *Loc.getPointer() == '\'';
883  // Translate the location of the error from the location in the MI string to
884  // the corresponding location in the MIR file.
885  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
886  (HasQuote ? 1 : 0));
887 
888  // TODO: Translate any source ranges as well.
889  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
890  Error.getFixIts());
891 }
892 
893 SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
894  SMRange SourceRange) {
895  assert(SourceRange.isValid());
896 
897  // Translate the location of the error from the location in the llvm IR string
898  // to the corresponding location in the MIR file.
899  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
900  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
901  unsigned Column = Error.getColumnNo();
902  StringRef LineStr = Error.getLineContents();
903  SMLoc Loc = Error.getLoc();
904 
905  // Get the full line and adjust the column number by taking the indentation of
906  // LLVM IR into account.
907  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
908  L != E; ++L) {
909  if (L.line_number() == Line) {
910  LineStr = *L;
911  Loc = SMLoc::getFromPointer(LineStr.data());
912  auto Indent = LineStr.find(Error.getLineContents());
913  if (Indent != StringRef::npos)
914  Column += Indent;
915  break;
916  }
917  }
918 
919  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
920  Error.getMessage(), LineStr, Error.getRanges(),
921  Error.getFixIts());
922 }
923 
924 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
925  : Impl(std::move(Impl)) {}
926 
928 
929 std::unique_ptr<Module> MIRParser::parseIRModule() {
930  return Impl->parseIRModule();
931 }
932 
934  return Impl->parseMachineFunctions(M, MMI);
935 }
936 
937 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(
938  StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
939  std::function<void(Function &)> ProcessIRFunction) {
940  auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
941  if (std::error_code EC = FileOrErr.getError()) {
942  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
943  "Could not open input file: " + EC.message());
944  return nullptr;
945  }
946  return createMIRParser(std::move(FileOrErr.get()), Context,
947  ProcessIRFunction);
948 }
949 
950 std::unique_ptr<MIRParser>
951 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
952  LLVMContext &Context,
953  std::function<void(Function &)> ProcessIRFunction) {
954  auto Filename = Contents->getBufferIdentifier();
955  if (Context.shouldDiscardValueNames()) {
957  DS_Error,
958  SMDiagnostic(
959  Filename, SourceMgr::DK_Error,
960  "Can't read MIR with a Context that discards named Values")));
961  return nullptr;
962  }
963  return std::make_unique<MIRParser>(std::make_unique<MIRParserImpl>(
964  std::move(Contents), Filename, Context, ProcessIRFunction));
965 }
void setHasStackMap(bool s=true)
virtual bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const
Parse out the target&#39;s MachineFunctionInfo from the YAML reprsentation.
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:48
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:641
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
void setSavePoint(MachineBasicBlock *NewSave)
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
Definition: MIParser.cpp:3157
void setRestorePoint(MachineBasicBlock *NewRestore)
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:172
LLVMContext & Context
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
void setCalleeSavedInfoValid(bool v)
virtual bool isSupportedStackID(TargetStackID::Value ID) const
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:171
This class represents lattice values for constants.
Definition: AllocatorList.h:23
SMLoc getLoc() const
Definition: SourceMgr.h:287
MachineFunctionProperties & reset(Property P)
virtual yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
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:147
unsigned EnableDebugEntryValues
Emit debug info about parameter&#39;s entry values.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
const MachineFunctionProperties & getProperties() const
Get the function properties.
unsigned size() const
Optional< std::vector< FlowStringValue > > CalleeSavedRegisters
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
unsigned Reg
Diagnostic information for machine IR parser.
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI)
Parse the machine function in the current YAML document.
Definition: MIRParser.cpp:279
void ensureMaxAlignment(Align Alignment)
Make sure the function is at least Align bytes aligned.
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:170
Externally visible function.
Definition: GlobalValue.h:48
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:31
Metadata node.
Definition: Metadata.h:872
F(f)
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition: Register.h:83
ArrayRef< SMFixIt > getFixIts() const
Definition: SourceMgr.h:300
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3168
const TargetRegisterClass * RC
Definition: MIParser.h:40
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:352
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. ...
Definition: SourceMgr.cpp:125
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist...
std::unique_ptr< Module > parseIRModule()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:219
SMLoc Start
Definition: SMLoc.h:50
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:195
void setAlignment(Align A)
setAlignment - Set the alignment of the function.
const TimePointType Start
Definition: BitVector.h:937
void setHasPatchPoint(bool s=true)
void setLocalFrameSize(int64_t sz)
Set the size of the local object blob.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:168
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:245
int getLineNo() const
Definition: SourceMgr.h:289
void freezeReservedRegs(const MachineFunction &)
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI...
Definition: MIRParser.cpp:933
int CreateVariableSizedObject(Align Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:169
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:132
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:246
std::vector< VirtualRegisterDefinition > VirtualRegisters
StringRef getLineContents() const
Definition: SourceMgr.h:293
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:583
void setHasMustTailInVarArgFunc(bool B)
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:153
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:167
unsigned PreferredReg
Definition: MIParser.h:44
virtual void mirFileLoaded(MachineFunction &MF) const
This is called after a .mir file was loaded.
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3186
Debug location.
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
union llvm::VRegInfo::@178 D
Analysis containing CSE Info
Definition: CSEInfo.cpp:25
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true, StringRef DataLayoutString="")
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:41
unsigned getMainFileID() const
Definition: SourceMgr.h:141
Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
Definition: MIRParser.cpp:265
#define P(N)
const char * getPointer() const
Definition: SMLoc.h:34
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.
Definition: MIRParser.cpp:937
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3192
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:135
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Definition: MIRParser.cpp:251
unsigned const MachineRegisterInfo * MRI
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:502
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const T &Object, int FrameIdx)
Definition: MIRParser.cpp:786
static bool isSSA(const MachineFunction &MF)
Definition: MIRParser.cpp:315
LLVM Basic Block Representation.
Definition: BasicBlock.h:57
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:63
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Definition: Constant.h:41
void setStackSize(uint64_t Size)
Set the size of the stack.
MachineJumpTable JumpTableInfo
Identifies call instruction location in machine function.
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
Definition: MIRParser.cpp:847
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:306
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3180
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:165
void addCallArgsForwardingRegs(const MachineInstr *CallI, CallSiteInfoImpl &&CallInfo)
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.
Definition: MIRParser.cpp:772
This class describes a target machine that is implemented with the LLVM target-independent code gener...
unsigned MaxCallFrameSize
~0u means: not computed yet.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:301
std::vector< MachineStackObject > StackObjects
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:99
void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
void reportDiagnostic(const SMDiagnostic &Diag)
Definition: MIRParser.cpp:200
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
Serializable representation of MachineFrameInfo.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
void setStackID(int ObjectIdx, uint8_t ID)
MachineFunction & getOrCreateMachineFunction(const Function &F)
Returns the MachineFunction constructed for the IR function F.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
Return an SMDiagnostic at the specified location with the specified string.
Definition: SourceMgr.cpp:163
This class implements the parsing of LLVM IR that&#39;s embedded inside a MIR file.
Definition: MIRParser.cpp:52
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:3163
bool isValid() const
Definition: SMLoc.h:59
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr...
enum llvm::VRegInfo::uint8_t Kind
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
Module.h This file contains the declarations for the Module class.
StringRef getMessage() const
Definition: SourceMgr.h:292
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.
Definition: MIRParser.cpp:951
Information about stack frame layout on the target.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition: SourceMgr.h:294
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
This class implements the register bank concept.
Definition: RegisterBank.h:28
DWARF expression.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition: Function.h:683
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:174
Target - Wrapper for Target specific information.
SMLoc End
Definition: SMLoc.h:50
A wrapper around std::string which contains a source range that&#39;s being set during parsing...
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:291
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:32
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3198
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition: MIRParser.cpp:182
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:181
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
const LLVMTargetMachine & getTarget() const
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:38
Representation of each machine instruction.
Definition: MachineInstr.h:63
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function&#39;s callee saved information.
std::vector< MachineFunctionLiveIn > LiveIns
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context, std::function< void(Function &)> ProcessIRFunction)
Definition: MIRParser.cpp:171
int getColumnNo() const
Definition: SourceMgr.h:290
static const size_t npos
Definition: StringRef.h:56
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:635
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
std::vector< Entry > Entries
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:215
TargetOptions Options
unsigned VReg
Definition: MIParser.h:43
VRegInfo & getVRegInfo(unsigned Num)
Definition: MIParser.cpp:324
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:58
void setMaxCallFrameSize(unsigned S)
virtual const TargetFrameLowering * getFrameLowering() const
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
std::vector< MachineConstantPoolValue > Constants
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
void setCVBytesOfCalleeSavedRegisters(unsigned S)
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition: MIRParser.cpp:924
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there&#39;s a call to a "returns twice" function...
std::vector< CallSiteInfo > CallSitesInfo
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
void setSimpleHint(unsigned VReg, unsigned PrefReg)
Specify the preferred (target independent) register allocation hint for the specified virtual registe...
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:143
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:818
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< FixedMachineStackObject > FixedStackObjects
void setReturnAddressIsTaken(bool s)
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...
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:575
LLVM Value Representation.
Definition: Value.h:74
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
std::unique_ptr< Module > parseIRModule()
Parses the optional LLVM IR module in the MIR file.
Definition: MIRParser.cpp:929
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock *> &DestBBs)
createJumpTableIndex - Create a new jump table.
print Print MemDeps of function
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
IRTranslator LLVM IR MI
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
const RegisterBank * RegBank
Definition: MIParser.h:41
MachineJumpTableInfo::JTEntryKind Kind
Represents a location in source code.
Definition: SMLoc.h:23
DenseMap< unsigned, VRegInfo * > VRegInfos
Definition: MIParser.h:167
bool parseRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3174
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
bool initializeMachineFunction(const yaml::MachineFunction &YamlMF, MachineFunction &MF)
Initialize the machine function to the state that&#39;s described in the MIR file.
Definition: MIRParser.cpp:394
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx)
Definition: MIRParser.cpp:755
Properties which a MachineFunction may have at a given point in time.
This class contains meta information specific to a module.
an instruction to allocate memory on the stack
Definition: Instructions.h:59
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:261