Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VEMCInstLower.cpp
35269 views
//===-- VEMCInstLower.cpp - Convert VE 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 VE MachineInstrs to their corresponding9// MCInst records.10//11//===----------------------------------------------------------------------===//1213#include "MCTargetDesc/VEMCExpr.h"14#include "VE.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;2627static MCOperand LowerSymbolOperand(const MachineInstr *MI,28const MachineOperand &MO,29const MCSymbol *Symbol, AsmPrinter &AP) {30VEMCExpr::VariantKind Kind = (VEMCExpr::VariantKind)MO.getTargetFlags();3132const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, AP.OutContext);33// Add offset iff MO is not jump table info or machine basic block.34if (!MO.isJTI() && !MO.isMBB() && MO.getOffset())35Expr = MCBinaryExpr::createAdd(36Expr, MCConstantExpr::create(MO.getOffset(), AP.OutContext),37AP.OutContext);38Expr = VEMCExpr::create(Kind, Expr, AP.OutContext);39return MCOperand::createExpr(Expr);40}4142static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO,43AsmPrinter &AP) {44switch (MO.getType()) {45default:46report_fatal_error("unsupported operand type");4748case MachineOperand::MO_Register:49if (MO.isImplicit())50break;51return MCOperand::createReg(MO.getReg());5253case MachineOperand::MO_BlockAddress:54return LowerSymbolOperand(55MI, MO, AP.GetBlockAddressSymbol(MO.getBlockAddress()), AP);56case MachineOperand::MO_ConstantPoolIndex:57return LowerSymbolOperand(MI, MO, AP.GetCPISymbol(MO.getIndex()), AP);58case MachineOperand::MO_ExternalSymbol:59return LowerSymbolOperand(60MI, MO, AP.GetExternalSymbolSymbol(MO.getSymbolName()), AP);61case MachineOperand::MO_GlobalAddress:62return LowerSymbolOperand(MI, MO, AP.getSymbol(MO.getGlobal()), AP);63case MachineOperand::MO_Immediate:64return MCOperand::createImm(MO.getImm());65case MachineOperand::MO_JumpTableIndex:66return LowerSymbolOperand(MI, MO, AP.GetJTISymbol(MO.getIndex()), AP);67case MachineOperand::MO_MachineBasicBlock:68return LowerSymbolOperand(MI, MO, MO.getMBB()->getSymbol(), AP);6970case MachineOperand::MO_RegisterMask:71break;72}73return MCOperand();74}7576void llvm::LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,77AsmPrinter &AP) {78OutMI.setOpcode(MI->getOpcode());7980for (const MachineOperand &MO : MI->operands()) {81MCOperand MCOp = LowerOperand(MI, MO, AP);8283if (MCOp.isValid())84OutMI.addOperand(MCOp);85}86}878889