1 //===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===//
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/StringMap.h"
19 #include "llvm/Support/Allocator.h"
23 class MachineBasicBlock;
24 class MachineFunction;
31 class TargetRegisterClass;
35 UNKNOWN, NORMAL, GENERIC, REGBANK
37 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
39 const TargetRegisterClass *RC;
40 const RegisterBank *RegBank;
43 unsigned PreferredReg = 0;
46 using Name2RegClassMap = StringMap<const TargetRegisterClass *>;
47 using Name2RegBankMap = StringMap<const RegisterBank *>;
49 struct PerFunctionMIParsingState {
50 BumpPtrAllocator Allocator;
53 const SlotMapping &IRSlots;
54 const Name2RegClassMap &Names2RegClasses;
55 const Name2RegBankMap &Names2RegBanks;
57 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
58 DenseMap<unsigned, VRegInfo*> VRegInfos;
59 DenseMap<unsigned, int> FixedStackObjectSlots;
60 DenseMap<unsigned, int> StackObjectSlots;
61 DenseMap<unsigned, unsigned> ConstantPoolSlots;
62 DenseMap<unsigned, unsigned> JumpTableSlots;
64 PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
65 const SlotMapping &IRSlots,
66 const Name2RegClassMap &Names2RegClasses,
67 const Name2RegBankMap &Names2RegBanks);
69 VRegInfo &getVRegInfo(unsigned VReg);
72 /// Parse the machine basic block definitions, and skip the machine
75 /// This function runs the first parsing pass on the machine function's body.
76 /// It parses only the machine basic block definitions and creates the machine
77 /// basic blocks in the given machine function.
79 /// The machine instructions aren't parsed during the first pass because all
80 /// the machine basic blocks aren't defined yet - this makes it impossible to
81 /// resolve the machine basic block references.
83 /// Return true if an error occurred.
84 bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
85 StringRef Src, SMDiagnostic &Error);
87 /// Parse the machine instructions.
89 /// This function runs the second parsing pass on the machine function's body.
90 /// It skips the machine basic block definitions and parses only the machine
91 /// instructions and basic block attributes like liveins and successors.
93 /// The second parsing pass assumes that the first parsing pass already ran
94 /// on the given source string.
96 /// Return true if an error occurred.
97 bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
100 bool parseMBBReference(PerFunctionMIParsingState &PFS,
101 MachineBasicBlock *&MBB, StringRef Src,
102 SMDiagnostic &Error);
104 bool parseRegisterReference(PerFunctionMIParsingState &PFS,
105 unsigned &Reg, StringRef Src,
106 SMDiagnostic &Error);
108 bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
109 StringRef Src, SMDiagnostic &Error);
111 bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
112 VRegInfo *&Info, StringRef Src,
113 SMDiagnostic &Error);
115 bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
116 StringRef Src, SMDiagnostic &Error);
118 bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
119 SMDiagnostic &Error);
121 } // end namespace llvm
123 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H