2013-05-06 18:15:19 +02:00
|
|
|
//===-- SystemZAsmPrinter.cpp - SystemZ LLVM assembly printer -------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2013-05-06 18:15:19 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Streams SystemZ assembly language and associated data, in the form of
|
|
|
|
// MCInsts and MCExprs respectively.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SystemZAsmPrinter.h"
|
2019-05-11 05:36:16 +02:00
|
|
|
#include "MCTargetDesc/SystemZInstPrinter.h"
|
2013-05-06 18:15:19 +02:00
|
|
|
#include "SystemZConstantPoolValue.h"
|
|
|
|
#include "SystemZMCInstLower.h"
|
2019-05-15 02:46:18 +02:00
|
|
|
#include "TargetInfo/SystemZTargetInfo.h"
|
2013-05-06 18:15:19 +02:00
|
|
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2014-01-07 22:19:40 +01:00
|
|
|
#include "llvm/IR/Mangler.h"
|
2013-05-06 18:15:19 +02:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2013-09-25 12:20:08 +02:00
|
|
|
#include "llvm/MC/MCInstBuilder.h"
|
2013-05-06 18:15:19 +02:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2013-09-25 13:11:53 +02: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-22 18:28:28 +01: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 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
2013-10-01 15:18:56 +02: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-22 18:28:28 +01: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 15:18:56 +02:00
|
|
|
}
|
|
|
|
|
2013-10-01 13:26:28 +02: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 10:13:27 +01:00
|
|
|
static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
|
|
|
|
StringRef Name = "__tls_get_offset";
|
2015-05-30 03:25:56 +02:00
|
|
|
return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
|
2015-02-18 10:13:27 +01:00
|
|
|
MCSymbolRefExpr::VK_PLT,
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MCSymbolRefExpr *getGlobalOffsetTable(MCContext &Context) {
|
|
|
|
StringRef Name = "_GLOBAL_OFFSET_TABLE_";
|
2015-05-30 03:25:56 +02:00
|
|
|
return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
|
2015-02-18 10:13:27 +01:00
|
|
|
MCSymbolRefExpr::VK_None,
|
|
|
|
Context);
|
|
|
|
}
|
|
|
|
|
2019-06-19 16:20:00 +02:00
|
|
|
// MI is an instruction that accepts an optional alignment hint,
|
|
|
|
// and which was already lowered to LoweredMI. If the alignment
|
|
|
|
// of the original memory operand is known, update LoweredMI to
|
|
|
|
// an instruction with the corresponding hint set.
|
|
|
|
static void lowerAlignmentHint(const MachineInstr *MI, MCInst &LoweredMI,
|
|
|
|
unsigned Opcode) {
|
|
|
|
if (!MI->hasOneMemOperand())
|
|
|
|
return;
|
|
|
|
const MachineMemOperand *MMO = *MI->memoperands_begin();
|
|
|
|
unsigned AlignmentHint = 0;
|
|
|
|
if (MMO->getAlignment() >= 16)
|
|
|
|
AlignmentHint = 4;
|
|
|
|
else if (MMO->getAlignment() >= 8)
|
|
|
|
AlignmentHint = 3;
|
|
|
|
if (AlignmentHint == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LoweredMI.setOpcode(Opcode);
|
|
|
|
LoweredMI.addOperand(MCOperand::createImm(AlignmentHint));
|
|
|
|
}
|
|
|
|
|
2015-05-05 21:28:34 +02: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-06 18:15:19 +02:00
|
|
|
void SystemZAsmPrinter::EmitInstruction(const MachineInstr *MI) {
|
2013-10-29 17:18:15 +01:00
|
|
|
SystemZMCInstLower Lower(MF->getContext(), *this);
|
2013-05-06 18:15:19 +02:00
|
|
|
MCInst LoweredMI;
|
2013-09-25 12:20:08 +02:00
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case SystemZ::Return:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R14D);
|
|
|
|
break;
|
|
|
|
|
2016-04-07 18:11:44 +02: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 12:37:17 +02: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-08 19:22:19 +02: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 12:37:17 +02:00
|
|
|
case SystemZ::CallBR:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BR).addReg(SystemZ::R1D);
|
|
|
|
break;
|
|
|
|
|
2016-04-11 14:12:32 +02: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 10:13:27 +01: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 13:11:53 +02:00
|
|
|
case SystemZ::IILF64:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::IILF)
|
|
|
|
.addReg(SystemZMC::getRegAsGR32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
|
|
|
break;
|
|
|
|
|
2013-10-01 15:02:28 +02:00
|
|
|
case SystemZ::IIHF64:
|
|
|
|
LoweredMI = MCInstBuilder(SystemZ::IIHF)
|
|
|
|
.addReg(SystemZMC::getRegAsGRH32(MI->getOperand(0).getReg()))
|
|
|
|
.addImm(MI->getOperand(2).getImm());
|
|
|
|
break;
|
|
|
|
|
2013-10-01 13:26:28 +02: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-05 21:25:42 +02: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-05 21:28:34 +02: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;
|
|
|
|
|
2019-06-19 16:20:00 +02:00
|
|
|
case SystemZ::VL:
|
|
|
|
Lower.lower(MI, LoweredMI);
|
|
|
|
lowerAlignmentHint(MI, LoweredMI, SystemZ::VLAlign);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VST:
|
|
|
|
Lower.lower(MI, LoweredMI);
|
|
|
|
lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTAlign);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VLM:
|
|
|
|
Lower.lower(MI, LoweredMI);
|
|
|
|
lowerAlignmentHint(MI, LoweredMI, SystemZ::VLMAlign);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SystemZ::VSTM:
|
|
|
|
Lower.lower(MI, LoweredMI);
|
|
|
|
lowerAlignmentHint(MI, LoweredMI, SystemZ::VSTMAlign);
|
|
|
|
break;
|
|
|
|
|
2015-05-05 21:28:34 +02:00
|
|
|
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-05 21:27:45 +02: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 13:11:53 +02:00
|
|
|
#define LOWER_LOW(NAME) \
|
|
|
|
case SystemZ::NAME##64: LoweredMI = lowerRILow(MI, SystemZ::NAME); break
|
|
|
|
|
|
|
|
LOWER_LOW(IILL);
|
|
|
|
LOWER_LOW(IILH);
|
2013-11-22 18:28:28 +01:00
|
|
|
LOWER_LOW(TMLL);
|
|
|
|
LOWER_LOW(TMLH);
|
2013-09-25 13:11:53 +02: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 15:18:56 +02:00
|
|
|
#define LOWER_HIGH(NAME) \
|
|
|
|
case SystemZ::NAME##64: LoweredMI = lowerRIHigh(MI, SystemZ::NAME); break
|
|
|
|
|
|
|
|
LOWER_HIGH(IIHL);
|
|
|
|
LOWER_HIGH(IIHH);
|
2013-11-22 18:28:28 +01:00
|
|
|
LOWER_HIGH(TMHL);
|
|
|
|
LOWER_HIGH(TMHH);
|
2013-10-01 16:20:41 +02:00
|
|
|
LOWER_HIGH(NIHL);
|
|
|
|
LOWER_HIGH(NIHH);
|
|
|
|
LOWER_HIGH(NIHF);
|
2013-10-01 15:22:41 +02:00
|
|
|
LOWER_HIGH(OIHL);
|
|
|
|
LOWER_HIGH(OIHH);
|
|
|
|
LOWER_HIGH(OIHF);
|
2013-10-01 16:08:44 +02:00
|
|
|
LOWER_HIGH(XIHF);
|
2013-10-01 15:18:56 +02:00
|
|
|
|
|
|
|
#undef LOWER_HIGH
|
|
|
|
|
2013-12-10 11:36:34 +01:00
|
|
|
case SystemZ::Serialize:
|
2015-02-19 02:26:28 +01:00
|
|
|
if (MF->getSubtarget<SystemZSubtarget>().hasFastSerialization())
|
2016-11-08 19:30:50 +01:00
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
|
2013-12-10 11:36:34 +01:00
|
|
|
.addImm(14).addReg(SystemZ::R0D);
|
|
|
|
else
|
2016-11-08 19:30:50 +01:00
|
|
|
LoweredMI = MCInstBuilder(SystemZ::BCRAsm)
|
2013-12-10 11:36:34 +01:00
|
|
|
.addImm(15).addReg(SystemZ::R0D);
|
|
|
|
break;
|
|
|
|
|
2016-04-04 14:45:44 +02:00
|
|
|
// Emit nothing here but a comment if we can.
|
|
|
|
case SystemZ::MemBarrier:
|
|
|
|
OutStreamer->emitRawComment("MEMBARRIER");
|
|
|
|
return;
|
|
|
|
|
2016-06-10 21:58:10 +02: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-02 21:39:30 +01:00
|
|
|
case TargetOpcode::STACKMAP:
|
|
|
|
LowerSTACKMAP(*MI);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case TargetOpcode::PATCHPOINT:
|
|
|
|
LowerPATCHPOINT(*MI, Lower);
|
|
|
|
return;
|
|
|
|
|
2013-09-25 12:20:08 +02:00
|
|
|
default:
|
2013-09-25 12:37:17 +02:00
|
|
|
Lower.lower(MI, LoweredMI);
|
2013-09-25 12:20:08 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-04-24 21:11:51 +02:00
|
|
|
EmitToStreamer(*OutStreamer, LoweredMI);
|
2013-05-06 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
2018-03-02 21:39:30 +01: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-06 18:15:19 +02: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 10:13:27 +01:00
|
|
|
case SystemZCP::TLSGD: return MCSymbolRefExpr::VK_TLSGD;
|
|
|
|
case SystemZCP::TLSLDM: return MCSymbolRefExpr::VK_TLSLDM;
|
|
|
|
case SystemZCP::DTPOFF: return MCSymbolRefExpr::VK_DTPOFF;
|
2013-05-06 18:15:19 +02:00
|
|
|
case SystemZCP::NTPOFF: return MCSymbolRefExpr::VK_NTPOFF;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Invalid SystemCPModifier!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemZAsmPrinter::
|
|
|
|
EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
|
2014-03-06 12:22:58 +01:00
|
|
|
auto *ZCPV = static_cast<SystemZConstantPoolValue*>(MCPV);
|
2013-05-06 18:15:19 +02:00
|
|
|
|
|
|
|
const MCExpr *Expr =
|
2015-05-30 03:25:56 +02:00
|
|
|
MCSymbolRefExpr::create(getSymbol(ZCPV->getGlobalValue()),
|
2013-05-06 18:15:19 +02:00
|
|
|
getModifierVariantKind(ZCPV->getModifier()),
|
|
|
|
OutContext);
|
2015-07-16 08:11:10 +02:00
|
|
|
uint64_t Size = getDataLayout().getTypeAllocSize(ZCPV->getType());
|
2013-05-06 18:15:19 +02:00
|
|
|
|
2015-04-24 21:11:51 +02:00
|
|
|
OutStreamer->EmitValue(Expr, Size);
|
2013-05-06 18:15:19 +02:00
|
|
|
}
|
|
|
|
|
[AsmPrinter] refactor to remove remove AsmVariant. NFC
Summary:
The InlineAsm::AsmDialect is only required for X86; no architecture
makes use of it and as such it gets passed around between arch-specific
and general code while being unused for all architectures but X86.
Since the AsmDialect is queried from a MachineInstr, which we also pass
around, remove the additional AsmDialect parameter and query for it deep
in the X86AsmPrinter only when needed/as late as possible.
This refactor should help later planned refactors to AsmPrinter, as this
difference in the X86AsmPrinter makes it harder to make AsmPrinter more
generic.
Reviewers: craig.topper
Subscribers: jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, nhaehnle, javed.absar, sbc100, jgravelle-google, eraman, hiraditya, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, jsji, llvm-commits, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60488
llvm-svn: 358101
2019-04-10 18:38:43 +02:00
|
|
|
bool SystemZAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
|
2013-05-06 18:15:19 +02:00
|
|
|
const char *ExtraCode,
|
|
|
|
raw_ostream &OS) {
|
[AsmPrinter] refactor to support %c w/ GlobalAddress'
Summary:
Targets like ARM, MSP430, PPC, and SystemZ have complex behavior when
printing the address of a MachineOperand::MO_GlobalAddress. Move that
handling into a new overriden method in each base class. A virtual
method was added to the base class for handling the generic case.
Refactors a few subclasses to support the target independent %a, %c, and
%n.
The patch also contains small cleanups for AVRAsmPrinter and
SystemZAsmPrinter.
It seems that NVPTXTargetLowering is possibly missing some logic to
transform GlobalAddressSDNodes for
TargetLowering::LowerAsmOperandForConstraint to handle with "i" extended
inline assembly asm constraints.
Fixes:
- https://bugs.llvm.org/show_bug.cgi?id=41402
- https://github.com/ClangBuiltLinux/linux/issues/449
Reviewers: echristo, void
Reviewed By: void
Subscribers: void, craig.topper, jholewinski, dschuff, jyknight, dylanmckay, sdardis, nemanjai, javed.absar, sbc100, jgravelle-google, eraman, kristof.beyls, hiraditya, aheejin, kbarton, fedor.sergeev, jrtc27, atanasyan, jsji, llvm-commits, kees, tpimh, nathanchance, peter.smith, srhines
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60887
llvm-svn: 359337
2019-04-26 20:45:04 +02:00
|
|
|
if (ExtraCode)
|
|
|
|
return AsmPrinter::PrintAsmOperand(MI, OpNo, ExtraCode, OS);
|
|
|
|
SystemZMCInstLower Lower(MF->getContext(), *this);
|
|
|
|
MCOperand MO(Lower.lowerOperand(MI->getOperand(OpNo)));
|
|
|
|
SystemZInstPrinter::printOperand(MO, MAI, OS);
|
2013-05-06 18:15:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemZAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|
|
|
unsigned OpNo,
|
|
|
|
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-02 21:39:30 +01:00
|
|
|
void SystemZAsmPrinter::EmitEndOfAsmFile(Module &M) {
|
2018-11-26 19:43:48 +01:00
|
|
|
emitStackMaps(SM);
|
2018-03-02 21:39:30 +01:00
|
|
|
}
|
|
|
|
|
2013-05-06 18:15:19 +02:00
|
|
|
// Force static initialization.
|
2019-06-11 05:21:13 +02:00
|
|
|
extern "C" void LLVMInitializeSystemZAsmPrinter() {
|
2016-10-10 01:00:34 +02:00
|
|
|
RegisterAsmPrinter<SystemZAsmPrinter> X(getTheSystemZTarget());
|
2013-05-06 18:15:19 +02:00
|
|
|
}
|