1 //===- MIParser.h - Machine Instructions Parser ---------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the function that parses the machine instructions.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
15 #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallSet.h"
24 class MachineBasicBlock;
25 class MachineFunction;
27 class MachineRegisterInfo;
33 class TargetRegisterClass;
37 UNKNOWN, NORMAL, GENERIC, REGBANK
39 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
41 const TargetRegisterClass *RC;
42 const RegisterBank *RegBank;
45 unsigned PreferredReg = 0;
48 struct PerFunctionMIParsingState {
49 BumpPtrAllocator Allocator;
52 const SlotMapping &IRSlots;
54 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
55 DenseMap<unsigned, VRegInfo*> VRegInfos;
56 DenseMap<unsigned, int> FixedStackObjectSlots;
57 DenseMap<unsigned, int> StackObjectSlots;
58 DenseMap<unsigned, unsigned> ConstantPoolSlots;
59 DenseMap<unsigned, unsigned> JumpTableSlots;
61 PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
62 const SlotMapping &IRSlots);
64 VRegInfo &getVRegInfo(unsigned VReg);
67 /// Parse the machine basic block definitions, and skip the machine
70 /// This function runs the first parsing pass on the machine function's body.
71 /// It parses only the machine basic block definitions and creates the machine
72 /// basic blocks in the given machine function.
74 /// The machine instructions aren't parsed during the first pass because all
75 /// the machine basic blocks aren't defined yet - this makes it impossible to
76 /// resolve the machine basic block references.
78 /// Return true if an error occurred.
79 bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
80 StringRef Src, SMDiagnostic &Error);
82 /// Parse the machine instructions.
84 /// This function runs the second parsing pass on the machine function's body.
85 /// It skips the machine basic block definitions and parses only the machine
86 /// instructions and basic block attributes like liveins and successors.
88 /// The second parsing pass assumes that the first parsing pass already ran
89 /// on the given source string.
91 /// Return true if an error occurred.
92 bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
95 bool parseMBBReference(PerFunctionMIParsingState &PFS,
96 MachineBasicBlock *&MBB, StringRef Src,
99 bool parseRegisterReference(PerFunctionMIParsingState &PFS,
100 unsigned &Reg, StringRef Src,
101 SMDiagnostic &Error);
103 bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
104 StringRef Src, SMDiagnostic &Error);
106 bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
107 VRegInfo *&Info, StringRef Src,
108 SMDiagnostic &Error);
110 bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
111 StringRef Src, SMDiagnostic &Error);
113 bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
114 SMDiagnostic &Error);
116 } // end namespace llvm