blob: a5f86ad945d6b3939d9f18197a14e8664a69a472 [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;
Matthias Braun74ad41c2016-10-11 03:13:01 +000029class RegisterBank;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000030struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000031class SMDiagnostic;
32class SourceMgr;
Matthias Braun74ad41c2016-10-11 03:13:01 +000033class TargetRegisterClass;
34
35struct VRegInfo {
36 enum uint8_t {
37 UNKNOWN, NORMAL, GENERIC, REGBANK
38 } Kind = UNKNOWN;
39 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
40 union {
41 const TargetRegisterClass *RC;
42 const RegisterBank *RegBank;
43 } D;
44 unsigned VReg;
45 unsigned PreferredReg = 0;
46};
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000047
Alex Lorenz7a503fa2015-07-07 17:46:43 +000048struct PerFunctionMIParsingState {
Matthias Braun74ad41c2016-10-11 03:13:01 +000049 BumpPtrAllocator Allocator;
Matthias Braun83947862016-07-13 22:23:23 +000050 MachineFunction &MF;
Matthias Braune35861d2016-07-13 23:27:50 +000051 SourceMgr *SM;
52 const SlotMapping &IRSlots;
Matthias Braun83947862016-07-13 22:23:23 +000053
Alex Lorenz7a503fa2015-07-07 17:46:43 +000054 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Matthias Braun74ad41c2016-10-11 03:13:01 +000055 DenseMap<unsigned, VRegInfo*> VRegInfos;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000056 DenseMap<unsigned, int> FixedStackObjectSlots;
57 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000058 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000059 DenseMap<unsigned, unsigned> JumpTableSlots;
Matthias Braun83947862016-07-13 22:23:23 +000060
Matthias Braune35861d2016-07-13 23:27:50 +000061 PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
62 const SlotMapping &IRSlots);
Matthias Braun74ad41c2016-10-11 03:13:01 +000063
64 VRegInfo &getVRegInfo(unsigned VReg);
Alex Lorenz7a503fa2015-07-07 17:46:43 +000065};
66
Alex Lorenz5022f6b2015-08-13 23:10:16 +000067/// Parse the machine basic block definitions, and skip the machine
68/// instructions.
69///
70/// This function runs the first parsing pass on the machine function's body.
71/// It parses only the machine basic block definitions and creates the machine
72/// basic blocks in the given machine function.
73///
74/// The machine instructions aren't parsed during the first pass because all
75/// the machine basic blocks aren't defined yet - this makes it impossible to
76/// resolve the machine basic block references.
77///
78/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000079bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000080 StringRef Src, SMDiagnostic &Error);
Alex Lorenz5022f6b2015-08-13 23:10:16 +000081
82/// Parse the machine instructions.
83///
84/// This function runs the second parsing pass on the machine function's body.
85/// It skips the machine basic block definitions and parses only the machine
86/// instructions and basic block attributes like liveins and successors.
87///
88/// The second parsing pass assumes that the first parsing pass already ran
89/// on the given source string.
90///
91/// Return true if an error occurred.
Matthias Braun74ad41c2016-10-11 03:13:01 +000092bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
93 SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000094
Matthias Braun74ad41c2016-10-11 03:13:01 +000095bool parseMBBReference(PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000096 MachineBasicBlock *&MBB, StringRef Src,
Matthias Braun83947862016-07-13 22:23:23 +000097 SMDiagnostic &Error);
Alex Lorenzf09df002015-06-30 18:16:42 +000098
Matthias Braun74ad41c2016-10-11 03:13:01 +000099bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
100 StringRef Src, SMDiagnostic &Error);
Alex Lorenz9fab3702015-07-14 21:24:41 +0000101
Matthias Braun74ad41c2016-10-11 03:13:01 +0000102bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
103 VRegInfo *&Info, StringRef Src,
Alex Lorenz12045a42015-07-27 17:42:45 +0000104 SMDiagnostic &Error);
105
Matthias Braun74ad41c2016-10-11 03:13:01 +0000106bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
107 StringRef Src, SMDiagnostic &Error);
Alex Lorenza314d812015-08-18 22:26:26 +0000108
Matthias Braun74ad41c2016-10-11 03:13:01 +0000109bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
110 SMDiagnostic &Error);
Alex Lorenzdf9e3c62015-08-19 00:13:25 +0000111
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000112} // end namespace llvm
113
114#endif