LLVM  4.0.0
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  StringRef Filename;
54  LLVMContext &Context;
56  SlotMapping IRSlots;
57  /// Maps from register class names to register classes.
59  /// Maps from register bank names to register banks.
60  StringMap<const RegisterBank *> Names2RegBanks;
61 
62 public:
63  MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
64  LLVMContext &Context);
65 
66  void reportDiagnostic(const SMDiagnostic &Diag);
67 
68  /// Report an error with the given message at unknown location.
69  ///
70  /// Always returns true.
71  bool error(const Twine &Message);
72 
73  /// Report an error with the given message at the given location.
74  ///
75  /// Always returns true.
76  bool error(SMLoc Loc, const Twine &Message);
77 
78  /// Report a given error with the location translated from the location in an
79  /// embedded string literal to a location in the MIR file.
80  ///
81  /// Always returns true.
82  bool error(const SMDiagnostic &Error, SMRange SourceRange);
83 
84  /// Try to parse the optional LLVM module and the machine functions in the MIR
85  /// file.
86  ///
87  /// Return null if an error occurred.
88  std::unique_ptr<Module> parse();
89 
90  /// Parse the machine function in the current YAML document.
91  ///
92  /// \param NoLLVMIR - set to true when the MIR file doesn't have LLVM IR.
93  /// A dummy IR function is created and inserted into the given module when
94  /// this parameter is true.
95  ///
96  /// Return true if an error occurred.
97  bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR);
98 
99  /// Initialize the machine function to the state that's described in the MIR
100  /// file.
101  ///
102  /// Return true if error occurred.
104 
106  const yaml::MachineFunction &YamlMF);
107 
109  const yaml::MachineFunction &YamlMF);
110 
112  const yaml::MachineFunction &YamlMF);
113 
115  std::vector<CalleeSavedInfo> &CSIInfo,
116  const yaml::StringValue &RegisterSource,
117  int FrameIdx);
118 
120  const yaml::MachineStackObject &Object,
121  int FrameIdx);
122 
125  const yaml::MachineFunction &YamlMF);
126 
128  const yaml::MachineJumpTable &YamlJTI);
129 
130 private:
131  bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node,
132  const yaml::StringValue &Source);
133 
134  bool parseMBBReference(PerFunctionMIParsingState &PFS,
136  const yaml::StringValue &Source);
137 
138  /// Return a MIR diagnostic converted from an MI string diagnostic.
139  SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
140  SMRange SourceRange);
141 
142  /// Return a MIR diagnostic converted from a diagnostic located in a YAML
143  /// block scalar string.
144  SMDiagnostic diagFromBlockStringDiag(const SMDiagnostic &Error,
145  SMRange SourceRange);
146 
147  /// Create an empty function with the given name.
148  void createDummyFunction(StringRef Name, Module &M);
149 
150  void initNames2RegClasses(const MachineFunction &MF);
151  void initNames2RegBanks(const MachineFunction &MF);
152 
153  /// Check if the given identifier is a name of a register class.
154  ///
155  /// Return null if the name isn't a register class.
156  const TargetRegisterClass *getRegClass(const MachineFunction &MF,
157  StringRef Name);
158 
159  /// Check if the given identifier is a name of a register bank.
160  ///
161  /// Return null if the name isn't a register bank.
162  const RegisterBank *getRegBank(const MachineFunction &MF, StringRef Name);
163 
164  void computeFunctionProperties(MachineFunction &MF);
165 };
166 
167 } // end namespace llvm
168 
169 MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
170  StringRef Filename, LLVMContext &Context)
171  : SM(), Filename(Filename), Context(Context) {
172  SM.AddNewSourceBuffer(std::move(Contents), SMLoc());
173 }
174 
175 bool MIRParserImpl::error(const Twine &Message) {
177  DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
178  return true;
179 }
180 
181 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
183  DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
184  return true;
185 }
186 
187 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
188  assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
189  reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
190  return true;
191 }
192 
195  switch (Diag.getKind()) {
196  case SourceMgr::DK_Error:
197  Kind = DS_Error;
198  break;
200  Kind = DS_Warning;
201  break;
202  case SourceMgr::DK_Note:
203  Kind = DS_Note;
204  break;
205  }
206  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
207 }
208 
209 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
210  reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
211 }
212 
213 std::unique_ptr<Module> MIRParserImpl::parse() {
214  yaml::Input In(SM.getMemoryBuffer(SM.getMainFileID())->getBuffer(),
215  /*Ctxt=*/nullptr, handleYAMLDiag, this);
216  In.setContext(&In);
217 
218  if (!In.setCurrentDocument()) {
219  if (In.error())
220  return nullptr;
221  // Create an empty module when the MIR file is empty.
222  return llvm::make_unique<Module>(Filename, Context);
223  }
224 
225  std::unique_ptr<Module> M;
226  bool NoLLVMIR = false;
227  // Parse the block scalar manually so that we can return unique pointer
228  // without having to go trough YAML traits.
229  if (const auto *BSN =
230  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
232  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
233  Context, &IRSlots);
234  if (!M) {
235  reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
236  return nullptr;
237  }
238  In.nextDocument();
239  if (!In.setCurrentDocument())
240  return M;
241  } else {
242  // Create an new, empty module.
243  M = llvm::make_unique<Module>(Filename, Context);
244  NoLLVMIR = true;
245  }
246 
247  // Parse the machine functions.
248  do {
249  if (parseMachineFunction(In, *M, NoLLVMIR))
250  return nullptr;
251  In.nextDocument();
252  } while (In.setCurrentDocument());
253 
254  return M;
255 }
256 
258  bool NoLLVMIR) {
259  auto MF = llvm::make_unique<yaml::MachineFunction>();
260  yaml::EmptyContext Ctx;
261  yaml::yamlize(In, *MF, false, Ctx);
262  if (In.error())
263  return true;
264  auto FunctionName = MF->Name;
265  if (Functions.find(FunctionName) != Functions.end())
266  return error(Twine("redefinition of machine function '") + FunctionName +
267  "'");
268  Functions.insert(std::make_pair(FunctionName, std::move(MF)));
269  if (NoLLVMIR)
270  createDummyFunction(FunctionName, M);
271  else if (!M.getFunction(FunctionName))
272  return error(Twine("function '") + FunctionName +
273  "' isn't defined in the provided LLVM IR");
274  return false;
275 }
276 
277 void MIRParserImpl::createDummyFunction(StringRef Name, Module &M) {
278  auto &Context = M.getContext();
279  Function *F = cast<Function>(M.getOrInsertFunction(
280  Name, FunctionType::get(Type::getVoidTy(Context), false)));
281  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
282  new UnreachableInst(Context, BB);
283 }
284 
285 static bool isSSA(const MachineFunction &MF) {
286  const MachineRegisterInfo &MRI = MF.getRegInfo();
287  for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
289  if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
290  return false;
291  }
292  return true;
293 }
294 
295 void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
296  MachineFunctionProperties &Properties = MF.getProperties();
297 
298  bool HasPHI = false;
299  bool HasInlineAsm = false;
300  for (const MachineBasicBlock &MBB : MF) {
301  for (const MachineInstr &MI : MBB) {
302  if (MI.isPHI())
303  HasPHI = true;
304  if (MI.isInlineAsm())
305  HasInlineAsm = true;
306  }
307  }
308  if (!HasPHI)
310  MF.setHasInlineAsm(HasInlineAsm);
311 
312  if (isSSA(MF))
314  else
316 
317  const MachineRegisterInfo &MRI = MF.getRegInfo();
318  if (MRI.getNumVirtRegs() == 0)
320 }
321 
323  auto It = Functions.find(MF.getName());
324  if (It == Functions.end())
325  return error(Twine("no machine function information for function '") +
326  MF.getName() + "' in the MIR file");
327  // TODO: Recreate the machine function.
328  const yaml::MachineFunction &YamlMF = *It->getValue();
329  if (YamlMF.Alignment)
330  MF.setAlignment(YamlMF.Alignment);
332 
333  if (YamlMF.Legalized)
335  if (YamlMF.RegBankSelected)
336  MF.getProperties().set(
338  if (YamlMF.Selected)
340 
341  PerFunctionMIParsingState PFS(MF, SM, IRSlots);
342  if (parseRegisterInfo(PFS, YamlMF))
343  return true;
344  if (!YamlMF.Constants.empty()) {
345  auto *ConstantPool = MF.getConstantPool();
346  assert(ConstantPool && "Constant pool must be created");
347  if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
348  return true;
349  }
350 
351  StringRef BlockStr = YamlMF.Body.Value.Value;
353  SourceMgr BlockSM;
354  BlockSM.AddNewSourceBuffer(
355  MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
356  SMLoc());
357  PFS.SM = &BlockSM;
358  if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
360  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
361  return true;
362  }
363  PFS.SM = &SM;
364 
365  if (MF.empty())
366  return error(Twine("machine function '") + Twine(MF.getName()) +
367  "' requires at least one machine basic block in its body");
368  // Initialize the frame information after creating all the MBBs so that the
369  // MBB references in the frame information can be resolved.
370  if (initializeFrameInfo(PFS, YamlMF))
371  return true;
372  // Initialize the jump table after creating all the MBBs so that the MBB
373  // references can be resolved.
374  if (!YamlMF.JumpTableInfo.Entries.empty() &&
376  return true;
377  // Parse the machine instructions after creating all of the MBBs so that the
378  // parser can resolve the MBB references.
379  StringRef InsnStr = YamlMF.Body.Value.Value;
380  SourceMgr InsnSM;
381  InsnSM.AddNewSourceBuffer(
382  MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
383  SMLoc());
384  PFS.SM = &InsnSM;
385  if (parseMachineInstructions(PFS, InsnStr, Error)) {
387  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
388  return true;
389  }
390  PFS.SM = &SM;
391 
392  if (setupRegisterInfo(PFS, YamlMF))
393  return true;
394 
395  computeFunctionProperties(MF);
396 
397  MF.verify();
398  return false;
399 }
400 
402  const yaml::MachineFunction &YamlMF) {
403  MachineFunction &MF = PFS.MF;
404  MachineRegisterInfo &RegInfo = MF.getRegInfo();
405  assert(RegInfo.tracksLiveness());
406  if (!YamlMF.TracksRegLiveness)
407  RegInfo.invalidateLiveness();
408 
410  // Parse the virtual register information.
411  for (const auto &VReg : YamlMF.VirtualRegisters) {
412  VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
413  if (Info.Explicit)
414  return error(VReg.ID.SourceRange.Start,
415  Twine("redefinition of virtual register '%") +
416  Twine(VReg.ID.Value) + "'");
417  Info.Explicit = true;
418 
419  if (StringRef(VReg.Class.Value).equals("_")) {
420  Info.Kind = VRegInfo::GENERIC;
421  } else {
422  const auto *RC = getRegClass(MF, VReg.Class.Value);
423  if (RC) {
424  Info.Kind = VRegInfo::NORMAL;
425  Info.D.RC = RC;
426  } else {
427  const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
428  if (!RegBank)
429  return error(
430  VReg.Class.SourceRange.Start,
431  Twine("use of undefined register class or register bank '") +
432  VReg.Class.Value + "'");
433  Info.Kind = VRegInfo::REGBANK;
434  Info.D.RegBank = RegBank;
435  }
436  }
437 
438  if (!VReg.PreferredRegister.Value.empty()) {
439  if (Info.Kind != VRegInfo::NORMAL)
440  return error(VReg.Class.SourceRange.Start,
441  Twine("preferred register can only be set for normal vregs"));
442 
443  if (parseRegisterReference(PFS, Info.PreferredReg,
444  VReg.PreferredRegister.Value, Error))
445  return error(Error, VReg.PreferredRegister.SourceRange);
446  }
447  }
448 
449  // Parse the liveins.
450  for (const auto &LiveIn : YamlMF.LiveIns) {
451  unsigned Reg = 0;
452  if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
453  return error(Error, LiveIn.Register.SourceRange);
454  unsigned VReg = 0;
455  if (!LiveIn.VirtualRegister.Value.empty()) {
456  VRegInfo *Info;
457  if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
458  Error))
459  return error(Error, LiveIn.VirtualRegister.SourceRange);
460  VReg = Info->VReg;
461  }
462  RegInfo.addLiveIn(Reg, VReg);
463  }
464 
465  // Parse the callee saved register mask.
466  BitVector CalleeSavedRegisterMask(RegInfo.getUsedPhysRegsMask().size());
467  if (!YamlMF.CalleeSavedRegisters)
468  return false;
469  for (const auto &RegSource : YamlMF.CalleeSavedRegisters.getValue()) {
470  unsigned Reg = 0;
471  if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
472  return error(Error, RegSource.SourceRange);
473  CalleeSavedRegisterMask[Reg] = true;
474  }
475  RegInfo.setUsedPhysRegMask(CalleeSavedRegisterMask.flip());
476  return false;
477 }
478 
480  const yaml::MachineFunction &YamlMF) {
481  MachineFunction &MF = PFS.MF;
482  MachineRegisterInfo &MRI = MF.getRegInfo();
483  bool Error = false;
484  // Create VRegs
485  for (auto P : PFS.VRegInfos) {
486  const VRegInfo &Info = *P.second;
487  unsigned Reg = Info.VReg;
488  switch (Info.Kind) {
489  case VRegInfo::UNKNOWN:
490  error(Twine("Cannot determine class/bank of virtual register ") +
491  Twine(P.first) + " in function '" + MF.getName() + "'");
492  Error = true;
493  break;
494  case VRegInfo::NORMAL:
495  MRI.setRegClass(Reg, Info.D.RC);
496  if (Info.PreferredReg != 0)
497  MRI.setSimpleHint(Reg, Info.PreferredReg);
498  break;
499  case VRegInfo::GENERIC:
500  break;
501  case VRegInfo::REGBANK:
502  MRI.setRegBank(Reg, *Info.D.RegBank);
503  break;
504  }
505  }
506 
507  // Compute MachineRegisterInfo::UsedPhysRegMask
508  if (!YamlMF.CalleeSavedRegisters) {
509  for (const MachineBasicBlock &MBB : MF) {
510  for (const MachineInstr &MI : MBB) {
511  for (const MachineOperand &MO : MI.operands()) {
512  if (!MO.isRegMask())
513  continue;
514  MRI.addPhysRegsUsedFromRegMask(MO.getRegMask());
515  }
516  }
517  }
518  }
519 
520  // FIXME: This is a temporary workaround until the reserved registers can be
521  // serialized.
522  MRI.freezeReservedRegs(MF);
523  return Error;
524 }
525 
527  const yaml::MachineFunction &YamlMF) {
528  MachineFunction &MF = PFS.MF;
529  MachineFrameInfo &MFI = MF.getFrameInfo();
530  const Function &F = *MF.getFunction();
531  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
534  MFI.setHasStackMap(YamlMFI.HasStackMap);
535  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
536  MFI.setStackSize(YamlMFI.StackSize);
538  if (YamlMFI.MaxAlignment)
539  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
540  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
541  MFI.setHasCalls(YamlMFI.HasCalls);
544  MFI.setHasVAStart(YamlMFI.HasVAStart);
546  if (!YamlMFI.SavePoint.Value.empty()) {
547  MachineBasicBlock *MBB = nullptr;
548  if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
549  return true;
550  MFI.setSavePoint(MBB);
551  }
552  if (!YamlMFI.RestorePoint.Value.empty()) {
553  MachineBasicBlock *MBB = nullptr;
554  if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
555  return true;
556  MFI.setRestorePoint(MBB);
557  }
558 
559  std::vector<CalleeSavedInfo> CSIInfo;
560  // Initialize the fixed frame objects.
561  for (const auto &Object : YamlMF.FixedStackObjects) {
562  int ObjectIdx;
563  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
564  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
565  Object.IsImmutable, Object.IsAliased);
566  else
567  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
568  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
569  if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
570  ObjectIdx))
571  .second)
572  return error(Object.ID.SourceRange.Start,
573  Twine("redefinition of fixed stack object '%fixed-stack.") +
574  Twine(Object.ID.Value) + "'");
575  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
576  ObjectIdx))
577  return true;
578  }
579 
580  // Initialize the ordinary frame objects.
581  for (const auto &Object : YamlMF.StackObjects) {
582  int ObjectIdx;
583  const AllocaInst *Alloca = nullptr;
584  const yaml::StringValue &Name = Object.Name;
585  if (!Name.Value.empty()) {
586  Alloca = dyn_cast_or_null<AllocaInst>(
587  F.getValueSymbolTable()->lookup(Name.Value));
588  if (!Alloca)
589  return error(Name.SourceRange.Start,
590  "alloca instruction named '" + Name.Value +
591  "' isn't defined in the function '" + F.getName() +
592  "'");
593  }
594  if (Object.Type == yaml::MachineStackObject::VariableSized)
595  ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
596  else
597  ObjectIdx = MFI.CreateStackObject(
598  Object.Size, Object.Alignment,
599  Object.Type == yaml::MachineStackObject::SpillSlot, Alloca);
600  MFI.setObjectOffset(ObjectIdx, Object.Offset);
601  if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
602  .second)
603  return error(Object.ID.SourceRange.Start,
604  Twine("redefinition of stack object '%stack.") +
605  Twine(Object.ID.Value) + "'");
606  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
607  ObjectIdx))
608  return true;
609  if (Object.LocalOffset)
610  MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
611  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
612  return true;
613  }
614  MFI.setCalleeSavedInfo(CSIInfo);
615  if (!CSIInfo.empty())
616  MFI.setCalleeSavedInfoValid(true);
617 
618  // Initialize the various stack object references after initializing the
619  // stack objects.
620  if (!YamlMFI.StackProtector.Value.empty()) {
622  int FI;
623  if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
624  return error(Error, YamlMFI.StackProtector.SourceRange);
625  MFI.setStackProtectorIndex(FI);
626  }
627  return false;
628 }
629 
631  std::vector<CalleeSavedInfo> &CSIInfo,
632  const yaml::StringValue &RegisterSource, int FrameIdx) {
633  if (RegisterSource.Value.empty())
634  return false;
635  unsigned Reg = 0;
637  if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
638  return error(Error, RegisterSource.SourceRange);
639  CSIInfo.push_back(CalleeSavedInfo(Reg, FrameIdx));
640  return false;
641 }
642 
643 /// Verify that given node is of a certain type. Return true on error.
644 template <typename T>
645 static bool typecheckMDNode(T *&Result, MDNode *Node,
646  const yaml::StringValue &Source,
647  StringRef TypeString, MIRParserImpl &Parser) {
648  if (!Node)
649  return false;
650  Result = dyn_cast<T>(Node);
651  if (!Result)
652  return Parser.error(Source.SourceRange.Start,
653  "expected a reference to a '" + TypeString +
654  "' metadata node");
655  return false;
656 }
657 
659  const yaml::MachineStackObject &Object, int FrameIdx) {
660  // Debug information can only be attached to stack objects; Fixed stack
661  // objects aren't supported.
662  assert(FrameIdx >= 0 && "Expected a stack object frame index");
663  MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
664  if (parseMDNode(PFS, Var, Object.DebugVar) ||
665  parseMDNode(PFS, Expr, Object.DebugExpr) ||
666  parseMDNode(PFS, Loc, Object.DebugLoc))
667  return true;
668  if (!Var && !Expr && !Loc)
669  return false;
670  DILocalVariable *DIVar = nullptr;
671  DIExpression *DIExpr = nullptr;
672  DILocation *DILoc = nullptr;
673  if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
674  typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
675  typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
676  return true;
677  PFS.MF.setVariableDbgInfo(DIVar, DIExpr, unsigned(FrameIdx), DILoc);
678  return false;
679 }
680 
681 bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
682  MDNode *&Node, const yaml::StringValue &Source) {
683  if (Source.Value.empty())
684  return false;
686  if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
687  return error(Error, Source.SourceRange);
688  return false;
689 }
690 
693  DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
694  const MachineFunction &MF = PFS.MF;
695  const auto &M = *MF.getFunction()->getParent();
697  for (const auto &YamlConstant : YamlMF.Constants) {
698  const Constant *Value = dyn_cast_or_null<Constant>(
699  parseConstantValue(YamlConstant.Value.Value, Error, M));
700  if (!Value)
701  return error(Error, YamlConstant.Value.SourceRange);
702  unsigned Alignment =
703  YamlConstant.Alignment
704  ? YamlConstant.Alignment
706  unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
707  if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
708  .second)
709  return error(YamlConstant.ID.SourceRange.Start,
710  Twine("redefinition of constant pool item '%const.") +
711  Twine(YamlConstant.ID.Value) + "'");
712  }
713  return false;
714 }
715 
717  const yaml::MachineJumpTable &YamlJTI) {
719  for (const auto &Entry : YamlJTI.Entries) {
720  std::vector<MachineBasicBlock *> Blocks;
721  for (const auto &MBBSource : Entry.Blocks) {
722  MachineBasicBlock *MBB = nullptr;
723  if (parseMBBReference(PFS, MBB, MBBSource.Value))
724  return true;
725  Blocks.push_back(MBB);
726  }
727  unsigned Index = JTI->createJumpTableIndex(Blocks);
728  if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
729  .second)
730  return error(Entry.ID.SourceRange.Start,
731  Twine("redefinition of jump table entry '%jump-table.") +
732  Twine(Entry.ID.Value) + "'");
733  }
734  return false;
735 }
736 
737 bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
738  MachineBasicBlock *&MBB,
739  const yaml::StringValue &Source) {
741  if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
742  return error(Error, Source.SourceRange);
743  return false;
744 }
745 
746 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
747  SMRange SourceRange) {
748  assert(SourceRange.isValid() && "Invalid source range");
749  SMLoc Loc = SourceRange.Start;
750  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
751  *Loc.getPointer() == '\'';
752  // Translate the location of the error from the location in the MI string to
753  // the corresponding location in the MIR file.
754  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
755  (HasQuote ? 1 : 0));
756 
757  // TODO: Translate any source ranges as well.
758  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
759  Error.getFixIts());
760 }
761 
762 SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
763  SMRange SourceRange) {
764  assert(SourceRange.isValid());
765 
766  // Translate the location of the error from the location in the llvm IR string
767  // to the corresponding location in the MIR file.
768  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
769  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
770  unsigned Column = Error.getColumnNo();
771  StringRef LineStr = Error.getLineContents();
772  SMLoc Loc = Error.getLoc();
773 
774  // Get the full line and adjust the column number by taking the indentation of
775  // LLVM IR into account.
776  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
777  L != E; ++L) {
778  if (L.line_number() == Line) {
779  LineStr = *L;
780  Loc = SMLoc::getFromPointer(LineStr.data());
781  auto Indent = LineStr.find(Error.getLineContents());
782  if (Indent != StringRef::npos)
783  Column += Indent;
784  break;
785  }
786  }
787 
788  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
789  Error.getMessage(), LineStr, Error.getRanges(),
790  Error.getFixIts());
791 }
792 
793 void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
794  if (!Names2RegClasses.empty())
795  return;
796  const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
797  for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
798  const auto *RC = TRI->getRegClass(I);
799  Names2RegClasses.insert(
800  std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
801  }
802 }
803 
804 void MIRParserImpl::initNames2RegBanks(const MachineFunction &MF) {
805  if (!Names2RegBanks.empty())
806  return;
807  const RegisterBankInfo *RBI = MF.getSubtarget().getRegBankInfo();
808  // If the target does not support GlobalISel, we may not have a
809  // register bank info.
810  if (!RBI)
811  return;
812  for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
813  const auto &RegBank = RBI->getRegBank(I);
814  Names2RegBanks.insert(
815  std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
816  }
817 }
818 
819 const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
820  StringRef Name) {
821  initNames2RegClasses(MF);
822  auto RegClassInfo = Names2RegClasses.find(Name);
823  if (RegClassInfo == Names2RegClasses.end())
824  return nullptr;
825  return RegClassInfo->getValue();
826 }
827 
828 const RegisterBank *MIRParserImpl::getRegBank(const MachineFunction &MF,
829  StringRef Name) {
830  initNames2RegBanks(MF);
831  auto RegBankInfo = Names2RegBanks.find(Name);
832  if (RegBankInfo == Names2RegBanks.end())
833  return nullptr;
834  return RegBankInfo->getValue();
835 }
836 
837 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
838  : Impl(std::move(Impl)) {}
839 
841 
842 std::unique_ptr<Module> MIRParser::parseLLVMModule() { return Impl->parse(); }
843 
845  return Impl->initializeMachineFunction(MF);
846 }
847 
848 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
849  SMDiagnostic &Error,
850  LLVMContext &Context) {
851  auto FileOrErr = MemoryBuffer::getFile(Filename);
852  if (std::error_code EC = FileOrErr.getError()) {
853  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
854  "Could not open input file: " + EC.message());
855  return nullptr;
856  }
857  return createMIRParser(std::move(FileOrErr.get()), Context);
858 }
859 
860 std::unique_ptr<MIRParser>
861 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
862  LLVMContext &Context) {
863  auto Filename = Contents->getBufferIdentifier();
864  if (Context.shouldDiscardValueNames()) {
866  DS_Error,
867  SMDiagnostic(
868  Filename, SourceMgr::DK_Error,
869  "Can't read MIR with a Context that discards named Values")));
870  return nullptr;
871  }
872  return llvm::make_unique<MIRParser>(
873  llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
874 }
MachineLoop * L
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:49
std::error_code error()
Definition: YAMLTraits.cpp:59
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:2257
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...
void setRestorePoint(MachineBasicBlock *NewRestore)
size_type size() const
size - Returns the number of bits in this bitvector.
Definition: BitVector.h:119
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:59
LLVMContext & Context
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
const char * getPointer() const
Definition: SMLoc.h:35
void setCalleeSavedInfoValid(bool v)
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:58
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:70
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:52
union llvm::VRegInfo::@253 D
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:78
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
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:861
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
Optional< std::vector< FlowStringValue > > CalleeSavedRegisters
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Definition: DataLayout.cpp:699
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
const BitVector & getUsedPhysRegsMask() const
Diagnostic information for machine IR parser.
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:57
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:32
Metadata node.
Definition: Metadata.h:830
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
DenseMap< unsigned, VRegInfo * > VRegInfos
Definition: MIParser.h:55
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:2268
const TargetRegisterClass * RC
Definition: MIParser.h:41
bool initializeMachineFunction(MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
Definition: MIRParser.cpp:322
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:191
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist...
SMLoc Start
Definition: SMLoc.h:51
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:172
unsigned getMainFileID() const
Definition: SourceMgr.h:106
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
Holds all the information related to register banks.
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
void setHasPatchPoint(bool s=true)
unsigned getNumRegClasses() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
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
std::unique_ptr< Module > parse()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:213
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
SMLoc getLoc() const
Definition: SourceMgr.h:255
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
void setUsedPhysRegMask(BitVector &Mask)
StringRef getLineContents() const
Definition: SourceMgr.h:261
const MachineFunctionProperties & getProperties() const
Get the function properties.
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:166
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 parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const yaml::MachineStackObject &Object, int FrameIdx)
Definition: MIRParser.cpp:658
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:169
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:1099
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:56
#define F(x, y, z)
Definition: MD5.cpp:51
std::vector< VirtualRegisterDefinition > VirtualRegisters
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:479
void setHasMustTailInVarArgFunc(bool B)
MachineBasicBlock * MBB
StringRef getMessage() const
Definition: SourceMgr.h:260
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:118
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:291
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, int FrameIdx)
Definition: MIRParser.cpp:630
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:209
unsigned PreferredReg
Definition: MIParser.h:45
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
Definition: Parser.cpp:34
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2286
Debug location.
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:196
VRegInfo & getVRegInfo(unsigned VReg)
Definition: MIParser.cpp:48
#define P(N)
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2292
unsigned const MachineRegisterInfo * MRI
Serializable representation of stack object from the MachineFrameInfo class.
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:401
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:295
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:123
static bool isSSA(const MachineFunction &MF)
Definition: MIRParser.cpp:285
LLVM Basic Block Representation.
Definition: BasicBlock.h:51
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This function has undefined behavior.
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:716
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2280
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:154
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:645
std::vector< MachineStackObject > StackObjects
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:93
ArrayRef< SMFixIt > getFixIts() const
Definition: SourceMgr.h:270
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void reportDiagnostic(const SMDiagnostic &Diag)
Definition: MIRParser.cpp:193
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
MachineFunction & MF
Definition: MIParser.h:50
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:35
Serializable representation of MachineFrameInfo.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition: SourceMgr.h:262
std::unique_ptr< Module > parseLLVMModule()
Parse the optional LLVM IR module that's embedded in the MIR file.
Definition: MIRParser.cpp:842
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements the parsing of LLVM IR that'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:2263
int getColumnNo() const
Definition: SourceMgr.h:258
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:259
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
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.
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:230
int getLineNo() const
Definition: SourceMgr.h:257
~MIRParser() override
Definition: MIRParser.cpp:840
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
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.
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition: Function.h:527
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:223
bool initializeMachineFunction(MachineFunction &MF) override
Initialize the machine function to the state that's described in the MIR file.
Definition: MIRParser.cpp:844
SMLoc End
Definition: SMLoc.h:51
A wrapper around std::string which contains a source range that's being set during parsing...
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:33
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2298
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition: MIRParser.cpp:175
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)
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:39
Representation of each machine instruction.
Definition: MachineInstr.h:52
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
std::vector< MachineFunctionLiveIn > LiveIns
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.cpp:384
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:97
static const size_t npos
Definition: StringRef.h:51
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:526
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
std::vector< Entry > Entries
unsigned VReg
Definition: MIParser.h:44
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:54
bool isValid() const
Definition: SMLoc.h:60
void setMaxCallFrameSize(unsigned S)
unsigned getNumRegBanks() const
Get the total number of register banks.
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
std::vector< MachineConstantPoolValue > Constants
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:287
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition: MIRParser.cpp:837
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there'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:752
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.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
const unsigned Kind
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:691
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:537
LLVM Value Representation.
Definition: Value.h:71
Lightweight error class with error context and mandatory checking.
void setAlignment(unsigned A)
setAlignment - Set the alignment (log2, not bytes) of the function.
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
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:125
bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR)
Parse the machine function in the current YAML document.
Definition: MIRParser.cpp:257
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
IRTranslator LLVM IR MI
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
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:47
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:136
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const RegisterBank * RegBank
Definition: MIParser.h:42
MachineJumpTableInfo::JTEntryKind Kind
Represents a location in source code.
Definition: SMLoc.h:24
bool parseRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2274
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:848
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.
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
Properties which a MachineFunction may have at a given point in time.
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:222
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:228