LLVM  3.7.0
SparcMCInstLower.cpp
Go to the documentation of this file.
1 //===-- SparcMCInstLower.cpp - Convert Sparc MachineInstr to MCInst -------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains code to lower Sparc MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "Sparc.h"
17 #include "llvm/ADT/SmallString.h"
22 #include "llvm/IR/Mangler.h"
23 #include "llvm/MC/MCAsmInfo.h"
24 #include "llvm/MC/MCContext.h"
25 #include "llvm/MC/MCExpr.h"
26 #include "llvm/MC/MCInst.h"
27 
28 using namespace llvm;
29 
30 
32  const MachineOperand &MO,
33  AsmPrinter &AP) {
34 
37  const MCSymbol *Symbol = nullptr;
38 
39  switch(MO.getType()) {
40  default: llvm_unreachable("Unknown type in LowerSymbolOperand");
42  Symbol = MO.getMBB()->getSymbol();
43  break;
44 
46  Symbol = AP.getSymbol(MO.getGlobal());
47  break;
48 
50  Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());
51  break;
52 
54  Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());
55  break;
56 
58  Symbol = AP.GetCPISymbol(MO.getIndex());
59  break;
60  }
61 
62  const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol,
63  AP.OutContext);
64  const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym,
65  AP.OutContext);
66  return MCOperand::createExpr(expr);
67 }
68 
70  const MachineOperand &MO,
71  AsmPrinter &AP) {
72  switch(MO.getType()) {
73  default: llvm_unreachable("unknown operand type"); break;
75  if (MO.isImplicit())
76  break;
77  return MCOperand::createReg(MO.getReg());
78 
80  return MCOperand::createImm(MO.getImm());
81 
87  return LowerSymbolOperand(MI, MO, AP);
88 
90 
91  }
92  return MCOperand();
93 }
94 
96  MCInst &OutMI,
97  AsmPrinter &AP)
98 {
99 
100  OutMI.setOpcode(MI->getOpcode());
101 
102  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
103  const MachineOperand &MO = MI->getOperand(i);
104  MCOperand MCOp = LowerOperand(MI, MO, AP);
105 
106  if (MCOp.isValid())
107  OutMI.addOperand(MCOp);
108  }
109 }
bool isImplicit() const
const GlobalValue * getGlobal() const
bool isValid() const
Definition: MCInst.h:55
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:315
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:339
MachineBasicBlock * getMBB() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:78
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:129
MachineBasicBlock reference.
const char * getSymbolName() const
Mask of preserved registers.
static MCOperand LowerOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:111
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
Name of external global symbol.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:159
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
int64_t getImm() const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:150
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:267
Address of a global value.
unsigned getTargetFlags() const
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:273
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
Address of a basic block.
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
void setOpcode(unsigned Op)
Definition: MCInst.h:158
static MCOperand LowerSymbolOperand(const MachineInstr *MI, const MachineOperand &MO, AsmPrinter &AP)
MachineOperand class - Representation of each machine instruction operand.
Representation of each machine instruction.
Definition: MachineInstr.h:51
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
void LowerSparcMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
static const SparcMCExpr * create(VariantKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: SparcMCExpr.cpp:28
virtual MCSymbol * GetCPISymbol(unsigned CPID) const
Return the symbol for the specified constant pool entry.
unsigned getReg() const
getReg - Returns the register number.
const ARM::ArchExtKind Kind
void addOperand(const MCOperand &Op)
Definition: MCInst.h:168
const BlockAddress * getBlockAddress() const
Address of indexed Constant in Constant Pool.
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:33
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
Return the MCSymbol for the specified ExternalSymbol.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:117