Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 1 | //===- 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 Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Quentin Colombet | 2c64696 | 2016-06-08 23:27:46 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallSet.h" |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Mehdi Amini | b550cb1 | 2016-04-18 09:17:29 +0000 | [diff] [blame] | 22 | class StringRef; |
Alex Lorenz | 8a1915b | 2015-07-27 22:42:41 +0000 | [diff] [blame] | 23 | class BasicBlock; |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 24 | class MachineBasicBlock; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 25 | class MachineFunction; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 26 | class MachineInstr; |
| 27 | class MachineRegisterInfo; |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 28 | class MDNode; |
Alex Lorenz | 5d6108e | 2015-06-26 22:56:48 +0000 | [diff] [blame] | 29 | struct SlotMapping; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 30 | class SMDiagnostic; |
| 31 | class SourceMgr; |
| 32 | |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 33 | struct PerFunctionMIParsingState { |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 34 | MachineFunction &MF; |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 35 | SourceMgr *SM; |
| 36 | const SlotMapping &IRSlots; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 37 | |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 38 | DenseMap<unsigned, MachineBasicBlock *> MBBSlots; |
Alex Lorenz | 5346451 | 2015-07-10 22:51:20 +0000 | [diff] [blame] | 39 | DenseMap<unsigned, unsigned> VirtualRegisterSlots; |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 40 | DenseMap<unsigned, int> FixedStackObjectSlots; |
| 41 | DenseMap<unsigned, int> StackObjectSlots; |
Alex Lorenz | ab98049 | 2015-07-20 20:51:18 +0000 | [diff] [blame] | 42 | DenseMap<unsigned, unsigned> ConstantPoolSlots; |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 43 | DenseMap<unsigned, unsigned> JumpTableSlots; |
Quentin Colombet | 2c64696 | 2016-06-08 23:27:46 +0000 | [diff] [blame] | 44 | /// Hold the generic virtual registers. |
| 45 | SmallSet<unsigned, 8> GenericVRegs; |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 46 | |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 47 | PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM, |
| 48 | const SlotMapping &IRSlots); |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Alex Lorenz | 5022f6b | 2015-08-13 23:10:16 +0000 | [diff] [blame] | 51 | /// 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 Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 63 | bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 64 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | 5022f6b | 2015-08-13 23:10:16 +0000 | [diff] [blame] | 65 | |
| 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 Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 76 | bool parseMachineInstructions(const PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 77 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 78 | |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 79 | bool parseMBBReference(const PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 80 | MachineBasicBlock *&MBB, StringRef Src, |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 81 | SMDiagnostic &Error); |
Alex Lorenz | f09df00 | 2015-06-30 18:16:42 +0000 | [diff] [blame] | 82 | |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 83 | bool parseNamedRegisterReference(const PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 84 | unsigned &Reg, StringRef Src, |
Alex Lorenz | 9fab370 | 2015-07-14 21:24:41 +0000 | [diff] [blame] | 85 | SMDiagnostic &Error); |
| 86 | |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 87 | bool parseVirtualRegisterReference(const PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 88 | unsigned &Reg, StringRef Src, |
Alex Lorenz | 12045a4 | 2015-07-27 17:42:45 +0000 | [diff] [blame] | 89 | SMDiagnostic &Error); |
| 90 | |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 91 | bool parseStackObjectReference(const PerFunctionMIParsingState &PFS, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 92 | int &FI, StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | a314d81 | 2015-08-18 22:26:26 +0000 | [diff] [blame] | 93 | |
Matthias Braun | 8394786 | 2016-07-13 22:23:23 +0000 | [diff] [blame] | 94 | bool parseMDNode(const PerFunctionMIParsingState &PFS, MDNode *&Node, |
Matthias Braun | e35861d | 2016-07-13 23:27:50 +0000 | [diff] [blame] | 95 | StringRef Src, SMDiagnostic &Error); |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 96 | |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 97 | } // end namespace llvm |
| 98 | |
| 99 | #endif |