blob: 3557b9a6d5d8e5319821c48325a798ea519f2567 [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 MachineInstr;
26class MachineFunction;
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000027class MDNode;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000028struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000029class SMDiagnostic;
30class SourceMgr;
31
Alex Lorenz7a503fa2015-07-07 17:46:43 +000032struct PerFunctionMIParsingState {
33 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Alex Lorenz53464512015-07-10 22:51:20 +000034 DenseMap<unsigned, unsigned> VirtualRegisterSlots;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000035 DenseMap<unsigned, int> FixedStackObjectSlots;
36 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000037 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000038 DenseMap<unsigned, unsigned> JumpTableSlots;
Quentin Colombet2c646962016-06-08 23:27:46 +000039 /// Hold the generic virtual registers.
40 SmallSet<unsigned, 8> GenericVRegs;
Alex Lorenz7a503fa2015-07-07 17:46:43 +000041};
42
Alex Lorenz5022f6b2015-08-13 23:10:16 +000043/// Parse the machine basic block definitions, and skip the machine
44/// instructions.
45///
46/// This function runs the first parsing pass on the machine function's body.
47/// It parses only the machine basic block definitions and creates the machine
48/// basic blocks in the given machine function.
49///
50/// The machine instructions aren't parsed during the first pass because all
51/// the machine basic blocks aren't defined yet - this makes it impossible to
52/// resolve the machine basic block references.
53///
54/// Return true if an error occurred.
55bool parseMachineBasicBlockDefinitions(MachineFunction &MF, StringRef Src,
56 PerFunctionMIParsingState &PFS,
57 const SlotMapping &IRSlots,
58 SMDiagnostic &Error);
59
60/// Parse the machine instructions.
61///
62/// This function runs the second parsing pass on the machine function's body.
63/// It skips the machine basic block definitions and parses only the machine
64/// instructions and basic block attributes like liveins and successors.
65///
66/// The second parsing pass assumes that the first parsing pass already ran
67/// on the given source string.
68///
69/// Return true if an error occurred.
70bool parseMachineInstructions(MachineFunction &MF, StringRef Src,
71 const PerFunctionMIParsingState &PFS,
72 const SlotMapping &IRSlots, SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000073
Alex Lorenzf09df002015-06-30 18:16:42 +000074bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
75 MachineFunction &MF, StringRef Src,
Alex Lorenz7a503fa2015-07-07 17:46:43 +000076 const PerFunctionMIParsingState &PFS,
Alex Lorenzf09df002015-06-30 18:16:42 +000077 const SlotMapping &IRSlots, SMDiagnostic &Error);
78
Alex Lorenz9fab3702015-07-14 21:24:41 +000079bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
80 MachineFunction &MF, StringRef Src,
81 const PerFunctionMIParsingState &PFS,
82 const SlotMapping &IRSlots,
83 SMDiagnostic &Error);
84
Alex Lorenz12045a42015-07-27 17:42:45 +000085bool parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM,
86 MachineFunction &MF, StringRef Src,
87 const PerFunctionMIParsingState &PFS,
88 const SlotMapping &IRSlots,
89 SMDiagnostic &Error);
90
Alex Lorenza314d812015-08-18 22:26:26 +000091bool parseStackObjectReference(int &FI, SourceMgr &SM, MachineFunction &MF,
92 StringRef Src,
93 const PerFunctionMIParsingState &PFS,
94 const SlotMapping &IRSlots, SMDiagnostic &Error);
95
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000096bool parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF,
97 StringRef Src, const PerFunctionMIParsingState &PFS,
98 const SlotMapping &IRSlots, SMDiagnostic &Error);
99
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000100} // end namespace llvm
101
102#endif