LLVM  8.0.0svn
MIRParser.cpp
Go to the documentation of this file.
1 //===- MIRParser.cpp - MIR serialization format parser implementation -----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the class that parses the optional LLVM IR and machine
11 // functions that are stored in MIR files.
12 //
13 //===----------------------------------------------------------------------===//
14 
16 #include "MIParser.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #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"
43 #include <memory>
44 
45 using namespace llvm;
46 
47 namespace llvm {
48 
49 /// This class implements the parsing of LLVM IR that's embedded inside a MIR
50 /// file.
52  SourceMgr SM;
53  yaml::Input In;
54  StringRef Filename;
55  LLVMContext &Context;
56  SlotMapping IRSlots;
57  /// Maps from register class names to register classes.
58  Name2RegClassMap Names2RegClasses;
59  /// Maps from register bank names to register banks.
60  Name2RegBankMap Names2RegBanks;
61  /// True when the MIR file doesn't have LLVM IR. Dummy IR functions are
62  /// created and inserted into the given module when this is true.
63  bool NoLLVMIR = false;
64  /// True when a well formed MIR file does not contain any MIR/machine function
65  /// parts.
66  bool NoMIRDocuments = false;
67 
68 public:
69  MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
70  StringRef Filename, LLVMContext &Context);
71 
72  void reportDiagnostic(const SMDiagnostic &Diag);
73 
74  /// Report an error with the given message at unknown location.
75  ///
76  /// Always returns true.
77  bool error(const Twine &Message);
78 
79  /// Report an error with the given message at the given location.
80  ///
81  /// Always returns true.
82  bool error(SMLoc Loc, const Twine &Message);
83 
84  /// Report a given error with the location translated from the location in an
85  /// embedded string literal to a location in the MIR file.
86  ///
87  /// Always returns true.
88  bool error(const SMDiagnostic &Error, SMRange SourceRange);
89 
90  /// Try to parse the optional LLVM module and the machine functions in the MIR
91  /// file.
92  ///
93  /// Return null if an error occurred.
94  std::unique_ptr<Module> parseIRModule();
95 
97 
98  /// Parse the machine function in the current YAML document.
99  ///
100  ///
101  /// Return true if an error occurred.
103 
104  /// Initialize the machine function to the state that's described in the MIR
105  /// file.
106  ///
107  /// Return true if error occurred.
109  MachineFunction &MF);
110 
112  const yaml::MachineFunction &YamlMF);
113 
115  const yaml::MachineFunction &YamlMF);
116 
118  const yaml::MachineFunction &YamlMF);
119 
121  std::vector<CalleeSavedInfo> &CSIInfo,
122  const yaml::StringValue &RegisterSource,
123  bool IsRestored, int FrameIdx);
124 
125  template <typename T>
127  const T &Object,
128  int FrameIdx);
129 
132  const yaml::MachineFunction &YamlMF);
133 
135  const yaml::MachineJumpTable &YamlJTI);
136 
137 private:
138  bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node,
139  const yaml::StringValue &Source);
140 
141  bool parseMBBReference(PerFunctionMIParsingState &PFS,
142  MachineBasicBlock *&MBB,
143  const yaml::StringValue &Source);
144 
145  /// Return a MIR diagnostic converted from an MI string diagnostic.
146  SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
147  SMRange SourceRange);
148 
149  /// Return a MIR diagnostic converted from a diagnostic located in a YAML
150  /// block scalar string.
151  SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
152  SMRange SourceRange);
153 
154  void initNames2RegClasses(const MachineFunction &MF);
155  void initNames2RegBanks(const MachineFunction &MF);
156 
157  /// Check if the given identifier is a name of a register class.
158  ///
159  /// Return null if the name isn't a register class.
160  const TargetRegisterClass *getRegClass(const MachineFunction &MF,
161  StringRef Name);
162 
163  /// Check if the given identifier is a name of a register bank.
164  ///
165  /// Return null if the name isn't a register bank.
166  const RegisterBank *getRegBank(const MachineFunction &MF, StringRef Name);
167 
168  void computeFunctionProperties(MachineFunction &MF);
169 };
170 
171 } // end namespace llvm
172 
173 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
174  reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
175 }
176 
177 MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
178  StringRef Filename, LLVMContext &Context)
179  : SM(),
180  In(SM.getMemoryBuffer(
181  SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))->getBuffer(),
182  nullptr, handleYAMLDiag, this),
183  Filename(Filename),
184  Context(Context) {
185  In.setContext(&In);
186 }
187 
188 bool MIRParserImpl::error(const Twine &Message) {
190  DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
191  return true;
192 }
193 
194 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
196  DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
197  return true;
198 }
199 
200 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
201  assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
202  reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
203  return true;
204 }
205 
208  switch (Diag.getKind()) {
209  case SourceMgr::DK_Error:
210  Kind = DS_Error;
211  break;
213  Kind = DS_Warning;
214  break;
215  case SourceMgr::DK_Note:
216  Kind = DS_Note;
217  break;
219  llvm_unreachable("remark unexpected");
220  break;
221  }
222  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
223 }
224 
225 std::unique_ptr<Module> MIRParserImpl::parseIRModule() {
226  if (!In.setCurrentDocument()) {
227  if (In.error())
228  return nullptr;
229  // Create an empty module when the MIR file is empty.
230  NoMIRDocuments = true;
231  return llvm::make_unique<Module>(Filename, Context);
232  }
233 
234  std::unique_ptr<Module> M;
235  // Parse the block scalar manually so that we can return unique pointer
236  // without having to go trough YAML traits.
237  if (const auto *BSN =
238  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
240  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
241  Context, &IRSlots, /*UpgradeDebugInfo=*/false);
242  if (!M) {
243  reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
244  return nullptr;
245  }
246  In.nextDocument();
247  if (!In.setCurrentDocument())
248  NoMIRDocuments = true;
249  } else {
250  // Create an new, empty module.
251  M = llvm::make_unique<Module>(Filename, Context);
252  NoLLVMIR = true;
253  }
254  return M;
255 }
256 
258  if (NoMIRDocuments)
259  return false;
260 
261  // Parse the machine functions.
262  do {
263  if (parseMachineFunction(M, MMI))
264  return true;
265  In.nextDocument();
266  } while (In.setCurrentDocument());
267 
268  return false;
269 }
270 
271 /// Create an empty function with the given name.
273  auto &Context = M.getContext();
274  Function *F = cast<Function>(M.getOrInsertFunction(
275  Name, FunctionType::get(Type::getVoidTy(Context), false)));
276  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
277  new UnreachableInst(Context, BB);
278  return F;
279 }
280 
282  // Parse the yaml.
283  yaml::MachineFunction YamlMF;
284  yaml::EmptyContext Ctx;
285  yaml::yamlize(In, YamlMF, false, Ctx);
286  if (In.error())
287  return true;
288 
289  // Search for the corresponding IR function.
290  StringRef FunctionName = YamlMF.Name;
291  Function *F = M.getFunction(FunctionName);
292  if (!F) {
293  if (NoLLVMIR) {
294  F = createDummyFunction(FunctionName, M);
295  } else {
296  return error(Twine("function '") + FunctionName +
297  "' isn't defined in the provided LLVM IR");
298  }
299  }
300  if (MMI.getMachineFunction(*F) != nullptr)
301  return error(Twine("redefinition of machine function '") + FunctionName +
302  "'");
303 
304  // Create the MachineFunction.
306  if (initializeMachineFunction(YamlMF, MF))
307  return true;
308 
309  return false;
310 }
311 
312 static bool isSSA(const MachineFunction &MF) {
313  const MachineRegisterInfo &MRI = MF.getRegInfo();
314  for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
316  if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
317  return false;
318  }
319  return true;
320 }
321 
322 void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
323  MachineFunctionProperties &Properties = MF.getProperties();
324 
325  bool HasPHI = false;
326  bool HasInlineAsm = false;
327  for (const MachineBasicBlock &MBB : MF) {
328  for (const MachineInstr &MI : MBB) {
329  if (MI.isPHI())
330  HasPHI = true;
331  if (MI.isInlineAsm())
332  HasInlineAsm = true;
333  }
334  }
335  if (!HasPHI)
337  MF.setHasInlineAsm(HasInlineAsm);
338 
339  if (isSSA(MF))
341  else
343 
344  const MachineRegisterInfo &MRI = MF.getRegInfo();
345  if (MRI.getNumVirtRegs() == 0)
347 }
348 
349 bool
351  MachineFunction &MF) {
352  // TODO: Recreate the machine function.
353  initNames2RegClasses(MF);
354  initNames2RegBanks(MF);
355  if (YamlMF.Alignment)
356  MF.setAlignment(YamlMF.Alignment);
358 
359  if (YamlMF.Legalized)
361  if (YamlMF.RegBankSelected)
362  MF.getProperties().set(
364  if (YamlMF.Selected)
366  if (YamlMF.FailedISel)
368 
369  PerFunctionMIParsingState PFS(MF, SM, IRSlots, Names2RegClasses,
370  Names2RegBanks);
371  if (parseRegisterInfo(PFS, YamlMF))
372  return true;
373  if (!YamlMF.Constants.empty()) {
374  auto *ConstantPool = MF.getConstantPool();
375  assert(ConstantPool && "Constant pool must be created");
376  if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
377  return true;
378  }
379 
380  StringRef BlockStr = YamlMF.Body.Value.Value;
382  SourceMgr BlockSM;
383  BlockSM.AddNewSourceBuffer(
384  MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
385  SMLoc());
386  PFS.SM = &BlockSM;
387  if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
389  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
390  return true;
391  }
392  PFS.SM = &SM;
393 
394  // Initialize the frame information after creating all the MBBs so that the
395  // MBB references in the frame information can be resolved.
396  if (initializeFrameInfo(PFS, YamlMF))
397  return true;
398  // Initialize the jump table after creating all the MBBs so that the MBB
399  // references can be resolved.
400  if (!YamlMF.JumpTableInfo.Entries.empty() &&
402  return true;
403  // Parse the machine instructions after creating all of the MBBs so that the
404  // parser can resolve the MBB references.
405  StringRef InsnStr = YamlMF.Body.Value.Value;
406  SourceMgr InsnSM;
407  InsnSM.AddNewSourceBuffer(
408  MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
409  SMLoc());
410  PFS.SM = &InsnSM;
411  if (parseMachineInstructions(PFS, InsnStr, Error)) {
413  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
414  return true;
415  }
416  PFS.SM = &SM;
417 
418  if (setupRegisterInfo(PFS, YamlMF))
419  return true;
420 
421  computeFunctionProperties(MF);
422 
423  MF.getSubtarget().mirFileLoaded(MF);
424 
425  MF.verify();
426  return false;
427 }
428 
430  const yaml::MachineFunction &YamlMF) {
431  MachineFunction &MF = PFS.MF;
432  MachineRegisterInfo &RegInfo = MF.getRegInfo();
433  assert(RegInfo.tracksLiveness());
434  if (!YamlMF.TracksRegLiveness)
435  RegInfo.invalidateLiveness();
436 
438  // Parse the virtual register information.
439  for (const auto &VReg : YamlMF.VirtualRegisters) {
440  VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
441  if (Info.Explicit)
442  return error(VReg.ID.SourceRange.Start,
443  Twine("redefinition of virtual register '%") +
444  Twine(VReg.ID.Value) + "'");
445  Info.Explicit = true;
446 
447  if (StringRef(VReg.Class.Value).equals("_")) {
448  Info.Kind = VRegInfo::GENERIC;
449  Info.D.RegBank = nullptr;
450  } else {
451  const auto *RC = getRegClass(MF, VReg.Class.Value);
452  if (RC) {
453  Info.Kind = VRegInfo::NORMAL;
454  Info.D.RC = RC;
455  } else {
456  const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
457  if (!RegBank)
458  return error(
459  VReg.Class.SourceRange.Start,
460  Twine("use of undefined register class or register bank '") +
461  VReg.Class.Value + "'");
462  Info.Kind = VRegInfo::REGBANK;
463  Info.D.RegBank = RegBank;
464  }
465  }
466 
467  if (!VReg.PreferredRegister.Value.empty()) {
468  if (Info.Kind != VRegInfo::NORMAL)
469  return error(VReg.Class.SourceRange.Start,
470  Twine("preferred register can only be set for normal vregs"));
471 
472  if (parseRegisterReference(PFS, Info.PreferredReg,
473  VReg.PreferredRegister.Value, Error))
474  return error(Error, VReg.PreferredRegister.SourceRange);
475  }
476  }
477 
478  // Parse the liveins.
479  for (const auto &LiveIn : YamlMF.LiveIns) {
480  unsigned Reg = 0;
481  if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
482  return error(Error, LiveIn.Register.SourceRange);
483  unsigned VReg = 0;
484  if (!LiveIn.VirtualRegister.Value.empty()) {
485  VRegInfo *Info;
486  if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
487  Error))
488  return error(Error, LiveIn.VirtualRegister.SourceRange);
489  VReg = Info->VReg;
490  }
491  RegInfo.addLiveIn(Reg, VReg);
492  }
493 
494  // Parse the callee saved registers (Registers that will
495  // be saved for the caller).
496  if (YamlMF.CalleeSavedRegisters) {
497  SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
498  for (const auto &RegSource : YamlMF.CalleeSavedRegisters.getValue()) {
499  unsigned Reg = 0;
500  if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
501  return error(Error, RegSource.SourceRange);
502  CalleeSavedRegisters.push_back(Reg);
503  }
504  RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
505  }
506 
507  return false;
508 }
509 
511  const yaml::MachineFunction &YamlMF) {
512  MachineFunction &MF = PFS.MF;
514  bool Error = false;
515  // Create VRegs
516  auto populateVRegInfo = [&] (const VRegInfo &Info, Twine Name) {
517  unsigned Reg = Info.VReg;
518  switch (Info.Kind) {
519  case VRegInfo::UNKNOWN:
520  error(Twine("Cannot determine class/bank of virtual register ") +
521  Name + " in function '" + MF.getName() + "'");
522  Error = true;
523  break;
524  case VRegInfo::NORMAL:
525  MRI.setRegClass(Reg, Info.D.RC);
526  if (Info.PreferredReg != 0)
527  MRI.setSimpleHint(Reg, Info.PreferredReg);
528  break;
529  case VRegInfo::GENERIC:
530  break;
531  case VRegInfo::REGBANK:
532  MRI.setRegBank(Reg, *Info.D.RegBank);
533  break;
534  }
535  };
536 
537  for (auto I = PFS.VRegInfosNamed.begin(), E = PFS.VRegInfosNamed.end();
538  I != E; I++) {
539  const VRegInfo &Info = *I->second;
540  populateVRegInfo(Info, Twine(I->first()));
541  }
542 
543  for (auto P : PFS.VRegInfos) {
544  const VRegInfo &Info = *P.second;
545  populateVRegInfo(Info, Twine(P.first));
546  }
547 
548  // Compute MachineRegisterInfo::UsedPhysRegMask
549  for (const MachineBasicBlock &MBB : MF) {
550  for (const MachineInstr &MI : MBB) {
551  for (const MachineOperand &MO : MI.operands()) {
552  if (!MO.isRegMask())
553  continue;
554  MRI.addPhysRegsUsedFromRegMask(MO.getRegMask());
555  }
556  }
557  }
558 
559  // FIXME: This is a temporary workaround until the reserved registers can be
560  // serialized.
561  MRI.freezeReservedRegs(MF);
562  return Error;
563 }
564 
566  const yaml::MachineFunction &YamlMF) {
567  MachineFunction &MF = PFS.MF;
568  MachineFrameInfo &MFI = MF.getFrameInfo();
569  const Function &F = MF.getFunction();
570  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
573  MFI.setHasStackMap(YamlMFI.HasStackMap);
574  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
575  MFI.setStackSize(YamlMFI.StackSize);
577  if (YamlMFI.MaxAlignment)
578  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
579  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
580  MFI.setHasCalls(YamlMFI.HasCalls);
581  if (YamlMFI.MaxCallFrameSize != ~0u)
584  MFI.setHasVAStart(YamlMFI.HasVAStart);
586  MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
587  if (!YamlMFI.SavePoint.Value.empty()) {
588  MachineBasicBlock *MBB = nullptr;
589  if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
590  return true;
591  MFI.setSavePoint(MBB);
592  }
593  if (!YamlMFI.RestorePoint.Value.empty()) {
594  MachineBasicBlock *MBB = nullptr;
595  if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
596  return true;
597  MFI.setRestorePoint(MBB);
598  }
599 
600  std::vector<CalleeSavedInfo> CSIInfo;
601  // Initialize the fixed frame objects.
602  for (const auto &Object : YamlMF.FixedStackObjects) {
603  int ObjectIdx;
604  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
605  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
606  Object.IsImmutable, Object.IsAliased);
607  else
608  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
609  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
610  MFI.setStackID(ObjectIdx, Object.StackID);
611  if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
612  ObjectIdx))
613  .second)
614  return error(Object.ID.SourceRange.Start,
615  Twine("redefinition of fixed stack object '%fixed-stack.") +
616  Twine(Object.ID.Value) + "'");
617  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
618  Object.CalleeSavedRestored, ObjectIdx))
619  return true;
620  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
621  return true;
622  }
623 
624  // Initialize the ordinary frame objects.
625  for (const auto &Object : YamlMF.StackObjects) {
626  int ObjectIdx;
627  const AllocaInst *Alloca = nullptr;
628  const yaml::StringValue &Name = Object.Name;
629  if (!Name.Value.empty()) {
630  Alloca = dyn_cast_or_null<AllocaInst>(
631  F.getValueSymbolTable()->lookup(Name.Value));
632  if (!Alloca)
633  return error(Name.SourceRange.Start,
634  "alloca instruction named '" + Name.Value +
635  "' isn't defined in the function '" + F.getName() +
636  "'");
637  }
638  if (Object.Type == yaml::MachineStackObject::VariableSized)
639  ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
640  else
641  ObjectIdx = MFI.CreateStackObject(
642  Object.Size, Object.Alignment,
643  Object.Type == yaml::MachineStackObject::SpillSlot, Alloca);
644  MFI.setObjectOffset(ObjectIdx, Object.Offset);
645  MFI.setStackID(ObjectIdx, Object.StackID);
646 
647  if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
648  .second)
649  return error(Object.ID.SourceRange.Start,
650  Twine("redefinition of stack object '%stack.") +
651  Twine(Object.ID.Value) + "'");
652  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
653  Object.CalleeSavedRestored, ObjectIdx))
654  return true;
655  if (Object.LocalOffset)
656  MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
657  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
658  return true;
659  }
660  MFI.setCalleeSavedInfo(CSIInfo);
661  if (!CSIInfo.empty())
662  MFI.setCalleeSavedInfoValid(true);
663 
664  // Initialize the various stack object references after initializing the
665  // stack objects.
666  if (!YamlMFI.StackProtector.Value.empty()) {
668  int FI;
669  if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
670  return error(Error, YamlMFI.StackProtector.SourceRange);
671  MFI.setStackProtectorIndex(FI);
672  }
673  return false;
674 }
675 
677  std::vector<CalleeSavedInfo> &CSIInfo,
678  const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
679  if (RegisterSource.Value.empty())
680  return false;
681  unsigned Reg = 0;
683  if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
684  return error(Error, RegisterSource.SourceRange);
685  CalleeSavedInfo CSI(Reg, FrameIdx);
686  CSI.setRestored(IsRestored);
687  CSIInfo.push_back(CSI);
688  return false;
689 }
690 
691 /// Verify that given node is of a certain type. Return true on error.
692 template <typename T>
693 static bool typecheckMDNode(T *&Result, MDNode *Node,
694  const yaml::StringValue &Source,
695  StringRef TypeString, MIRParserImpl &Parser) {
696  if (!Node)
697  return false;
698  Result = dyn_cast<T>(Node);
699  if (!Result)
700  return Parser.error(Source.SourceRange.Start,
701  "expected a reference to a '" + TypeString +
702  "' metadata node");
703  return false;
704 }
705 
706 template <typename T>
708  const T &Object, int FrameIdx) {
709  // Debug information can only be attached to stack objects; Fixed stack
710  // objects aren't supported.
711  MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
712  if (parseMDNode(PFS, Var, Object.DebugVar) ||
713  parseMDNode(PFS, Expr, Object.DebugExpr) ||
714  parseMDNode(PFS, Loc, Object.DebugLoc))
715  return true;
716  if (!Var && !Expr && !Loc)
717  return false;
718  DILocalVariable *DIVar = nullptr;
719  DIExpression *DIExpr = nullptr;
720  DILocation *DILoc = nullptr;
721  if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
722  typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
723  typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
724  return true;
725  PFS.MF.setVariableDbgInfo(DIVar, DIExpr, FrameIdx, DILoc);
726  return false;
727 }
728 
729 bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
730  MDNode *&Node, const yaml::StringValue &Source) {
731  if (Source.Value.empty())
732  return false;
734  if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
735  return error(Error, Source.SourceRange);
736  return false;
737 }
738 
741  DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
742  const MachineFunction &MF = PFS.MF;
743  const auto &M = *MF.getFunction().getParent();
745  for (const auto &YamlConstant : YamlMF.Constants) {
746  if (YamlConstant.IsTargetSpecific)
747  // FIXME: Support target-specific constant pools
748  return error(YamlConstant.Value.SourceRange.Start,
749  "Can't parse target-specific constant pool entries yet");
750  const Constant *Value = dyn_cast_or_null<Constant>(
751  parseConstantValue(YamlConstant.Value.Value, Error, M));
752  if (!Value)
753  return error(Error, YamlConstant.Value.SourceRange);
754  unsigned Alignment =
755  YamlConstant.Alignment
756  ? YamlConstant.Alignment
757  : M.getDataLayout().getPrefTypeAlignment(Value->getType());
758  unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
759  if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
760  .second)
761  return error(YamlConstant.ID.SourceRange.Start,
762  Twine("redefinition of constant pool item '%const.") +
763  Twine(YamlConstant.ID.Value) + "'");
764  }
765  return false;
766 }
767 
769  const yaml::MachineJumpTable &YamlJTI) {
771  for (const auto &Entry : YamlJTI.Entries) {
772  std::vector<MachineBasicBlock *> Blocks;
773  for (const auto &MBBSource : Entry.Blocks) {
774  MachineBasicBlock *MBB = nullptr;
775  if (parseMBBReference(PFS, MBB, MBBSource.Value))
776  return true;
777  Blocks.push_back(MBB);
778  }
779  unsigned Index = JTI->createJumpTableIndex(Blocks);
780  if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
781  .second)
782  return error(Entry.ID.SourceRange.Start,
783  Twine("redefinition of jump table entry '%jump-table.") +
784  Twine(Entry.ID.Value) + "'");
785  }
786  return false;
787 }
788 
789 bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
790  MachineBasicBlock *&MBB,
791  const yaml::StringValue &Source) {
793  if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
794  return error(Error, Source.SourceRange);
795  return false;
796 }
797 
798 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
799  SMRange SourceRange) {
800  assert(SourceRange.isValid() && "Invalid source range");
801  SMLoc Loc = SourceRange.Start;
802  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
803  *Loc.getPointer() == '\'';
804  // Translate the location of the error from the location in the MI string to
805  // the corresponding location in the MIR file.
806  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
807  (HasQuote ? 1 : 0));
808 
809  // TODO: Translate any source ranges as well.
810  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
811  Error.getFixIts());
812 }
813 
814 SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
815  SMRange SourceRange) {
816  assert(SourceRange.isValid());
817 
818  // Translate the location of the error from the location in the llvm IR string
819  // to the corresponding location in the MIR file.
820  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
821  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
822  unsigned Column = Error.getColumnNo();
823  StringRef LineStr = Error.getLineContents();
824  SMLoc Loc = Error.getLoc();
825 
826  // Get the full line and adjust the column number by taking the indentation of
827  // LLVM IR into account.
828  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
829  L != E; ++L) {
830  if (L.line_number() == Line) {
831  LineStr = *L;
832  Loc = SMLoc::getFromPointer(LineStr.data());
833  auto Indent = LineStr.find(Error.getLineContents());
834  if (Indent != StringRef::npos)
835  Column += Indent;
836  break;
837  }
838  }
839 
840  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
841  Error.getMessage(), LineStr, Error.getRanges(),
842  Error.getFixIts());
843 }
844 
845 void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
846  if (!Names2RegClasses.empty())
847  return;
849  for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
850  const auto *RC = TRI->getRegClass(I);
851  Names2RegClasses.insert(
852  std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
853  }
854 }
855 
856 void MIRParserImpl::initNames2RegBanks(const MachineFunction &MF) {
857  if (!Names2RegBanks.empty())
858  return;
859  const RegisterBankInfo *RBI = MF.getSubtarget().getRegBankInfo();
860  // If the target does not support GlobalISel, we may not have a
861  // register bank info.
862  if (!RBI)
863  return;
864  for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
865  const auto &RegBank = RBI->getRegBank(I);
866  Names2RegBanks.insert(
867  std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
868  }
869 }
870 
871 const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
872  StringRef Name) {
873  auto RegClassInfo = Names2RegClasses.find(Name);
874  if (RegClassInfo == Names2RegClasses.end())
875  return nullptr;
876  return RegClassInfo->getValue();
877 }
878 
879 const RegisterBank *MIRParserImpl::getRegBank(const MachineFunction &MF,
880  StringRef Name) {
881  auto RegBankInfo = Names2RegBanks.find(Name);
882  if (RegBankInfo == Names2RegBanks.end())
883  return nullptr;
884  return RegBankInfo->getValue();
885 }
886 
887 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
888  : Impl(std::move(Impl)) {}
889 
891 
892 std::unique_ptr<Module> MIRParser::parseIRModule() {
893  return Impl->parseIRModule();
894 }
895 
897  return Impl->parseMachineFunctions(M, MMI);
898 }
899 
900 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
901  SMDiagnostic &Error,
902  LLVMContext &Context) {
903  auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
904  if (std::error_code EC = FileOrErr.getError()) {
905  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
906  "Could not open input file: " + EC.message());
907  return nullptr;
908  }
909  return createMIRParser(std::move(FileOrErr.get()), Context);
910 }
911 
912 std::unique_ptr<MIRParser>
913 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
914  LLVMContext &Context) {
915  auto Filename = Contents->getBufferIdentifier();
916  if (Context.shouldDiscardValueNames()) {
918  DS_Error,
919  SMDiagnostic(
920  Filename, SourceMgr::DK_Error,
921  "Can't read MIR with a Context that discards named Values")));
922  return nullptr;
923  }
924  return llvm::make_unique<MIRParser>(
925  llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
926 }
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:49
void push_back(const T &Elt)
Definition: SmallVector.h:218
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:2842
void setRestorePoint(MachineBasicBlock *NewRestore)
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:63
LLVMContext & Context
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
void setCalleeSavedInfoValid(bool v)
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:62
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
SMLoc getLoc() const
Definition: SourceMgr.h:286
MachineFunctionProperties & reset(Property P)
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:148
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:142
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
const MachineFunctionProperties & getProperties() const
Get the function properties.
std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context)
This function is another interface to the MIR serialization format parser.
Definition: MIRParser.cpp:913
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
unsigned getNumRegBanks() const
Get the total number of register banks.
Diagnostic information for machine IR parser.
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI)
Parse the machine function in the current YAML document.
Definition: MIRParser.cpp:281
iterator find(StringRef Key)
Definition: StringMap.h:333
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:61
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:32
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
unsigned const TargetRegisterInfo * TRI
Metadata node.
Definition: Metadata.h:862
F(f)
DenseMap< unsigned, VRegInfo * > VRegInfos
Definition: MIParser.h:58
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
ArrayRef< SMFixIt > getFixIts() const
Definition: SourceMgr.h:299
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:2853
const TargetRegisterClass * RC
Definition: MIParser.h:39
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:130
int CreateStackObject(uint64_t Size, unsigned 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_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:128
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist...
static Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
Definition: MIRParser.cpp:272
std::unique_ptr< Module > parseIRModule()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:225
SMLoc Start
Definition: SMLoc.h:51
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:191
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
Holds all the information related to register banks.
Definition: BitVector.h:938
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.
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:81
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:242
int getLineNo() const
Definition: SourceMgr.h:288
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:896
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context)
Definition: MIRParser.cpp:177
unsigned getNumRegClasses() const
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:60
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:131
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:245
std::vector< VirtualRegisterDefinition > VirtualRegisters
StringRef getLineContents() const
Definition: SourceMgr.h:292
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:510
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:152
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:173
unsigned PreferredReg
Definition: MIParser.h:43
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:2871
Debug location.
void setStackProtectorIndex(int I)
union llvm::VRegInfo::@325 D
void setHasOpaqueSPAdjustment(bool B)
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:42
unsigned getMainFileID() const
Definition: SourceMgr.h:140
#define P(N)
const char * getPointer() const
Definition: SMLoc.h:35
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2877
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Definition: MIRParser.cpp:257
unsigned const MachineRegisterInfo * MRI
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:429
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const T &Object, int FrameIdx)
Definition: MIRParser.cpp:707
static bool isSSA(const MachineFunction &MF)
Definition: MIRParser.cpp:312
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
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:69
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:42
void setStackSize(uint64_t Size)
Set the size of the stack.
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:59
MachineJumpTable JumpTableInfo
Constant pool.
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
Definition: MIRParser.cpp:768
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2865
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:161
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:693
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:297
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:101
void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
void reportDiagnostic(const SMDiagnostic &Diag)
Definition: MIRParser.cpp:206
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
MachineFunction & MF
Definition: MIParser.h:51
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:42
Serializable representation of MachineFrameInfo.
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
void setStackID(int ObjectIdx, uint8_t ID)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
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:168
This class implements the parsing of LLVM IR that&#39;s embedded inside a MIR file.
Definition: MIRParser.cpp:51
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:2848
bool isValid() const
Definition: SMLoc.h:60
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
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.
Module.h This file contains the declarations for the Module class.
StringRef getMessage() const
Definition: SourceMgr.h:291
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:293
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
This class implements the register bank concept.
Definition: RegisterBank.h:29
DWARF expression.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:366
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:648
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
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
SMLoc End
Definition: SMLoc.h:51
A wrapper around std::string which contains a source range that&#39;s being set during parsing...
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:290
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:33
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Definition: StringRef.h:169
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2883
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition: MIRParser.cpp:188
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:37
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
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 "-".
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:37
Representation of each machine instruction.
Definition: MachineInstr.h:64
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
int getColumnNo() const
Definition: SourceMgr.h:289
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
static const size_t npos
Definition: StringRef.h:51
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:565
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:224
unsigned VReg
Definition: MIParser.h:42
VRegInfo & getVRegInfo(unsigned Num)
Definition: MIParser.cpp:92
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:58
void setMaxCallFrameSize(unsigned S)
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:323
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition: MIRParser.cpp:887
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there&#39;s a call to a "returns twice" function...
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
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:18
const unsigned Kind
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:739
bool empty() const
Definition: StringMap.h:111
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< FixedMachineStackObject > FixedStackObjects
Definition: JSON.cpp:592
void setReturnAddressIsTaken(bool s)
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:566
LLVM Value Representation.
Definition: Value.h:73
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
std::unique_ptr< Module > parseIRModule()
Parses the optional LLVM IR module in the MIR file.
Definition: MIRParser.cpp:892
void setAlignment(unsigned A)
setAlignment - Set the alignment (log2, not bytes) of the function.
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock *> &DestBBs)
createJumpTableIndex - Create a new jump table.
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:49
const RegisterBank * RegBank
Definition: MIParser.h:40
MachineJumpTableInfo::JTEntryKind Kind
Represents a location in source code.
Definition: SMLoc.h:24
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:298
bool parseRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2859
std::unique_ptr< MIRParser > createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context)
This function is the main interface to the MIR serialization format parser.
Definition: MIRParser.cpp:900
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, int Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
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:350
iterator end()
Definition: StringMap.h:318
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:676
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:60
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:260