LLVM  3.7.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/StringRef.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/ADT/STLExtras.h"
21 #include "llvm/AsmParser/Parser.h"
27 #include "llvm/IR/BasicBlock.h"
28 #include "llvm/IR/DiagnosticInfo.h"
29 #include "llvm/IR/Instructions.h"
30 #include "llvm/IR/LLVMContext.h"
31 #include "llvm/IR/Module.h"
34 #include "llvm/Support/SMLoc.h"
35 #include "llvm/Support/SourceMgr.h"
38 #include <memory>
39 
40 using namespace llvm;
41 
42 namespace llvm {
43 
44 /// This class implements the parsing of LLVM IR that's embedded inside a MIR
45 /// file.
47  SourceMgr SM;
48  StringRef Filename;
49  LLVMContext &Context;
51  SlotMapping IRSlots;
52  /// Maps from register class names to register classes.
54 
55 public:
56  MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents, StringRef Filename,
57  LLVMContext &Context);
58 
59  void reportDiagnostic(const SMDiagnostic &Diag);
60 
61  /// Report an error with the given message at unknown location.
62  ///
63  /// Always returns true.
64  bool error(const Twine &Message);
65 
66  /// Report an error with the given message at the given location.
67  ///
68  /// Always returns true.
69  bool error(SMLoc Loc, const Twine &Message);
70 
71  /// Report a given error with the location translated from the location in an
72  /// embedded string literal to a location in the MIR file.
73  ///
74  /// Always returns true.
75  bool error(const SMDiagnostic &Error, SMRange SourceRange);
76 
77  /// Try to parse the optional LLVM module and the machine functions in the MIR
78  /// file.
79  ///
80  /// Return null if an error occurred.
81  std::unique_ptr<Module> parse();
82 
83  /// Parse the machine function in the current YAML document.
84  ///
85  /// \param NoLLVMIR - set to true when the MIR file doesn't have LLVM IR.
86  /// A dummy IR function is created and inserted into the given module when
87  /// this parameter is true.
88  ///
89  /// Return true if an error occurred.
90  bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR);
91 
92  /// Initialize the machine function to the state that's described in the MIR
93  /// file.
94  ///
95  /// Return true if error occurred.
97 
98  /// Initialize the machine basic block using it's YAML representation.
99  ///
100  /// Return true if an error occurred.
102  const yaml::MachineBasicBlock &YamlMBB,
103  const PerFunctionMIParsingState &PFS);
104 
105  bool
107  MachineRegisterInfo &RegInfo,
108  const yaml::MachineFunction &YamlMF,
109  DenseMap<unsigned, unsigned> &VirtualRegisterSlots);
110 
112  const yaml::MachineFunction &YamlMF);
113 
114 private:
115  /// Return a MIR diagnostic converted from an MI string diagnostic.
116  SMDiagnostic diagFromMIStringDiag(const SMDiagnostic &Error,
117  SMRange SourceRange);
118 
119  /// Return a MIR diagnostic converted from an LLVM assembly diagnostic.
120  SMDiagnostic diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
121  SMRange SourceRange);
122 
123  /// Create an empty function with the given name.
124  void createDummyFunction(StringRef Name, Module &M);
125 
126  void initNames2RegClasses(const MachineFunction &MF);
127 
128  /// Check if the given identifier is a name of a register class.
129  ///
130  /// Return null if the name isn't a register class.
131  const TargetRegisterClass *getRegClass(const MachineFunction &MF,
132  StringRef Name);
133 };
134 
135 } // end namespace llvm
136 
137 MIRParserImpl::MIRParserImpl(std::unique_ptr<MemoryBuffer> Contents,
138  StringRef Filename, LLVMContext &Context)
139  : SM(), Filename(Filename), Context(Context) {
140  SM.AddNewSourceBuffer(std::move(Contents), SMLoc());
141 }
142 
143 bool MIRParserImpl::error(const Twine &Message) {
145  DS_Error, SMDiagnostic(Filename, SourceMgr::DK_Error, Message.str())));
146  return true;
147 }
148 
149 bool MIRParserImpl::error(SMLoc Loc, const Twine &Message) {
151  DS_Error, SM.GetMessage(Loc, SourceMgr::DK_Error, Message)));
152  return true;
153 }
154 
155 bool MIRParserImpl::error(const SMDiagnostic &Error, SMRange SourceRange) {
156  assert(Error.getKind() == SourceMgr::DK_Error && "Expected an error");
157  reportDiagnostic(diagFromMIStringDiag(Error, SourceRange));
158  return true;
159 }
160 
163  switch (Diag.getKind()) {
164  case SourceMgr::DK_Error:
165  Kind = DS_Error;
166  break;
168  Kind = DS_Warning;
169  break;
170  case SourceMgr::DK_Note:
171  Kind = DS_Note;
172  break;
173  }
174  Context.diagnose(DiagnosticInfoMIRParser(Kind, Diag));
175 }
176 
177 static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context) {
178  reinterpret_cast<MIRParserImpl *>(Context)->reportDiagnostic(Diag);
179 }
180 
181 std::unique_ptr<Module> MIRParserImpl::parse() {
182  yaml::Input In(SM.getMemoryBuffer(SM.getMainFileID())->getBuffer(),
183  /*Ctxt=*/nullptr, handleYAMLDiag, this);
184  In.setContext(&In);
185 
186  if (!In.setCurrentDocument()) {
187  if (In.error())
188  return nullptr;
189  // Create an empty module when the MIR file is empty.
190  return llvm::make_unique<Module>(Filename, Context);
191  }
192 
193  std::unique_ptr<Module> M;
194  bool NoLLVMIR = false;
195  // Parse the block scalar manually so that we can return unique pointer
196  // without having to go trough YAML traits.
197  if (const auto *BSN =
198  dyn_cast_or_null<yaml::BlockScalarNode>(In.getCurrentNode())) {
200  M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error,
201  Context, &IRSlots);
202  if (!M) {
203  reportDiagnostic(diagFromLLVMAssemblyDiag(Error, BSN->getSourceRange()));
204  return M;
205  }
206  In.nextDocument();
207  if (!In.setCurrentDocument())
208  return M;
209  } else {
210  // Create an new, empty module.
211  M = llvm::make_unique<Module>(Filename, Context);
212  NoLLVMIR = true;
213  }
214 
215  // Parse the machine functions.
216  do {
217  if (parseMachineFunction(In, *M, NoLLVMIR))
218  return nullptr;
219  In.nextDocument();
220  } while (In.setCurrentDocument());
221 
222  return M;
223 }
224 
226  bool NoLLVMIR) {
227  auto MF = llvm::make_unique<yaml::MachineFunction>();
228  yaml::yamlize(In, *MF, false);
229  if (In.error())
230  return true;
231  auto FunctionName = MF->Name;
232  if (Functions.find(FunctionName) != Functions.end())
233  return error(Twine("redefinition of machine function '") + FunctionName +
234  "'");
235  Functions.insert(std::make_pair(FunctionName, std::move(MF)));
236  if (NoLLVMIR)
237  createDummyFunction(FunctionName, M);
238  else if (!M.getFunction(FunctionName))
239  return error(Twine("function '") + FunctionName +
240  "' isn't defined in the provided LLVM IR");
241  return false;
242 }
243 
244 void MIRParserImpl::createDummyFunction(StringRef Name, Module &M) {
245  auto &Context = M.getContext();
246  Function *F = cast<Function>(M.getOrInsertFunction(
247  Name, FunctionType::get(Type::getVoidTy(Context), false)));
248  BasicBlock *BB = BasicBlock::Create(Context, "entry", F);
249  new UnreachableInst(Context, BB);
250 }
251 
253  auto It = Functions.find(MF.getName());
254  if (It == Functions.end())
255  return error(Twine("no machine function information for function '") +
256  MF.getName() + "' in the MIR file");
257  // TODO: Recreate the machine function.
258  const yaml::MachineFunction &YamlMF = *It->getValue();
259  if (YamlMF.Alignment)
260  MF.setAlignment(YamlMF.Alignment);
262  MF.setHasInlineAsm(YamlMF.HasInlineAsm);
264  if (initializeRegisterInfo(MF, MF.getRegInfo(), YamlMF,
266  return true;
267  if (initializeFrameInfo(*MF.getFrameInfo(), YamlMF))
268  return true;
269 
270  const auto &F = *MF.getFunction();
271  for (const auto &YamlMBB : YamlMF.BasicBlocks) {
272  const BasicBlock *BB = nullptr;
273  const yaml::StringValue &Name = YamlMBB.Name;
274  if (!Name.Value.empty()) {
275  BB = dyn_cast_or_null<BasicBlock>(
276  F.getValueSymbolTable().lookup(Name.Value));
277  if (!BB)
278  return error(Name.SourceRange.Start,
279  Twine("basic block '") + Name.Value +
280  "' is not defined in the function '" + MF.getName() +
281  "'");
282  }
283  auto *MBB = MF.CreateMachineBasicBlock(BB);
284  MF.insert(MF.end(), MBB);
285  bool WasInserted =
286  PFS.MBBSlots.insert(std::make_pair(YamlMBB.ID, MBB)).second;
287  if (!WasInserted)
288  return error(Twine("redefinition of machine basic block with id #") +
289  Twine(YamlMBB.ID));
290  }
291 
292  if (YamlMF.BasicBlocks.empty())
293  return error(Twine("machine function '") + Twine(MF.getName()) +
294  "' requires at least one machine basic block in its body");
295  // Initialize the machine basic blocks after creating them all so that the
296  // machine instructions parser can resolve the MBB references.
297  unsigned I = 0;
298  for (const auto &YamlMBB : YamlMF.BasicBlocks) {
299  if (initializeMachineBasicBlock(MF, *MF.getBlockNumbered(I++), YamlMBB,
300  PFS))
301  return true;
302  }
303  return false;
304 }
305 
308  const yaml::MachineBasicBlock &YamlMBB,
309  const PerFunctionMIParsingState &PFS) {
310  MBB.setAlignment(YamlMBB.Alignment);
311  if (YamlMBB.AddressTaken)
312  MBB.setHasAddressTaken();
313  MBB.setIsLandingPad(YamlMBB.IsLandingPad);
315  // Parse the successors.
316  for (const auto &MBBSource : YamlMBB.Successors) {
317  MachineBasicBlock *SuccMBB = nullptr;
318  if (parseMBBReference(SuccMBB, SM, MF, MBBSource.Value, PFS, IRSlots,
319  Error))
320  return error(Error, MBBSource.SourceRange);
321  // TODO: Report an error when adding the same successor more than once.
322  MBB.addSuccessor(SuccMBB);
323  }
324  // Parse the liveins.
325  for (const auto &LiveInSource : YamlMBB.LiveIns) {
326  unsigned Reg = 0;
327  if (parseNamedRegisterReference(Reg, SM, MF, LiveInSource.Value, PFS,
328  IRSlots, Error))
329  return error(Error, LiveInSource.SourceRange);
330  MBB.addLiveIn(Reg);
331  }
332  // Parse the instructions.
333  for (const auto &MISource : YamlMBB.Instructions) {
334  MachineInstr *MI = nullptr;
335  if (parseMachineInstr(MI, SM, MF, MISource.Value, PFS, IRSlots, Error))
336  return error(Error, MISource.SourceRange);
337  MBB.insert(MBB.end(), MI);
338  }
339  return false;
340 }
341 
343  const MachineFunction &MF, MachineRegisterInfo &RegInfo,
344  const yaml::MachineFunction &YamlMF,
345  DenseMap<unsigned, unsigned> &VirtualRegisterSlots) {
346  assert(RegInfo.isSSA());
347  if (!YamlMF.IsSSA)
348  RegInfo.leaveSSA();
349  assert(RegInfo.tracksLiveness());
350  if (!YamlMF.TracksRegLiveness)
351  RegInfo.invalidateLiveness();
353 
354  // Parse the virtual register information.
355  for (const auto &VReg : YamlMF.VirtualRegisters) {
356  const auto *RC = getRegClass(MF, VReg.Class.Value);
357  if (!RC)
358  return error(VReg.Class.SourceRange.Start,
359  Twine("use of undefined register class '") +
360  VReg.Class.Value + "'");
361  unsigned Reg = RegInfo.createVirtualRegister(RC);
362  // TODO: Report an error when the same virtual register with the same ID is
363  // redefined.
364  VirtualRegisterSlots.insert(std::make_pair(VReg.ID, Reg));
365  }
366  return false;
367 }
368 
370  const yaml::MachineFunction &YamlMF) {
371  const yaml::MachineFrameInfo &YamlMFI = YamlMF.FrameInfo;
374  MFI.setHasStackMap(YamlMFI.HasStackMap);
375  MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
376  MFI.setStackSize(YamlMFI.StackSize);
378  if (YamlMFI.MaxAlignment)
379  MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
380  MFI.setAdjustsStack(YamlMFI.AdjustsStack);
381  MFI.setHasCalls(YamlMFI.HasCalls);
384  MFI.setHasVAStart(YamlMFI.HasVAStart);
386 
387  // Initialize the fixed frame objects.
388  for (const auto &Object : YamlMF.FixedStackObjects) {
389  int ObjectIdx;
390  if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
391  ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
392  Object.IsImmutable, Object.IsAliased);
393  else
394  ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
395  MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
396  // TODO: Store the mapping between fixed object IDs and object indices to
397  // parse fixed stack object references correctly.
398  }
399 
400  // Initialize the ordinary frame objects.
401  for (const auto &Object : YamlMF.StackObjects) {
402  int ObjectIdx;
403  if (Object.Type == yaml::MachineStackObject::VariableSized)
404  ObjectIdx =
405  MFI.CreateVariableSizedObject(Object.Alignment, /*Alloca=*/nullptr);
406  else
407  ObjectIdx = MFI.CreateStackObject(
408  Object.Size, Object.Alignment,
409  Object.Type == yaml::MachineStackObject::SpillSlot);
410  MFI.setObjectOffset(ObjectIdx, Object.Offset);
411  // TODO: Store the mapping between object IDs and object indices to parse
412  // stack object references correctly.
413  }
414  return false;
415 }
416 
417 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
418  SMRange SourceRange) {
419  assert(SourceRange.isValid() && "Invalid source range");
420  SMLoc Loc = SourceRange.Start;
421  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
422  *Loc.getPointer() == '\'';
423  // Translate the location of the error from the location in the MI string to
424  // the corresponding location in the MIR file.
425  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
426  (HasQuote ? 1 : 0));
427 
428  // TODO: Translate any source ranges as well.
429  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
430  Error.getFixIts());
431 }
432 
433 SMDiagnostic MIRParserImpl::diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
434  SMRange SourceRange) {
435  assert(SourceRange.isValid());
436 
437  // Translate the location of the error from the location in the llvm IR string
438  // to the corresponding location in the MIR file.
439  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
440  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
441  unsigned Column = Error.getColumnNo();
442  StringRef LineStr = Error.getLineContents();
443  SMLoc Loc = Error.getLoc();
444 
445  // Get the full line and adjust the column number by taking the indentation of
446  // LLVM IR into account.
447  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
448  L != E; ++L) {
449  if (L.line_number() == Line) {
450  LineStr = *L;
451  Loc = SMLoc::getFromPointer(LineStr.data());
452  auto Indent = LineStr.find(Error.getLineContents());
453  if (Indent != StringRef::npos)
454  Column += Indent;
455  break;
456  }
457  }
458 
459  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
460  Error.getMessage(), LineStr, Error.getRanges(),
461  Error.getFixIts());
462 }
463 
464 void MIRParserImpl::initNames2RegClasses(const MachineFunction &MF) {
465  if (!Names2RegClasses.empty())
466  return;
467  const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
468  for (unsigned I = 0, E = TRI->getNumRegClasses(); I < E; ++I) {
469  const auto *RC = TRI->getRegClass(I);
470  Names2RegClasses.insert(
471  std::make_pair(StringRef(TRI->getRegClassName(RC)).lower(), RC));
472  }
473 }
474 
475 const TargetRegisterClass *MIRParserImpl::getRegClass(const MachineFunction &MF,
476  StringRef Name) {
477  initNames2RegClasses(MF);
478  auto RegClassInfo = Names2RegClasses.find(Name);
479  if (RegClassInfo == Names2RegClasses.end())
480  return nullptr;
481  return RegClassInfo->getValue();
482 }
483 
484 MIRParser::MIRParser(std::unique_ptr<MIRParserImpl> Impl)
485  : Impl(std::move(Impl)) {}
486 
488 
489 std::unique_ptr<Module> MIRParser::parseLLVMModule() { return Impl->parse(); }
490 
492  return Impl->initializeMachineFunction(MF);
493 }
494 
495 std::unique_ptr<MIRParser> llvm::createMIRParserFromFile(StringRef Filename,
496  SMDiagnostic &Error,
497  LLVMContext &Context) {
498  auto FileOrErr = MemoryBuffer::getFile(Filename);
499  if (std::error_code EC = FileOrErr.getError()) {
500  Error = SMDiagnostic(Filename, SourceMgr::DK_Error,
501  "Could not open input file: " + EC.message());
502  return nullptr;
503  }
504  return createMIRParser(std::move(FileOrErr.get()), Context);
505 }
506 
507 std::unique_ptr<MIRParser>
508 llvm::createMIRParser(std::unique_ptr<MemoryBuffer> Contents,
509  LLVMContext &Context) {
510  auto Filename = Contents->getBufferIdentifier();
511  return llvm::make_unique<MIRParser>(
512  llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
513 }
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
Definition: SMLoc.h:47
std::vector< FlowStringValue > Successors
std::error_code error()
Definition: YAMLTraits.cpp:62
const char * getPointer() const
Definition: SMLoc.h:33
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:114
void setIsLandingPad(bool V=true)
setIsLandingPad - Indicates the block is a landing pad.
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:77
bool parseMachineInstr(MachineInstr *&MI, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
Definition: MIParser.cpp:586
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
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:508
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:240
Diagnostic information for machine IR parser.
void addLiveIn(unsigned Reg)
Adds the specified register as a live in.
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:32
F(f)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
bool initializeMachineFunction(MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
Definition: MIRParser.cpp:252
std::enable_if< has_ScalarEnumerationTraits< T >::value, void >::type yamlize(IO &io, T &Val, bool)
Definition: YAMLTraits.h:661
void setAlignment(unsigned Align)
setAlignment - Set alignment of the basic block.
SMLoc Start
Definition: SMLoc.h:49
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:169
unsigned getMainFileID() const
Definition: SourceMgr.h:111
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:16
void setHasPatchPoint(bool s=true)
unsigned getNumRegClasses() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
std::unique_ptr< Module > parse()
Try to parse the optional LLVM module and the machine functions in the MIR file.
Definition: MIRParser.cpp:181
SMLoc getLoc() const
Definition: SourceMgr.h:260
const TargetRegisterClass * getRegClass(unsigned i) const
getRegClass - Returns the register class associated with the enumeration value.
StringRef getLineContents() const
Definition: SourceMgr.h:266
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...
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context)
Definition: MIRParser.cpp:137
The Input class is used to parse a yaml document into in-memory structs and vectors.
Definition: YAMLTraits.h:970
DenseMap< unsigned, unsigned > VirtualRegisterSlots
Definition: MIParser.h:31
std::vector< VirtualRegisterDefinition > VirtualRegisters
void setHasMustTailInVarArgFunc(bool B)
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:107
StringRef getMessage() const
Definition: SourceMgr.h:265
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:123
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:361
const char * getRegClassName(const TargetRegisterClass *Class) const
getRegClassName - Returns the name of the register class.
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
Definition: MIRParser.cpp:177
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
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
ValueSymbolTable & getValueSymbolTable()
getSymbolTable() - Return the symbol table...
Definition: Function.h:450
void setHasOpaqueSPAdjustment(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:188
std::vector< FlowStringValue > LiveIns
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
Definition: Module.cpp:115
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:41
UnreachableInst - This function has undefined behavior.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:225
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:103
void setHasInlineAsm(bool B)
Set a flag that indicates that the function contains inline assembly.
ArrayRef< SMFixIt > getFixIts() const
Definition: SourceMgr.h:275
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void reportDiagnostic(const SMDiagnostic &Diag)
Definition: MIRParser.cpp:161
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:35
Serializable representation of MachineFrameInfo.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
Definition: SourceMgr.h:267
std::unique_ptr< Module > parseLLVMModule()
Parse the optional LLVM IR module that's embedded in the MIR file.
Definition: MIRParser.cpp:489
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
Definition: MIRParser.cpp:46
bool initializeMachineBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB, const yaml::MachineBasicBlock &YamlMBB, const PerFunctionMIParsingState &PFS)
Initialize the machine basic block using it's YAML representation.
Definition: MIRParser.cpp:306
int getColumnNo() const
Definition: SourceMgr.h:263
SourceMgr::DiagKind getKind() const
Definition: SourceMgr.h:264
Module.h This file contains the declarations for the Module class.
int getLineNo() const
Definition: SourceMgr.h:262
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
std::vector< MachineBasicBlock > BasicBlocks
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:214
bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
Definition: MIParser.cpp:593
bool initializeMachineFunction(MachineFunction &MF) override
Initialize the machine function to the state that's described in the MIR file.
Definition: MIRParser.cpp:491
SMLoc End
Definition: SMLoc.h:49
A wrapper around std::string which contains a source range that's being set during parsing...
void setHasAddressTaken()
setHasAddressTaken - Set this block to reflect that it potentially is the target of an indirect branc...
bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
Definition: MIParser.cpp:600
This struct contains the mapping from the slot numbers to unnamed metadata nodes and global values...
Definition: SlotMapping.h:27
bool error(const Twine &Message)
Report an error with the given message at unknown location.
Definition: MIRParser.cpp:143
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:35
std::vector< StringValue > Instructions
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool initializeFrameInfo(MachineFrameInfo &MFI, const yaml::MachineFunction &YamlMF)
Definition: MIRParser.cpp:369
Representation of each machine instruction.
Definition: MachineInstr.h:51
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:102
static const size_t npos
Definition: StringRef.h:44
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
#define I(x, y, z)
Definition: MD5.cpp:54
bool isValid() const
Definition: SMLoc.h:57
void setMaxCallFrameSize(unsigned S)
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition: MIParser.h:30
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset)
Create a spill slot at a fixed location on the stack.
void enableSubRegLiveness(bool Enable=true)
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
Definition: MIRParser.cpp:484
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function...
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
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...
std::vector< FixedMachineStackObject > FixedStackObjects
void insert(iterator MBBI, MachineBasicBlock *MBB)
const ARM::ArchExtKind Kind
void setReturnAddressIsTaken(bool s)
bool initializeRegisterInfo(const MachineFunction &MF, MachineRegisterInfo &RegInfo, const yaml::MachineFunction &YamlMF, DenseMap< unsigned, unsigned > &VirtualRegisterSlots)
Definition: MIRParser.cpp:342
void setAlignment(unsigned A)
setAlignment - Set the alignment (log2, not bytes) of the function.
bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR)
Parse the machine function in the current YAML document.
Definition: MIRParser.cpp:225
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40
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:135
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Represents a location in source code.
Definition: SMLoc.h:23
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:495
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.
void addSuccessor(MachineBasicBlock *succ, uint32_t weight=0)
addSuccessor - Add succ as a successor of this MachineBasicBlock.
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
LLVMContext & getContext() const
Get the global data context.
Definition: Module.h:265
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:233