LLVM 20.0.0git
MIParser.h
Go to the documentation of this file.
1//===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===//
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 declares the function that parses the machine instructions.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_MIRPARSER_MIPARSER_H
14#define LLVM_CODEGEN_MIRPARSER_MIPARSER_H
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/ADT/StringMap.h"
22#include "llvm/Support/SMLoc.h"
23#include <map>
24#include <utility>
25
26namespace llvm {
27
28class MachineBasicBlock;
29class MachineFunction;
30class MDNode;
31class RegisterBank;
32struct SlotMapping;
33class SMDiagnostic;
34class SourceMgr;
35class StringRef;
36class TargetRegisterClass;
37class TargetSubtargetInfo;
38
39struct VRegInfo {
40 enum uint8_t {
43 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
44 union {
47 } D;
50};
51
54
56private:
57 const TargetSubtargetInfo &Subtarget;
58
59 /// Maps from instruction names to op codes.
60 StringMap<unsigned> Names2InstrOpCodes;
61
62 /// Maps from register names to registers.
63 StringMap<Register> Names2Regs;
64
65 /// Maps from register mask names to register masks.
66 StringMap<const uint32_t *> Names2RegMasks;
67
68 /// Maps from subregister names to subregister indices.
69 StringMap<unsigned> Names2SubRegIndices;
70
71 /// Maps from target index names to target indices.
72 StringMap<int> Names2TargetIndices;
73
74 /// Maps from direct target flag names to the direct target flag values.
75 StringMap<unsigned> Names2DirectTargetFlags;
76
77 /// Maps from direct target flag names to the bitmask target flag values.
78 StringMap<unsigned> Names2BitmaskTargetFlags;
79
80 /// Maps from MMO target flag names to MMO target flag values.
81 StringMap<MachineMemOperand::Flags> Names2MMOTargetFlags;
82
83 /// Maps from register class names to register classes.
84 Name2RegClassMap Names2RegClasses;
85
86 /// Maps from register bank names to register banks.
87 Name2RegBankMap Names2RegBanks;
88
89 void initNames2InstrOpCodes();
90 void initNames2Regs();
91 void initNames2RegMasks();
92 void initNames2SubRegIndices();
93 void initNames2TargetIndices();
94 void initNames2DirectTargetFlags();
95 void initNames2BitmaskTargetFlags();
96 void initNames2MMOTargetFlags();
97
98 void initNames2RegClasses();
99 void initNames2RegBanks();
100
101public:
102 /// Try to convert an instruction name to an opcode. Return true if the
103 /// instruction name is invalid.
104 bool parseInstrName(StringRef InstrName, unsigned &OpCode);
105
106 /// Try to convert a register name to a register number. Return true if the
107 /// register name is invalid.
109
110 /// Check if the given identifier is a name of a register mask.
111 ///
112 /// Return null if the identifier isn't a register mask.
113 const uint32_t *getRegMask(StringRef Identifier);
114
115 /// Check if the given identifier is a name of a subregister index.
116 ///
117 /// Return 0 if the name isn't a subregister index class.
118 unsigned getSubRegIndex(StringRef Name);
119
120 /// Try to convert a name of target index to the corresponding target index.
121 ///
122 /// Return true if the name isn't a name of a target index.
124
125 /// Try to convert a name of a direct target flag to the corresponding
126 /// target flag.
127 ///
128 /// Return true if the name isn't a name of a direct flag.
129 bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
130
131 /// Try to convert a name of a bitmask target flag to the corresponding
132 /// target flag.
133 ///
134 /// Return true if the name isn't a name of a bitmask target flag.
135 bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag);
136
137 /// Try to convert a name of a MachineMemOperand target flag to the
138 /// corresponding target flag.
139 ///
140 /// Return true if the name isn't a name of a target MMO flag.
142
143 /// Check if the given identifier is a name of a register class.
144 ///
145 /// Return null if the name isn't a register class.
147
148 /// Check if the given identifier is a name of a register bank.
149 ///
150 /// Return null if the name isn't a register bank.
152
154 : Subtarget(STI) {
155 initNames2RegClasses();
156 initNames2RegBanks();
157 }
158
160
161 void setTarget(const TargetSubtargetInfo &NewSubtarget);
162};
163
170
171 std::map<unsigned, TrackingMDNodeRef> MachineMetadataNodes;
172 std::map<unsigned, std::pair<TempMDTuple, SMLoc>> MachineForwardRefMDNodes;
173
181
182 /// Maps from slot numbers to function's unnamed values.
184
186 const SlotMapping &IRSlots,
188
191 const Value *getIRValue(unsigned Slot);
192};
193
194/// Parse the machine basic block definitions, and skip the machine
195/// instructions.
196///
197/// This function runs the first parsing pass on the machine function's body.
198/// It parses only the machine basic block definitions and creates the machine
199/// basic blocks in the given machine function.
200///
201/// The machine instructions aren't parsed during the first pass because all
202/// the machine basic blocks aren't defined yet - this makes it impossible to
203/// resolve the machine basic block references.
204///
205/// Return true if an error occurred.
208
209/// Parse the machine instructions.
210///
211/// This function runs the second parsing pass on the machine function's body.
212/// It skips the machine basic block definitions and parses only the machine
213/// instructions and basic block attributes like liveins and successors.
214///
215/// The second parsing pass assumes that the first parsing pass already ran
216/// on the given source string.
217///
218/// Return true if an error occurred.
221
225
227 Register &Reg, StringRef Src,
229
232
234 VRegInfo *&Info, StringRef Src,
236
239
242
244 SMRange SourceRange, SMDiagnostic &Error);
245
246} // end namespace llvm
247
248#endif // LLVM_CODEGEN_MIRPARSER_MIPARSER_H
This file defines the StringMap class.
MachineBasicBlock & MBB
This file defines the BumpPtrAllocator interface.
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
This file defines the DenseMap class.
std::string Name
#define RegName(no)
unsigned Reg
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Metadata node.
Definition: Metadata.h:1069
Flags
Flags values. These may be or'd together.
This class implements the register bank concept.
Definition: RegisterBank.h:28
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
Represents a range in source code.
Definition: SMLoc.h:48
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition: SourceMgr.h:31
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3609
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3615
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
Definition: MIParser.cpp:3574
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3585
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:3580
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3591
bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
Definition: MIParser.cpp:3620
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3603
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3597
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:180
VRegInfo & getVRegInfo(Register Num)
Definition: MIParser.cpp:320
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:177
const SlotMapping & IRSlots
Definition: MIParser.h:168
const Value * getIRValue(unsigned Slot)
Definition: MIParser.cpp:365
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:179
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition: MIParser.h:174
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:176
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition: MIParser.h:171
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition: MIParser.h:183
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:178
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
Definition: MIParser.h:172
PerTargetMIParsingState & Target
Definition: MIParser.h:169
DenseMap< Register, VRegInfo * > VRegInfos
Definition: MIParser.h:175
VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition: MIParser.cpp:331
BumpPtrAllocator Allocator
Definition: MIParser.h:165
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition: MIParser.h:153
bool getDirectTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a direct target flag to the corresponding target flag.
Definition: MIParser.cpp:218
const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition: MIParser.cpp:308
bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition: MIParser.cpp:139
unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition: MIParser.cpp:179
bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition: MIParser.cpp:197
void setTarget(const TargetSubtargetInfo &NewSubtarget)
Definition: MIParser.cpp:82
bool getRegisterByName(StringRef RegName, Register &Reg)
Try to convert a register name to a register number.
Definition: MIParser.cpp:120
bool getMMOTargetFlag(StringRef Name, MachineMemOperand::Flags &Flag)
Try to convert a name of a MachineMemOperand target flag to the corresponding target flag.
Definition: MIParser.cpp:261
bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a bitmask target flag to the corresponding target flag.
Definition: MIParser.cpp:240
const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition: MIParser.cpp:301
const uint32_t * getRegMask(StringRef Identifier)
Check if the given identifier is a name of a register mask.
Definition: MIParser.cpp:162
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:33
const RegisterBank * RegBank
Definition: MIParser.h:46
enum llvm::VRegInfo::uint8_t Kind
union llvm::VRegInfo::@215 D
const TargetRegisterClass * RC
Definition: MIParser.h:45
Register PreferredReg
Definition: MIParser.h:49
Register VReg
Definition: MIParser.h:48
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:43