blob: ab160dcf91c2cfb992de495f5bfa087c91d88a19 [file] [log] [blame]
Alex Lorenz8e0a1b42015-06-22 17:02:30 +00001//===- 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
Alex Lorenz33f0aef2015-06-26 16:46:11 +000017#include "llvm/ADT/DenseMap.h"
Quentin Colombet2c646962016-06-08 23:27:46 +000018#include "llvm/ADT/SmallSet.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000019
20namespace llvm {
21
Mehdi Aminib550cb12016-04-18 09:17:29 +000022class StringRef;
Alex Lorenz8a1915b2015-07-27 22:42:41 +000023class BasicBlock;
Alex Lorenz33f0aef2015-06-26 16:46:11 +000024class MachineBasicBlock;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000025class MachineFunction;
Matthias Braun83947862016-07-13 22:23:23 +000026class MachineInstr;
27class MachineRegisterInfo;
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000028class MDNode;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000029struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000030class SMDiagnostic;
31class SourceMgr;
32
Alex Lorenz7a503fa2015-07-07 17:46:43 +000033struct PerFunctionMIParsingState {
Matthias Braun83947862016-07-13 22:23:23 +000034 MachineFunction &MF;
35
Alex Lorenz7a503fa2015-07-07 17:46:43 +000036 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Alex Lorenz53464512015-07-10 22:51:20 +000037 DenseMap<unsigned, unsigned> VirtualRegisterSlots;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000038 DenseMap<unsigned, int> FixedStackObjectSlots;
39 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000040 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000041 DenseMap<unsigned, unsigned> JumpTableSlots;
Quentin Colombet2c646962016-06-08 23:27:46 +000042 /// Hold the generic virtual registers.
43 SmallSet<unsigned, 8> GenericVRegs;
Matthias Braun83947862016-07-13 22:23:23 +000044
45 PerFunctionMIParsingState(MachineFunction &MF);
Alex Lorenz7a503fa2015-07-07 17:46:43 +000046};
47
Alex Lorenz5022f6b2015-08-13 23:10:16 +000048/// Parse the machine basic block definitions, and skip the machine
49/// instructions.
50///
51/// This function runs the first parsing pass on the machine function's body.
52/// It parses only the machine basic block definitions and creates the machine
53/// basic blocks in the given machine function.
54///
55/// The machine instructions aren't parsed during the first pass because all
56/// the machine basic blocks aren't defined yet - this makes it impossible to
57/// resolve the machine basic block references.
58///
59/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000060bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
61 StringRef Src,
Alex Lorenz5022f6b2015-08-13 23:10:16 +000062 const SlotMapping &IRSlots,
63 SMDiagnostic &Error);
64
65/// Parse the machine instructions.
66///
67/// This function runs the second parsing pass on the machine function's body.
68/// It skips the machine basic block definitions and parses only the machine
69/// instructions and basic block attributes like liveins and successors.
70///
71/// The second parsing pass assumes that the first parsing pass already ran
72/// on the given source string.
73///
74/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000075bool parseMachineInstructions(const PerFunctionMIParsingState &PFS,
76 StringRef Src, const SlotMapping &IRSlots,
77 SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000078
Matthias Braun83947862016-07-13 22:23:23 +000079bool parseMBBReference(const PerFunctionMIParsingState &PFS,
80 MachineBasicBlock *&MBB, SourceMgr &SM,
81 StringRef Src, const SlotMapping &IRSlots,
82 SMDiagnostic &Error);
Alex Lorenzf09df002015-06-30 18:16:42 +000083
Matthias Braun83947862016-07-13 22:23:23 +000084bool parseNamedRegisterReference(const PerFunctionMIParsingState &PFS,
85 unsigned &Reg, SourceMgr &SM,
86 StringRef Src, const SlotMapping &IRSlots,
Alex Lorenz9fab3702015-07-14 21:24:41 +000087 SMDiagnostic &Error);
88
Matthias Braun83947862016-07-13 22:23:23 +000089bool parseVirtualRegisterReference(const PerFunctionMIParsingState &PFS,
90 unsigned &Reg, SourceMgr &SM,
91 StringRef Src, const SlotMapping &IRSlots,
Alex Lorenz12045a42015-07-27 17:42:45 +000092 SMDiagnostic &Error);
93
Matthias Braun83947862016-07-13 22:23:23 +000094bool parseStackObjectReference(const PerFunctionMIParsingState &PFS,
95 int &FI, SourceMgr &SM, StringRef Src,
Alex Lorenza314d812015-08-18 22:26:26 +000096 const SlotMapping &IRSlots, SMDiagnostic &Error);
97
Matthias Braun83947862016-07-13 22:23:23 +000098bool parseMDNode(const PerFunctionMIParsingState &PFS, MDNode *&Node,
99 SourceMgr &SM, StringRef Src, const SlotMapping &IRSlots,
100 SMDiagnostic &Error);
Alex Lorenzdf9e3c62015-08-19 00:13:25 +0000101
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000102} // end namespace llvm
103
104#endif