LLVM  3.7.0
SystemZMCInstLower.cpp
Go to the documentation of this file.
1 //===-- SystemZMCInstLower.cpp - Lower 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 #include "SystemZMCInstLower.h"
11 #include "SystemZAsmPrinter.h"
12 #include "llvm/IR/Mangler.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCInst.h"
15 #include "llvm/MC/MCStreamer.h"
16 
17 using namespace llvm;
18 
19 // Return the VK_* enumeration for MachineOperand target flags Flags.
21  switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
22  case 0:
24  case SystemZII::MO_GOT:
28  }
29  llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
30 }
31 
33  SystemZAsmPrinter &asmprinter)
34  : Ctx(ctx), AsmPrinter(asmprinter) {}
35 
36 const MCExpr *
39  const MCSymbol *Symbol;
40  bool HasOffset = true;
41  switch (MO.getType()) {
43  Symbol = MO.getMBB()->getSymbol();
44  HasOffset = false;
45  break;
46 
48  Symbol = AsmPrinter.getSymbol(MO.getGlobal());
49  break;
50 
53  break;
54 
56  Symbol = AsmPrinter.GetJTISymbol(MO.getIndex());
57  HasOffset = false;
58  break;
59 
61  Symbol = AsmPrinter.GetCPISymbol(MO.getIndex());
62  break;
63 
66  break;
67 
68  default:
69  llvm_unreachable("unknown operand type");
70  }
71  const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, Kind, Ctx);
72  if (HasOffset)
73  if (int64_t Offset = MO.getOffset()) {
74  const MCExpr *OffsetExpr = MCConstantExpr::create(Offset, Ctx);
75  Expr = MCBinaryExpr::createAdd(Expr, OffsetExpr, Ctx);
76  }
77  return Expr;
78 }
79 
81  switch (MO.getType()) {
83  return MCOperand::createReg(MO.getReg());
84 
86  return MCOperand::createImm(MO.getImm());
87 
88  default: {
90  return MCOperand::createExpr(getExpr(MO, Kind));
91  }
92  }
93 }
94 
95 void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
96  OutMI.setOpcode(MI->getOpcode());
97  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
98  const MachineOperand &MO = MI->getOperand(I);
99  // Ignore all implicit register operands.
100  if (!MO.isReg() || !MO.isImplicit())
101  OutMI.addOperand(lowerOperand(MO));
102  }
103 }
bool isImplicit() const
const GlobalValue * getGlobal() const
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
static MCOperand createExpr(const MCExpr *Val)
Definition: MCInst.h:129
Address of indexed Jump Table for switch.
MachineBasicBlock reference.
const char * getSymbolName() const
MCOperand lowerOperand(const MachineOperand &MO) const
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
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
Name of external global symbol.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
Return the symbol for the specified jump table entry.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
Context object for machine code objects.
Definition: MCContext.h:48
SystemZMCInstLower(MCContext &ctx, SystemZAsmPrinter &asmPrinter)
int64_t getImm() const
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:446
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.
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const
int64_t getOffset() const
Return the offset from the symbol in this operand.
MCSymbol * getSymbol() const
getSymbol - Return the MCSymbol for this basic block.
void setOpcode(unsigned Op)
Definition: MCInst.h:158
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.
#define I(x, y, z)
Definition: MD5.cpp:54
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
Return the MCSymbol used to satisfy BlockAddress uses of the specified basic block.
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.
void lower(const MachineInstr *MI, MCInst &OutMI) const
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
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:150