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());
|
|
|
|
}
|
|
|
|
|
2015-02-18 17:13:27 +08:00
|
|
|
static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
|
|
|
|
StringRef Name = "__tls_get_offset";
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
|
2015-02-18 17:13:27 +08:00
|
|
|
MCSymbolRefExpr::VK_PLT,
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MCSymbolRefExpr *getGlobalOffsetTable(MCContext &Context) {
|
|
|
|
StringRef Name = "_GLOBAL_OFFSET_TABLE_";
|
2015-05-30 09:25:56 +08:00
|
|
|
return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
|
2015-02-18 17:13:27 +08:00
|
|
|
MCSymbolRefExpr::VK_None,
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
2015-05-06 03:28:34 +08:00
|
|
|
// MI loads the high part of a vector from memory. Return an instruction
|
|
|
|
// that uses replicating vector load Opcode to do the same thing.
|
|
|
|
static MCInst lowerSubvectorLoad(const MachineInstr *MI, unsigned Opcode) {
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(MI->getOperand(3).getReg());
|
|
|
|
}
|
|
|
|
|
|
|
|
// MI stores the high part of a vector to memory. Return an instruction
|
|
|
|
// that uses elemental vector store Opcode to do the same thing.
|
|
|
|
static MCInst lowerSubvectorStore(const MachineInstr *MI, unsigned Opcode) {
|
|
|
|
return MCInstBuilder(Opcode)
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(MI->getOperand(3).getReg())
|
|
|
|
.addImm(0);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2016-04-08 00:11:44 +08:00
|
|
|
case SystemZ::CondReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCR)
|
|
|
|
.addImm(MI->getOperand(0).getImm())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addReg(SystemZ::R14D);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CRBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CGRBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CGRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CIBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CGIBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CGIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLRBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLGRBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLGRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLIBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLGIBReturn:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLGIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addImm(0);
|
|
|
|
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;
|
|
|
|
|
2016-04-09 01:22:19 +08:00
|
|
|
case SystemZ::CallBRCL:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BRCL)
|
|
|
|
.addImm(MI->getOperand(0).getImm())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addExpr(Lower.getExpr(MI->getOperand(2), MCSymbolRefExpr::VK_PLT));
|
|
|
|
break;
|
|
|
|
|
2013-09-25 18:37:17 +08:00
|
|
|
case SystemZ::CallBR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R1D);
|
|
|
|
break;
|
|
|
|
|
2016-04-11 20:12:32 +08:00
|
|
|
case SystemZ::CallBCR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCR)
|
|
|
|
.addImm(MI->getOperand(0).getImm())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addReg(SystemZ::R1D);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CRBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CGRBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CGRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CIBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CGIBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CGIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLRBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLGRBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLGRB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLIBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::CLGIBCall:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::CLGIB)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addImm(MI->getOperand(2).getImm())
|
|
|
|
.addReg(SystemZ::R1D)
|
|
|
|
.addImm(0);
|
|
|
|
break;
|
|
|
|
|
2015-02-18 17:13:27 +08:00
|
|
|
case SystemZ::TLS_GDCALL:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BRASL)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addExpr(getTLSGetOffset(MF->getContext()))
|
|
|
|
.addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_TLSGD));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::TLS_LDCALL:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BRASL)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addExpr(getTLSGetOffset(MF->getContext()))
|
|
|
|
.addExpr(Lower.getExpr(MI->getOperand(0), MCSymbolRefExpr::VK_TLSLDM));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::GOT:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::LARL)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addExpr(getGlobalOffsetTable(MF->getContext()));
|
|
|
|
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;
|
|
|
|
|
[SystemZ] Add CodeGen support for integer vector types
This the first of a series of patches to add CodeGen support exploiting
the instructions of the z13 vector facility. This patch adds support
for the native integer vector types (v16i8, v8i16, v4i32, v2i64).
When the vector facility is present, we default to the new vector ABI.
This is characterized by two major differences:
- Vector types are passed/returned in vector registers
(except for unnamed arguments of a variable-argument list function).
- Vector types are at most 8-byte aligned.
The reason for the choice of 8-byte vector alignment is that the hardware
is able to efficiently load vectors at 8-byte alignment, and the ABI only
guarantees 8-byte alignment of the stack pointer, so requiring any higher
alignment for vectors would require dynamic stack re-alignment code.
However, for compatibility with old code that may use vector types, when
*not* using the vector facility, the old alignment rules (vector types
are naturally aligned) remain in use.
These alignment rules are not only implemented at the C language level
(implemented in clang), but also at the LLVM IR level. This is done
by selecting a different DataLayout string depending on whether the
vector ABI is in effect or not.
Based on a patch by Richard Sandiford.
llvm-svn: 236521
2015-05-06 03:25:42 +08:00
|
|
|
case SystemZ::VLVGP32:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::VLVGP)
|
|
|
|
.addReg(MI->getOperand(0).getReg())
|
|
|
|
.addReg(SystemZMC::getRegAsGR64(MI->getOperand(1).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsGR64(MI->getOperand(2).getReg()));
|
|
|
|
break;
|
|
|
|
|
2015-05-06 03:28:34 +08:00
|
|
|
case SystemZ::VLR32:
|
|
|
|
case SystemZ::VLR64:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::VLR)
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VL32:
|
|
|
|
LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VL64:
|
|
|
|
LoweredMI = lowerSubvectorLoad(MI, SystemZ::VLREPG);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VST32:
|
|
|
|
LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEF);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VST64:
|
|
|
|
LoweredMI = lowerSubvectorStore(MI, SystemZ::VSTEG);
|
|
|
|
break;
|
|
|
|
|
2015-05-06 03:27:45 +08:00
|
|
|
case SystemZ::LFER:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::VLGVF)
|
|
|
|
.addReg(SystemZMC::getRegAsGR64(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(1).getReg()))
|
|
|
|
.addReg(0).addImm(0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::LEFR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::VLVGF)
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(SystemZMC::getRegAsVR128(MI->getOperand(0).getReg()))
|
|
|
|
.addReg(MI->getOperand(1).getReg())
|
|
|
|
.addReg(0).addImm(0);
|
|
|
|
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:
|
2015-02-19 09:26:28 +08:00
|
|
|
if (MF->getSubtarget<SystemZSubtarget>().hasFastSerialization())
|
2016-11-09 02:30:50 +08:00
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
|
2013-12-10 18:36:34 +08:00
|
|
|
.addImm(14).addReg(SystemZ::R0D);
|
|
|
|
else
|
2016-11-09 02:30:50 +08:00
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
|
2013-12-10 18:36:34 +08:00
|
|
|
.addImm(15).addReg(SystemZ::R0D);
|
|
|
|
break;
|
|
|
|
|
2016-04-04 20:45:44 +08:00
|
|
|
// Emit nothing here but a comment if we can.
|
|
|
|
case SystemZ::MemBarrier:
|
|
|
|
OutStreamer->emitRawComment("MEMBARRIER");
|
|
|
|
return;
|
|
|
|
|
2016-06-11 03:58:10 +08:00
|
|
|
// We want to emit "j .+2" for traps, jumping to the relative immediate field
|
|
|
|
// of the jump instruction, which is an illegal instruction. We cannot emit a
|
|
|
|
// "." symbol, so create and emit a temp label before the instruction and use
|
|
|
|
// that instead.
|
|
|
|
case SystemZ::Trap: {
|
|
|
|
MCSymbol *DotSym = OutContext.createTempSymbol();
|
|
|
|
OutStreamer->EmitLabel(DotSym);
|
|
|
|
|
|
|
|
const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(DotSym, OutContext);
|
|
|
|
const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::J)
|
|
|
|
.addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Conditional traps will create a branch on condition instruction that jumps
|
|
|
|
// to the relative immediate field of the jump instruction. (eg. "jo .+2")
|
|
|
|
case SystemZ::CondTrap: {
|
|
|
|
MCSymbol *DotSym = OutContext.createTempSymbol();
|
|
|
|
OutStreamer->EmitLabel(DotSym);
|
|
|
|
|
|
|
|
const MCSymbolRefExpr *Expr = MCSymbolRefExpr::create(DotSym, OutContext);
|
|
|
|
const MCConstantExpr *ConstExpr = MCConstantExpr::create(2, OutContext);
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BRC)
|
|
|
|
.addImm(MI->getOperand(0).getImm())
|
|
|
|
.addImm(MI->getOperand(1).getImm())
|
|
|
|
.addExpr(MCBinaryExpr::createAdd(Expr, ConstExpr, OutContext));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-03-03 04:39:30 +08:00
|
|
|
case TargetOpcode::STACKMAP:
|
|
|
|
LowerSTACKMAP(*MI);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TargetOpcode::PATCHPOINT:
|
|
|
|
LowerPATCHPOINT(*MI, Lower);
|
|
|
|
return;
|
|
|
|
|
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;
|
|
|
|
}
|
2015-04-25 03:11:51 +08:00
|
|
|
EmitToStreamer(*OutStreamer, LoweredMI);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
2018-03-03 04:39:30 +08:00
|
|
|
|
|
|
|
// Emit the largest nop instruction smaller than or equal to NumBytes
|
|
|
|
// bytes. Return the size of nop emitted.
|
|
|
|
static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer,
|
|
|
|
unsigned NumBytes, const MCSubtargetInfo &STI) {
|
|
|
|
if (NumBytes < 2) {
|
|
|
|
llvm_unreachable("Zero nops?");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (NumBytes < 4) {
|
|
|
|
OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BCRAsm)
|
|
|
|
.addImm(0).addReg(SystemZ::R0D), STI);
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
else if (NumBytes < 6) {
|
|
|
|
OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BCAsm)
|
|
|
|
.addImm(0).addReg(0).addImm(0).addReg(0),
|
|
|
|
STI);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MCSymbol *DotSym = OutContext.createTempSymbol();
|
|
|
|
const MCSymbolRefExpr *Dot = MCSymbolRefExpr::create(DotSym, OutContext);
|
|
|
|
OutStreamer.EmitInstruction(MCInstBuilder(SystemZ::BRCLAsm)
|
|
|
|
.addImm(0).addExpr(Dot), STI);
|
|
|
|
OutStreamer.EmitLabel(DotSym);
|
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
|
|
|
|
const SystemZInstrInfo *TII =
|
|
|
|
static_cast<const SystemZInstrInfo *>(MF->getSubtarget().getInstrInfo());
|
|
|
|
|
|
|
|
unsigned NumNOPBytes = MI.getOperand(1).getImm();
|
|
|
|
|
|
|
|
SM.recordStackMap(MI);
|
|
|
|
assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
|
|
|
|
|
|
|
|
// Scan ahead to trim the shadow.
|
|
|
|
unsigned ShadowBytes = 0;
|
|
|
|
const MachineBasicBlock &MBB = *MI.getParent();
|
|
|
|
MachineBasicBlock::const_iterator MII(MI);
|
|
|
|
++MII;
|
|
|
|
while (ShadowBytes < NumNOPBytes) {
|
|
|
|
if (MII == MBB.end() ||
|
|
|
|
MII->getOpcode() == TargetOpcode::PATCHPOINT ||
|
|
|
|
MII->getOpcode() == TargetOpcode::STACKMAP)
|
|
|
|
break;
|
|
|
|
ShadowBytes += TII->getInstSizeInBytes(*MII);
|
|
|
|
if (MII->isCall())
|
|
|
|
break;
|
|
|
|
++MII;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit nops.
|
|
|
|
while (ShadowBytes < NumNOPBytes)
|
|
|
|
ShadowBytes += EmitNop(OutContext, *OutStreamer, NumNOPBytes - ShadowBytes,
|
|
|
|
getSubtargetInfo());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lower a patchpoint of the form:
|
|
|
|
// [<def>], <id>, <numBytes>, <target>, <numArgs>
|
|
|
|
void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
|
|
|
|
SystemZMCInstLower &Lower) {
|
|
|
|
SM.recordPatchPoint(MI);
|
|
|
|
PatchPointOpers Opers(&MI);
|
|
|
|
|
|
|
|
unsigned EncodedBytes = 0;
|
|
|
|
const MachineOperand &CalleeMO = Opers.getCallTarget();
|
|
|
|
|
|
|
|
if (CalleeMO.isImm()) {
|
|
|
|
uint64_t CallTarget = CalleeMO.getImm();
|
|
|
|
if (CallTarget) {
|
|
|
|
unsigned ScratchIdx = -1;
|
|
|
|
unsigned ScratchReg = 0;
|
|
|
|
do {
|
|
|
|
ScratchIdx = Opers.getNextScratchIdx(ScratchIdx + 1);
|
|
|
|
ScratchReg = MI.getOperand(ScratchIdx).getReg();
|
|
|
|
} while (ScratchReg == SystemZ::R0D);
|
|
|
|
|
|
|
|
// Materialize the call target address
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::LLILF)
|
|
|
|
.addReg(ScratchReg)
|
|
|
|
.addImm(CallTarget & 0xFFFFFFFF));
|
|
|
|
EncodedBytes += 6;
|
|
|
|
if (CallTarget >> 32) {
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::IIHF)
|
|
|
|
.addReg(ScratchReg)
|
|
|
|
.addImm(CallTarget >> 32));
|
|
|
|
EncodedBytes += 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BASR)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addReg(ScratchReg));
|
|
|
|
EncodedBytes += 2;
|
|
|
|
}
|
|
|
|
} else if (CalleeMO.isGlobal()) {
|
|
|
|
const MCExpr *Expr = Lower.getExpr(CalleeMO, MCSymbolRefExpr::VK_PLT);
|
|
|
|
EmitToStreamer(*OutStreamer, MCInstBuilder(SystemZ::BRASL)
|
|
|
|
.addReg(SystemZ::R14D)
|
|
|
|
.addExpr(Expr));
|
|
|
|
EncodedBytes += 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit padding.
|
|
|
|
unsigned NumBytes = Opers.getNumPatchBytes();
|
|
|
|
assert(NumBytes >= EncodedBytes &&
|
|
|
|
"Patchpoint can't request size less than the length of a call.");
|
|
|
|
assert((NumBytes - EncodedBytes) % 2 == 0 &&
|
|
|
|
"Invalid number of NOP bytes requested!");
|
|
|
|
while (EncodedBytes < NumBytes)
|
|
|
|
EncodedBytes += EmitNop(OutContext, *OutStreamer, NumBytes - EncodedBytes,
|
|
|
|
getSubtargetInfo());
|
|
|
|
}
|
|
|
|
|
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) {
|
2015-02-18 17:13:27 +08:00
|
|
|
case SystemZCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
|
|
|
|
case SystemZCP::TLSLDM: return MCSymbolRefExpr::VK_TLSLDM;
|
|
|
|
case SystemZCP::DTPOFF: return MCSymbolRefExpr::VK_DTPOFF;
|
2013-05-07 00:15:19 +08:00
|
|
|
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 =
|
2015-05-30 09:25:56 +08:00
|
|
|
MCSymbolRefExpr::create(getSymbol(ZCPV->getGlobalValue()),
|
2013-05-07 00:15:19 +08:00
|
|
|
getModifierVariantKind(ZCPV->getModifier()),
|
|
|
|
OutContext);
|
2015-07-16 14:11:10 +08:00
|
|
|
uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
|
2013-05-07 00:15:19 +08:00
|
|
|
|
2015-04-25 03:11:51 +08:00
|
|
|
OutStreamer->EmitValue(Expr, Size);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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)));
|
2015-06-09 08:31:39 +08:00
|
|
|
SystemZInstPrinter::printOperand(MO, MAI, OS);
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-03 04:39:30 +08:00
|
|
|
void SystemZAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
|
|
|
SM.serializeToStackMapSection();
|
|
|
|
}
|
|
|
|
|
2013-05-07 00:15:19 +08:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeSystemZAsmPrinter() {
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterAsmPrinter<SystemZAsmPrinter> X(getTheSystemZTarget());
|
2013-05-07 00:15:19 +08:00
|
|
|
}
|