LLVM  6.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 
126  const yaml::MachineStackObject &Object,
127  int FrameIdx);
128 
131  const yaml::MachineFunction &YamlMF);
132 
134  const yaml::MachineJumpTable &YamlJTI);
135 
136 private:
137  bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node,
138  const yaml::StringValue &Source);
139 
140  bool parseMBBReference(PerFunctionMIParsingState &PFS,
141  MachineBasicBlock *&MBB,
142  const yaml::StringValue &Source);
143 
144  /// Return a MIR diagnostic converted from an MI string diagnostic.
145  SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
146  SMRange SourceRange);
147 
148  /// Return a MIR diagnostic converted from a diagnostic located in a YAML
149  /// block scalar string.
150  SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
151  SMRange SourceRange);
152 
153  void initNames2RegClasses(const MachineFunction &MF);
154  void initNames2RegBanks(const MachineFunction &MF);
155 
156  /// Check if the given identifier is a name of a register class.
157  ///
158  /// Return null if the name isn't a register class.
159  const TargetRegisterClass *getRegClass(const MachineFunction &MF,
160  StringRef Name);
161 
162  /// Check if the given identifier is a name of a register bank.
163  ///
164  /// Return null if the name isn't a register bank.
165  const RegisterBank *getRegBank(const MachineFunction &MF, StringRef Name);
166 
167  void computeFunctionProperties(MachineFunction &MF);
168 };
169 
170 } // end namespace llvm
171 
172 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
173  reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
174 }
175 
176 MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
177  StringRef Filename, LLVMContext &Context)
178  : SM(),
179  In(SM.getMemoryBuffer(
180  SM.AddNewSourceBuffer(std::move(Contents), SMLoc()))->getBuffer(),
181  nullptr, handleYAMLDiag, this),
182  Filename(Filename),
183  Context(Context) {
184  In.setContext(&In);
185 }
186 
187 bool MIRParserImpl::error(const Twine &Message) {
189  DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
190  return true;
191 }
192 
193 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
195  DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
196  return true;
197 }
198 
199 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
200  assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
201  reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
202  return true;
203 }
204 
207  switch (Diag.getKind()) {
208  case SourceMgr::DK_Error:
209  Kind = DS_Error;
210  break;
212  Kind = DS_Warning;
213  break;
214  case SourceMgr::DK_Note:
215  Kind = DS_Note;
216  break;
218  llvm_unreachable("remark unexpected");
219  break;
220  }
221  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
222 }
223 
224 std::unique_ptr<Module> MIRParserImpl::parseIRModule() {
225  if (!In.setCurrentDocument()) {
226  if (In.error())
227  return nullptr;
228  // Create an empty module when the MIR file is empty.
229  NoMIRDocuments = true;
230  return llvm::make_unique<Module>(Filename, Context);
231  }
232 
233  std::unique_ptr<Module> M;
234  // Parse the block scalar manually so that we can return unique pointer
235  // without having to go trough YAML traits.
236  if (const auto *BSN =
237  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
239  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
240  Context, &IRSlots);
241  if (!M) {
242  reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
243  return nullptr;
244  }
245  In.nextDocument();
246  if (!In.setCurrentDocument())
247  NoMIRDocuments = true;
248  } else {
249  // Create an new, empty module.
250  M = llvm::make_unique<Module>(Filename, Context);
251  NoLLVMIR = true;
252  }
253  return M;
254 }
255 
257  if (NoMIRDocuments)
258  return false;
259 
260  // Parse the machine functions.
261  do {
262  if (parseMachineFunction(M, MMI))
263  return true;
264  In.nextDocument();
265  } while (In.setCurrentDocument());
266 
267  return false;
268 }
269 
270 /// Create an empty function with the given name.
272  auto &Context = M.getContext();
273  Function *F = cast<Function>(M.getOrInsertFunction(
274  Name, FunctionType::get(Type::getVoidTy(Context), false)));
275  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
276  new UnreachableInst(Context, BB);
277  return F;
278 }
279 
281  // Parse the yaml.
282  yaml::MachineFunction YamlMF;
283  yaml::EmptyContext Ctx;
284  yaml::yamlize(In, YamlMF, false, Ctx);
285  if (In.error())
286  return true;
287 
288  // Search for the corresponding IR function.
289  StringRef FunctionName = YamlMF.Name;
290  Function *F = M.getFunction(FunctionName);
291  if (!F) {
292  if (NoLLVMIR) {
293  F = createDummyFunction(FunctionName, M);
294  } else {
295  return error(Twine("function '") + FunctionName +
296  "' isn't defined in the provided LLVM IR");
297  }
298  }
299  if (MMI.getMachineFunction(*F) != nullptr)
300  return error(Twine("redefinition of machine function '") + FunctionName +
301  "'");
302 
303  // Create the MachineFunction.
305  if (initializeMachineFunction(YamlMF, MF))
306  return true;
307 
308  return false;
309 }
310 
311 static bool isSSA(const MachineFunction &MF) {
312  const MachineRegisterInfo &MRI = MF.getRegInfo();
313  for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
315  if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
316  return false;
317  }
318  return true;
319 }
320 
321 void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
322  MachineFunctionProperties &Properties = MF.getProperties();
323 
324  bool HasPHI = false;
325  bool HasInlineAsm = false;
326  for (const MachineBasicBlock &MBB : MF) {
327  for (const MachineInstr &MI : MBB) {
328  if (MI.isPHI())
329  HasPHI = true;
330  if (MI.isInlineAsm())
331  HasInlineAsm = true;
332  }
333  }
334  if (!HasPHI)
336  MF.setHasInlineAsm(HasInlineAsm);
337 
338  if (isSSA(MF))
340  else
342 
343  const MachineRegisterInfo &MRI = MF.getRegInfo();
344  if (MRI.getNumVirtRegs() == 0)
346 }
347 
348 bool
350  MachineFunction &MF) {
351  // TODO: Recreate the machine function.
352  initNames2RegClasses(MF);
353  initNames2RegBanks(MF);
354  if (YamlMF.Alignment)
355  MF.setAlignment(YamlMF.Alignment);
357 
358  if (YamlMF.Legalized)
360  if (YamlMF.RegBankSelected)
361  MF.getProperties().set(
363  if (YamlMF.Selected)
365 
366  PerFunctionMIParsingState PFS(MF, SM, IRSlots, Names2RegClasses,
367  Names2RegBanks);
368  if (parseRegisterInfo(PFS, YamlMF))
369  return true;
370  if (!YamlMF.Constants.empty()) {
371  auto *ConstantPool = MF.getConstantPool();
372  assert(ConstantPool && "Constant pool must be created");
373  if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
374  return true;
375  }
376 
377  StringRef BlockStr = YamlMF.Body.Value.Value;
379  SourceMgr BlockSM;
380  BlockSM.AddNewSourceBuffer(
381  MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
382  SMLoc());
383  PFS.SM = &BlockSM;
384  if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
386  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
387  return true;
388  }
389  PFS.SM = &SM;
390 
391  // Initialize the frame information after creating all the MBBs so that the
392  // MBB references in the frame information can be resolved.
393  if (initializeFrameInfo(PFS, YamlMF))
394  return true;
395  // Initialize the jump table after creating all the MBBs so that the MBB
396  // references can be resolved.
397  if (!YamlMF.JumpTableInfo.Entries.empty() &&
399  return true;
400  // Parse the machine instructions after creating all of the MBBs so that the
401  // parser can resolve the MBB references.
402  StringRef InsnStr = YamlMF.Body.Value.Value;
403  SourceMgr InsnSM;
404  InsnSM.AddNewSourceBuffer(
405  MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
406  SMLoc());
407  PFS.SM = &InsnSM;
408  if (parseMachineInstructions(PFS, InsnStr, Error)) {
410  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
411  return true;
412  }
413  PFS.SM = &SM;
414 
415  if (setupRegisterInfo(PFS, YamlMF))
416  return true;
417 
418  computeFunctionProperties(MF);
419 
420  MF.verify();
421  return false;
422 }
423 
425  const yaml::MachineFunction &YamlMF) {
426  MachineFunction &MF = PFS.MF;
427  MachineRegisterInfo &RegInfo = MF.getRegInfo();
428  assert(RegInfo.tracksLiveness());
429  if (!YamlMF.TracksRegLiveness)
430  RegInfo.invalidateLiveness();
431 
433  // Parse the virtual register information.
434  for (const auto &VReg : YamlMF.VirtualRegisters) {
435  VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
436  if (Info.Explicit)
437  return error(VReg.ID.SourceRange.Start,
438  Twine("redefinition of virtual register '%") +
439  Twine(VReg.ID.Value) + "'");
440  Info.Explicit = true;
441 
442  if (StringRef(VReg.Class.Value).equals("_")) {
443  Info.Kind = VRegInfo::GENERIC;
444  Info.D.RegBank = nullptr;
445  } else {
446  const auto *RC = getRegClass(MF, VReg.Class.Value);
447  if (RC) {
448  Info.Kind = VRegInfo::NORMAL;
449  Info.D.RC = RC;
450  } else {
451  const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
452  if (!RegBank)
453  return error(
454  VReg.Class.SourceRange.Start,
455  Twine("use of undefined register class or register bank '") +
456  VReg.Class.Value + "'");
457  Info.Kind = VRegInfo::REGBANK;
458  Info.D.RegBank = RegBank;
459  }
460  }
461 
462  if (!VReg.PreferredRegister.Value.empty()) {
463  if (Info.Kind != VRegInfo::NORMAL)
464  return error(VReg.Class.SourceRange.Start,
465  Twine("preferred register can only be set for normal vregs"));
466 
467  if (parseRegisterReference(PFS, Info.PreferredReg,
468  VReg.PreferredRegister.Value, Error))
469  return error(Error, VReg.PreferredRegister.SourceRange);
470  }
471  }
472 
473  // Parse the liveins.
474  for (const auto &LiveIn : YamlMF.LiveIns) {
475  unsigned Reg = 0;
476  if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
477  return error(Error, LiveIn.Register.SourceRange);
478  unsigned VReg = 0;
479  if (!LiveIn.VirtualRegister.Value.empty()) {
480  VRegInfo *Info;
481  if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
482  Error))
483  return error(Error, LiveIn.VirtualRegister.SourceRange);
484  VReg = Info->VReg;
485  }
486  RegInfo.addLiveIn(Reg, VReg);
487  }
488 
489  // Parse the callee saved registers (Registers that will
490  // be saved for the caller).
491  if (YamlMF.CalleeSavedRegisters) {
492  SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
493  for (const auto &RegSource : YamlMF.CalleeSavedRegisters.getValue()) {
494  unsigned Reg = 0;
495  if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
496  return error(Error, RegSource.SourceRange);
497  CalleeSavedRegisters.push_back(Reg);
498  }
499  RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
500  }
501 
502  return false;
503 }
504 
506  const yaml::MachineFunction &YamlMF) {
507  MachineFunction &MF = PFS.MF;
509  bool Error = false;
510  // Create VRegs
511  for (auto P : PFS.VRegInfos) {
512  const VRegInfo &Info = *P.second;
513  unsigned Reg = Info.VReg;
514  switch (Info.Kind) {
515  case VRegInfo::UNKNOWN:
516  error(Twine("Cannot determine class/bank of virtual register ") +
517  Twine(P.first) + " in function '" + MF.getName() + "'");
518  Error = true;
519  break;
520  case VRegInfo::NORMAL:
521  MRI.setRegClass(Reg, Info.D.RC);
522  if (Info.PreferredReg != 0)
523  MRI.setSimpleHint(Reg, Info.PreferredReg);
524  break;
525  case VRegInfo::GENERIC:
526  break;
527  case VRegInfo::REGBANK:
528  MRI.setRegBank(Reg, *Info.D.RegBank);
529  break;
530  }
531  }
532 
533  // Compute MachineRegisterInfo::UsedPhysRegMask
534  for (const MachineBasicBlock &MBB : MF) {
535  for (const MachineInstr &MI : MBB) {
536  for (const MachineOperand &MO : MI.operands()) {
537  if (!MO.isRegMask())
538  continue;
539  MRI.addPhysRegsUsedFromRegMask(MO.getRegMask());
540  }
541  }
542  }
543 
544  // FIXME: This is a temporary workaround until the reserved registers can be
545  // serialized.
546  MRI.freezeReservedRegs(MF);
547  return Error;
548 }
549 
551  const yaml::MachineFunction &YamlMF) {
552  MachineFunction &MF = PFS.MF;
553  MachineFrameInfo &MFI = MF.getFrameInfo();
554  const Function &F = *MF.getFunction();
555  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
558  MFI.setHasStackMap(YamlMFI.HasStackMap);
559  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
560  MFI.setStackSize(YamlMFI.StackSize);
562  if (YamlMFI.MaxAlignment)
563  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
564  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
565  MFI.setHasCalls(YamlMFI.HasCalls);
566  if (YamlMFI.MaxCallFrameSize != ~0u)
569  MFI.setHasVAStart(YamlMFI.HasVAStart);
571  if (!YamlMFI.SavePoint.Value.empty()) {
572  MachineBasicBlock *MBB = nullptr;
573  if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
574  return true;
575  MFI.setSavePoint(MBB);
576  }
577  if (!YamlMFI.RestorePoint.Value.empty()) {
578  MachineBasicBlock *MBB = nullptr;
579  if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
580  return true;
581  MFI.setRestorePoint(MBB);
582  }
583 
584  std::vector<CalleeSavedInfo> CSIInfo;
585  // Initialize the fixed frame objects.
586  for (const auto &Object : YamlMF.FixedStackObjects) {
587  int ObjectIdx;
588  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
589  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
590  Object.IsImmutable, Object.IsAliased);
591  else
592  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
593  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
594  MFI.setStackID(ObjectIdx, Object.StackID);
595  if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
596  ObjectIdx))
597  .second)
598  return error(Object.ID.SourceRange.Start,
599  Twine("redefinition of fixed stack object '%fixed-stack.") +
600  Twine(Object.ID.Value) + "'");
601  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
602  Object.CalleeSavedRestored, ObjectIdx))
603  return true;
604  }
605 
606  // Initialize the ordinary frame objects.
607  for (const auto &Object : YamlMF.StackObjects) {
608  int ObjectIdx;
609  const AllocaInst *Alloca = nullptr;
610  const yaml::StringValue &Name = Object.Name;
611  if (!Name.Value.empty()) {
612  Alloca = dyn_cast_or_null<AllocaInst>(
613  F.getValueSymbolTable()->lookup(Name.Value));
614  if (!Alloca)
615  return error(Name.SourceRange.Start,
616  "alloca instruction named '" + Name.Value +
617  "' isn't defined in the function '" + F.getName() +
618  "'");
619  }
620  if (Object.Type == yaml::MachineStackObject::VariableSized)
621  ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
622  else
623  ObjectIdx = MFI.CreateStackObject(
624  Object.Size, Object.Alignment,
625  Object.Type == yaml::MachineStackObject::SpillSlot, Alloca);
626  MFI.setObjectOffset(ObjectIdx, Object.Offset);
627  MFI.setStackID(ObjectIdx, Object.StackID);
628 
629  if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
630  .second)
631  return error(Object.ID.SourceRange.Start,
632  Twine("redefinition of stack object '%stack.") +
633  Twine(Object.ID.Value) + "'");
634  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
635  Object.CalleeSavedRestored, ObjectIdx))
636  return true;
637  if (Object.LocalOffset)
638  MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
639  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
640  return true;
641  }
642  MFI.setCalleeSavedInfo(CSIInfo);
643  if (!CSIInfo.empty())
644  MFI.setCalleeSavedInfoValid(true);
645 
646  // Initialize the various stack object references after initializing the
647  // stack objects.
648  if (!YamlMFI.StackProtector.Value.empty()) {
650  int FI;
651  if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
652  return error(Error, YamlMFI.StackProtector.SourceRange);
653  MFI.setStackProtectorIndex(FI);
654  }
655  return false;
656 }
657 
659  std::vector<CalleeSavedInfo> &CSIInfo,
660  const yaml::StringValue &RegisterSource, bool IsRestored, int FrameIdx) {
661  if (RegisterSource.Value.empty())
662  return false;
663  unsigned Reg = 0;
665  if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
666  return error(Error, RegisterSource.SourceRange);
667  CalleeSavedInfo CSI(Reg, FrameIdx);
668  CSI.setRestored(IsRestored);
669  CSIInfo.push_back(CSI);
670  return false;
671 }
672 
673 /// Verify that given node is of a certain type. Return true on error.
674 template <typename T>
675 static bool typecheckMDNode(T *&Result, MDNode *Node,
676  const yaml::StringValue &Source,
677  StringRef TypeString, MIRParserImpl &Parser) {
678  if (!Node)
679  return false;
680  Result = dyn_cast<T>(Node);
681  if (!Result)
682  return Parser.error(Source.SourceRange.Start,
683  "expected a reference to a '" + TypeString +
684  "' metadata node");
685  return false;
686 }
687 
689  const yaml::MachineStackObject &Object, int FrameIdx) {
690  // Debug information can only be attached to stack objects; Fixed stack
691  // objects aren't supported.
692  assert(FrameIdx >= 0 && "Expected a stack object frame index");
693  MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
694  if (parseMDNode(PFS, Var, Object.DebugVar) ||
695  parseMDNode(PFS, Expr, Object.DebugExpr) ||
696  parseMDNode(PFS, Loc, Object.DebugLoc))
697  return true;
698  if (!Var && !Expr && !Loc)
699  return false;
700  DILocalVariable *DIVar = nullptr;
701  DIExpression *DIExpr = nullptr;
702  DILocation *DILoc = nullptr;
703  if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
704  typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
705  typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
706  return true;
707  PFS.MF.setVariableDbgInfo(DIVar, DIExpr, unsigned(FrameIdx), DILoc);
708  return false;
709 }
710 
711 bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
712  MDNode *&Node, const yaml::StringValue &Source) {
713  if (Source.Value.empty())
714  return false;
716  if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
717  return error(Error, Source.SourceRange);
718  return false;
719 }
720 
723  DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
724  const MachineFunction &MF = PFS.MF;
725  const auto &M = *MF.getFunction()->getParent();
727  for (const auto &YamlConstant : YamlMF.Constants) {
728  if (YamlConstant.IsTargetSpecific)
729  // FIXME: Support target-specific constant pools
730  return error(YamlConstant.Value.SourceRange.Start,
731  "Can't parse target-specific constant pool entries yet");
732  const Constant *Value = dyn_cast_or_null<Constant>(
733  parseConstantValue(YamlConstant.Value.Value, Error, M));
734  if (!Value)
735  return error(Error, YamlConstant.Value.SourceRange);
736  unsigned Alignment =
737  YamlConstant.Alignment
738  ? YamlConstant.Alignment
739  : M.getDataLayout().getPrefTypeAlignment(Value->getType());
740  unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
741  if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
742  .second)
743  return error(YamlConstant.ID.SourceRange.Start,
744  Twine("redefinition of constant pool item '%const.") +
745  Twine(YamlConstant.ID.Value) + "'");
746  }
747  return false;
748 }
749 
751  const yaml::MachineJumpTable &YamlJTI) {
753  for (const auto &Entry : YamlJTI.Entries) {
754  std::vector<MachineBasicBlock *> Blocks;
755  for (const auto &MBBSource : Entry.Blocks) {
756  MachineBasicBlock *MBB = nullptr;
757  if (parseMBBReference(PFS, MBB, MBBSource.Value))
758  return true;
759  Blocks.push_back(MBB);
760  }
761  unsigned Index = JTI->createJumpTableIndex(Blocks);
762  if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
763  .second)
764  return error(Entry.ID.SourceRange.Start,
765  Twine("redefinition of jump table entry '%jump-table.") +
766  Twine(Entry.ID.Value) + "'");
767  }
768  return false;
769 }
770 
771 bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
772  MachineBasicBlock *&MBB,
773  const yaml::StringValue &Source) {
775  if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
776  return error(Error, Source.SourceRange);
777  return false;
778 }
779 
780 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
781  SMRange SourceRange) {
782  assert(SourceRange.isValid() && "Invalid source range");
783  SMLoc Loc = SourceRange.Start;
784  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
785  *Loc.getPointer() == '\'';
786  // Translate the location of the error from the location in the MI string to
787  // the corresponding location in the MIR file.
788  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
789  (HasQuote ? 1 : 0));
790 
791  // TODO: Translate any source ranges as well.
792  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
793  Error.getFixIts());
794 }
795 
796 SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
797  SMRange SourceRange) {
798  assert(SourceRange.isValid());
799 
800  // Translate the location of the error from the location in the llvm IR string
801  // to the corresponding location in the MIR file.
802  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
803  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
804  unsigned Column = Error.getColumnNo();
805  StringRef LineStr = Error.getLineContents();
806  SMLoc Loc = Error.getLoc();
807 
808  // Get the full line and adjust the column number by taking the indentation of
809  // LLVM IR into account.
810  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
811  L != E; ++L) {
812  if (L.line_number() == Line) {
813  LineStr = *L;
814  Loc = SMLoc::getFromPointer(LineStr.data());
815  auto Indent = LineStr.find(Error.getLineContents());
816  if (Indent != StringRef::npos)
817  Column += Indent;
818  break;
819  }
820  }
821 
822  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
823  Error.getMessage(), LineStr, Error.getRanges(),
824  Error.getFixIts());
825 }
826 
827 void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
828  if (!Names2RegClasses.empty())
829  return;
830  const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
831  for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
832  const auto *RC = TRI->getRegClass(I);
833  Names2RegClasses.insert(
834  std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
835  }
836 }
837 
838 void MIRParserImpl::initNames2RegBanks(const MachineFunction &MF) {
839  if (!Names2RegBanks.empty())
840  return;
841  const RegisterBankInfo *RBI = MF.getSubtarget().getRegBankInfo();
842  // If the target does not support GlobalISel, we may not have a
843  // register bank info.
844  if (!RBI)
845  return;
846  for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
847  const auto &RegBank = RBI->getRegBank(I);
848  Names2RegBanks.insert(
849  std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
850  }
851 }
852 
853 const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
854  StringRef Name) {
855  auto RegClassInfo = Names2RegClasses.find(Name);
856  if (RegClassInfo == Names2RegClasses.end())
857  return nullptr;
858  return RegClassInfo->getValue();
859 }
860 
861 const RegisterBank *MIRParserImpl::getRegBank(const MachineFunction &MF,
862  StringRef Name) {
863  auto RegBankInfo = Names2RegBanks.find(Name);
864  if (RegBankInfo == Names2RegBanks.end())
865  return nullptr;
866  return RegBankInfo->getValue();
867 }
868 
869 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
870  : Impl(std::move(Impl)) {}
871 
873 
874 std::unique_ptr<Module> MIRParser::parseIRModule() {
875  return Impl->parseIRModule();
876 }
877 
879  return Impl->parseMachineFunctions(M, MMI);
880 }
881 
882 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
883  SMDiagnostic &Error,
884  LLVMContext &Context) {
885  auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
886  if (std::error_code EC = FileOrErr.getError()) {
887  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
888  "Could not open input file: " + EC.message());
889  return nullptr;
890  }
891  return createMIRParser(std::move(FileOrErr.get()), Context);
892 }
893 
894 std::unique_ptr<MIRParser>
895 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
896  LLVMContext &Context) {
897  auto Filename = Contents->getBufferIdentifier();
898  if (Context.shouldDiscardValueNames()) {
900  DS_Error,
901  SMDiagnostic(
902  Filename, SourceMgr::DK_Error,
903  "Can't read MIR with a Context that discards named Values")));
904  return nullptr;
905  }
906  return llvm::make_unique<MIRParser>(
907  llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
908 }
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:49
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr, bool UpgradeDebugInfo=true)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:35
void push_back(const T &Elt)
Definition: SmallVector.h:212
std::error_code error()
Definition: YAMLTraits.cpp:73
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:2593
void setRestorePoint(MachineBasicBlock *NewRestore)
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, unsigned Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:62
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:61
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
SMLoc getLoc() const
Definition: SourceMgr.h:259
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:72
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
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:895
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 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:280
iterator find(StringRef Key)
Definition: StringMap.h:337
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:60
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.
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:272
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:2604
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:89
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:271
std::unique_ptr< Module > parseIRModule()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:224
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:920
void setHasPatchPoint(bool s=true)
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
union llvm::VRegInfo::@310 D
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
int getLineNo() const
Definition: SourceMgr.h:261
void freezeReservedRegs(const MachineFunction &)
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
Reg
All possible values of the reg field in the ModR/M byte.
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:878
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const yaml::MachineStackObject &Object, int FrameIdx)
Definition: MIRParser.cpp:688
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool Immutable=false)
Create a spill slot at a fixed location on the stack.
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context)
Definition: MIRParser.cpp:176
unsigned getNumRegClasses() const
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:1108
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:59
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:104
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:265
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:505
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:125
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:172
unsigned PreferredReg
Definition: MIParser.h:43
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2622
Debug location.
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
unsigned getMainFileID() const
Definition: SourceMgr.h:113
VRegInfo & getVRegInfo(unsigned VReg)
Definition: MIParser.cpp:91
#define P(N)
const char * getPointer() const
Definition: SMLoc.h:35
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2628
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Definition: MIRParser.cpp:256
unsigned const MachineRegisterInfo * MRI
Serializable representation of stack object from the MachineFrameInfo class.
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:424
static bool isSSA(const MachineFunction &MF)
Definition: MIRParser.cpp:311
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.
MachineJumpTable JumpTableInfo
Constant pool.
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
Definition: MIRParser.cpp:750
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2616
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:675
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.
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
bool setCurrentDocument()
Definition: YAMLTraits.cpp:86
void reportDiagnostic(const SMDiagnostic &Diag)
Definition: MIRParser.cpp:205
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:41
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:146
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:2599
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:264
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition: SourceMgr.h:266
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:370
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition: Function.h:580
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:172
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:224
SMLoc End
Definition: SMLoc.h:51
void setContext(void *)
Definition: YAMLTraits.cpp:47
A wrapper around std::string which contains a source range that&#39;s being set during parsing...
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:263
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:2634
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition: MIRParser.cpp:187
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:59
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:262
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:550
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:220
unsigned VReg
Definition: MIParser.h:42
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:869
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there&#39;s a call to a "returns twice" function...
std::enable_if< has_ScalarEnumerationTraits< T >::value, void >::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx)
Definition: YAMLTraits.h:763
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void setSimpleHint(unsigned VReg, unsigned PrefReg)
Specify the preferred register allocation hint for the specified virtual register.
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
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
const unsigned Kind
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:721
bool empty() const
Definition: StringMap.h:111
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< FixedMachineStackObject > FixedStackObjects
void setReturnAddressIsTaken(bool s)
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:556
LLVM Value Representation.
Definition: Value.h:73
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
std::unique_ptr< Module > parseIRModule()
Parses the optional LLVM IR module in the MIR file.
Definition: MIRParser.cpp:874
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
const Node * getCurrentNode() const
Returns the current node that&#39;s being parsed by the YAML Parser.
Definition: YAMLTraits.cpp:111
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:2610
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:882
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:349
iterator end()
Definition: StringMap.h:322
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:658
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:233