LLVM  6.0.0svn
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 
16 #include "Sparc.h"
21 #include "llvm/IR/Mangler.h"
22 #include "llvm/MC/MCAsmInfo.h"
23 #include "llvm/MC/MCContext.h"
24 #include "llvm/MC/MCExpr.h"
25 #include "llvm/MC/MCInst.h"
26 
27 using namespace llvm;
28 
29 
31  const MachineOperand &MO,
32  AsmPrinter &AP) {
33 
36  const MCSymbol *Symbol = nullptr;
37 
38  switch(MO.getType()) {
39  default: llvm_unreachable("Unknown type in LowerSymbolOperand");
41  Symbol = MO.getMBB()->getSymbol();
42  break;
43 
45  Symbol = AP.getSymbol(MO.getGlobal());
46  break;
47 
49  Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());
50  break;
51 
53  Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());
54  break;
55 
57  Symbol = AP.GetCPISymbol(MO.getIndex());
58  break;
59  }
60 
61  const MCSymbolRefExpr *MCSym = MCSymbolRefExpr::create(Symbol,
62  AP.OutContext);
63  const SparcMCExpr *expr = SparcMCExpr::create(Kind, MCSym,
64  AP.OutContext);
65  return MCOperand::createExpr(expr);
66 }
67 
69  const MachineOperand &MO,
70  AsmPrinter &AP) {
71  switch(MO.getType()) {
72  default: llvm_unreachable("unknown operand type"); break;
74  if (MO.isImplicit())
75  break;
76  return MCOperand::createReg(MO.getReg());
77 
79  return MCOperand::createImm(MO.getImm());
80 
86  return LowerSymbolOperand(MI, MO, AP);
87 
89 
90  }
91  return MCOperand();
92 }
93 
95  MCInst &OutMI,
96  AsmPrinter &AP)
97 {
98 
99  OutMI.setOpcode(MI->getOpcode());
100 
101  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
102  const MachineOperand &MO = MI->getOperand(i);
103  MCOperand MCOp = LowerOperand(MI, MO, AP);
104 
105  if (MCOp.isValid())
106  OutMI.addOperand(MCOp);
107  }
108 }
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:305
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:87
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
unsigned getReg() const
getReg - Returns the register number.
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:116
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:293
Name of external global symbol.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:165
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:290
const char * getSymbolName() const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
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:77
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:171
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:433
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
Representation of each machine instruction.
Definition: MachineInstr.h:59
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:27
const unsigned Kind
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:184
bool isValid() const
Definition: MCInst.h:57
Address of indexed Constant in Constant Pool.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:295
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:35
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123
bool isImplicit() const