xref: /aosp_15_r20/external/llvm/lib/CodeGen/MIRParser/MIParser.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- MIParser.h - Machine Instructions Parser ---------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file declares the function that parses the machine instructions.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
15*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/SmallSet.h"
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker namespace llvm {
21*9880d681SAndroid Build Coastguard Worker 
22*9880d681SAndroid Build Coastguard Worker class StringRef;
23*9880d681SAndroid Build Coastguard Worker class BasicBlock;
24*9880d681SAndroid Build Coastguard Worker class MachineBasicBlock;
25*9880d681SAndroid Build Coastguard Worker class MachineFunction;
26*9880d681SAndroid Build Coastguard Worker class MachineInstr;
27*9880d681SAndroid Build Coastguard Worker class MachineRegisterInfo;
28*9880d681SAndroid Build Coastguard Worker class MDNode;
29*9880d681SAndroid Build Coastguard Worker struct SlotMapping;
30*9880d681SAndroid Build Coastguard Worker class SMDiagnostic;
31*9880d681SAndroid Build Coastguard Worker class SourceMgr;
32*9880d681SAndroid Build Coastguard Worker 
33*9880d681SAndroid Build Coastguard Worker struct PerFunctionMIParsingState {
34*9880d681SAndroid Build Coastguard Worker   MachineFunction &MF;
35*9880d681SAndroid Build Coastguard Worker   SourceMgr *SM;
36*9880d681SAndroid Build Coastguard Worker   const SlotMapping &IRSlots;
37*9880d681SAndroid Build Coastguard Worker 
38*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
39*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, unsigned> VirtualRegisterSlots;
40*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, int> FixedStackObjectSlots;
41*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, int> StackObjectSlots;
42*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, unsigned> ConstantPoolSlots;
43*9880d681SAndroid Build Coastguard Worker   DenseMap<unsigned, unsigned> JumpTableSlots;
44*9880d681SAndroid Build Coastguard Worker   /// Hold the generic virtual registers.
45*9880d681SAndroid Build Coastguard Worker   SmallSet<unsigned, 8> GenericVRegs;
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker   PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
48*9880d681SAndroid Build Coastguard Worker                             const SlotMapping &IRSlots);
49*9880d681SAndroid Build Coastguard Worker };
50*9880d681SAndroid Build Coastguard Worker 
51*9880d681SAndroid Build Coastguard Worker /// Parse the machine basic block definitions, and skip the machine
52*9880d681SAndroid Build Coastguard Worker /// instructions.
53*9880d681SAndroid Build Coastguard Worker ///
54*9880d681SAndroid Build Coastguard Worker /// This function runs the first parsing pass on the machine function's body.
55*9880d681SAndroid Build Coastguard Worker /// It parses only the machine basic block definitions and creates the machine
56*9880d681SAndroid Build Coastguard Worker /// basic blocks in the given machine function.
57*9880d681SAndroid Build Coastguard Worker ///
58*9880d681SAndroid Build Coastguard Worker /// The machine instructions aren't parsed during the first pass because all
59*9880d681SAndroid Build Coastguard Worker /// the machine basic blocks aren't defined yet - this makes it impossible to
60*9880d681SAndroid Build Coastguard Worker /// resolve the machine basic block references.
61*9880d681SAndroid Build Coastguard Worker ///
62*9880d681SAndroid Build Coastguard Worker /// Return true if an error occurred.
63*9880d681SAndroid Build Coastguard Worker bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
64*9880d681SAndroid Build Coastguard Worker                                        StringRef Src, SMDiagnostic &Error);
65*9880d681SAndroid Build Coastguard Worker 
66*9880d681SAndroid Build Coastguard Worker /// Parse the machine instructions.
67*9880d681SAndroid Build Coastguard Worker ///
68*9880d681SAndroid Build Coastguard Worker /// This function runs the second parsing pass on the machine function's body.
69*9880d681SAndroid Build Coastguard Worker /// It skips the machine basic block definitions and parses only the machine
70*9880d681SAndroid Build Coastguard Worker /// instructions and basic block attributes like liveins and successors.
71*9880d681SAndroid Build Coastguard Worker ///
72*9880d681SAndroid Build Coastguard Worker /// The second parsing pass assumes that the first parsing pass already ran
73*9880d681SAndroid Build Coastguard Worker /// on the given source string.
74*9880d681SAndroid Build Coastguard Worker ///
75*9880d681SAndroid Build Coastguard Worker /// Return true if an error occurred.
76*9880d681SAndroid Build Coastguard Worker bool parseMachineInstructions(const PerFunctionMIParsingState &PFS,
77*9880d681SAndroid Build Coastguard Worker                               StringRef Src, SMDiagnostic &Error);
78*9880d681SAndroid Build Coastguard Worker 
79*9880d681SAndroid Build Coastguard Worker bool parseMBBReference(const PerFunctionMIParsingState &PFS,
80*9880d681SAndroid Build Coastguard Worker                        MachineBasicBlock *&MBB, StringRef Src,
81*9880d681SAndroid Build Coastguard Worker                        SMDiagnostic &Error);
82*9880d681SAndroid Build Coastguard Worker 
83*9880d681SAndroid Build Coastguard Worker bool parseNamedRegisterReference(const PerFunctionMIParsingState &PFS,
84*9880d681SAndroid Build Coastguard Worker                                  unsigned &Reg, StringRef Src,
85*9880d681SAndroid Build Coastguard Worker                                  SMDiagnostic &Error);
86*9880d681SAndroid Build Coastguard Worker 
87*9880d681SAndroid Build Coastguard Worker bool parseVirtualRegisterReference(const PerFunctionMIParsingState &PFS,
88*9880d681SAndroid Build Coastguard Worker                                    unsigned &Reg, StringRef Src,
89*9880d681SAndroid Build Coastguard Worker                                    SMDiagnostic &Error);
90*9880d681SAndroid Build Coastguard Worker 
91*9880d681SAndroid Build Coastguard Worker bool parseStackObjectReference(const PerFunctionMIParsingState &PFS,
92*9880d681SAndroid Build Coastguard Worker                                int &FI, StringRef Src, SMDiagnostic &Error);
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker bool parseMDNode(const PerFunctionMIParsingState &PFS, MDNode *&Node,
95*9880d681SAndroid Build Coastguard Worker                  StringRef Src, SMDiagnostic &Error);
96*9880d681SAndroid Build Coastguard Worker 
97*9880d681SAndroid Build Coastguard Worker } // end namespace llvm
98*9880d681SAndroid Build Coastguard Worker 
99*9880d681SAndroid Build Coastguard Worker #endif
100