llvm/llvm/lib/CodeGen/MIRParser/MIParser.cpp

//===- MIParser.cpp - Machine instructions parser implementation ----------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file implements the parsing of machine instructions.
//
//===----------------------------------------------------------------------===//

#include "llvm/CodeGen/MIRParser/MIParser.h"
#include "MILexer.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/AsmParser/SlotMapping.h"
#include "llvm/CodeGen/MIRFormatter.h"
#include "llvm/CodeGen/MIRPrinter.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineMemOperand.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/PseudoSourceValueManager.h"
#include "llvm/CodeGen/RegisterBank.h"
#include "llvm/CodeGen/RegisterBankInfo.h"
#include "llvm/CodeGen/TargetInstrInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/CodeGenTypes/LowLevelType.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ModuleSlotTracker.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueSymbolTable.h"
#include "llvm/MC/LaneBitmask.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Target/TargetIntrinsicInfo.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cctype>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <string>
#include <utility>

usingnamespacellvm;

void PerTargetMIParsingState::setTarget(
  const TargetSubtargetInfo &NewSubtarget) {}

void PerTargetMIParsingState::initNames2Regs() {}

bool PerTargetMIParsingState::getRegisterByName(StringRef RegName,
                                                Register &Reg) {}

void PerTargetMIParsingState::initNames2InstrOpCodes() {}

bool PerTargetMIParsingState::parseInstrName(StringRef InstrName,
                                             unsigned &OpCode) {}

void PerTargetMIParsingState::initNames2RegMasks() {}

const uint32_t *PerTargetMIParsingState::getRegMask(StringRef Identifier) {}

void PerTargetMIParsingState::initNames2SubRegIndices() {}

unsigned PerTargetMIParsingState::getSubRegIndex(StringRef Name) {}

void PerTargetMIParsingState::initNames2TargetIndices() {}

bool PerTargetMIParsingState::getTargetIndex(StringRef Name, int &Index) {}

void PerTargetMIParsingState::initNames2DirectTargetFlags() {}

bool PerTargetMIParsingState::getDirectTargetFlag(StringRef Name,
                                                  unsigned &Flag) {}

void PerTargetMIParsingState::initNames2BitmaskTargetFlags() {}

bool PerTargetMIParsingState::getBitmaskTargetFlag(StringRef Name,
                                                   unsigned &Flag) {}

void PerTargetMIParsingState::initNames2MMOTargetFlags() {}

bool PerTargetMIParsingState::getMMOTargetFlag(StringRef Name,
                                               MachineMemOperand::Flags &Flag) {}

void PerTargetMIParsingState::initNames2RegClasses() {}

void PerTargetMIParsingState::initNames2RegBanks() {}

const TargetRegisterClass *
PerTargetMIParsingState::getRegClass(StringRef Name) {}

const RegisterBank *PerTargetMIParsingState::getRegBank(StringRef Name) {}

PerFunctionMIParsingState::PerFunctionMIParsingState(MachineFunction &MF,
    SourceMgr &SM, const SlotMapping &IRSlots, PerTargetMIParsingState &T)
  :{}

VRegInfo &PerFunctionMIParsingState::getVRegInfo(Register Num) {}

VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) {}

static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST,
                           DenseMap<unsigned, const Value *> &Slots2Values) {}

/// Creates the mapping from slot numbers to function's unnamed IR values.
static void initSlots2Values(const Function &F,
                             DenseMap<unsigned, const Value *> &Slots2Values) {}

const Value* PerFunctionMIParsingState::getIRValue(unsigned Slot) {}

namespace {

/// A wrapper struct around the 'MachineOperand' struct that includes a source
/// range and other attributes.
struct ParsedMachineOperand {};

class MIParser {};

} // end anonymous namespace

MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
                   StringRef Source)
    :{}

MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error,
                   StringRef Source, SMRange SourceRange)
    :{}

void MIParser::lex(unsigned SkipChar) {}

bool MIParser::error(const Twine &Msg) {}

bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) {}

SMLoc MIParser::mapSMLoc(StringRef::iterator Loc) {}

ErrorCallbackType;

static const char *toString(MIToken::TokenKind TokenKind) {}

bool MIParser::expectAndConsume(MIToken::TokenKind TokenKind) {}

bool MIParser::consumeIfPresent(MIToken::TokenKind TokenKind) {}

// Parse Machine Basic Block Section ID.
bool MIParser::parseSectionID(std::optional<MBBSectionID> &SID) {}

// Parse Machine Basic Block ID.
bool MIParser::parseBBID(std::optional<UniqueBBID> &BBID) {}

// Parse basic block call frame size.
bool MIParser::parseCallFrameSize(unsigned &CallFrameSize) {}

bool MIParser::parseBasicBlockDefinition(
    DenseMap<unsigned, MachineBasicBlock *> &MBBSlots) {}

bool MIParser::parseBasicBlockDefinitions(
    DenseMap<unsigned, MachineBasicBlock *> &MBBSlots) {}

bool MIParser::parseBasicBlockLiveins(MachineBasicBlock &MBB) {}

