blob: ce39805e0c526cb969ec8279d2b3839aed2bfb90 [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"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000018
19namespace llvm {
20
Mehdi Aminib550cb12016-04-18 09:17:29 +000021class StringRef;
Alex Lorenz8a1915b2015-07-27 22:42:41 +000022class BasicBlock;
Alex Lorenz33f0aef2015-06-26 16:46:11 +000023class MachineBasicBlock;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000024class MachineInstr;
25class MachineFunction;
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000026class MDNode;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000027struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000028class SMDiagnostic;
29class SourceMgr;
30
Alex Lorenz7a503fa2015-07-07 17:46:43 +000031struct PerFunctionMIParsingState {
32 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Alex Lorenz53464512015-07-10 22:51:20 +000033 DenseMap<unsigned, unsigned> VirtualRegisterSlots;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000034 DenseMap<unsigned, int> FixedStackObjectSlots;
35 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000036 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000037 DenseMap<unsigned, unsigned> JumpTableSlots;
Alex Lorenz7a503fa2015-07-07 17:46:43 +000038};
39
Alex Lorenz5022f6b2015-08-13 23:10:16 +000040/// Parse the machine basic block definitions, and skip the machine
41/// instructions.
42///
43/// This function runs the first parsing pass on the machine function's body.
44/// It parses only the machine basic block definitions and creates the machine
45/// basic blocks in the given machine function.
46///
47/// The machine instructions aren't parsed during the first pass because all
48/// the machine basic blocks aren't defined yet - this makes it impossible to
49/// resolve the machine basic block references.
50///
51/// Return true if an error occurred.
52bool parseMachineBasicBlockDefinitions(MachineFunction &MF, StringRef Src,
53 PerFunctionMIParsingState &PFS,
54 const SlotMapping &IRSlots,
55 SMDiagnostic &Error);
56
57/// Parse the machine instructions.
58///
59/// This function runs the second parsing pass on the machine function's body.
60/// It skips the machine basic block definitions and parses only the machine
61/// instructions and basic block attributes like liveins and successors.
62///
63/// The second parsing pass assumes that the first parsing pass already ran
64/// on the given source string.
65///
66/// Return true if an error occurred.
67bool parseMachineInstructions(MachineFunction &MF, StringRef Src,
68 const PerFunctionMIParsingState &PFS,
69 const SlotMapping &IRSlots, SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000070
Alex Lorenzf09df002015-06-30 18:16:42 +000071bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
72 MachineFunction &MF, StringRef Src,
Alex Lorenz7a503fa2015-07-07 17:46:43 +000073 const PerFunctionMIParsingState &PFS,
Alex Lorenzf09df002015-06-30 18:16:42 +000074 const SlotMapping &IRSlots, SMDiagnostic &Error);
75
Alex Lorenz9fab3702015-07-14 21:24:41 +000076bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
77 MachineFunction &MF, StringRef Src,
78 const PerFunctionMIParsingState &PFS,
79 const SlotMapping &IRSlots,
80 SMDiagnostic &Error);
81
Alex Lorenz12045a42015-07-27 17:42:45 +000082bool parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM,
83 MachineFunction &MF, StringRef Src,
84 const PerFunctionMIParsingState &PFS,
85 const SlotMapping &IRSlots,
86 SMDiagnostic &Error);
87
Alex Lorenza314d812015-08-18 22:26:26 +000088bool parseStackObjectReference(int &FI, SourceMgr &SM, MachineFunction &MF,
89 StringRef Src,
90 const PerFunctionMIParsingState &PFS,
91 const SlotMapping &IRSlots, SMDiagnostic &Error);
92
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000093bool parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF,
94 StringRef Src, const PerFunctionMIParsingState &PFS,
95 const SlotMapping &IRSlots, SMDiagnostic &Error);
96
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000097} // end namespace llvm
98
99#endif