LLVM  10.0.0svn
SparcMCInstLower.cpp
Go to the documentation of this file.
1 //===-- SparcMCInstLower.cpp - Convert Sparc 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 Sparc MachineInstrs to their corresponding
10 // MCInst records.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "Sparc.h"
20 #include "llvm/IR/Mangler.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCInst.h"
25 
26 using namespace llvm;
27 
28 
30  const MachineOperand &MO,
31  AsmPrinter &AP) {
32 
35  const MCSymbol *Symbol = nullptr;
36 
37  switch(MO.getType()) {
38  default: llvm_unreachable("Unknown type in LowerSymbolOperand");
40  Symbol = MO.getMBB()->getSymbol();
41  break;
42 
44  Symbol = AP.getSymbol(MO.getGlobal());
45  break;
46 
48  Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());
49  break;
50 
52  Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());
53  break;
54 
56  Symbol = AP.GetCPISymbol(MO.getIndex());
57  break;
58  }
59 
60  const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol,
61  AP.OutContext);
62  const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym,
63  AP.OutContext);
64  return MCOperand::createExpr(expr);
65 }
66 
68  const MachineOperand &MO,
69  AsmPrinter &AP) {
70  switch(MO.getType()) {
71  default: llvm_unreachable("unknown operand type"); break;
73  if (MO.isImplicit())
74  break;
75  return MCOperand::createReg(MO.getReg());
76 
78  return MCOperand::createImm(MO.getImm());
79 
85  return LowerSymbolOperand(MI, MO, AP);
86 
88 
89  }
90  return MCOperand();
91 }
92 
94  MCInst &OutMI,
95  AsmPrinter &AP)
96 {
97 
98  OutMI.setOpcode(MI->getOpcode());
99 
100  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
101  const MachineOperand &MO = MI->getOperand(i);
102  MCOperand MCOp = LowerOperand(MI, MO, AP);
103 
104  if (MCOp.isValid())
105  OutMI.addOperand(MCOp);
106  }
107 }
unsigned getTargetFlags() const
MachineBasicBlock * getMBB() const
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:327
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:88
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:136
MachineBasicBlock reference.
Mask of preserved registers.
static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:115
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:414
Name of external global symbol.
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:411
const char * getSymbolName() const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:158
Address of a global value.
const GlobalValue * getGlobal() const
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:78
Address of a basic block.
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setOpcode(unsigned Op)
Definition: MCInst.h:170
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
static MCOperand LowerSymbolOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:444
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
Representation of each machine instruction.
Definition: MachineInstr.h:64
void LowerSparcMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
const BlockAddress * getBlockAddress() const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
static const SparcMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: SparcMCExpr.cpp:26
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:183
bool isValid() const
Definition: MCInst.h:56
Address of indexed Constant in Constant Pool.
Register getReg() const
getReg - Returns the register number.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:416
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