LLVM  10.0.0
VEMCInstLower.cpp
Go to the documentation of this file.
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"
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 
25 using namespace llvm;
26 
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 
36  AsmPrinter &AP) {
37  switch (MO.getType()) {
38  default:
39  report_fatal_error("unsupported operand type");
40 
42  if (MO.isImplicit())
43  break;
44  return MCOperand::createReg(MO.getReg());
45 
47  return MCOperand::createImm(MO.getImm());
48 
50  return LowerSymbolOperand(MI, MO, MO.getMBB()->getSymbol(), AP);
51 
53  break;
54  }
55  return MCOperand();
56 }
57 
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 }
MachineBasicBlock * getMBB() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:329
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:90
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:136
MachineBasicBlock reference.
Mask of preserved registers.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:115
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:429
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:169
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:426
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:80
constexpr double e
Definition: MathExtras.h:57
static MCOperand LowerSymbolOperand(const MachineInstr *MI, const MachineOperand &MO, const MCSymbol *Symbol, AsmPrinter &AP)
static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
void setOpcode(unsigned Op)
Definition: MCInst.h:171
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
Representation of each machine instruction.
Definition: MachineInstr.h:63
void LowerVEMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:184
bool isValid() const
Definition: MCInst.h:56
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:431
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:34
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:122
bool isImplicit() const