Home | History | Annotate | Download | only in MIRParser
      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 
     17 #include "llvm/ADT/DenseMap.h"
     18 #include "llvm/ADT/SmallSet.h"
     19 
     20 namespace llvm {
     21 
     22 class StringRef;
     23 class BasicBlock;
     24 class MachineBasicBlock;
     25 class MachineFunction;
     26 class MachineInstr;
     27 class MachineRegisterInfo;
     28 class MDNode;
     29 struct SlotMapping;
     30 class SMDiagnostic;
     31 class SourceMgr;
     32 
     33 struct PerFunctionMIParsingState {
     34   MachineFunction &MF;
     35   SourceMgr *SM;
     36   const SlotMapping &IRSlots;
     37 
     38   DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
     39   DenseMap<unsigned, unsigned> VirtualRegisterSlots;
     40   DenseMap<unsigned, int> FixedStackObjectSlots;
     41   DenseMap<unsigned, int> StackObjectSlots;
     42   DenseMap<unsigned, unsigned> ConstantPoolSlots;
     43   DenseMap<unsigned, unsigned> JumpTableSlots;
     44   /// Hold the generic virtual registers.
     45   SmallSet<unsigned, 8> GenericVRegs;
     46 
     47   PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
     48                             const SlotMapping &IRSlots);
     49 };
     50 
     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.
     63 bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
     64                                        StringRef Src, SMDiagnostic &Error);
     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.
     76 bool parseMachineInstructions(const PerFunctionMIParsingState &PFS,
     77                               StringRef Src, SMDiagnostic &Error);
     78 
     79 bool parseMBBReference(const PerFunctionMIParsingState &PFS,
     80                        MachineBasicBlock *&MBB, StringRef Src,
     81                        SMDiagnostic &Error);
     82 
     83 bool parseNamedRegisterReference(const PerFunctionMIParsingState &PFS,
     84                                  unsigned &Reg, StringRef Src,
     85                                  SMDiagnostic &Error);
     86 
     87 bool parseVirtualRegisterReference(const PerFunctionMIParsingState &PFS,
     88                                    unsigned &Reg, StringRef Src,
     89                                    SMDiagnostic &Error);
     90 
     91 bool parseStackObjectReference(const PerFunctionMIParsingState &PFS,
     92                                int &FI, StringRef Src, SMDiagnostic &Error);
     93 
     94 bool parseMDNode(const PerFunctionMIParsingState &PFS, MDNode *&Node,
     95                  StringRef Src, SMDiagnostic &Error);
     96 
     97 } // end namespace llvm
     98 
     99 #endif
    100