2013-05-07 00:15:19 +08:00
|
|
|
//===-- SystemZMCInstLower.cpp - Lower MachineInstr to MCInst -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SystemZMCInstLower.h"
|
|
|
|
#include "SystemZAsmPrinter.h"
|
2014-01-08 05:19:40 +08:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-05-07 00:15:19 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Return the VK_* enumeration for MachineOperand target flags Flags.
|
|
|
|
static MCSymbolRefExpr::VariantKind getVariantKind(unsigned Flags) {
|
|
|
|
switch (Flags & SystemZII::MO_SYMBOL_MODIFIER) {
|
|
|
|
case 0:
|
|
|
|
return MCSymbolRefExpr::VK_None;
|
|
|
|
case SystemZII::MO_GOT:
|
|
|
|
return MCSymbolRefExpr::VK_GOT;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unrecognised MO_ACCESS_MODEL");
|
|
|
|
}
|
|
|
|
|
2013-10-30 00:18:15 +08:00
|
|
|
SystemZMCInstLower::SystemZMCInstLower(MCContext &ctx,
|
2013-05-07 00:15:19 +08:00
|
|
|
SystemZAsmPrinter &asmprinter)
|
2013-10-30 00:18:15 +08:00
|
|
|
: Ctx(ctx), AsmPrinter(asmprinter) {}
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2013-09-25 18:37:17 +08:00
|
|
|
const MCExpr *
|
|
|
|
SystemZMCInstLower::getExpr(const MachineOperand &MO,
|
|
|
|
MCSymbolRefExpr::VariantKind Kind) const {
|
|
|
|
const MCSymbol *Symbol;
|
|
|
|
bool HasOffset = true;
|
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
Symbol = MO.getMBB()->getSymbol();
|
|
|
|
HasOffset = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2013-10-30 01:07:16 +08:00
|
|
|
Symbol = AsmPrinter.getSymbol(MO.getGlobal());
|
2013-09-25 18:37:17 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
Symbol = AsmPrinter.GetExternalSymbolSymbol(MO.getSymbolName());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
Symbol = AsmPrinter.GetJTISymbol(MO.getIndex());
|
|
|
|
HasOffset = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
Symbol = AsmPrinter.GetCPISymbol(MO.getIndex());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
Symbol = AsmPrinter.GetBlockAddressSymbol(MO.getBlockAddress());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown operand type");
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
2013-09-25 18:37:17 +08:00
|
|
|
const MCExpr *Expr = MCSymbolRefExpr::Create(Symbol, Kind, Ctx);
|
|
|
|
if (HasOffset)
|
|
|
|
if (int64_t Offset = MO.getOffset()) {
|
|
|
|
const MCExpr *OffsetExpr = MCConstantExpr::Create(Offset, Ctx);
|
|
|
|
Expr = MCBinaryExpr::CreateAdd(Expr, OffsetExpr, Ctx);
|
|
|
|
}
|
|
|
|
return Expr;
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MCOperand SystemZMCInstLower::lowerOperand(const MachineOperand &MO) const {
|
|
|
|
switch (MO.getType()) {
|
|
|
|
case MachineOperand::MO_Register:
|
|
|
|
return MCOperand::CreateReg(MO.getReg());
|
|
|
|
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
return MCOperand::CreateImm(MO.getImm());
|
|
|
|
|
2013-09-25 18:37:17 +08:00
|
|
|
default: {
|
|
|
|
MCSymbolRefExpr::VariantKind Kind = getVariantKind(MO.getTargetFlags());
|
|
|
|
return MCOperand::CreateExpr(getExpr(MO, Kind));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemZMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI) const {
|
2013-09-25 18:37:17 +08:00
|
|
|
OutMI.setOpcode(MI->getOpcode());
|
2013-05-07 00:15:19 +08:00
|
|
|
for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
|
|
|
|
const MachineOperand &MO = MI->getOperand(I);
|
2013-07-12 17:08:12 +08:00
|
|
|
// Ignore all implicit register operands.
|
|
|
|
if (!MO.isReg() || !MO.isImplicit())
|
|
|
|
OutMI.addOperand(lowerOperand(MO));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
}
|