2017-06-07 06:22:41 +08:00
|
|
|
//===- MIParser.h - Machine Instructions Parser -----------------*- C++ -*-===//
|
2015-06-23 01:02:30 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-06-23 01:02:30 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the function that parses the machine instructions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
|
|
|
|
|
2015-06-27 00:46:11 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2017-06-07 06:22:41 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2015-06-23 01:02:30 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2015-06-27 00:46:11 +08:00
|
|
|
class MachineBasicBlock;
|
2015-06-23 01:02:30 +08:00
|
|
|
class MachineFunction;
|
2015-08-19 08:13:25 +08:00
|
|
|
class MDNode;
|
2016-10-11 11:13:01 +08:00
|
|
|
class RegisterBank;
|
2015-06-27 06:56:48 +08:00
|
|
|
struct SlotMapping;
|
2015-06-23 01:02:30 +08:00
|
|
|
class SMDiagnostic;
|
|
|
|
class SourceMgr;
|
2017-06-07 06:22:41 +08:00
|
|
|
class StringRef;
|
2016-10-11 11:13:01 +08:00
|
|
|
class TargetRegisterClass;
|
|
|
|
|
|
|
|
struct VRegInfo {
|
|
|
|
enum uint8_t {
|
|
|
|
UNKNOWN, NORMAL, GENERIC, REGBANK
|
|
|
|
} Kind = UNKNOWN;
|
|
|
|
bool Explicit = false; ///< VReg was explicitly specified in the .mir file.
|
|
|
|
union {
|
|
|
|
const TargetRegisterClass *RC;
|
|
|
|
const RegisterBank *RegBank;
|
|
|
|
} D;
|
|
|
|
unsigned VReg;
|
|
|
|
unsigned PreferredReg = 0;
|
|
|
|
};
|
2015-06-23 01:02:30 +08:00
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
using Name2RegClassMap = StringMap<const TargetRegisterClass *>;
|
|
|
|
using Name2RegBankMap = StringMap<const RegisterBank *>;
|
2017-01-18 08:59:19 +08:00
|
|
|
|
2015-07-08 01:46:43 +08:00
|
|
|
struct PerFunctionMIParsingState {
|
2016-10-11 11:13:01 +08:00
|
|
|
BumpPtrAllocator Allocator;
|
2016-07-14 06:23:23 +08:00
|
|
|
MachineFunction &MF;
|
2016-07-14 07:27:50 +08:00
|
|
|
SourceMgr *SM;
|
|
|
|
const SlotMapping &IRSlots;
|
2017-01-18 08:59:19 +08:00
|
|
|
const Name2RegClassMap &Names2RegClasses;
|
|
|
|
const Name2RegBankMap &Names2RegBanks;
|
2016-07-14 06:23:23 +08:00
|
|
|
|
2015-07-08 01:46:43 +08:00
|
|
|
DenseMap<unsigned, MachineBasicBlock *> MBBSlots;
|
2016-10-11 11:13:01 +08:00
|
|
|
DenseMap<unsigned, VRegInfo*> VRegInfos;
|
2018-03-31 02:15:54 +08:00
|
|
|
StringMap<VRegInfo*> VRegInfosNamed;
|
2015-07-17 07:37:45 +08:00
|
|
|
DenseMap<unsigned, int> FixedStackObjectSlots;
|
|
|
|
DenseMap<unsigned, int> StackObjectSlots;
|
2015-07-21 04:51:18 +08:00
|
|
|
DenseMap<unsigned, unsigned> ConstantPoolSlots;
|
2015-07-16 07:38:35 +08:00
|
|
|
DenseMap<unsigned, unsigned> JumpTableSlots;
|
2016-07-14 06:23:23 +08:00
|
|
|
|
2016-07-14 07:27:50 +08:00
|
|
|
PerFunctionMIParsingState(MachineFunction &MF, SourceMgr &SM,
|
2017-01-18 08:59:19 +08:00
|
|
|
const SlotMapping &IRSlots,
|
|
|
|
const Name2RegClassMap &Names2RegClasses,
|
|
|
|
const Name2RegBankMap &Names2RegBanks);
|
2016-10-11 11:13:01 +08:00
|
|
|
|
2018-07-17 02:51:40 +08:00
|
|
|
VRegInfo &getVRegInfo(unsigned Num);
|
2018-03-31 02:15:54 +08:00
|
|
|
VRegInfo &getVRegInfoNamed(StringRef RegName);
|
2015-07-08 01:46:43 +08:00
|
|
|
};
|
|
|
|
|
2015-08-14 07:10:16 +08:00
|
|
|
/// Parse the machine basic block definitions, and skip the machine
|
|
|
|
/// instructions.
|
|
|
|
///
|
|
|
|
/// This function runs the first parsing pass on the machine function's body.
|
|
|
|
/// It parses only the machine basic block definitions and creates the machine
|
|
|
|
/// basic blocks in the given machine function.
|
|
|
|
///
|
|
|
|
/// The machine instructions aren't parsed during the first pass because all
|
|
|
|
/// the machine basic blocks aren't defined yet - this makes it impossible to
|
|
|
|
/// resolve the machine basic block references.
|
|
|
|
///
|
|
|
|
/// Return true if an error occurred.
|
2016-07-14 06:23:23 +08:00
|
|
|
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
|
2016-07-14 07:27:50 +08:00
|
|
|
StringRef Src, SMDiagnostic &Error);
|
2015-08-14 07:10:16 +08:00
|
|
|
|
|
|
|
/// Parse the machine instructions.
|
|
|
|
///
|
|
|
|
/// This function runs the second parsing pass on the machine function's body.
|
|
|
|
/// It skips the machine basic block definitions and parses only the machine
|
|
|
|
/// instructions and basic block attributes like liveins and successors.
|
|
|
|
///
|
|
|
|
/// The second parsing pass assumes that the first parsing pass already ran
|
|
|
|
/// on the given source string.
|
|
|
|
///
|
|
|
|
/// Return true if an error occurred.
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src,
|
|
|
|
SMDiagnostic &Error);
|
2016-07-14 06:23:23 +08:00
|
|
|
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseMBBReference(PerFunctionMIParsingState &PFS,
|
2016-07-14 07:27:50 +08:00
|
|
|
MachineBasicBlock *&MBB, StringRef Src,
|
2016-07-14 06:23:23 +08:00
|
|
|
SMDiagnostic &Error);
|
|
|
|
|
2016-11-15 08:03:14 +08:00
|
|
|
bool parseRegisterReference(PerFunctionMIParsingState &PFS,
|
|
|
|
unsigned &Reg, StringRef Src,
|
|
|
|
SMDiagnostic &Error);
|
|
|
|
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg,
|
|
|
|
StringRef Src, SMDiagnostic &Error);
|
2015-07-15 05:24:41 +08:00
|
|
|
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
|
|
|
|
VRegInfo *&Info, StringRef Src,
|
2015-07-28 01:42:45 +08:00
|
|
|
SMDiagnostic &Error);
|
|
|
|
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI,
|
|
|
|
StringRef Src, SMDiagnostic &Error);
|
2015-08-19 06:26:26 +08:00
|
|
|
|
2016-10-11 11:13:01 +08:00
|
|
|
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src,
|
|
|
|
SMDiagnostic &Error);
|
2015-08-19 08:13:25 +08:00
|
|
|
|
2015-06-23 01:02:30 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-06-07 06:22:41 +08:00
|
|
|
#endif // LLVM_LIB_CODEGEN_MIRPARSER_MIPARSER_H
|