LLVM 18.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"
21#include "llvm/Support/SMLoc.h"
22#include <utility>
23
24namespace llvm {
25
26class MachineBasicBlock;
27class MachineFunction;
28class MDNode;
29class RegisterBank;
30struct SlotMapping;
31class SMDiagnostic;
32class SourceMgr;
33class StringRef;
34class TargetRegisterClass;
35class TargetSubtargetInfo;
36
37struct VRegInfo {
38 enum uint8_t {
41 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
42 union {
45 } D;
48};
49
52
54private:
55 const TargetSubtargetInfo &Subtarget;
56
57 /// Maps from instruction names to op codes.
58 StringMap<unsigned> Names2InstrOpCodes;
59
60 /// Maps from register names to registers.
61 StringMap<Register> Names2Regs;
62
63 /// Maps from register mask names to register masks.
64 StringMap<const uint32_t *> Names2RegMasks;
65
66 /// Maps from subregister names to subregister indices.
67 StringMap<unsigned> Names2SubRegIndices;
68
69 /// Maps from target index names to target indices.
70 StringMap<int> Names2TargetIndices;
71
72 /// Maps from direct target flag names to the direct target flag values.
73 StringMap<unsigned> Names2DirectTargetFlags;
74
75 /// Maps from direct target flag names to the bitmask target flag values.
76 StringMap<unsigned> Names2BitmaskTargetFlags;
77
78 /// Maps from MMO target flag names to MMO target flag values.
79 StringMap<MachineMemOperand::Flags> Names2MMOTargetFlags;
80
81 /// Maps from register class names to register classes.
82 Name2RegClassMap Names2RegClasses;
83
84 /// Maps from register bank names to register banks.
85 Name2RegBankMap Names2RegBanks;
86
87 void initNames2InstrOpCodes();
88 void initNames2Regs();
89 void initNames2RegMasks();
90 void initNames2SubRegIndices();
91 void initNames2TargetIndices();
92 void initNames2DirectTargetFlags();
93 void initNames2BitmaskTargetFlags();
94 void initNames2MMOTargetFlags();
95
96 void initNames2RegClasses();
97 void initNames2RegBanks();
98
99public:
100 /// Try to convert an instruction name to an opcode. Return true if the
101 /// instruction name is invalid.
102 bool parseInstrName(StringRef InstrName, unsigned &OpCode);
103
104 /// Try to convert a register name to a register number. Return true if the
105 /// register name is invalid.
107
108 /// Check if the given identifier is a name of a register mask.
109 ///
110 /// Return null if the identifier isn't a register mask.
111 const uint32_t *getRegMask(StringRef Identifier);
112
113 /// Check if the given identifier is a name of a subregister index.
114 ///
115 /// Return 0 if the name isn't a subregister index class.
116 unsigned getSubRegIndex(StringRef Name);
117
118 /// Try to convert a name of target index to the corresponding target index.
119 ///
120 /// Return true if the name isn't a name of a target index.
122
123 /// Try to convert a name of a direct target flag to the corresponding
124 /// target flag.
125 ///
126 /// Return true if the name isn't a name of a direct flag.
127 bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
128
129 /// Try to convert a name of a bitmask target flag to the corresponding
130 /// target flag.
131 ///
132 /// Return true if the name isn't a name of a bitmask target flag.
133 bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag);
134
135 /// Try to convert a name of a MachineMemOperand target flag to the
136 /// corresponding target flag.
137 ///
138 /// Return true if the name isn't a name of a target MMO flag.
140
141 /// Check if the given identifier is a name of a register class.
142 ///
143 /// Return null if the name isn't a register class.
145
146 /// Check if the given identifier is a name of a register bank.
147 ///
148 /// Return null if the name isn't a register bank.
150
152 : Subtarget(STI) {
153 initNames2RegClasses();
154 initNames2RegBanks();
155 }
156
158
159 void setTarget(const TargetSubtargetInfo &NewSubtarget);
160};
161
168
169 std::map<unsigned, TrackingMDNodeRef> MachineMetadataNodes;
170 std::map<unsigned, std::pair<TempMDTuple, SMLoc>> MachineForwardRefMDNodes;
171
179
180 /// Maps from slot numbers to function's unnamed values.
182
184 const SlotMapping &IRSlots,
186
189 const Value *getIRValue(unsigned Slot);
190};
191
192/// Parse the machine basic block definitions, and skip the machine
193/// instructions.
194///
195/// This function runs the first parsing pass on the machine function's body.
196/// It parses only the machine basic block definitions and creates the machine
197/// basic blocks in the given machine function.
198///
199/// The machine instructions aren't parsed during the first pass because all
200/// the machine basic blocks aren't defined yet - this makes it impossible to
201/// resolve the machine basic block references.
202///
203/// Return true if an error occurred.
206
207/// Parse the machine instructions.
208///
209/// This function runs the second parsing pass on the machine function's body.
210/// It skips the machine basic block definitions and parses only the machine
211/// instructions and basic block attributes like liveins and successors.
212///
213/// The second parsing pass assumes that the first parsing pass already ran
214/// on the given source string.
215///
216/// Return true if an error occurred.
219
223
225 Register &Reg, StringRef Src,
227
230
232 VRegInfo *&Info, StringRef Src,
234
237
240
242 SMRange SourceRange, SMDiagnostic &Error);
243
244} // end namespace llvm
245
246#endif // LLVM_CODEGEN_MIRPARSER_MIPARSER_H
MachineBasicBlock & MBB
This file defines the StringMap class.
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:950
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:3618
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3624
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
Definition: MIParser.cpp:3583
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3594
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:3589
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3600
bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
Definition: MIParser.cpp:3629
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3612
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3606
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:178
VRegInfo & getVRegInfo(Register Num)
Definition: MIParser.cpp:319
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:175
const SlotMapping & IRSlots
Definition: MIParser.h:166
const Value * getIRValue(unsigned Slot)
Definition: MIParser.cpp:364
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:177
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition: MIParser.h:172
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:174
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition: MIParser.h:169
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition: MIParser.h:181
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:176
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
Definition: MIParser.h:170
PerTargetMIParsingState & Target
Definition: MIParser.h:167
DenseMap< Register, VRegInfo * > VRegInfos
Definition: MIParser.h:173
VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition: MIParser.cpp:330
BumpPtrAllocator Allocator
Definition: MIParser.h:163
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition: MIParser.h:151
bool getDirectTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a direct target flag to the corresponding target flag.
Definition: MIParser.cpp:217
const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition: MIParser.cpp:307
bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition: MIParser.cpp:138
unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition: MIParser.cpp:178
bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition: MIParser.cpp:196
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:260
bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a bitmask target flag to the corresponding target flag.
Definition: MIParser.cpp:239
const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition: MIParser.cpp:300
const uint32_t * getRegMask(StringRef Identifier)
Check if the given identifier is a name of a register mask.
Definition: MIParser.cpp:161
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition: SlotMapping.h:32
const RegisterBank * RegBank
Definition: MIParser.h:44
enum llvm::VRegInfo::uint8_t Kind
const TargetRegisterClass * RC
Definition: MIParser.h:43
Register PreferredReg
Definition: MIParser.h:47
Register VReg
Definition: MIParser.h:46
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:41
union llvm::VRegInfo::@206 D