LLVM  5.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  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  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;
217  }
218  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
219 }
220 
221 std::unique_ptr<Module> MIRParserImpl::parseIRModule() {
222  if (!In.setCurrentDocument()) {
223  if (In.error())
224  return nullptr;
225  // Create an empty module when the MIR file is empty.
226  NoMIRDocuments = true;
227  return llvm::make_unique<Module>(Filename, Context);
228  }
229 
230  std::unique_ptr<Module> M;
231  // Parse the block scalar manually so that we can return unique pointer
232  // without having to go trough YAML traits.
233  if (const auto *BSN =
234  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
236  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
237  Context, &IRSlots);
238  if (!M) {
239  reportDiagnostic(diagFromBlockStringDiag(Error, BSN->getSourceRange()));
240  return nullptr;
241  }
242  In.nextDocument();
243  if (!In.setCurrentDocument())
244  NoMIRDocuments = true;
245  } else {
246  // Create an new, empty module.
247  M = llvm::make_unique<Module>(Filename, Context);
248  NoLLVMIR = true;
249  }
250  return M;
251 }
252 
254  if (NoMIRDocuments)
255  return false;
256 
257  // Parse the machine functions.
258  do {
259  if (parseMachineFunction(M, MMI))
260  return true;
261  In.nextDocument();
262  } while (In.setCurrentDocument());
263 
264  return false;
265 }
266 
267 /// Create an empty function with the given name.
269  auto &Context = M.getContext();
270  Function *F = cast<Function>(M.getOrInsertFunction(
271  Name, FunctionType::get(Type::getVoidTy(Context), false)));
272  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
273  new UnreachableInst(Context, BB);
274  return F;
275 }
276 
278  // Parse the yaml.
279  yaml::MachineFunction YamlMF;
280  yaml::EmptyContext Ctx;
281  yaml::yamlize(In, YamlMF, false, Ctx);
282  if (In.error())
283  return true;
284 
285  // Search for the corresponding IR function.
286  StringRef FunctionName = YamlMF.Name;
287  Function *F = M.getFunction(FunctionName);
288  if (!F) {
289  if (NoLLVMIR) {
290  F = createDummyFunction(FunctionName, M);
291  } else {
292  return error(Twine("function '") + FunctionName +
293  "' isn't defined in the provided LLVM IR");
294  }
295  }
296  if (MMI.getMachineFunction(*F) != nullptr)
297  return error(Twine("redefinition of machine function '") + FunctionName +
298  "'");
299 
300  // Create the MachineFunction.
302  if (initializeMachineFunction(YamlMF, MF))
303  return true;
304 
305  return false;
306 }
307 
308 static bool isSSA(const MachineFunction &MF) {
309  const MachineRegisterInfo &MRI = MF.getRegInfo();
310  for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
312  if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg))
313  return false;
314  }
315  return true;
316 }
317 
318 void MIRParserImpl::computeFunctionProperties(MachineFunction &MF) {
319  MachineFunctionProperties &Properties = MF.getProperties();
320 
321  bool HasPHI = false;
322  bool HasInlineAsm = false;
323  for (const MachineBasicBlock &MBB : MF) {
324  for (const MachineInstr &MI : MBB) {
325  if (MI.isPHI())
326  HasPHI = true;
327  if (MI.isInlineAsm())
328  HasInlineAsm = true;
329  }
330  }
331  if (!HasPHI)
333  MF.setHasInlineAsm(HasInlineAsm);
334 
335  if (isSSA(MF))
337  else
339 
340  const MachineRegisterInfo &MRI = MF.getRegInfo();
341  if (MRI.getNumVirtRegs() == 0)
343 }
344 
345 bool
347  MachineFunction &MF) {
348  // TODO: Recreate the machine function.
349  initNames2RegClasses(MF);
350  initNames2RegBanks(MF);
351  if (YamlMF.Alignment)
352  MF.setAlignment(YamlMF.Alignment);
354 
355  if (YamlMF.Legalized)
357  if (YamlMF.RegBankSelected)
358  MF.getProperties().set(
360  if (YamlMF.Selected)
362 
363  PerFunctionMIParsingState PFS(MF, SM, IRSlots, Names2RegClasses,
364  Names2RegBanks);
365  if (parseRegisterInfo(PFS, YamlMF))
366  return true;
367  if (!YamlMF.Constants.empty()) {
368  auto *ConstantPool = MF.getConstantPool();
369  assert(ConstantPool && "Constant pool must be created");
370  if (initializeConstantPool(PFS, *ConstantPool, YamlMF))
371  return true;
372  }
373 
374  StringRef BlockStr = YamlMF.Body.Value.Value;
376  SourceMgr BlockSM;
377  BlockSM.AddNewSourceBuffer(
378  MemoryBuffer::getMemBuffer(BlockStr, "",/*RequiresNullTerminator=*/false),
379  SMLoc());
380  PFS.SM = &BlockSM;
381  if (parseMachineBasicBlockDefinitions(PFS, BlockStr, Error)) {
383  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
384  return true;
385  }
386  PFS.SM = &SM;
387 
388  // Initialize the frame information after creating all the MBBs so that the
389  // MBB references in the frame information can be resolved.
390  if (initializeFrameInfo(PFS, YamlMF))
391  return true;
392  // Initialize the jump table after creating all the MBBs so that the MBB
393  // references can be resolved.
394  if (!YamlMF.JumpTableInfo.Entries.empty() &&
396  return true;
397  // Parse the machine instructions after creating all of the MBBs so that the
398  // parser can resolve the MBB references.
399  StringRef InsnStr = YamlMF.Body.Value.Value;
400  SourceMgr InsnSM;
401  InsnSM.AddNewSourceBuffer(
402  MemoryBuffer::getMemBuffer(InsnStr, "", /*RequiresNullTerminator=*/false),
403  SMLoc());
404  PFS.SM = &InsnSM;
405  if (parseMachineInstructions(PFS, InsnStr, Error)) {
407  diagFromBlockStringDiag(Error, YamlMF.Body.Value.SourceRange));
408  return true;
409  }
410  PFS.SM = &SM;
411 
412  if (setupRegisterInfo(PFS, YamlMF))
413  return true;
414 
415  computeFunctionProperties(MF);
416 
417  MF.verify();
418  return false;
419 }
420 
422  const yaml::MachineFunction &YamlMF) {
423  MachineFunction &MF = PFS.MF;
424  MachineRegisterInfo &RegInfo = MF.getRegInfo();
425  assert(RegInfo.tracksLiveness());
426  if (!YamlMF.TracksRegLiveness)
427  RegInfo.invalidateLiveness();
428 
430  // Parse the virtual register information.
431  for (const auto &VReg : YamlMF.VirtualRegisters) {
432  VRegInfo &Info = PFS.getVRegInfo(VReg.ID.Value);
433  if (Info.Explicit)
434  return error(VReg.ID.SourceRange.Start,
435  Twine("redefinition of virtual register '%") +
436  Twine(VReg.ID.Value) + "'");
437  Info.Explicit = true;
438 
439  if (StringRef(VReg.Class.Value).equals("_")) {
440  Info.Kind = VRegInfo::GENERIC;
441  } else {
442  const auto *RC = getRegClass(MF, VReg.Class.Value);
443  if (RC) {
444  Info.Kind = VRegInfo::NORMAL;
445  Info.D.RC = RC;
446  } else {
447  const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
448  if (!RegBank)
449  return error(
450  VReg.Class.SourceRange.Start,
451  Twine("use of undefined register class or register bank '") +
452  VReg.Class.Value + "'");
453  Info.Kind = VRegInfo::REGBANK;
454  Info.D.RegBank = RegBank;
455  }
456  }
457 
458  if (!VReg.PreferredRegister.Value.empty()) {
459  if (Info.Kind != VRegInfo::NORMAL)
460  return error(VReg.Class.SourceRange.Start,
461  Twine("preferred register can only be set for normal vregs"));
462 
463  if (parseRegisterReference(PFS, Info.PreferredReg,
464  VReg.PreferredRegister.Value, Error))
465  return error(Error, VReg.PreferredRegister.SourceRange);
466  }
467  }
468 
469  // Parse the liveins.
470  for (const auto &LiveIn : YamlMF.LiveIns) {
471  unsigned Reg = 0;
472  if (parseNamedRegisterReference(PFS, Reg, LiveIn.Register.Value, Error))
473  return error(Error, LiveIn.Register.SourceRange);
474  unsigned VReg = 0;
475  if (!LiveIn.VirtualRegister.Value.empty()) {
476  VRegInfo *Info;
477  if (parseVirtualRegisterReference(PFS, Info, LiveIn.VirtualRegister.Value,
478  Error))
479  return error(Error, LiveIn.VirtualRegister.SourceRange);
480  VReg = Info->VReg;
481  }
482  RegInfo.addLiveIn(Reg, VReg);
483  }
484 
485  // Parse the callee saved registers (Registers that will
486  // be saved for the caller).
487  if (YamlMF.CalleeSavedRegisters) {
488  SmallVector<MCPhysReg, 16> CalleeSavedRegisters;
489  for (const auto &RegSource : YamlMF.CalleeSavedRegisters.getValue()) {
490  unsigned Reg = 0;
491  if (parseNamedRegisterReference(PFS, Reg, RegSource.Value, Error))
492  return error(Error, RegSource.SourceRange);
493  CalleeSavedRegisters.push_back(Reg);
494  }
495  RegInfo.setCalleeSavedRegs(CalleeSavedRegisters);
496  }
497 
498  return false;
499 }
500 
502  const yaml::MachineFunction &YamlMF) {
503  MachineFunction &MF = PFS.MF;
504  MachineRegisterInfo &MRI = MF.getRegInfo();
505  bool Error = false;
506  // Create VRegs
507  for (auto P : PFS.VRegInfos) {
508  const VRegInfo &Info = *P.second;
509  unsigned Reg = Info.VReg;
510  switch (Info.Kind) {
511  case VRegInfo::UNKNOWN:
512  error(Twine("Cannot determine class/bank of virtual register ") +
513  Twine(P.first) + " in function '" + MF.getName() + "'");
514  Error = true;
515  break;
516  case VRegInfo::NORMAL:
517  MRI.setRegClass(Reg, Info.D.RC);
518  if (Info.PreferredReg != 0)
519  MRI.setSimpleHint(Reg, Info.PreferredReg);
520  break;
521  case VRegInfo::GENERIC:
522  break;
523  case VRegInfo::REGBANK:
524  MRI.setRegBank(Reg, *Info.D.RegBank);
525  break;
526  }
527  }
528 
529  // Compute MachineRegisterInfo::UsedPhysRegMask
530  for (const MachineBasicBlock &MBB : MF) {
531  for (const MachineInstr &MI : MBB) {
532  for (const MachineOperand &MO : MI.operands()) {
533  if (!MO.isRegMask())
534  continue;
535  MRI.addPhysRegsUsedFromRegMask(MO.getRegMask());
536  }
537  }
538  }
539 
540  // FIXME: This is a temporary workaround until the reserved registers can be
541  // serialized.
542  MRI.freezeReservedRegs(MF);
543  return Error;
544 }
545 
547  const yaml::MachineFunction &YamlMF) {
548  MachineFunction &MF = PFS.MF;
549  MachineFrameInfo &MFI = MF.getFrameInfo();
550  const Function &F = *MF.getFunction();
551  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
554  MFI.setHasStackMap(YamlMFI.HasStackMap);
555  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
556  MFI.setStackSize(YamlMFI.StackSize);
558  if (YamlMFI.MaxAlignment)
559  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
560  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
561  MFI.setHasCalls(YamlMFI.HasCalls);
562  if (YamlMFI.MaxCallFrameSize != ~0u)
565  MFI.setHasVAStart(YamlMFI.HasVAStart);
567  if (!YamlMFI.SavePoint.Value.empty()) {
568  MachineBasicBlock *MBB = nullptr;
569  if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
570  return true;
571  MFI.setSavePoint(MBB);
572  }
573  if (!YamlMFI.RestorePoint.Value.empty()) {
574  MachineBasicBlock *MBB = nullptr;
575  if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
576  return true;
577  MFI.setRestorePoint(MBB);
578  }
579 
580  std::vector<CalleeSavedInfo> CSIInfo;
581  // Initialize the fixed frame objects.
582  for (const auto &Object : YamlMF.FixedStackObjects) {
583  int ObjectIdx;
584  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
585  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
586  Object.IsImmutable, Object.IsAliased);
587  else
588  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
589  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
590  if (!PFS.FixedStackObjectSlots.insert(std::make_pair(Object.ID.Value,
591  ObjectIdx))
592  .second)
593  return error(Object.ID.SourceRange.Start,
594  Twine("redefinition of fixed stack object '%fixed-stack.") +
595  Twine(Object.ID.Value) + "'");
596  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
597  ObjectIdx))
598  return true;
599  }
600 
601  // Initialize the ordinary frame objects.
602  for (const auto &Object : YamlMF.StackObjects) {
603  int ObjectIdx;
604  const AllocaInst *Alloca = nullptr;
605  const yaml::StringValue &Name = Object.Name;
606  if (!Name.Value.empty()) {
607  Alloca = dyn_cast_or_null<AllocaInst>(
608  F.getValueSymbolTable()->lookup(Name.Value));
609  if (!Alloca)
610  return error(Name.SourceRange.Start,
611  "alloca instruction named '" + Name.Value +
612  "' isn't defined in the function '" + F.getName() +
613  "'");
614  }
615  if (Object.Type == yaml::MachineStackObject::VariableSized)
616  ObjectIdx = MFI.CreateVariableSizedObject(Object.Alignment, Alloca);
617  else
618  ObjectIdx = MFI.CreateStackObject(
619  Object.Size, Object.Alignment,
620  Object.Type == yaml::MachineStackObject::SpillSlot, Alloca);
621  MFI.setObjectOffset(ObjectIdx, Object.Offset);
622  if (!PFS.StackObjectSlots.insert(std::make_pair(Object.ID.Value, ObjectIdx))
623  .second)
624  return error(Object.ID.SourceRange.Start,
625  Twine("redefinition of stack object '%stack.") +
626  Twine(Object.ID.Value) + "'");
627  if (parseCalleeSavedRegister(PFS, CSIInfo, Object.CalleeSavedRegister,
628  ObjectIdx))
629  return true;
630  if (Object.LocalOffset)
631  MFI.mapLocalFrameObject(ObjectIdx, Object.LocalOffset.getValue());
632  if (parseStackObjectsDebugInfo(PFS, Object, ObjectIdx))
633  return true;
634  }
635  MFI.setCalleeSavedInfo(CSIInfo);
636  if (!CSIInfo.empty())
637  MFI.setCalleeSavedInfoValid(true);
638 
639  // Initialize the various stack object references after initializing the
640  // stack objects.
641  if (!YamlMFI.StackProtector.Value.empty()) {
643  int FI;
644  if (parseStackObjectReference(PFS, FI, YamlMFI.StackProtector.Value, Error))
645  return error(Error, YamlMFI.StackProtector.SourceRange);
646  MFI.setStackProtectorIndex(FI);
647  }
648  return false;
649 }
650 
652  std::vector<CalleeSavedInfo> &CSIInfo,
653  const yaml::StringValue &RegisterSource, int FrameIdx) {
654  if (RegisterSource.Value.empty())
655  return false;
656  unsigned Reg = 0;
658  if (parseNamedRegisterReference(PFS, Reg, RegisterSource.Value, Error))
659  return error(Error, RegisterSource.SourceRange);
660  CSIInfo.push_back(CalleeSavedInfo(Reg, FrameIdx));
661  return false;
662 }
663 
664 /// Verify that given node is of a certain type. Return true on error.
665 template <typename T>
666 static bool typecheckMDNode(T *&Result, MDNode *Node,
667  const yaml::StringValue &Source,
668  StringRef TypeString, MIRParserImpl &Parser) {
669  if (!Node)
670  return false;
671  Result = dyn_cast<T>(Node);
672  if (!Result)
673  return Parser.error(Source.SourceRange.Start,
674  "expected a reference to a '" + TypeString +
675  "' metadata node");
676  return false;
677 }
678 
680  const yaml::MachineStackObject &Object, int FrameIdx) {
681  // Debug information can only be attached to stack objects; Fixed stack
682  // objects aren't supported.
683  assert(FrameIdx >= 0 && "Expected a stack object frame index");
684  MDNode *Var = nullptr, *Expr = nullptr, *Loc = nullptr;
685  if (parseMDNode(PFS, Var, Object.DebugVar) ||
686  parseMDNode(PFS, Expr, Object.DebugExpr) ||
687  parseMDNode(PFS, Loc, Object.DebugLoc))
688  return true;
689  if (!Var && !Expr && !Loc)
690  return false;
691  DILocalVariable *DIVar = nullptr;
692  DIExpression *DIExpr = nullptr;
693  DILocation *DILoc = nullptr;
694  if (typecheckMDNode(DIVar, Var, Object.DebugVar, "DILocalVariable", *this) ||
695  typecheckMDNode(DIExpr, Expr, Object.DebugExpr, "DIExpression", *this) ||
696  typecheckMDNode(DILoc, Loc, Object.DebugLoc, "DILocation", *this))
697  return true;
698  PFS.MF.setVariableDbgInfo(DIVar, DIExpr, unsigned(FrameIdx), DILoc);
699  return false;
700 }
701 
702 bool MIRParserImpl::parseMDNode(PerFunctionMIParsingState &PFS,
703  MDNode *&Node, const yaml::StringValue &Source) {
704  if (Source.Value.empty())
705  return false;
707  if (llvm::parseMDNode(PFS, Node, Source.Value, Error))
708  return error(Error, Source.SourceRange);
709  return false;
710 }
711 
714  DenseMap<unsigned, unsigned> &ConstantPoolSlots = PFS.ConstantPoolSlots;
715  const MachineFunction &MF = PFS.MF;
716  const auto &M = *MF.getFunction()->getParent();
718  for (const auto &YamlConstant : YamlMF.Constants) {
719  const Constant *Value = dyn_cast_or_null<Constant>(
720  parseConstantValue(YamlConstant.Value.Value, Error, M));
721  if (!Value)
722  return error(Error, YamlConstant.Value.SourceRange);
723  unsigned Alignment =
724  YamlConstant.Alignment
725  ? YamlConstant.Alignment
726  : M.getDataLayout().getPrefTypeAlignment(Value->getType());
727  unsigned Index = ConstantPool.getConstantPoolIndex(Value, Alignment);
728  if (!ConstantPoolSlots.insert(std::make_pair(YamlConstant.ID.Value, Index))
729  .second)
730  return error(YamlConstant.ID.SourceRange.Start,
731  Twine("redefinition of constant pool item '%const.") +
732  Twine(YamlConstant.ID.Value) + "'");
733  }
734  return false;
735 }
736 
738  const yaml::MachineJumpTable &YamlJTI) {
740  for (const auto &Entry : YamlJTI.Entries) {
741  std::vector<MachineBasicBlock *> Blocks;
742  for (const auto &MBBSource : Entry.Blocks) {
743  MachineBasicBlock *MBB = nullptr;
744  if (parseMBBReference(PFS, MBB, MBBSource.Value))
745  return true;
746  Blocks.push_back(MBB);
747  }
748  unsigned Index = JTI->createJumpTableIndex(Blocks);
749  if (!PFS.JumpTableSlots.insert(std::make_pair(Entry.ID.Value, Index))
750  .second)
751  return error(Entry.ID.SourceRange.Start,
752  Twine("redefinition of jump table entry '%jump-table.") +
753  Twine(Entry.ID.Value) + "'");
754  }
755  return false;
756 }
757 
758 bool MIRParserImpl::parseMBBReference(PerFunctionMIParsingState &PFS,
759  MachineBasicBlock *&MBB,
760  const yaml::StringValue &Source) {
762  if (llvm::parseMBBReference(PFS, MBB, Source.Value, Error))
763  return error(Error, Source.SourceRange);
764  return false;
765 }
766 
767 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
768  SMRange SourceRange) {
769  assert(SourceRange.isValid() && "Invalid source range");
770  SMLoc Loc = SourceRange.Start;
771  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
772  *Loc.getPointer() == '\'';
773  // Translate the location of the error from the location in the MI string to
774  // the corresponding location in the MIR file.
775  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
776  (HasQuote ? 1 : 0));
777 
778  // TODO: Translate any source ranges as well.
779  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
780  Error.getFixIts());
781 }
782 
783 SMDiagnostic MIRParserImpl::diagFromBlockStringDiag(const SMDiagnostic &Error,
784  SMRange SourceRange) {
785  assert(SourceRange.isValid());
786 
787  // Translate the location of the error from the location in the llvm IR string
788  // to the corresponding location in the MIR file.
789  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
790  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
791  unsigned Column = Error.getColumnNo();
792  StringRef LineStr = Error.getLineContents();
793  SMLoc Loc = Error.getLoc();
794 
795  // Get the full line and adjust the column number by taking the indentation of
796  // LLVM IR into account.
797  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
798  L != E; ++L) {
799  if (L.line_number() == Line) {
800  LineStr = *L;
801  Loc = SMLoc::getFromPointer(LineStr.data());
802  auto Indent = LineStr.find(Error.getLineContents());
803  if (Indent != StringRef::npos)
804  Column += Indent;
805  break;
806  }
807  }
808 
809  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
810  Error.getMessage(), LineStr, Error.getRanges(),
811  Error.getFixIts());
812 }
813 
814 void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
815  if (!Names2RegClasses.empty())
816  return;
817  const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
818  for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
819  const auto *RC = TRI->getRegClass(I);
820  Names2RegClasses.insert(
821  std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
822  }
823 }
824 
825 void MIRParserImpl::initNames2RegBanks(const MachineFunction &MF) {
826  if (!Names2RegBanks.empty())
827  return;
828  const RegisterBankInfo *RBI = MF.getSubtarget().getRegBankInfo();
829  // If the target does not support GlobalISel, we may not have a
830  // register bank info.
831  if (!RBI)
832  return;
833  for (unsigned I = 0, E = RBI->getNumRegBanks(); I < E; ++I) {
834  const auto &RegBank = RBI->getRegBank(I);
835  Names2RegBanks.insert(
836  std::make_pair(StringRef(RegBank.getName()).lower(), &RegBank));
837  }
838 }
839 
840 const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
841  StringRef Name) {
842  auto RegClassInfo = Names2RegClasses.find(Name);
843  if (RegClassInfo == Names2RegClasses.end())
844  return nullptr;
845  return RegClassInfo->getValue();
846 }
847 
848 const RegisterBank *MIRParserImpl::getRegBank(const MachineFunction &MF,
849  StringRef Name) {
850  auto RegBankInfo = Names2RegBanks.find(Name);
851  if (RegBankInfo == Names2RegBanks.end())
852  return nullptr;
853  return RegBankInfo->getValue();
854 }
855 
856 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
857  : Impl(std::move(Impl)) {}
858 
860 
861 std::unique_ptr<Module> MIRParser::parseIRModule() {
862  return Impl->parseIRModule();
863 }
864 
866  return Impl->parseMachineFunctions(M, MMI);
867 }
868 
869 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
870  SMDiagnostic &Error,
871  LLVMContext &Context) {
872  auto FileOrErr = MemoryBuffer::getFileOrSTDIN(Filename);
873  if (std::error_code EC = FileOrErr.getError()) {
874  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
875  "Could not open input file: " + EC.message());
876  return nullptr;
877  }
878  return createMIRParser(std::move(FileOrErr.get()), Context);
879 }
880 
881 std::unique_ptr<MIRParser>
882 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
883  LLVMContext &Context) {
884  auto Filename = Contents->getBufferIdentifier();
885  if (Context.shouldDiscardValueNames()) {
887  DS_Error,
888  SMDiagnostic(
889  Filename, SourceMgr::DK_Error,
890  "Can't read MIR with a Context that discards named Values")));
891  return nullptr;
892  }
893  return llvm::make_unique<MIRParser>(
894  llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
895 }
MachineLoop * L
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:49
void push_back(const T &Elt)
Definition: SmallVector.h:211
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:2529
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)
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.
const char * getPointer() const
Definition: SMLoc.h:35
void setCalleeSavedInfoValid(bool v)
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:61
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
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
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
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
union llvm::VRegInfo::@284 D
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:882
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
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.
bool empty() const
Definition: StringMap.h:110
Diagnostic information for machine IR parser.
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI)
Parse the machine function in the current YAML document.
Definition: MIRParser.cpp:277
iterator find(StringRef Key)
Definition: StringMap.h:333
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:60
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:32
Metadata node.
Definition: Metadata.h:862
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
DenseMap< unsigned, VRegInfo * > VRegInfos
Definition: MIParser.h:58
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:2540
const TargetRegisterClass * RC
Definition: MIParser.h:39
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:218
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:268
std::unique_ptr< Module > parseIRModule()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:221
SMLoc Start
Definition: SMLoc.h:51
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:176
unsigned getMainFileID() const
Definition: SourceMgr.h:112
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
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
SMLoc getLoc() const
Definition: SourceMgr.h:258
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
StringRef getLineContents() const
Definition: SourceMgr.h:264
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:169
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:865
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const yaml::MachineStackObject &Object, int FrameIdx)
Definition: MIRParser.cpp:679
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
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
#define F(x, y, z)
Definition: MD5.cpp:55
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:501
void setHasMustTailInVarArgFunc(bool B)
StringRef getMessage() const
Definition: SourceMgr.h:263
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:124
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
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:651
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:172
unsigned PreferredReg
Definition: MIParser.h:43
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:2558
Debug location.
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
const char * Name
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:172
VRegInfo & getVRegInfo(unsigned VReg)
Definition: MIParser.cpp:90
const Node * getCurrentNode() const
Returns the current node that's being parsed by the YAML Parser.
Definition: YAMLTraits.cpp:111
#define P(N)
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2564
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Definition: MIRParser.cpp:253
unsigned const MachineRegisterInfo * MRI
Serializable representation of stack object from the MachineFrameInfo class.
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:421
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
static bool isSSA(const MachineFunction &MF)
Definition: MIRParser.cpp:308
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
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:737
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2552
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:666
unsigned MaxCallFrameSize
~0u means: not computed yet.
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:101
ArrayRef< SMFixIt > getFixIts() const
Definition: SourceMgr.h:271
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.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition: SourceMgr.h:265
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.
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:2535
#define E
Definition: LargeTest.cpp:27
int getColumnNo() const
Definition: SourceMgr.h:261
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:262
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:245
int getLineNo() const
Definition: SourceMgr.h:260
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.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:366
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
Definition: Function.h:572
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
SMLoc End
Definition: SMLoc.h:51
void setContext(void *)
Definition: YAMLTraits.cpp:47
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
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr...
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:2570
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'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.
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:103
static const size_t npos
Definition: StringRef.h:51
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:546
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
std::vector< Entry > Entries
unsigned VReg
Definition: MIParser.h:42
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:58
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:323
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition: MIRParser.cpp:856
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: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.
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:712
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:545
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:861
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:128
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:49
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
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const RegisterBank * RegBank
Definition: MIParser.h:40
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:2546
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:869
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's described in the MIR file.
Definition: MIRParser.cpp:346
iterator end()
Definition: StringMap.h:318
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.
This class contains meta information specific to a module.
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:237
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:232