2013-05-07 00:15:19 +08:00
|
|
|
//===-- SystemZAsmPrinter.cpp - SystemZ LLVM assembly printer -------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Streams SystemZ assembly language and associated data, in the form of
|
|
|
|
// MCInsts and MCExprs respectively.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SystemZAsmPrinter.h"
|
|
|
|
#include "InstPrinter/SystemZInstPrinter.h"
|
|
|
|
#include "SystemZConstantPoolValue.h"
|
|
|
|
#include "SystemZMCInstLower.h"
|
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.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"
|
2013-09-25 18:20:08 +08:00
|
|
|
#include "llvm/MC/MCInstBuilder.h"
|
2013-05-07 00:15:19 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-09-25 19:11:53 +08:00
|
|
|
// Return an RI instruction like MI with opcode Opcode, but with the
|
|
|
|
// GR64 register operands turned into GR32s.
|
|
|
|
static MCInst lowerRILow(const MachineInstr *MI, unsigned Opcode) {
|
2013-11-23 01:28:28 +08:00
|
|
|
if (MI->isCompare())
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(1).getImm());
|
|
|
|
else
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsGR32(MI->getOperand(1).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
2013-09-25 19:11:53 +08:00
|
|
|
}
|
|
|
|
|
2013-10-01 21:18:56 +08:00
|
|
|
// Return an RI instruction like MI with opcode Opcode, but with the
|
|
|
|
// GR64 register operands turned into GRH32s.
|
|
|
|
static MCInst lowerRIHigh(const MachineInstr *MI, unsigned Opcode) {
|
2013-11-23 01:28:28 +08:00
|
|
|
if (MI->isCompare())
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(1).getImm());
|
|
|
|
else
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsGRH32(MI->getOperand(1).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
2013-10-01 21:18:56 +08:00
|
|
|
}
|
|
|
|
|
2013-10-01 19:26:28 +08:00
|
|
|
// Return an RI instruction like MI with opcode Opcode, but with the
|
|
|
|
// R2 register turned into a GR64.
|
|
|
|
static MCInst lowerRIEfLow(const MachineInstr *MI, unsigned Opcode) {
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()))
|
|
|
|
.addImm(MI->getOperand(3).getImm())
|
|
|
|
.addImm(MI->getOperand(4).getImm())
|
|
|
|
.addImm(MI->getOperand(5).getImm());
|
|
|
|
}
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
void SystemZAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
2013-10-30 00:18:15 +08:00
|
|
|
SystemZMCInstLower Lower(MF->getContext(), *this);
|
2013-05-07 00:15:19 +08:00
|
|
|
MCInst LoweredMI;
|
2013-09-25 18:20:08 +08:00
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case SystemZ::Return:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D);
|
|
|
|
break;
|
|
|
|
|
2013-09-25 18:37:17 +08:00
|
|
|
case SystemZ::CallBRASL:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BRASL)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CallBASR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BASR)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addReg(MI->getOperand(0).getReg());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CallJG:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::JG)
|
|
|
|
.addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_PLT));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CallBR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R1D);
|
|
|
|
break;
|
|
|
|
|
2013-09-25 19:11:53 +08:00
|
|
|
case SystemZ::IILF64:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::IILF)
|
|
|
|
.addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
|
|
|
break;
|
|
|
|
|
2013-10-01 21:02:28 +08:00
|
|
|
case SystemZ::IIHF64:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::IIHF)
|
|
|
|
.addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
|
|
|
break;
|
|
|
|
|
2013-10-01 19:26:28 +08:00
|
|
|
case SystemZ::RISBHH:
|
|
|
|
case SystemZ::RISBHL:
|
|
|
|
LoweredMI = lowerRIEfLow(MI, SystemZ::RISBHG);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::RISBLH:
|
|
|
|
case SystemZ::RISBLL:
|
|
|
|
LoweredMI = lowerRIEfLow(MI, SystemZ::RISBLG);
|
|
|
|
break;
|
|
|
|
|
2013-09-25 19:11:53 +08:00
|
|
|
#define LOWER_LOW(NAME) \
|
|
|
|
case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
|
|
|
|
|
|
|
|
LOWER_LOW(IILL);
|
|
|
|
LOWER_LOW(IILH);
|
2013-11-23 01:28:28 +08:00
|
|
|
LOWER_LOW(TMLL);
|
|
|
|
LOWER_LOW(TMLH);
|
2013-09-25 19:11:53 +08:00
|
|
|
LOWER_LOW(NILL);
|
|
|
|
LOWER_LOW(NILH);
|
|
|
|
LOWER_LOW(NILF);
|
|
|
|
LOWER_LOW(OILL);
|
|
|
|
LOWER_LOW(OILH);
|
|
|
|
LOWER_LOW(OILF);
|
|
|
|
LOWER_LOW(XILF);
|
|
|
|
|
|
|
|
#undef LOWER_LOW
|
|
|
|
|
2013-10-01 21:18:56 +08:00
|
|
|
#define LOWER_HIGH(NAME) \
|
|
|
|
case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
|
|
|
|
|
|
|
|
LOWER_HIGH(IIHL);
|
|
|
|
LOWER_HIGH(IIHH);
|
2013-11-23 01:28:28 +08:00
|
|
|
LOWER_HIGH(TMHL);
|
|
|
|
LOWER_HIGH(TMHH);
|
2013-10-01 22:20:41 +08:00
|
|
|
LOWER_HIGH(NIHL);
|
|
|
|
LOWER_HIGH(NIHH);
|
|
|
|
LOWER_HIGH(NIHF);
|
2013-10-01 21:22:41 +08:00
|
|
|
LOWER_HIGH(OIHL);
|
|
|
|
LOWER_HIGH(OIHH);
|
|
|
|
LOWER_HIGH(OIHF);
|
2013-10-01 22:08:44 +08:00
|
|
|
LOWER_HIGH(XIHF);
|
2013-10-01 21:18:56 +08:00
|
|
|
|
|
|
|
#undef LOWER_HIGH
|
|
|
|
|
2013-12-10 18:36:34 +08:00
|
|
|
case SystemZ::Serialize:
|
|
|
|
if (Subtarget->hasFastSerialization())
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::AsmBCR)
|
|
|
|
.addImm(14).addReg(SystemZ::R0D);
|
|
|
|
else
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::AsmBCR)
|
|
|
|
.addImm(15).addReg(SystemZ::R0D);
|
|
|
|
break;
|
|
|
|
|
2013-09-25 18:20:08 +08:00
|
|
|
default:
|
2013-09-25 18:37:17 +08:00
|
|
|
Lower.lower(MI, LoweredMI);
|
2013-09-25 18:20:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-01-29 07:12:42 +08:00
|
|
|
EmitToStreamer(OutStreamer, LoweredMI);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert a SystemZ-specific constant pool modifier into the associated
|
|
|
|
// MCSymbolRefExpr variant kind.
|
|
|
|
static MCSymbolRefExpr::VariantKind
|
|
|
|
getModifierVariantKind(SystemZCP::SystemZCPModifier Modifier) {
|
|
|
|
switch (Modifier) {
|
|
|
|
case SystemZCP::NTPOFF: return MCSymbolRefExpr::VK_NTPOFF;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid SystemCPModifier!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemZAsmPrinter::
|
|
|
|
EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2014-03-06 19:22:58 +08:00
|
|
|
auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
|
2013-05-07 00:15:19 +08:00
|
|
|
|
|
|
|
const MCExpr *Expr =
|
2013-10-30 01:07:16 +08:00
|
|
|
MCSymbolRefExpr::Create(getSymbol(ZCPV->getGlobalValue()),
|
2013-05-07 00:15:19 +08:00
|
|
|
getModifierVariantKind(ZCPV->getModifier()),
|
|
|
|
OutContext);
|
|
|
|
uint64_t Size = TM.getDataLayout()->getTypeAllocSize(ZCPV->getType());
|
|
|
|
|
|
|
|
OutStreamer.EmitValue(Expr, Size);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
if (ExtraCode && *ExtraCode == 'n') {
|
|
|
|
if (!MI->getOperand(OpNo).isImm())
|
|
|
|
return true;
|
|
|
|
OS << -int64_t(MI->getOperand(OpNo).getImm());
|
|
|
|
} else {
|
2013-10-30 00:18:15 +08:00
|
|
|
SystemZMCInstLower Lower(MF->getContext(), *this);
|
2013-05-07 00:15:19 +08:00
|
|
|
MCOperand MO(Lower.lowerOperand(MI->getOperand(OpNo)));
|
|
|
|
SystemZInstPrinter::printOperand(MO, OS);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo,
|
|
|
|
unsigned AsmVariant,
|
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
SystemZInstPrinter::printAddress(MI->getOperand(OpNo).getReg(),
|
|
|
|
MI->getOperand(OpNo + 1).getImm(),
|
|
|
|
MI->getOperand(OpNo + 2).getReg(), OS);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemZAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
|
|
|
if (Subtarget->isTargetELF()) {
|
2014-03-06 19:22:58 +08:00
|
|
|
auto &TLOFELF =
|
2013-05-07 00:15:19 +08:00
|
|
|
static_cast<const TargetLoweringObjectFileELF &>(getObjFileLowering());
|
|
|
|
|
|
|
|
MachineModuleInfoELF &MMIELF = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
|
|
|
|
|
|
|
// Output stubs for external and common global variables.
|
|
|
|
MachineModuleInfoELF::SymbolListTy Stubs = MMIELF.GetGVStubList();
|
|
|
|
if (!Stubs.empty()) {
|
|
|
|
OutStreamer.SwitchSection(TLOFELF.getDataRelSection());
|
|
|
|
const DataLayout *TD = TM.getDataLayout();
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
|
|
|
|
OutStreamer.EmitLabel(Stubs[i].first);
|
|
|
|
OutStreamer.EmitSymbolValue(Stubs[i].second.getPointer(),
|
2013-07-02 23:49:13 +08:00
|
|
|
TD->getPointerSize(0));
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
Stubs.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeSystemZAsmPrinter() {
|
|
|
|
RegisterAsmPrinter<SystemZAsmPrinter> X(TheSystemZTarget);
|
|
|
|
}
|