blob: 18895b9e54eb403607a6d23849a89ed0dcd13d0f [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;
Matthias Braune35861d2016-07-13 23:27:50 +000035 SourceMgr *SM;
36 const SlotMapping &IRSlots;
Matthias Braun83947862016-07-13 22:23:23 +000037
Alex Lorenz7a503fa2015-07-07 17:46:43 +000038 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Alex Lorenz53464512015-07-10 22:51:20 +000039 DenseMap<unsigned, unsigned> VirtualRegisterSlots;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000040 DenseMap<unsigned, int> FixedStackObjectSlots;
41 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000042 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000043 DenseMap<unsigned, unsigned> JumpTableSlots;
Quentin Colombet2c646962016-06-08 23:27:46 +000044 /// Hold the generic virtual registers.
45 SmallSet<unsigned, 8> GenericVRegs;
Matthias Braun83947862016-07-13 22:23:23 +000046
Matthias Braune35861d2016-07-13 23:27:50 +000047 PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
48 const SlotMapping &IRSlots);
Alex Lorenz7a503fa2015-07-07 17:46:43 +000049};
50
Alex Lorenz5022f6b2015-08-13 23:10:16 +000051/// Parse the machine basic block definitions, and skip the machine
52/// instructions.
53///
54/// This function runs the first parsing pass on the machine function's body.
55/// It parses only the machine basic block definitions and creates the machine
56/// basic blocks in the given machine function.
57///
58/// The machine instructions aren't parsed during the first pass because all
59/// the machine basic blocks aren't defined yet - this makes it impossible to
60/// resolve the machine basic block references.
61///
62/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000063bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000064 StringRef Src, SMDiagnostic &Error);
Alex Lorenz5022f6b2015-08-13 23:10:16 +000065
66/// Parse the machine instructions.
67///
68/// This function runs the second parsing pass on the machine function's body.
69/// It skips the machine basic block definitions and parses only the machine
70/// instructions and basic block attributes like liveins and successors.
71///
72/// The second parsing pass assumes that the first parsing pass already ran
73/// on the given source string.
74///
75/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000076bool parseMachineInstructions(const PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000077 StringRef Src, SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000078
Matthias Braun83947862016-07-13 22:23:23 +000079bool parseMBBReference(const PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000080 MachineBasicBlock *&MBB, StringRef Src,
Matthias Braun83947862016-07-13 22:23:23 +000081 SMDiagnostic &Error);
Alex Lorenzf09df002015-06-30 18:16:42 +000082
Matthias Braun83947862016-07-13 22:23:23 +000083bool parseNamedRegisterReference(const PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000084 unsigned &Reg, StringRef Src,
Alex Lorenz9fab3702015-07-14 21:24:41 +000085 SMDiagnostic &Error);
86
Matthias Braun83947862016-07-13 22:23:23 +000087bool parseVirtualRegisterReference(const PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000088 unsigned &Reg, StringRef Src,
Alex Lorenz12045a42015-07-27 17:42:45 +000089 SMDiagnostic &Error);
90
Matthias Braun83947862016-07-13 22:23:23 +000091bool parseStackObjectReference(const PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000092 int &FI, StringRef Src, SMDiagnostic &Error);
Alex Lorenza314d812015-08-18 22:26:26 +000093
Matthias Braun83947862016-07-13 22:23:23 +000094bool parseMDNode(const PerFunctionMIParsingState &PFS, MDNode *&Node,
Matthias Braune35861d2016-07-13 23:27:50 +000095 StringRef Src, SMDiagnostic &Error);
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000096
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000097} // end namespace llvm
98
99#endif