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 {
41 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
42 union {
45 } D;
49};
50
53
55private:
56 const TargetSubtargetInfo &Subtarget;
57
58 /// Maps from instruction names to op codes.
59 StringMap<unsigned> Names2InstrOpCodes;
60
61 /// Maps from register names to registers.
62 StringMap<Register> Names2Regs;
63
64 /// Maps from register mask names to register masks.
65 StringMap<const uint32_t *> Names2RegMasks;
66
67 /// Maps from subregister names to subregister indices.
68 StringMap<unsigned> Names2SubRegIndices;
69
70 /// Maps from target index names to target indices.
71 StringMap<int> Names2TargetIndices;
72
73 /// Maps from direct target flag names to the direct target flag values.
74 StringMap<unsigned> Names2DirectTargetFlags;
75
76 /// Maps from direct target flag names to the bitmask target flag values.
77 StringMap<unsigned> Names2BitmaskTargetFlags;
78
79 /// Maps from MMO target flag names to MMO target flag values.
80 StringMap<MachineMemOperand::Flags> Names2MMOTargetFlags;
81
82 /// Maps from register class names to register classes.
83 Name2RegClassMap Names2RegClasses;
84
85 /// Maps from register bank names to register banks.
86 Name2RegBankMap Names2RegBanks;
87
88 void initNames2InstrOpCodes();
89 void initNames2Regs();
90 void initNames2RegMasks();
91 void initNames2SubRegIndices();
92 void initNames2TargetIndices();
93 void initNames2DirectTargetFlags();
94 void initNames2BitmaskTargetFlags();
95 void initNames2MMOTargetFlags();
96
97 void initNames2RegClasses();
98 void initNames2RegBanks();
99
100public:
101 /// Try to convert an instruction name to an opcode. Return true if the
102 /// instruction name is invalid.
103 bool parseInstrName(StringRef InstrName, unsigned &OpCode);
104
105 /// Try to convert a register name to a register number. Return true if the
106 /// register name is invalid.
108
109 /// Check if the given identifier is a name of a register mask.
110 ///
111 /// Return null if the identifier isn't a register mask.
112 const uint32_t *getRegMask(StringRef Identifier);
113
114 /// Check if the given identifier is a name of a subregister index.
115 ///
116 /// Return 0 if the name isn't a subregister index class.
117 unsigned getSubRegIndex(StringRef Name);
118
119 /// Try to convert a name of target index to the corresponding target index.
120 ///
121 /// Return true if the name isn't a name of a target index.
123
124 /// Try to convert a name of a direct target flag to the corresponding
125 /// target flag.
126 ///
127 /// Return true if the name isn't a name of a direct flag.
128 bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
129
130 /// Try to convert a name of a bitmask target flag to the corresponding
131 /// target flag.
132 ///
133 /// Return true if the name isn't a name of a bitmask target flag.
134 bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag);
135
136 /// Try to convert a name of a MachineMemOperand target flag to the
137 /// corresponding target flag.
138 ///
139 /// Return true if the name isn't a name of a target MMO flag.
141
142 /// Check if the given identifier is a name of a register class.
143 ///
144 /// Return null if the name isn't a register class.
146
147 /// Check if the given identifier is a name of a register bank.
148 ///
149 /// Return null if the name isn't a register bank.
151
152 bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const;
153
155 : Subtarget(STI) {
156 initNames2RegClasses();
157 initNames2RegBanks();
158 }
159
161
162 void setTarget(const TargetSubtargetInfo &NewSubtarget);
163};
164
171
172 std::map<unsigned, TrackingMDNodeRef> MachineMetadataNodes;
173 std::map<unsigned, std::pair<TempMDTuple, SMLoc>> MachineForwardRefMDNodes;
174
182
183 /// Maps from slot numbers to function's unnamed values.
185
187 const SlotMapping &IRSlots,
189
192 const Value *getIRValue(unsigned Slot);
193};
194
195/// Parse the machine basic block definitions, and skip the machine
196/// instructions.
197///
198/// This function runs the first parsing pass on the machine function's body.
199/// It parses only the machine basic block definitions and creates the machine
200/// basic blocks in the given machine function.
201///
202/// The machine instructions aren't parsed during the first pass because all
203/// the machine basic blocks aren't defined yet - this makes it impossible to
204/// resolve the machine basic block references.
205///
206/// Return true if an error occurred.
209
210/// Parse the machine instructions.
211///
212/// This function runs the second parsing pass on the machine function's body.
213/// It skips the machine basic block definitions and parses only the machine
214/// instructions and basic block attributes like liveins and successors.
215///
216/// The second parsing pass assumes that the first parsing pass already ran
217/// on the given source string.
218///
219/// Return true if an error occurred.
222
226
228 Register &Reg, StringRef Src,
230
233
235 VRegInfo *&Info, StringRef Src,
237
240
243
245 SMRange SourceRange, SMDiagnostic &Error);
246
247} // end namespace llvm
248
249#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
uint32_t Index
#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:51
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:3620
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3626
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
Definition: MIParser.cpp:3585
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3596
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:3591
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3602
bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
Definition: MIParser.cpp:3631
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3614
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3608
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:181
VRegInfo & getVRegInfo(Register Num)
Definition: MIParser.cpp:329
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:178
const SlotMapping & IRSlots
Definition: MIParser.h:169
const Value * getIRValue(unsigned Slot)
Definition: MIParser.cpp:374
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:180
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition: MIParser.h:175
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:177
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition: MIParser.h:172
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition: MIParser.h:184
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:179
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
Definition: MIParser.h:173
PerTargetMIParsingState & Target
Definition: MIParser.h:170
DenseMap< Register, VRegInfo * > VRegInfos
Definition: MIParser.h:176
VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition: MIParser.cpp:340
BumpPtrAllocator Allocator
Definition: MIParser.h:166
bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const
Definition: MIParser.cpp:129
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition: MIParser.h:154
bool getDirectTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a direct target flag to the corresponding target flag.
Definition: MIParser.cpp:227
const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition: MIParser.cpp:317
bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition: MIParser.cpp:148
unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition: MIParser.cpp:188
bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition: MIParser.cpp:206
void setTarget(const TargetSubtargetInfo &NewSubtarget)
Definition: MIParser.cpp:81
bool getRegisterByName(StringRef RegName, Register &Reg)
Try to convert a register name to a register number.
Definition: MIParser.cpp:119
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:270
bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a bitmask target flag to the corresponding target flag.
Definition: MIParser.cpp:249
const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition: MIParser.cpp:310
const uint32_t * getRegMask(StringRef Identifier)
Check if the given identifier is a name of a register mask.
Definition: MIParser.cpp:171
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:33
const RegisterBank * RegBank
Definition: MIParser.h:44
union llvm::VRegInfo::@216 D
const TargetRegisterClass * RC
Definition: MIParser.h:43
Register PreferredReg
Definition: MIParser.h:47
Register VReg
Definition: MIParser.h:46
enum llvm::VRegInfo::@215 Kind
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:41
uint8_t Flags
Definition: MIParser.h:48