LLVM  8.0.1
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 }
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
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.
void lower(const MachineInstr *MI, MCInst &OutMI) const
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags)
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
Name of external global symbol.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:409
const char * getSymbolName() const
Context object for machine code objects.
Definition: MCContext.h:63
SystemZMCInstLower(MCContext &ctx, SystemZAsmPrinter &asmPrinter)
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:461
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
MCOperand lowerOperand(const MachineOperand &MO) const
Address of a global value.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const GlobalValue * getGlobal() const
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
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.
int64_t getOffset() const
Return the offset from the symbol in this operand.
const BlockAddress * getBlockAddress() const
MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
#define I(x, y, z)
Definition: MD5.cpp:58
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const unsigned Kind
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:186
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
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
bool isImplicit() const