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;
37class MCRegisterClass;
40
41struct VRegInfo {
43 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
44 union {
47 } D;
51};
52
55
57private:
58 const TargetSubtargetInfo &Subtarget;
59
60 /// Maps from instruction names to op codes.
61 StringMap<unsigned> Names2InstrOpCodes;
62
63 /// Maps from register names to registers.
64 StringMap<Register> Names2Regs;
65
66 /// Maps from register mask names to register masks.
67 StringMap<const uint32_t *> Names2RegMasks;
68
69 /// Maps from subregister names to subregister indices.
70 StringMap<unsigned> Names2SubRegIndices;
71
72 /// Maps from target index names to target indices.
73 StringMap<int> Names2TargetIndices;
74
75 /// Maps from direct target flag names to the direct target flag values.
76 StringMap<unsigned> Names2DirectTargetFlags;
77
78 /// Maps from direct target flag names to the bitmask target flag values.
79 StringMap<unsigned> Names2BitmaskTargetFlags;
80
81 /// Maps from MMO target flag names to MMO target flag values.
82 StringMap<MachineMemOperand::Flags> Names2MMOTargetFlags;
83
84 /// Maps from register class names to register classes.
85 Name2RegClassMap Names2RegClasses;
86
87 /// Maps from register bank names to register banks.
88 Name2RegBankMap Names2RegBanks;
89
90 void initNames2InstrOpCodes();
91 void initNames2Regs();
92 void initNames2RegMasks();
93 void initNames2SubRegIndices();
94 void initNames2TargetIndices();
95 void initNames2DirectTargetFlags();
96 void initNames2BitmaskTargetFlags();
97 void initNames2MMOTargetFlags();
98
99 LLVM_ABI void initNames2RegClasses();
100 LLVM_ABI void initNames2RegBanks();
101
102public:
103 /// Try to convert an instruction name to an opcode. Return true if the
104 /// instruction name is invalid.
105 LLVM_ABI bool parseInstrName(StringRef InstrName, unsigned &OpCode);
106
107 /// Try to convert a register name to a register number. Return true if the
108 /// register name is invalid.
110
111 /// Check if the given identifier is a name of a register mask.
112 ///
113 /// Return null if the identifier isn't a register mask.
114 LLVM_ABI const uint32_t *getRegMask(StringRef Identifier);
115
116 /// Check if the given identifier is a name of a subregister index.
117 ///
118 /// Return 0 if the name isn't a subregister index class.
119 LLVM_ABI unsigned getSubRegIndex(StringRef Name);
120
121 /// Try to convert a name of target index to the corresponding target index.
122 ///
123 /// Return true if the name isn't a name of a target index.
124 LLVM_ABI bool getTargetIndex(StringRef Name, int &Index);
125
126 /// Try to convert a name of a direct target flag to the corresponding
127 /// target flag.
128 ///
129 /// Return true if the name isn't a name of a direct flag.
130 LLVM_ABI bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
131
132 /// Try to convert a name of a bitmask target flag to the corresponding
133 /// target flag.
134 ///
135 /// Return true if the name isn't a name of a bitmask target flag.
136 LLVM_ABI bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag);
137
138 /// Try to convert a name of a MachineMemOperand target flag to the
139 /// corresponding target flag.
140 ///
141 /// Return true if the name isn't a name of a target MMO flag.
144
145 /// Check if the given identifier is a name of a register class.
146 ///
147 /// Return null if the name isn't a register class.
149
150 /// Check if the given identifier is a name of a register bank.
151 ///
152 /// Return null if the name isn't a register bank.
154
155 LLVM_ABI bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const;
156
158 : Subtarget(STI) {
159 initNames2RegClasses();
160 initNames2RegBanks();
161 }
162
164
165 LLVM_ABI void setTarget(const TargetSubtargetInfo &NewSubtarget);
166};
167
197
198/// Parse the machine basic block definitions, and skip the machine
199/// instructions.
200///
201/// This function runs the first parsing pass on the machine function's body.
202/// It parses only the machine basic block definitions and creates the machine
203/// basic blocks in the given machine function.
204///
205/// The machine instructions aren't parsed during the first pass because all
206/// the machine basic blocks aren't defined yet - this makes it impossible to
207/// resolve the machine basic block references.
208///
209/// Return true if an error occurred.
211 StringRef Src,
213
214/// Parse the machine instructions.
215///
216/// This function runs the second parsing pass on the machine function's body.
217/// It skips the machine basic block definitions and parses only the machine
218/// instructions and basic block attributes like liveins and successors.
219///
220/// The second parsing pass assumes that the first parsing pass already ran
221/// on the given source string.
222///
223/// Return true if an error occurred.
226
230
232 Register &Reg, StringRef Src,
234
236 Register &Reg, StringRef Src,
238
240 VRegInfo *&Info, StringRef Src,
242
245
251
253 StringRef Src, SMRange SourceRange,
255
256} // end namespace llvm
257
258#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")
#define LLVM_ABI
Definition Compiler.h:215
This file defines the DenseMap class.
#define RegName(no)
Register Reg
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
MCRegisterClass - Base class of TargetRegisterClass.
Metadata node.
Definition Metadata.h:1069
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:303
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:128
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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.
LLVM_ABI bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
LLVM_ABI bool parsePrefetchTarget(PerFunctionMIParsingState &PFS, CallsiteID &Target, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
StringMap< const TargetRegisterClass * > Name2RegClassMap
Definition MIParser.h:53
StringMap< const RegisterBank * > Name2RegBankMap
Definition MIParser.h:54
LLVM_ABI bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
LLVM_ABI bool parseRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
LLVM_ABI bool parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src, SMRange SourceRange, SMDiagnostic &Error)
LLVM_ABI 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:390
LLVM_ABI bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, Register &Reg, StringRef Src, SMDiagnostic &Error)
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
DenseMap< unsigned, unsigned > JumpTableSlots
Definition MIParser.h:184
LLVM_ABI VRegInfo & getVRegInfo(Register Num)
Definition MIParser.cpp:329
DenseMap< unsigned, int > FixedStackObjectSlots
Definition MIParser.h:181
const SlotMapping & IRSlots
Definition MIParser.h:172
LLVM_ABI const Value * getIRValue(unsigned Slot)
Definition MIParser.cpp:374
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition MIParser.h:183
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition MIParser.h:178
StringMap< VRegInfo * > VRegInfosNamed
Definition MIParser.h:180
std::map< unsigned, TrackingMDNodeRef > MachineMetadataNodes
Definition MIParser.h:175
DenseMap< unsigned, const Value * > Slots2Values
Maps from slot numbers to function's unnamed values.
Definition MIParser.h:187
DenseMap< unsigned, int > StackObjectSlots
Definition MIParser.h:182
LLVM_ABI PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM, const SlotMapping &IRSlots, PerTargetMIParsingState &Target)
Definition MIParser.cpp:324
std::map< unsigned, std::pair< TempMDTuple, SMLoc > > MachineForwardRefMDNodes
Definition MIParser.h:176
PerTargetMIParsingState & Target
Definition MIParser.h:173
DenseMap< Register, VRegInfo * > VRegInfos
Definition MIParser.h:179
LLVM_ABI VRegInfo & getVRegInfoNamed(StringRef RegName)
Definition MIParser.cpp:340
LLVM_ABI bool getVRegFlagValue(StringRef FlagName, uint8_t &FlagValue) const
Definition MIParser.cpp:129
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition MIParser.h:157
LLVM_ABI 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
LLVM_ABI const RegisterBank * getRegBank(StringRef Name)
Check if the given identifier is a name of a register bank.
Definition MIParser.cpp:317
LLVM_ABI bool parseInstrName(StringRef InstrName, unsigned &OpCode)
Try to convert an instruction name to an opcode.
Definition MIParser.cpp:148
LLVM_ABI unsigned getSubRegIndex(StringRef Name)
Check if the given identifier is a name of a subregister index.
Definition MIParser.cpp:188
LLVM_ABI bool getTargetIndex(StringRef Name, int &Index)
Try to convert a name of target index to the corresponding target index.
Definition MIParser.cpp:206
LLVM_ABI void setTarget(const TargetSubtargetInfo &NewSubtarget)
Definition MIParser.cpp:81
LLVM_ABI bool getRegisterByName(StringRef RegName, Register &Reg)
Try to convert a register name to a register number.
Definition MIParser.cpp:119
LLVM_ABI 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
LLVM_ABI 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
LLVM_ABI const TargetRegisterClass * getRegClass(StringRef Name)
Check if the given identifier is a name of a register class.
Definition MIParser.cpp:310
LLVM_ABI 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:32
const RegisterBank * RegBank
Definition MIParser.h:46
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
uint8_t Flags
Definition MIParser.h:50