LLVM  9.0.0svn
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_LIB_CODEGEN_MIRPARSER_MIPARSER_H
14 #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
15 
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/StringMap.h"
19 #include "llvm/Support/Allocator.h"
20 
21 namespace llvm {
22 
23 class MachineBasicBlock;
24 class MachineFunction;
25 class MDNode;
26 class RegisterBank;
27 struct SlotMapping;
28 class SMDiagnostic;
29 class SourceMgr;
30 class StringRef;
31 class TargetRegisterClass;
32 class TargetSubtargetInfo;
33 
34 struct VRegInfo {
35  enum uint8_t {
37  } Kind = UNKNOWN;
38  bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
39  union {
42  } D;
43  unsigned VReg;
44  unsigned PreferredReg = 0;
45 };
46 
49 
51 private:
52  const TargetSubtargetInfo &Subtarget;
53 
54  /// Maps from instruction names to op codes.
55  StringMap<unsigned> Names2InstrOpCodes;
56 
57  /// Maps from register names to registers.
58  StringMap<unsigned> Names2Regs;
59 
60  /// Maps from register mask names to register masks.
61  StringMap<const uint32_t *> Names2RegMasks;
62 
63  /// Maps from subregister names to subregister indices.
64  StringMap<unsigned> Names2SubRegIndices;
65 
66  /// Maps from target index names to target indices.
67  StringMap<int> Names2TargetIndices;
68 
69  /// Maps from direct target flag names to the direct target flag values.
70  StringMap<unsigned> Names2DirectTargetFlags;
71 
72  /// Maps from direct target flag names to the bitmask target flag values.
73  StringMap<unsigned> Names2BitmaskTargetFlags;
74 
75  /// Maps from MMO target flag names to MMO target flag values.
76  StringMap<MachineMemOperand::Flags> Names2MMOTargetFlags;
77 
78  /// Maps from register class names to register classes.
79  Name2RegClassMap Names2RegClasses;
80 
81  /// Maps from register bank names to register banks.
82  Name2RegBankMap Names2RegBanks;
83 
84  void initNames2InstrOpCodes();
85  void initNames2Regs();
86  void initNames2RegMasks();
87  void initNames2SubRegIndices();
88  void initNames2TargetIndices();
89  void initNames2DirectTargetFlags();
90  void initNames2BitmaskTargetFlags();
91  void initNames2MMOTargetFlags();
92 
93  void initNames2RegClasses();
94  void initNames2RegBanks();
95 
96 public:
97  /// Try to convert an instruction name to an opcode. Return true if the
98  /// instruction name is invalid.
99  bool parseInstrName(StringRef InstrName, unsigned &OpCode);
100 
101  /// Try to convert a register name to a register number. Return true if the
102  /// register name is invalid.
103  bool getRegisterByName(StringRef RegName, unsigned &Reg);
104 
105  /// Check if the given identifier is a name of a register mask.
106  ///
107  /// Return null if the identifier isn't a register mask.
108  const uint32_t *getRegMask(StringRef Identifier);
109 
110  /// Check if the given identifier is a name of a subregister index.
111  ///
112  /// Return 0 if the name isn't a subregister index class.
113  unsigned getSubRegIndex(StringRef Name);
114 
115  /// Try to convert a name of target index to the corresponding target index.
116  ///
117  /// Return true if the name isn't a name of a target index.
118  bool getTargetIndex(StringRef Name, int &Index);
119 
120  /// Try to convert a name of a direct target flag to the corresponding
121  /// target flag.
122  ///
123  /// Return true if the name isn't a name of a direct flag.
124  bool getDirectTargetFlag(StringRef Name, unsigned &Flag);
125 
126  /// Try to convert a name of a bitmask target flag to the corresponding
127  /// target flag.
128  ///
129  /// Return true if the name isn't a name of a bitmask target flag.
130  bool getBitmaskTargetFlag(StringRef Name, unsigned &Flag);
131 
132  /// Try to convert a name of a MachineMemOperand target flag to the
133  /// corresponding target flag.
134  ///
135  /// Return true if the name isn't a name of a target MMO flag.
136  bool getMMOTargetFlag(StringRef Name, MachineMemOperand::Flags &Flag);
137 
138  /// Check if the given identifier is a name of a register class.
139  ///
140  /// Return null if the name isn't a register class.
142 
143  /// Check if the given identifier is a name of a register bank.
144  ///
145  /// Return null if the name isn't a register bank.
146  const RegisterBank *getRegBank(StringRef Name);
147 
149  : Subtarget(STI) {
150  initNames2RegClasses();
151  initNames2RegBanks();
152  }
153 
154  ~PerTargetMIParsingState() = default;
155 
156  void setTarget(const TargetSubtargetInfo &NewSubtarget);
157 };
158 
165 
173 
175  const SlotMapping &IRSlots,
176  PerTargetMIParsingState &Target);
177 
178  VRegInfo &getVRegInfo(unsigned Num);
179  VRegInfo &getVRegInfoNamed(StringRef RegName);
180 };
181 
182 /// Parse the machine basic block definitions, and skip the machine
183 /// instructions.
184 ///
185 /// This function runs the first parsing pass on the machine function's body.
186 /// It parses only the machine basic block definitions and creates the machine
187 /// basic blocks in the given machine function.
188 ///
189 /// The machine instructions aren't parsed during the first pass because all
190 /// the machine basic blocks aren't defined yet - this makes it impossible to
191 /// resolve the machine basic block references.
192 ///
193 /// Return true if an error occurred.
196 
197 /// Parse the machine instructions.
198 ///
199 /// This function runs the second parsing pass on the machine function's body.
200 /// It skips the machine basic block definitions and parses only the machine
201 /// instructions and basic block attributes like liveins and successors.
202 ///
203 /// The second parsing pass assumes that the first parsing pass already ran
204 /// on the given source string.
205 ///
206 /// Return true if an error occurred.
209 
211  MachineBasicBlock *&MBB, StringRef Src,
213 
215  unsigned &Reg, StringRef Src,
217 
220 
222  VRegInfo *&Info, StringRef Src,
224 
227 
230 
231 } // end namespace llvm
232 
233 #endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
Definition: MIParser.cpp:2997
DenseMap< unsigned, unsigned > JumpTableSlots
Definition: MIParser.h:172
DenseMap< unsigned, unsigned > ConstantPoolSlots
Definition: MIParser.h:171
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
union llvm::VRegInfo::@176 D
unsigned Reg
DenseMap< unsigned, int > StackObjectSlots
Definition: MIParser.h:170
Metadata node.
Definition: Metadata.h:863
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3008
const TargetRegisterClass * RC
Definition: MIParser.h:40
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
StringMap< VRegInfo * > VRegInfosNamed
Definition: MIParser.h:168
static int getRegClass(RegisterKind Is, unsigned RegWidth)
DenseMap< unsigned, int > FixedStackObjectSlots
Definition: MIParser.h:169
unsigned PreferredReg
Definition: MIParser.h:44
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3026
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:117
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3032
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
BumpPtrAllocator Allocator
Definition: MIParser.h:160
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3020
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
const SlotMapping & IRSlots
Definition: MIParser.h:163
PerTargetMIParsingState(const TargetSubtargetInfo &STI)
Definition: MIParser.h:148
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
Definition: MIParser.cpp:3003
enum llvm::VRegInfo::uint8_t Kind
This class implements the register bank concept.
Definition: RegisterBank.h:28
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:219
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
Definition: SlotMapping.h:32
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3038
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
Flags
Flags values. These may be or&#39;d together.
TargetSubtargetInfo - Generic base class for all target subtargets.
bool Explicit
VReg was explicitly specified in the .mir file.
Definition: MIParser.h:38
unsigned VReg
Definition: MIParser.h:43
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
Definition: MIParser.h:166
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const RegisterBank * RegBank
Definition: MIParser.h:41
PerTargetMIParsingState & Target
Definition: MIParser.h:164
DenseMap< unsigned, VRegInfo * > VRegInfos
Definition: MIParser.h:167
bool parseRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
Definition: MIParser.cpp:3014
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:261