blob: 2307881068efbc546074505c9130f6f565a369f5 [file] [log] [blame]
Eugene Zelenkofb69e662017-06-06 22:22:41 +00001//===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===//
Alex Lorenz8e0a1b42015-06-22 17:02:30 +00002//
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"
Eugene Zelenkofb69e662017-06-06 22:22:41 +000018#include "llvm/ADT/StringMap.h"
19#include "llvm/Support/Allocator.h"
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000020
21namespace llvm {
22
Alex Lorenz33f0aef2015-06-26 16:46:11 +000023class MachineBasicBlock;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000024class MachineFunction;
Alex Lorenzdf9e3c62015-08-19 00:13:25 +000025class MDNode;
Matthias Braun74ad41c2016-10-11 03:13:01 +000026class RegisterBank;
Alex Lorenz5d6108e2015-06-26 22:56:48 +000027struct SlotMapping;
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000028class SMDiagnostic;
29class SourceMgr;
Eugene Zelenkofb69e662017-06-06 22:22:41 +000030class StringRef;
Matthias Braun74ad41c2016-10-11 03:13:01 +000031class TargetRegisterClass;
32
33struct VRegInfo {
34 enum uint8_t {
35 UNKNOWN, NORMAL, GENERIC, REGBANK
36 } Kind = UNKNOWN;
37 bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
38 union {
39 const TargetRegisterClass *RC;
40 const RegisterBank *RegBank;
41 } D;
42 unsigned VReg;
43 unsigned PreferredReg = 0;
44};
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000045
Eugene Zelenkofb69e662017-06-06 22:22:41 +000046using Name2RegClassMap = StringMap<const TargetRegisterClass *>;
47using Name2RegBankMap = StringMap<const RegisterBank *>;
Matthias Braunde5fea22017-01-18 00:59:19 +000048
Alex Lorenz7a503fa2015-07-07 17:46:43 +000049struct PerFunctionMIParsingState {
Matthias Braun74ad41c2016-10-11 03:13:01 +000050 BumpPtrAllocator Allocator;
Matthias Braun83947862016-07-13 22:23:23 +000051 MachineFunction &MF;
Matthias Braune35861d2016-07-13 23:27:50 +000052 SourceMgr *SM;
53 const SlotMapping &IRSlots;
Matthias Braunde5fea22017-01-18 00:59:19 +000054 const Name2RegClassMap &Names2RegClasses;
55 const Name2RegBankMap &Names2RegBanks;
Matthias Braun83947862016-07-13 22:23:23 +000056
Alex Lorenz7a503fa2015-07-07 17:46:43 +000057 DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
Matthias Braun74ad41c2016-10-11 03:13:01 +000058 DenseMap<unsigned, VRegInfo*> VRegInfos;
Alex Lorenz7feaf7c2015-07-16 23:37:45 +000059 DenseMap<unsigned, int> FixedStackObjectSlots;
60 DenseMap<unsigned, int> StackObjectSlots;
Alex Lorenzab980492015-07-20 20:51:18 +000061 DenseMap<unsigned, unsigned> ConstantPoolSlots;
Alex Lorenz31d70682015-07-15 23:38:35 +000062 DenseMap<unsigned, unsigned> JumpTableSlots;
Matthias Braun83947862016-07-13 22:23:23 +000063
Matthias Braune35861d2016-07-13 23:27:50 +000064 PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
Matthias Braunde5fea22017-01-18 00:59:19 +000065 const SlotMapping &IRSlots,
66 const Name2RegClassMap &Names2RegClasses,
67 const Name2RegBankMap &Names2RegBanks);
Matthias Braun74ad41c2016-10-11 03:13:01 +000068
69 VRegInfo &getVRegInfo(unsigned VReg);
Alex Lorenz7a503fa2015-07-07 17:46:43 +000070};
71
Alex Lorenz5022f6b2015-08-13 23:10:16 +000072/// Parse the machine basic block definitions, and skip the machine
73/// instructions.
74///
75/// This function runs the first parsing pass on the machine function's body.
76/// It parses only the machine basic block definitions and creates the machine
77/// basic blocks in the given machine function.
78///
79/// The machine instructions aren't parsed during the first pass because all
80/// the machine basic blocks aren't defined yet - this makes it impossible to
81/// resolve the machine basic block references.
82///
83/// Return true if an error occurred.
Matthias Braun83947862016-07-13 22:23:23 +000084bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +000085 StringRef Src, SMDiagnostic &Error);
Alex Lorenz5022f6b2015-08-13 23:10:16 +000086
87/// Parse the machine instructions.
88///
89/// This function runs the second parsing pass on the machine function's body.
90/// It skips the machine basic block definitions and parses only the machine
91/// instructions and basic block attributes like liveins and successors.
92///
93/// The second parsing pass assumes that the first parsing pass already ran
94/// on the given source string.
95///
96/// Return true if an error occurred.
Matthias Braun74ad41c2016-10-11 03:13:01 +000097bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
98 SMDiagnostic &Error);
Alex Lorenz8e0a1b42015-06-22 17:02:30 +000099
Matthias Braun74ad41c2016-10-11 03:13:01 +0000100bool parseMBBReference(PerFunctionMIParsingState &PFS,
Matthias Braune35861d2016-07-13 23:27:50 +0000101 MachineBasicBlock *&MBB, StringRef Src,
Matthias Braun83947862016-07-13 22:23:23 +0000102 SMDiagnostic &Error);
Alex Lorenzf09df002015-06-30 18:16:42 +0000103
Tom Stellard9c884e42016-11-15 00:03:14 +0000104bool parseRegisterReference(PerFunctionMIParsingState &PFS,
105 unsigned &Reg, StringRef Src,
106 SMDiagnostic &Error);
107
Matthias Braun74ad41c2016-10-11 03:13:01 +0000108bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
109 StringRef Src, SMDiagnostic &Error);
Alex Lorenz9fab3702015-07-14 21:24:41 +0000110
Matthias Braun74ad41c2016-10-11 03:13:01 +0000111bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
112 VRegInfo *&Info, StringRef Src,
Alex Lorenz12045a42015-07-27 17:42:45 +0000113 SMDiagnostic &Error);
114
Matthias Braun74ad41c2016-10-11 03:13:01 +0000115bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
116 StringRef Src, SMDiagnostic &Error);
Alex Lorenza314d812015-08-18 22:26:26 +0000117
Matthias Braun74ad41c2016-10-11 03:13:01 +0000118bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
119 SMDiagnostic &Error);
Alex Lorenzdf9e3c62015-08-19 00:13:25 +0000120
Alex Lorenz8e0a1b42015-06-22 17:02:30 +0000121} // end namespace llvm
122
Eugene Zelenkofb69e662017-06-06 22:22:41 +0000123#endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H