blob: 03408991f7ca12e438839fbe566b6ca82c7ad0b3 [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#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21
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 Lorenz5d6108e2015-06-26 22:56:48 +000026struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000027class SMDiagnostic;
28class SourceMgr;
29
Alex Lorenz7a503fa2015-07-07 17:46:43 +000030struct PerFunctionMIParsingState {
31 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Alex Lorenz53464512015-07-10 22:51:20 +000032 DenseMap<unsigned, unsigned> VirtualRegisterSlots;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000033 DenseMap<unsigned, int> FixedStackObjectSlots;
34 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000035 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000036 DenseMap<unsigned, unsigned> JumpTableSlots;
Alex Lorenz7a503fa2015-07-07 17:46:43 +000037};
38
Alex Lorenz5022f6b2015-08-13 23:10:16 +000039/// Parse the machine basic block definitions, and skip the machine
40/// instructions.
41///
42/// This function runs the first parsing pass on the machine function's body.
43/// It parses only the machine basic block definitions and creates the machine
44/// basic blocks in the given machine function.
45///
46/// The machine instructions aren't parsed during the first pass because all
47/// the machine basic blocks aren't defined yet - this makes it impossible to
48/// resolve the machine basic block references.
49///
50/// Return true if an error occurred.
51bool parseMachineBasicBlockDefinitions(MachineFunction &MF, StringRef Src,
52 PerFunctionMIParsingState &PFS,
53 const SlotMapping &IRSlots,
54 SMDiagnostic &Error);
55
56/// Parse the machine instructions.
57///
58/// This function runs the second parsing pass on the machine function's body.
59/// It skips the machine basic block definitions and parses only the machine
60/// instructions and basic block attributes like liveins and successors.
61///
62/// The second parsing pass assumes that the first parsing pass already ran
63/// on the given source string.
64///
65/// Return true if an error occurred.
66bool parseMachineInstructions(MachineFunction &MF, StringRef Src,
67 const PerFunctionMIParsingState &PFS,
68 const SlotMapping &IRSlots, SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000069
Alex Lorenzf09df002015-06-30 18:16:42 +000070bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM,
71 MachineFunction &MF, StringRef Src,
Alex Lorenz7a503fa2015-07-07 17:46:43 +000072 const PerFunctionMIParsingState &PFS,
Alex Lorenzf09df002015-06-30 18:16:42 +000073 const SlotMapping &IRSlots, SMDiagnostic &Error);
74
Alex Lorenz9fab3702015-07-14 21:24:41 +000075bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM,
76 MachineFunction &MF, StringRef Src,
77 const PerFunctionMIParsingState &PFS,
78 const SlotMapping &IRSlots,
79 SMDiagnostic &Error);
80
Alex Lorenz12045a42015-07-27 17:42:45 +000081bool parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM,
82 MachineFunction &MF, StringRef Src,
83 const PerFunctionMIParsingState &PFS,
84 const SlotMapping &IRSlots,
85 SMDiagnostic &Error);
86
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000087} // end namespace llvm
88
89#endif