LLVM  8.0.0svn
Nios2MCInstLower.cpp
Go to the documentation of this file.
1 //===-- Nios2MCInstLower.cpp - Convert Nios2 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 Nios2 MachineInstrs to their corresponding
11 // MCInst records.
12 //
13 //===----------------------------------------------------------------------===//
14 
17 #include "Nios2.h"
21 
22 using namespace llvm;
23 
27  const MCSymbol *Symbol;
28 
29  switch (MO.getTargetFlags()) {
30  default:
31  llvm_unreachable("Invalid target flag!");
33  break;
34  case Nios2FG::MO_ABS_HI:
35  TargetKind = Nios2MCExpr::CEK_ABS_HI;
36  break;
37  case Nios2FG::MO_ABS_LO:
38  TargetKind = Nios2MCExpr::CEK_ABS_LO;
39  break;
40  }
41 
42  switch (MO.getType()) {
44  Symbol = AP.getSymbol(MO.getGlobal());
45  break;
46 
48  Symbol = MO.getMBB()->getSymbol();
49  break;
50 
52  Symbol = AP.GetBlockAddressSymbol(MO.getBlockAddress());
53  break;
54 
56  Symbol = AP.GetExternalSymbolSymbol(MO.getSymbolName());
57  break;
58 
60  Symbol = AP.GetJTISymbol(MO.getIndex());
61  break;
62 
64  Symbol = AP.GetCPISymbol(MO.getIndex());
65  break;
66 
67  default:
68  llvm_unreachable("<unknown operand type>");
69  }
70 
71  const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, AP.OutContext);
72 
73  if (TargetKind != Nios2MCExpr::CEK_None)
74  Expr = Nios2MCExpr::create(TargetKind, Expr, AP.OutContext);
75 
76  return MCOperand::createExpr(Expr);
77 }
78 
80 
81  switch (MO.getType()) {
82  default:
83  llvm_unreachable("unknown operand type");
85  // Ignore all implicit register operands.
86  if (MO.isImplicit())
87  break;
88  return MCOperand::createReg(MO.getReg());
90  return MCOperand::createImm(MO.getImm());
97  return LowerSymbolOperand(MO, AP);
99  break;
100  }
101 
102  return MCOperand();
103 }
104 
106  AsmPrinter &AP) {
107 
108  OutMI.setOpcode(MI->getOpcode());
109 
110  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
111  const MachineOperand &MO = MI->getOperand(i);
112  MCOperand MCOp = LowerOperand(MO, AP);
113 
114  if (MCOp.isValid())
115  OutMI.addOperand(MCOp);
116  }
117 }
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:323
This class represents lattice values for constants.
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:89
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:137
unsigned getReg() const
getReg - Returns the register number.
Address of indexed Jump Table for switch.
MachineBasicBlock reference.
static MCOperand LowerSymbolOperand(const MachineOperand &MO, AsmPrinter &AP)
Mask of preserved registers.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Name of external global symbol.
static MCOperand LowerOperand(const MachineOperand &MO, AsmPrinter &AP)
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
const char * getSymbolName() const
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
Address of a global value.
const GlobalValue * getGlobal() const
void LowerNios2MachineInstToMCInst(const MachineInstr *MI, MCInst &OutMI, AsmPrinter &AP)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:79
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:173
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:430
MachineOperand class - Representation of each machine instruction operand.
int64_t getImm() const
static const Nios2MCExpr * create(Nios2ExprKind Kind, const MCExpr *Expr, MCContext &Ctx)
Definition: Nios2MCExpr.cpp:23
Representation of each machine instruction.
Definition: MachineInstr.h:64
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
const BlockAddress * getBlockAddress() const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const unsigned Kind
MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol address.
Definition: Nios2BaseInfo.h:31
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:186
bool isValid() const
Definition: MCInst.h:57
Address of indexed Constant in Constant Pool.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
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