1//===-- VEMCInstLower.cpp - Convert VE MachineInstr to MCInst -------------===// 2// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6// 7//===----------------------------------------------------------------------===// 8// 9// This file contains code to lower VE MachineInstrs to their corresponding 10// MCInst records. 11// 12//===----------------------------------------------------------------------===// 13 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" 24 25using namespace llvm; 26 27static MCOperand LowerSymbolOperand(const MachineInstr *MI, 28 const MachineOperand &MO, 29 const MCSymbol *Symbol, AsmPrinter &AP) { 30 31 const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol, AP.OutContext); 32 return MCOperand::createExpr(MCSym); 33} 34 35static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO, 36 AsmPrinter &AP) { 37 switch (MO.getType()) { 38 default: 39 report_fatal_error("unsupported operand type"); 40 41 case MachineOperand::MO_Register: 42 if (MO.isImplicit()) 43 break; 44 return MCOperand::createReg(MO.getReg()); 45 46 case MachineOperand::MO_Immediate: 47 return MCOperand::createImm(MO.getImm()); 48 49 case MachineOperand::MO_MachineBasicBlock: 50 return LowerSymbolOperand(MI, MO, MO.getMBB()->getSymbol(), AP); 51 52 case MachineOperand::MO_RegisterMask: 53 break; 54 } 55 return MCOperand(); 56} 57 58void llvm::LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, 59 AsmPrinter &AP) { 60 OutMI.setOpcode(MI->getOpcode()); 61 62 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 63 const MachineOperand &MO = MI->getOperand(i); 64 MCOperand MCOp = LowerOperand(MI, MO, AP); 65 66 if (MCOp.isValid()) 67 OutMI.addOperand(MCOp); 68 } 69} 70