Path: blob/main/contrib/llvm-project/llvm/lib/Target/Sparc/SparcMCInstLower.cpp
35269 views
//===-- SparcMCInstLower.cpp - Convert Sparc MachineInstr to MCInst -------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file contains code to lower Sparc MachineInstrs to their corresponding9// MCInst records.10//11//===----------------------------------------------------------------------===//1213#include "MCTargetDesc/SparcMCExpr.h"14#include "Sparc.h"15#include "llvm/CodeGen/AsmPrinter.h"16#include "llvm/CodeGen/MachineFunction.h"17#include "llvm/CodeGen/MachineInstr.h"18#include "llvm/CodeGen/MachineOperand.h"19#include "llvm/IR/Mangler.h"20#include "llvm/MC/MCAsmInfo.h"21#include "llvm/MC/MCContext.h"22#include "llvm/MC/MCExpr.h"23#include "llvm/MC/MCInst.h"2425using namespace llvm;262728static MCOperand LowerSymbolOperand(const MachineInstr *MI,29const MachineOperand &MO,30AsmPrinter &AP) {3132SparcMCExpr::VariantKind Kind =33(SparcMCExpr::VariantKind)MO.getTargetFlags();34const MCSymbol *Symbol = nullptr;3536switch(MO.getType()) {37default: llvm_unreachable("Unknown type in LowerSymbolOperand");38case MachineOperand::MO_MachineBasicBlock:39Symbol = MO.getMBB()->getSymbol();40break;4142case MachineOperand::MO_GlobalAddress:43Symbol = AP.getSymbol(MO.getGlobal());44break;4546case MachineOperand::MO_BlockAddress:47Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());48break;4950case MachineOperand::MO_ExternalSymbol:51Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());52break;5354case MachineOperand::MO_ConstantPoolIndex:55Symbol = AP.GetCPISymbol(MO.getIndex());56break;57}5859const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol,60AP.OutContext);61const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym,62AP.OutContext);63return MCOperand::createExpr(expr);64}6566static MCOperand LowerOperand(const MachineInstr *MI,67const MachineOperand &MO,68AsmPrinter &AP) {69switch(MO.getType()) {70default: llvm_unreachable("unknown operand type"); break;71case MachineOperand::MO_Register:72if (MO.isImplicit())73break;74return MCOperand::createReg(MO.getReg());7576case MachineOperand::MO_Immediate:77return MCOperand::createImm(MO.getImm());7879case MachineOperand::MO_MachineBasicBlock:80case MachineOperand::MO_GlobalAddress:81case MachineOperand::MO_BlockAddress:82case MachineOperand::MO_ExternalSymbol:83case MachineOperand::MO_ConstantPoolIndex:84return LowerSymbolOperand(MI, MO, AP);8586case MachineOperand::MO_RegisterMask: break;8788}89return MCOperand();90}9192void llvm::LowerSparcMachineInstrToMCInst(const MachineInstr *MI,93MCInst &OutMI,94AsmPrinter &AP)95{9697OutMI.setOpcode(MI->getOpcode());9899for (const MachineOperand &MO : MI->operands()) {100MCOperand MCOp = LowerOperand(MI, MO, AP);101102if (MCOp.isValid())103OutMI.addOperand(MCOp);104}105}106107108