bool MIParser::parseBasicBlockSuccessors(MachineBasicBlock &MBB) {}

bool MIParser::parseBasicBlock(MachineBasicBlock &MBB,
                               MachineBasicBlock *&AddFalthroughFrom) {}

bool MIParser::parseBasicBlocks() {}

bool MIParser::parse(MachineInstr *&MI) {}

bool MIParser::parseStandaloneMBB(MachineBasicBlock *&MBB) {}

bool MIParser::parseStandaloneNamedRegister(Register &Reg) {}

bool MIParser::parseStandaloneVirtualRegister(VRegInfo *&Info) {}

bool MIParser::parseStandaloneRegister(Register &Reg) {}

bool MIParser::parseStandaloneStackObject(int &FI) {}

bool MIParser::parseStandaloneMDNode(MDNode *&Node) {}

bool MIParser::parseMachineMetadata() {}

bool MIParser::parseMDTuple(MDNode *&MD, bool IsDistinct) {}

bool MIParser::parseMDNodeVector(SmallVectorImpl<Metadata *> &Elts) {}

// ::= !42
// ::= !"string"
bool MIParser::parseMetadata(Metadata *&MD) {}

static const char *printImplicitRegisterFlag(const MachineOperand &MO) {}

static std::string getRegisterName(const TargetRegisterInfo *TRI,
                                   Register Reg) {}

/// Return true if the parsed machine operands contain a given machine operand.
static bool isImplicitOperandIn(const MachineOperand &ImplicitOperand,
                                ArrayRef<ParsedMachineOperand> Operands) {}

bool MIParser::verifyImplicitOperands(ArrayRef<ParsedMachineOperand> Operands,
                                      const MCInstrDesc &MCID) {}

bool MIParser::parseInstruction(unsigned &OpCode, unsigned &Flags) {}

bool MIParser::parseNamedRegister(Register &Reg) {}

bool MIParser::parseNamedVirtualRegister(VRegInfo *&Info) {}

bool MIParser::parseVirtualRegister(VRegInfo *&Info) {}

bool MIParser::parseRegister(Register &Reg, VRegInfo *&Info) {}

bool MIParser::parseRegisterClassOrBank(VRegInfo &RegInfo) {}

bool MIParser::parseRegisterFlag(unsigned &Flags) {}

bool MIParser::parseSubRegisterIndex(unsigned &SubReg) {}

bool MIParser::parseRegisterTiedDefIndex(unsigned &TiedDefIdx) {}

bool MIParser::assignRegisterTies(MachineInstr &MI,
                                  ArrayRef<ParsedMachineOperand> Operands) {}

bool MIParser::parseRegisterOperand(MachineOperand &Dest,
                                    std::optional<unsigned> &TiedDefIdx,
                                    bool IsDef) {}

bool MIParser::parseImmediateOperand(MachineOperand &Dest) {}

bool MIParser::parseTargetImmMnemonic(const unsigned OpCode,
                                      const unsigned OpIdx,
                                      MachineOperand &Dest,
                                      const MIRFormatter &MF) {}

static bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
                            PerFunctionMIParsingState &PFS, const Constant *&C,
                            ErrorCallbackType ErrCB) {}

bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue,
                               const Constant *&C) {}

bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) {}

// See LLT implementation for bit size limits.
static bool verifyScalarSize(uint64_t Size) {}

static bool verifyVectorElementCount(uint64_t NumElts) {}

static bool verifyAddrSpace(uint64_t AddrSpace) {}

bool MIParser::parseLowLevelType(StringRef::iterator Loc, LLT &Ty) {}

bool MIParser::parseTypedImmediateOperand(MachineOperand &Dest) {}

bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) {}

static bool getHexUint(const MIToken &Token, APInt &Result) {}

static bool getUnsigned(const MIToken &Token, unsigned &Result,
                        ErrorCallbackType ErrCB) {}

bool MIParser::getUnsigned(unsigned &Result) {}

bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) {}

bool MIParser::parseMBBOperand(MachineOperand &Dest) {}

bool MIParser::parseStackFrameIndex(int &FI) {}

bool MIParser::parseStackObjectOperand(MachineOperand &Dest) {}

bool MIParser::parseFixedStackFrameIndex(int &FI) {}

bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) {}

static bool parseGlobalValue(const MIToken &Token,
                             PerFunctionMIParsingState &PFS, GlobalValue *&GV,
                             ErrorCallbackType ErrCB) {}

bool MIParser::parseGlobalValue(GlobalValue *&GV) {}

bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) {}

bool MIParser::parseConstantPoolIndexOperand(MachineOperand &Dest) {}

bool MIParser::parseJumpTableIndexOperand(MachineOperand &Dest) {}

bool MIParser::parseExternalSymbolOperand(MachineOperand &Dest) {}

bool MIParser::parseMCSymbolOperand(MachineOperand &Dest) {}

bool MIParser::parseSubRegisterIndexOperand(MachineOperand &Dest) {}

bool MIParser::parseMDNode(MDNode *&Node) {}

