LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/MC/MCExpr.h"
13 #include "llvm/MC/MCStreamer.h"
14 #include "llvm/Target/Mangler.h"
15 
16 using namespace llvm;
17 
18 // Return the VK_* enumeration for MachineOperand target flags Flags.
20  switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
21  case 0:
23  case SystemZII::MO_GOT:
25  }
26  llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
27 }
28 
30  SystemZAsmPrinter &asmprinter)
31  : Ctx(ctx), AsmPrinter(asmprinter) {}
32 
33 const MCExpr *
36  const MCSymbol *Symbol;
37  bool HasOffset = true;
38  switch (MO.getType()) {
40  Symbol = MO.getMBB()->getSymbol();
41  HasOffset = false;
42  break;
43 
45  Symbol = AsmPrinter.getSymbol(MO.getGlobal());
46  break;
47 
50  break;
51 
53  Symbol = AsmPrinter.GetJTISymbol(MO.getIndex());
54  HasOffset = false;
55  break;
56 
58  Symbol = AsmPrinter.GetCPISymbol(MO.getIndex());
59  break;
60 
63  break;
64 
65  default:
66  llvm_unreachable("unknown operand type");
67  }
68  const MCExpr *Expr = MCSymbolRefExpr::Create(Symbol, Kind, Ctx);
69  if (HasOffset)
70  if (int64_t Offset = MO.getOffset()) {
71  const MCExpr *OffsetExpr = MCConstantExpr::Create(Offset, Ctx);
72  Expr = MCBinaryExpr::CreateAdd(Expr, OffsetExpr, Ctx);
73  }
74  return Expr;
75 }
76 
78  switch (MO.getType()) {
80  return MCOperand::CreateReg(MO.getReg());
81 
83  return MCOperand::CreateImm(MO.getImm());
84 
85  default: {
87  return MCOperand::CreateExpr(getExpr(MO, Kind));
88  }
89  }
90 }
91 
92 void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
93  OutMI.setOpcode(MI->getOpcode());
94  for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
95  const MachineOperand &MO = MI->getOperand(I);
96  // Ignore all implicit register operands.
97  if (!MO.isReg() || !MO.isImplicit())
98  OutMI.addOperand(lowerOperand(MO));
99  }
100 }
bool isImplicit() const
const GlobalValue * getGlobal() const
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:277
static MCOperand CreateReg(unsigned Reg)
Definition: MCInst.h:111
MachineBasicBlock * getMBB() const
static const MCConstantExpr * Create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:152
static MCOperand CreateExpr(const MCExpr *Val)
Definition: MCInst.h:129
const char * getSymbolName() const
MCOperand lowerOperand(const MachineOperand &MO) const
Address of indexed Jump Table for switch.
#define llvm_unreachable(msg)
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MCSymbol * GetJTISymbol(unsigned JTID, bool isLinkerPrivate=false) const
GetJTISymbol - Return the symbol for the specified jump table entry.
unsigned getNumOperands() const
Definition: MachineInstr.h:265
int getOpcode() const
Definition: MachineInstr.h:261
SystemZMCInstLower(MCContext &ctx, SystemZAsmPrinter &asmPrinter)
int64_t getImm() const
Address of indexed Constant in Constant Pool.
static const MCSymbolRefExpr * Create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:270
unsigned getTargetFlags() const
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:267
const MCExpr * getExpr(const MachineOperand &MO, MCSymbolRefExpr::VariantKind Kind) const
int64_t getOffset() const
MCSymbol * getSymbol() const
void setOpcode(unsigned Op)
Definition: MCInst.h:157
static const MCBinaryExpr * CreateAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:396
MachineOperandType getType() const
static MCOperand CreateImm(int64_t Val)
Definition: MCInst.h:117
#define I(x, y, z)
Definition: MD5.cpp:54
MCSymbol * GetBlockAddressSymbol(const BlockAddress *BA) const
MCSymbol * GetCPISymbol(unsigned CPID) const
GetCPISymbol - Return the symbol for the specified constant pool entry.
unsigned getReg() const
getReg - Returns the register number.
Address of a basic block.
void addOperand(const MCOperand &Op)
Definition: MCInst.h:167
const BlockAddress * getBlockAddress() const
void lower(const MachineInstr *MI, MCInst &OutMI) const
MCSymbol * GetExternalSymbolSymbol(StringRef Sym) const
MachineBasicBlock reference.
Address of a global value.
Name of external global symbol.