Eugene Zelenko | fb69e66 | 2017-06-06 22:22:41 +0000 | [diff] [blame] | 1 | //===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===// |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file declares the function that parses the machine instructions. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H |
| 14 | #define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H |
| 15 | |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/DenseMap.h" |
Eugene Zelenko | fb69e66 | 2017-06-06 22:22:41 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/StringMap.h" |
| 18 | #include "llvm/Support/Allocator.h" |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 22 | class MachineBasicBlock; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 23 | class MachineFunction; |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 24 | class MDNode; |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 25 | class RegisterBank; |
Alex Lorenz | 5d6108e | 2015-06-26 22:56:48 +0000 | [diff] [blame] | 26 | struct SlotMapping; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 27 | class SMDiagnostic; |
| 28 | class SourceMgr; |
Eugene Zelenko | fb69e66 | 2017-06-06 22:22:41 +0000 | [diff] [blame] | 29 | class StringRef; |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 30 | class TargetRegisterClass; |
| 31 | |
| 32 | struct VRegInfo { |
| 33 | enum uint8_t { |
| 34 | UNKNOWN, NORMAL, GENERIC, REGBANK |
| 35 | } Kind = UNKNOWN; |
| 36 | bool Explicit = false; ///< VReg was explicitly specified in the .mir file. |
| 37 | union { |
| 38 | const TargetRegisterClass *RC; |
| 39 | const RegisterBank *RegBank; |
| 40 | } D; |
| 41 | unsigned VReg; |
| 42 | unsigned PreferredReg = 0; |
| 43 | }; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 44 | |
Eugene Zelenko | fb69e66 | 2017-06-06 22:22:41 +0000 | [diff] [blame] | 45 | using Name2RegClassMap = StringMap<const TargetRegisterClass *>; |
| 46 | using Name2RegBankMap = StringMap<const RegisterBank *>; |
Matthias Braun | de5fea2 | 2017-01-18 00:59:19 +0000 | [diff] [blame] | 47 | |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 48 | struct PerFunctionMIParsingState { |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 49 | BumpPtrAllocator Allocator; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 50 | MachineFunction &MF; |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 51 | SourceMgr *SM; |
| 52 | const SlotMapping &IRSlots; |
Matthias Braun | de5fea2 | 2017-01-18 00:59:19 +0000 | [diff] [blame] | 53 | const Name2RegClassMap &Names2RegClasses; |
| 54 | const Name2RegBankMap &Names2RegBanks; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 55 | |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 56 | DenseMap<unsigned, MachineBasicBlock *> MBBSlots; |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 57 | DenseMap<unsigned, VRegInfo*> VRegInfos; |
Puyan Lotfi | 399b46c | 2018-03-30 18:15:54 +0000 | [diff] [blame] | 58 | StringMap<VRegInfo*> VRegInfosNamed; |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 59 | DenseMap<unsigned, int> FixedStackObjectSlots; |
| 60 | DenseMap<unsigned, int> StackObjectSlots; |
Alex Lorenz | ab98049 | 2015-07-20 20:51:18 +0000 | [diff] [blame] | 61 | DenseMap<unsigned, unsigned> ConstantPoolSlots; |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 62 | DenseMap<unsigned, unsigned> JumpTableSlots; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 63 | |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 64 | PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM, |
Matthias Braun | de5fea2 | 2017-01-18 00:59:19 +0000 | [diff] [blame] | 65 | const SlotMapping &IRSlots, |
| 66 | const Name2RegClassMap &Names2RegClasses, |
| 67 | const Name2RegBankMap &Names2RegBanks); |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 68 | |
Fangrui Song | cb0bab8 | 2018-07-16 18:51:40 +0000 | [diff] [blame] | 69 | VRegInfo &getVRegInfo(unsigned Num); |
Puyan Lotfi | 399b46c | 2018-03-30 18:15:54 +0000 | [diff] [blame] | 70 | VRegInfo &getVRegInfoNamed(StringRef RegName); |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Alex Lorenz | 5022f6b | 2015-08-13 23:10:16 +0000 | [diff] [blame] | 73 | /// Parse the machine basic block definitions, and skip the machine |
| 74 | /// instructions. |
| 75 | /// |
| 76 | /// This function runs the first parsing pass on the machine function's body. |
| 77 | /// It parses only the machine basic block definitions and creates the machine |
| 78 | /// basic blocks in the given machine function. |
| 79 | /// |
| 80 | /// The machine instructions aren't parsed during the first pass because all |
| 81 | /// the machine basic blocks aren't defined yet - this makes it impossible to |
| 82 | /// resolve the machine basic block references. |
| 83 | /// |
| 84 | /// Return true if an error occurred. |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 85 | bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 86 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | 5022f6b | 2015-08-13 23:10:16 +0000 | [diff] [blame] | 87 | |
| 88 | /// Parse the machine instructions. |
| 89 | /// |
| 90 | /// This function runs the second parsing pass on the machine function's body. |
| 91 | /// It skips the machine basic block definitions and parses only the machine |
| 92 | /// instructions and basic block attributes like liveins and successors. |
| 93 | /// |
| 94 | /// The second parsing pass assumes that the first parsing pass already ran |
| 95 | /// on the given source string. |
| 96 | /// |
| 97 | /// Return true if an error occurred. |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 98 | bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, |
| 99 | SMDiagnostic &Error); |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 100 | |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 101 | bool parseMBBReference(PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 102 | MachineBasicBlock *&MBB, StringRef Src, |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 103 | SMDiagnostic &Error); |
Alex Lorenz | f09df00 | 2015-06-30 18:16:42 +0000 | [diff] [blame] | 104 | |
Tom Stellard | 9c884e4 | 2016-11-15 00:03:14 +0000 | [diff] [blame] | 105 | bool parseRegisterReference(PerFunctionMIParsingState &PFS, |
| 106 | unsigned &Reg, StringRef Src, |
| 107 | SMDiagnostic &Error); |
| 108 | |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 109 | bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, |
| 110 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | 9fab370 | 2015-07-14 21:24:41 +0000 | [diff] [blame] | 111 | |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 112 | bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, |
| 113 | VRegInfo *&Info, StringRef Src, |
Alex Lorenz | 12045a4 | 2015-07-27 17:42:45 +0000 | [diff] [blame] | 114 | SMDiagnostic &Error); |
| 115 | |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 116 | bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, |
| 117 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | a314d81 | 2015-08-18 22:26:26 +0000 | [diff] [blame] | 118 | |
Matthias Braun | 74ad41c | 2016-10-11 03:13:01 +0000 | [diff] [blame] | 119 | bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, |
| 120 | SMDiagnostic &Error); |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 121 | |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 122 | } // end namespace llvm |
| 123 | |
Eugene Zelenko | fb69e66 | 2017-06-06 22:22:41 +0000 | [diff] [blame] | 124 | #endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H |