]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/CodeGen/MIRParser/MIParser.h
Update clang, llvm, lld, lldb, compiler-rt and libc++ to 4.0.0 release.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / CodeGen / MIRParser / MIParser.h
1 //===- MIParser.h - Machine Instructions Parser ---------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the function that parses the machine instructions.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
15 #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
16
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallSet.h"
19
20 namespace llvm {
21
22 class StringRef;
23 class BasicBlock;
24 class MachineBasicBlock;
25 class MachineFunction;
26 class MachineInstr;
27 class MachineRegisterInfo;
28 class MDNode;
29 class RegisterBank;
30 struct SlotMapping;
31 class SMDiagnostic;
32 class SourceMgr;
33 class TargetRegisterClass;
34
35 struct VRegInfo {
36   enum uint8_t {
37     UNKNOWN, NORMAL, GENERIC, REGBANK
38   } Kind = UNKNOWN;
39   bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
40   union {
41     const TargetRegisterClass *RC;
42     const RegisterBank *RegBank;
43   } D;
44   unsigned VReg;
45   unsigned PreferredReg = 0;
46 };
47
48 struct PerFunctionMIParsingState {
49   BumpPtrAllocator Allocator;
50   MachineFunction &MF;
51   SourceMgr *SM;
52   const SlotMapping &IRSlots;
53
54   DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
55   DenseMap<unsigned, VRegInfo*> VRegInfos;
56   DenseMap<unsigned, int> FixedStackObjectSlots;
57   DenseMap<unsigned, int> StackObjectSlots;
58   DenseMap<unsigned, unsigned> ConstantPoolSlots;
59   DenseMap<unsigned, unsigned> JumpTableSlots;
60
61   PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
62                             const SlotMapping &IRSlots);
63
64   VRegInfo &getVRegInfo(unsigned VReg);
65 };
66
67 /// Parse the machine basic block definitions, and skip the machine
68 /// instructions.
69 ///
70 /// This function runs the first parsing pass on the machine function's body.
71 /// It parses only the machine basic block definitions and creates the machine
72 /// basic blocks in the given machine function.
73 ///
74 /// The machine instructions aren't parsed during the first pass because all
75 /// the machine basic blocks aren't defined yet - this makes it impossible to
76 /// resolve the machine basic block references.
77 ///
78 /// Return true if an error occurred.
79 bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
80                                        StringRef Src, SMDiagnostic &Error);
81
82 /// Parse the machine instructions.
83 ///
84 /// This function runs the second parsing pass on the machine function's body.
85 /// It skips the machine basic block definitions and parses only the machine
86 /// instructions and basic block attributes like liveins and successors.
87 ///
88 /// The second parsing pass assumes that the first parsing pass already ran
89 /// on the given source string.
90 ///
91 /// Return true if an error occurred.
92 bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
93                               SMDiagnostic &Error);
94
95 bool parseMBBReference(PerFunctionMIParsingState &PFS,
96                        MachineBasicBlock *&MBB, StringRef Src,
97                        SMDiagnostic &Error);
98
99 bool parseRegisterReference(PerFunctionMIParsingState &PFS,
100                             unsigned &Reg, StringRef Src,
101                             SMDiagnostic &Error);
102
103 bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
104                                  StringRef Src, SMDiagnostic &Error);
105
106 bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
107                                    VRegInfo *&Info, StringRef Src,
108                                    SMDiagnostic &Error);
109
110 bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
111                                StringRef Src, SMDiagnostic &Error);
112
113 bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
114                  SMDiagnostic &Error);
115
116 } // end namespace llvm
117
118 #endif