LLVM 23.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"
24#include <map>
25#include <utility>
26
27namespace llvm {
28
30class MachineFunction;
31class MDNode;
32class RegisterBank;
33struct SlotMapping;
34class SMDiagnostic;
35class SourceMgr;
36class StringRef;
39
40struct VRegInfo {
42 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
43 union {
46 } 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.
123 bool getTargetIndex(StringRef Name, int &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.
151 const RegisterBank *getRegBank(StringRef Name);
152
153 bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const;
154
156 : Subtarget(STI) {
157 initNames2RegClasses();
158 initNames2RegBanks();
159 }
160
162
163 void setTarget(const TargetSubtargetInfo &NewSubtarget);
164};
165
195
196/// Parse the machine basic block definitions, and skip the machine
197/// instructions.
198///
199/// This function runs the first parsing pass on the machine function's body.
200/// It parses only the machine basic block definitions and creates the machine
201/// basic blocks in the given machine function.
202///
203/// The machine instructions aren't parsed during the first pass because all
204/// the machine basic blocks aren't defined yet - this makes it impossible to
205/// resolve the machine basic block references.
206///
207/// Return true if an error occurred.
210
211/// Parse the machine instructions.
212///
213/// This function runs the second parsing pass on the machine function's body.
214/// It skips the machine basic block definitions and parses only the machine
215/// instructions and basic block attributes like liveins and successors.
216///
217/// The second parsing pass assumes that the first parsing pass already ran
218/// on the given source string.
219///
220/// Return true if an error occurred.
223
227
229 Register &Reg, StringRef Src,
231
234
236 VRegInfo *&Info, StringRef Src,
238
241
246
248 SMRange SourceRange, SMDiagnostic &Error);
249
250} // end namespace llvm
251
252#endif // LLVM_CODEGEN_MIRPARSER_MIPARSER_H
This file defines the StringMap class.
MachineBasicBlock & MBB
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file defines the DenseMap class.
#define RegName(no)
Register Reg
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Metadata node.
Definition Metadata.h:1080
Flags
Flags values. These may be or'd together.
This class implements the register bank concept.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:297
Represents a range in source code.
Definition SMLoc.h:47
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
LLVM Value Representation.
Definition Value.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
bool parsePrefetchTarget(PerFunctionMIParsingState &PFS, CallsiteID &Target, StringRef Src, SMDiagnostic &Error)
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
StringMap< const TargetRegisterClass * > Name2RegClassMap
Definition MIParser.h:52
StringMap< const RegisterBank * > Name2RegBankMap
Definition MIParser.h:53
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
DenseMap< unsigned, unsigned > JumpTableSlots
Definition MIParser.h:182
VRegInfo & getVRegInfo(Register Num)
Definition MIParser.cpp:328
DenseMap< unsigned, int > FixedStackObjectSlots
Definition MIParser.h:179
const SlotMapping & IRSlots
Definition MIParser.h:170
const Value * getIRValue(unsigned Slot)
Definition MIParser.cpp:373
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition MIParser.h:181
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition MIParser.h:176
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:178
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition MIParser.h:173
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition MIParser.h:185
DenseMap< unsigned, int > StackObjectSlots
Definition MIParser.h:180
PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM, const SlotMapping &IRSlots, PerTargetMIParsingState &Target)
Definition MIParser.cpp:323
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
Definition MIParser.h:174
PerTargetMIParsingState & Target
Definition MIParser.h:171
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:177
VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition MIParser.cpp:339
bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const
Definition MIParser.cpp:128
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition MIParser.h:155
bool getDirectTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a direct target flag to the corresponding target flag.
Definition MIParser.cpp:226
const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition MIParser.cpp:316
bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition MIParser.cpp:147
unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition MIParser.cpp:187
bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition MIParser.cpp:205
void setTarget(const TargetSubtargetInfo &NewSubtarget)
Definition MIParser.cpp:80
bool getRegisterByName(StringRef RegName, Register &Reg)
Try to convert a register name to a register number.
Definition MIParser.cpp:118
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:269
bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag)
Try to convert a name of a bitmask target flag to the corresponding target flag.
Definition MIParser.cpp:248
const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition MIParser.cpp:309
const uint32_t * getRegMask(StringRef Identifier)
Check if the given identifier is a name of a register mask.
Definition MIParser.cpp:170
This struct contains the mappings from the slot numbers to unnamed metadata nodes,...
Definition SlotMapping.h:32
const RegisterBank * RegBank
Definition MIParser.h:45
const TargetRegisterClass * RC
Definition MIParser.h:44
Register PreferredReg
Definition MIParser.h:48
Register VReg
Definition MIParser.h:47
bool Explicit
VReg was explicitly specified in the .mir file.
Definition MIParser.h:42
uint8_t Flags
Definition MIParser.h:49