1 //===-- VEMCInstLower.cpp - Convert VE MachineInstr to MCInst -------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file contains code to lower VE MachineInstrs to their corresponding
12 //===----------------------------------------------------------------------===//
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"
27 static MCOperand LowerSymbolOperand(const MachineInstr *MI,
28 const MachineOperand &MO,
29 const MCSymbol *Symbol, AsmPrinter &AP) {
31 const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol, AP.OutContext);
32 return MCOperand::createExpr(MCSym);
35 static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO,
37 switch (MO.getType()) {
39 report_fatal_error("unsupported operand type");
41 case MachineOperand::MO_Register:
44 return MCOperand::createReg(MO.getReg());
46 case MachineOperand::MO_Immediate:
47 return MCOperand::createImm(MO.getImm());
49 case MachineOperand::MO_MachineBasicBlock:
50 return LowerSymbolOperand(MI, MO, MO.getMBB()->getSymbol(), AP);
52 case MachineOperand::MO_RegisterMask:
58 void llvm::LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
60 OutMI.setOpcode(MI->getOpcode());
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);
67 OutMI.addOperand(MCOp);