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 MachineInstr; |
| 26 | class MachineFunction; |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 27 | class MDNode; |
Alex Lorenz | 5d6108e | 2015-06-26 22:56:48 +0000 | [diff] [blame] | 28 | struct SlotMapping; |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 29 | class SMDiagnostic; |
| 30 | class SourceMgr; |
| 31 | |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 32 | struct PerFunctionMIParsingState { |
| 33 | DenseMap<unsigned, MachineBasicBlock *> MBBSlots; |
Alex Lorenz | 5346451 | 2015-07-10 22:51:20 +0000 | [diff] [blame] | 34 | DenseMap<unsigned, unsigned> VirtualRegisterSlots; |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 35 | DenseMap<unsigned, int> FixedStackObjectSlots; |
| 36 | DenseMap<unsigned, int> StackObjectSlots; |
Alex Lorenz | ab98049 | 2015-07-20 20:51:18 +0000 | [diff] [blame] | 37 | DenseMap<unsigned, unsigned> ConstantPoolSlots; |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 38 | DenseMap<unsigned, unsigned> JumpTableSlots; |
Quentin Colombet | 2c64696 | 2016-06-08 23:27:46 +0000 | [diff] [blame^] | 39 | /// Hold the generic virtual registers. |
| 40 | SmallSet<unsigned, 8> GenericVRegs; |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Alex Lorenz | 5022f6b | 2015-08-13 23:10:16 +0000 | [diff] [blame] | 43 | /// Parse the machine basic block definitions, and skip the machine |
| 44 | /// instructions. |
| 45 | /// |
| 46 | /// This function runs the first parsing pass on the machine function's body. |
| 47 | /// It parses only the machine basic block definitions and creates the machine |
| 48 | /// basic blocks in the given machine function. |
| 49 | /// |
| 50 | /// The machine instructions aren't parsed during the first pass because all |
| 51 | /// the machine basic blocks aren't defined yet - this makes it impossible to |
| 52 | /// resolve the machine basic block references. |
| 53 | /// |
| 54 | /// Return true if an error occurred. |
| 55 | bool parseMachineBasicBlockDefinitions(MachineFunction &MF, StringRef Src, |
| 56 | PerFunctionMIParsingState &PFS, |
| 57 | const SlotMapping &IRSlots, |
| 58 | SMDiagnostic &Error); |
| 59 | |
| 60 | /// Parse the machine instructions. |
| 61 | /// |
| 62 | /// This function runs the second parsing pass on the machine function's body. |
| 63 | /// It skips the machine basic block definitions and parses only the machine |
| 64 | /// instructions and basic block attributes like liveins and successors. |
| 65 | /// |
| 66 | /// The second parsing pass assumes that the first parsing pass already ran |
| 67 | /// on the given source string. |
| 68 | /// |
| 69 | /// Return true if an error occurred. |
| 70 | bool parseMachineInstructions(MachineFunction &MF, StringRef Src, |
| 71 | const PerFunctionMIParsingState &PFS, |
| 72 | const SlotMapping &IRSlots, SMDiagnostic &Error); |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 73 | |
Alex Lorenz | f09df00 | 2015-06-30 18:16:42 +0000 | [diff] [blame] | 74 | bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM, |
| 75 | MachineFunction &MF, StringRef Src, |
Alex Lorenz | 7a503fa | 2015-07-07 17:46:43 +0000 | [diff] [blame] | 76 | const PerFunctionMIParsingState &PFS, |
Alex Lorenz | f09df00 | 2015-06-30 18:16:42 +0000 | [diff] [blame] | 77 | const SlotMapping &IRSlots, SMDiagnostic &Error); |
| 78 | |
Alex Lorenz | 9fab370 | 2015-07-14 21:24:41 +0000 | [diff] [blame] | 79 | bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM, |
| 80 | MachineFunction &MF, StringRef Src, |
| 81 | const PerFunctionMIParsingState &PFS, |
| 82 | const SlotMapping &IRSlots, |
| 83 | SMDiagnostic &Error); |
| 84 | |
Alex Lorenz | 12045a4 | 2015-07-27 17:42:45 +0000 | [diff] [blame] | 85 | bool parseVirtualRegisterReference(unsigned &Reg, SourceMgr &SM, |
| 86 | MachineFunction &MF, StringRef Src, |
| 87 | const PerFunctionMIParsingState &PFS, |
| 88 | const SlotMapping &IRSlots, |
| 89 | SMDiagnostic &Error); |
| 90 | |
Alex Lorenz | a314d81 | 2015-08-18 22:26:26 +0000 | [diff] [blame] | 91 | bool parseStackObjectReference(int &FI, SourceMgr &SM, MachineFunction &MF, |
| 92 | StringRef Src, |
| 93 | const PerFunctionMIParsingState &PFS, |
| 94 | const SlotMapping &IRSlots, SMDiagnostic &Error); |
| 95 | |
Alex Lorenz | df9e3c6 | 2015-08-19 00:13:25 +0000 | [diff] [blame] | 96 | bool parseMDNode(MDNode *&Node, SourceMgr &SM, MachineFunction &MF, |
| 97 | StringRef Src, const PerFunctionMIParsingState &PFS, |
| 98 | const SlotMapping &IRSlots, SMDiagnostic &Error); |
| 99 | |
Alex Lorenz | 8e0a1b4 | 2015-06-22 17:02:30 +0000 | [diff] [blame] | 100 | } // end namespace llvm |
| 101 | |
| 102 | #endif |