bool MIParser::parseDIExpression(MDNode *&Expr) {}

bool MIParser::parseDILocation(MDNode *&Loc) {}

bool MIParser::parseMetadataOperand(MachineOperand &Dest) {}

bool MIParser::parseCFIOffset(int &Offset) {}

bool MIParser::parseCFIRegister(Register &Reg) {}

bool MIParser::parseCFIAddressSpace(unsigned &AddressSpace) {}

bool MIParser::parseCFIEscapeValues(std::string &Values) {}

bool MIParser::parseCFIOperand(MachineOperand &Dest) {}

bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) {}

bool MIParser::parseBlockAddressOperand(MachineOperand &Dest) {}

bool MIParser::parseIntrinsicOperand(MachineOperand &Dest) {}

bool MIParser::parsePredicateOperand(MachineOperand &Dest) {}

bool MIParser::parseShuffleMaskOperand(MachineOperand &Dest) {}

bool MIParser::parseDbgInstrRefOperand(MachineOperand &Dest) {}

bool MIParser::parseTargetIndexOperand(MachineOperand &Dest) {}

bool MIParser::parseCustomRegisterMaskOperand(MachineOperand &Dest) {}

bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) {}

bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx,
                                   MachineOperand &Dest,
                                   std::optional<unsigned> &TiedDefIdx) {}

bool MIParser::parseMachineOperandAndTargetFlags(
    const unsigned OpCode, const unsigned OpIdx, MachineOperand &Dest,
    std::optional<unsigned> &TiedDefIdx) {}

bool MIParser::parseOffset(int64_t &Offset) {}

bool MIParser::parseIRBlockAddressTaken(BasicBlock *&BB) {}

bool MIParser::parseAlignment(uint64_t &Alignment) {}

bool MIParser::parseAddrspace(unsigned &Addrspace) {}

bool MIParser::parseOperandsOffset(MachineOperand &Op) {}

static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS,
                         const Value *&V, ErrorCallbackType ErrCB) {}

bool MIParser::parseIRValue(const Value *&V) {}

bool MIParser::getUint64(uint64_t &Result) {}

bool MIParser::getHexUint(APInt &Result) {}

bool MIParser::parseMemoryOperandFlag(MachineMemOperand::Flags &Flags) {}

bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) {}

bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) {}

bool MIParser::parseOptionalScope(LLVMContext &Context,
                                  SyncScope::ID &SSID) {}

bool MIParser::parseOptionalAtomicOrdering(AtomicOrdering &Order) {}

bool MIParser::parseMachineMemoryOperand(MachineMemOperand *&Dest) {}

bool MIParser::parsePreOrPostInstrSymbol(MCSymbol *&Symbol) {}

bool MIParser::parseHeapAllocMarker(MDNode *&Node) {}

bool MIParser::parsePCSections(MDNode *&Node) {}

static void initSlots2BasicBlocks(
    const Function &F,
    DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {}

static const BasicBlock *getIRBlockFromSlot(
    unsigned Slot,
    const DenseMap<unsigned, const BasicBlock *> &Slots2BasicBlocks) {}

const BasicBlock *MIParser::getIRBlock(unsigned Slot) {}

const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) {}

MCSymbol *MIParser::getOrCreateMCSymbol(StringRef Name) {}

bool MIParser::parseStringConstant(std::string &Result) {}

bool llvm::parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS,
                                             StringRef Src,
                                             SMDiagnostic &Error) {}

bool llvm::parseMachineInstructions(PerFunctionMIParsingState &PFS,
                                    StringRef Src, SMDiagnostic &Error) {}

bool llvm::parseMBBReference(PerFunctionMIParsingState &PFS,
                             MachineBasicBlock *&MBB, StringRef Src,
                             SMDiagnostic &Error) {}

bool llvm::parseRegisterReference(PerFunctionMIParsingState &PFS,
                                  Register &Reg, StringRef Src,
                                  SMDiagnostic &Error) {}

bool llvm::parseNamedRegisterReference(PerFunctionMIParsingState &PFS,
                                       Register &Reg, StringRef Src,
                                       SMDiagnostic &Error) {}

bool llvm::parseVirtualRegisterReference(PerFunctionMIParsingState &PFS,
                                         VRegInfo *&Info, StringRef Src,
                                         SMDiagnostic &Error) {}

bool llvm::parseStackObjectReference(PerFunctionMIParsingState &PFS,
                                     int &FI, StringRef Src,
                                     SMDiagnostic &Error) {}

bool llvm::parseMDNode(PerFunctionMIParsingState &PFS,
                       MDNode *&Node, StringRef Src, SMDiagnostic &Error) {}

bool llvm::parseMachineMetadata(PerFunctionMIParsingState &PFS, StringRef Src,
                                SMRange SrcRange, SMDiagnostic &Error) {}

bool MIRFormatter::parseIRValue(StringRef Src, MachineFunction &MF,
                                PerFunctionMIParsingState &PFS, const Value *&V,
                                ErrorCallbackType ErrorCallback) {}