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