1 //===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares the function that parses the machine instructions.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
14 #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/StringMap.h"
18 #include "llvm/Support/Allocator.h"
22 class MachineBasicBlock
;
23 class MachineFunction
;
30 class TargetRegisterClass
;
34 UNKNOWN
, NORMAL
, GENERIC
, REGBANK
36 bool Explicit
= false; ///< VReg was explicitly specified in the .mir file.
38 const TargetRegisterClass
*RC
;
39 const RegisterBank
*RegBank
;
42 unsigned PreferredReg
= 0;
45 using Name2RegClassMap
= StringMap
<const TargetRegisterClass
*>;
46 using Name2RegBankMap
= StringMap
<const RegisterBank
*>;
48 struct PerFunctionMIParsingState
{
49 BumpPtrAllocator Allocator
;
52 const SlotMapping
&IRSlots
;
53 const Name2RegClassMap
&Names2RegClasses
;
54 const Name2RegBankMap
&Names2RegBanks
;
56 DenseMap
<unsigned, MachineBasicBlock
*> MBBSlots
;
57 DenseMap
<unsigned, VRegInfo
*> VRegInfos
;
58 StringMap
<VRegInfo
*> VRegInfosNamed
;
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 Num
);
70 VRegInfo
&getVRegInfoNamed(StringRef RegName
);
73 /// Parse the machine basic block definitions, and skip the machine
76 /// This function runs the first parsing pass on the machine function's body.
77 /// It parses only the machine basic block definitions and creates the machine
78 /// basic blocks in the given machine function.
80 /// The machine instructions aren't parsed during the first pass because all
81 /// the machine basic blocks aren't defined yet - this makes it impossible to
82 /// resolve the machine basic block references.
84 /// Return true if an error occurred.
85 bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState
&PFS
,
86 StringRef Src
, SMDiagnostic
&Error
);
88 /// Parse the machine instructions.
90 /// This function runs the second parsing pass on the machine function's body.
91 /// It skips the machine basic block definitions and parses only the machine
92 /// instructions and basic block attributes like liveins and successors.
94 /// The second parsing pass assumes that the first parsing pass already ran
95 /// on the given source string.
97 /// Return true if an error occurred.
98 bool parseMachineInstructions(PerFunctionMIParsingState
&PFS
, StringRef Src
,
101 bool parseMBBReference(PerFunctionMIParsingState
&PFS
,
102 MachineBasicBlock
*&MBB
, StringRef Src
,
103 SMDiagnostic
&Error
);
105 bool parseRegisterReference(PerFunctionMIParsingState
&PFS
,
106 unsigned &Reg
, StringRef Src
,
107 SMDiagnostic
&Error
);
109 bool parseNamedRegisterReference(PerFunctionMIParsingState
&PFS
, unsigned &Reg
,
110 StringRef Src
, SMDiagnostic
&Error
);
112 bool parseVirtualRegisterReference(PerFunctionMIParsingState
&PFS
,
113 VRegInfo
*&Info
, StringRef Src
,
114 SMDiagnostic
&Error
);
116 bool parseStackObjectReference(PerFunctionMIParsingState
&PFS
, int &FI
,
117 StringRef Src
, SMDiagnostic
&Error
);
119 bool parseMDNode(PerFunctionMIParsingState
&PFS
, MDNode
*&Node
, StringRef Src
,
120 SMDiagnostic
&Error
);
122 } // end namespace llvm
124 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H