2012-03-17 17:39:20 +08:00
|
|
|
//===-- HexagonMCTargetDesc.cpp - Hexagon Target Descriptions -------------===//
|
2011-12-16 06:29:08 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-03-17 17:28:37 +08:00
|
|
|
// This file provides Hexagon specific target descriptions.
|
2011-12-16 06:29:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "HexagonTargetStreamer.h"
|
2014-11-21 05:56:35 +08:00
|
|
|
#include "MCTargetDesc/HexagonInstPrinter.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCAsmInfo.h"
|
|
|
|
#include "MCTargetDesc/HexagonMCELFStreamer.h"
|
2016-12-17 09:17:18 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCInstrInfo.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCTargetDesc.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2015-06-17 11:06:16 +08:00
|
|
|
#include "llvm/MC/MCContext.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "llvm/MC/MCDwarf.h"
|
2014-11-07 01:05:51 +08:00
|
|
|
#include "llvm/MC/MCELFStreamer.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2013-02-21 00:13:27 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2015-06-17 11:06:16 +08:00
|
|
|
#include "llvm/Support/ELF.h"
|
2012-02-05 15:21:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <new>
|
|
|
|
#include <string>
|
2011-12-16 06:29:08 +08:00
|
|
|
|
2014-04-22 10:03:14 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-12-16 06:29:08 +08:00
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "HexagonGenInstrInfo.inc"
|
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "HexagonGenSubtargetInfo.inc"
|
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "HexagonGenRegisterInfo.inc"
|
|
|
|
|
2015-11-09 12:07:48 +08:00
|
|
|
cl::opt<bool> llvm::HexagonDisableCompound
|
|
|
|
("mno-compound",
|
|
|
|
cl::desc("Disable looking for compound instructions for Hexagon"));
|
|
|
|
|
|
|
|
cl::opt<bool> llvm::HexagonDisableDuplex
|
|
|
|
("mno-pairing",
|
|
|
|
cl::desc("Disable looking for duplex instructions for Hexagon"));
|
|
|
|
|
2016-04-21 05:17:40 +08:00
|
|
|
static cl::opt<bool> HexagonV4ArchVariant("mv4", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Build for Hexagon V4"));
|
|
|
|
|
|
|
|
static cl::opt<bool> HexagonV5ArchVariant("mv5", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Build for Hexagon V5"));
|
|
|
|
|
|
|
|
static cl::opt<bool> HexagonV55ArchVariant("mv55", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Build for Hexagon V55"));
|
|
|
|
|
|
|
|
static cl::opt<bool> HexagonV60ArchVariant("mv60", cl::Hidden, cl::init(false),
|
|
|
|
cl::desc("Build for Hexagon V60"));
|
|
|
|
|
|
|
|
static StringRef DefaultArch = "hexagonv60";
|
|
|
|
|
|
|
|
static StringRef HexagonGetArchVariant() {
|
|
|
|
if (HexagonV4ArchVariant)
|
|
|
|
return "hexagonv4";
|
|
|
|
if (HexagonV5ArchVariant)
|
|
|
|
return "hexagonv5";
|
|
|
|
if (HexagonV55ArchVariant)
|
|
|
|
return "hexagonv55";
|
|
|
|
if (HexagonV60ArchVariant)
|
|
|
|
return "hexagonv60";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-08-19 22:09:47 +08:00
|
|
|
StringRef Hexagon_MC::selectHexagonCPU(const Triple &TT, StringRef CPU) {
|
2016-04-21 05:17:40 +08:00
|
|
|
StringRef ArchV = HexagonGetArchVariant();
|
|
|
|
if (!ArchV.empty() && !CPU.empty()) {
|
|
|
|
if (ArchV != CPU)
|
|
|
|
report_fatal_error("conflicting architectures specified.");
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
if (ArchV.empty()) {
|
|
|
|
if (CPU.empty())
|
|
|
|
CPU = DefaultArch;
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
return ArchV;
|
2015-12-14 23:03:54 +08:00
|
|
|
}
|
|
|
|
|
2015-02-20 01:38:39 +08:00
|
|
|
MCInstrInfo *llvm::createHexagonMCInstrInfo() {
|
2011-12-16 06:29:08 +08:00
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitHexagonMCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCRegisterInfo *createHexagonMCRegisterInfo(const Triple &TT) {
|
2011-12-16 06:29:08 +08:00
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
2016-04-26 05:05:19 +08:00
|
|
|
InitHexagonMCRegisterInfo(X, Hexagon::R31);
|
2011-12-16 06:29:08 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCSubtargetInfo *
|
|
|
|
createHexagonMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
|
2016-08-19 22:09:47 +08:00
|
|
|
CPU = Hexagon_MC::selectHexagonCPU(TT, CPU);
|
2015-12-14 23:03:54 +08:00
|
|
|
return createHexagonMCSubtargetInfoImpl(TT, CPU, FS);
|
2011-12-16 06:29:08 +08:00
|
|
|
}
|
|
|
|
|
2015-06-19 04:43:50 +08:00
|
|
|
namespace {
|
2016-12-17 09:09:05 +08:00
|
|
|
|
2015-06-19 04:43:50 +08:00
|
|
|
class HexagonTargetAsmStreamer : public HexagonTargetStreamer {
|
|
|
|
public:
|
|
|
|
HexagonTargetAsmStreamer(MCStreamer &S,
|
2015-06-19 05:03:13 +08:00
|
|
|
formatted_raw_ostream &, bool,
|
|
|
|
MCInstPrinter &)
|
|
|
|
: HexagonTargetStreamer(S) {}
|
2016-12-17 09:09:05 +08:00
|
|
|
|
2015-06-19 04:43:50 +08:00
|
|
|
void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
|
|
|
|
const MCInst &Inst, const MCSubtargetInfo &STI) override {
|
|
|
|
assert(HexagonMCInstrInfo::isBundle(Inst));
|
|
|
|
assert(HexagonMCInstrInfo::bundleSize(Inst) <= HEXAGON_PACKET_SIZE);
|
|
|
|
std::string Buffer;
|
|
|
|
{
|
|
|
|
raw_string_ostream TempStream(Buffer);
|
|
|
|
InstPrinter.printInst(&Inst, TempStream, "", STI);
|
|
|
|
}
|
|
|
|
StringRef Contents(Buffer);
|
|
|
|
auto PacketBundle = Contents.rsplit('\n');
|
|
|
|
auto HeadTail = PacketBundle.first.split('\n');
|
2015-11-10 08:22:00 +08:00
|
|
|
StringRef Separator = "\n";
|
|
|
|
StringRef Indent = "\t\t";
|
|
|
|
OS << "\t{\n";
|
|
|
|
while (!HeadTail.first.empty()) {
|
|
|
|
StringRef InstTxt;
|
2015-06-19 04:43:50 +08:00
|
|
|
auto Duplex = HeadTail.first.split('\v');
|
2015-11-10 08:22:00 +08:00
|
|
|
if (!Duplex.second.empty()) {
|
|
|
|
OS << Indent << Duplex.first << Separator;
|
|
|
|
InstTxt = Duplex.second;
|
|
|
|
} else if (!HeadTail.first.trim().startswith("immext")) {
|
|
|
|
InstTxt = Duplex.first;
|
2015-06-19 04:43:50 +08:00
|
|
|
}
|
2015-11-10 08:22:00 +08:00
|
|
|
if (!InstTxt.empty())
|
|
|
|
OS << Indent << InstTxt << Separator;
|
2015-06-19 04:43:50 +08:00
|
|
|
HeadTail = HeadTail.second.split('\n');
|
|
|
|
}
|
2015-11-10 08:22:00 +08:00
|
|
|
OS << "\t}" << PacketBundle.second;
|
2015-06-19 04:43:50 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-17 11:06:16 +08:00
|
|
|
class HexagonTargetELFStreamer : public HexagonTargetStreamer {
|
|
|
|
public:
|
|
|
|
HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
|
|
|
|
: HexagonTargetStreamer(S) {
|
|
|
|
auto Bits = STI.getFeatureBits();
|
2016-04-25 20:49:47 +08:00
|
|
|
unsigned Flags = 0;
|
|
|
|
if (Bits[Hexagon::ArchV60])
|
|
|
|
Flags = ELF::EF_HEXAGON_MACH_V60;
|
|
|
|
else if (Bits[Hexagon::ArchV55])
|
|
|
|
Flags = ELF::EF_HEXAGON_MACH_V55;
|
|
|
|
else if (Bits[Hexagon::ArchV5])
|
2015-06-17 11:06:16 +08:00
|
|
|
Flags = ELF::EF_HEXAGON_MACH_V5;
|
2016-04-25 20:49:47 +08:00
|
|
|
else if (Bits[Hexagon::ArchV4])
|
2015-06-17 11:06:16 +08:00
|
|
|
Flags = ELF::EF_HEXAGON_MACH_V4;
|
|
|
|
getStreamer().getAssembler().setELFHeaderEFlags(Flags);
|
|
|
|
}
|
2016-12-17 09:09:05 +08:00
|
|
|
|
|
|
|
MCELFStreamer &getStreamer() {
|
|
|
|
return static_cast<MCELFStreamer &>(Streamer);
|
|
|
|
}
|
|
|
|
|
2015-06-17 11:06:16 +08:00
|
|
|
void EmitCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment,
|
|
|
|
unsigned AccessSize) override {
|
|
|
|
HexagonMCELFStreamer &HexagonELFStreamer =
|
|
|
|
static_cast<HexagonMCELFStreamer &>(getStreamer());
|
|
|
|
HexagonELFStreamer.HexagonMCEmitCommonSymbol(Symbol, Size, ByteAlignment,
|
|
|
|
AccessSize);
|
|
|
|
}
|
2016-12-17 09:09:05 +08:00
|
|
|
|
2015-06-17 11:06:16 +08:00
|
|
|
void EmitLocalCommonSymbolSorted(MCSymbol *Symbol, uint64_t Size,
|
|
|
|
unsigned ByteAlignment,
|
|
|
|
unsigned AccessSize) override {
|
|
|
|
HexagonMCELFStreamer &HexagonELFStreamer =
|
|
|
|
static_cast<HexagonMCELFStreamer &>(getStreamer());
|
|
|
|
HexagonELFStreamer.HexagonMCEmitLocalCommonSymbol(
|
|
|
|
Symbol, Size, ByteAlignment, AccessSize);
|
|
|
|
}
|
|
|
|
};
|
2016-12-17 09:09:05 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
2015-06-17 11:06:16 +08:00
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
static MCAsmInfo *createHexagonMCAsmInfo(const MCRegisterInfo &MRI,
|
2015-09-16 00:17:27 +08:00
|
|
|
const Triple &TT) {
|
2013-05-11 02:16:59 +08:00
|
|
|
MCAsmInfo *MAI = new HexagonMCAsmInfo(TT);
|
2011-12-16 06:29:08 +08:00
|
|
|
|
|
|
|
// VirtualFP = (R30 + #0).
|
2014-10-03 21:18:11 +08:00
|
|
|
MCCFIInstruction Inst =
|
|
|
|
MCCFIInstruction::createDefCfa(nullptr, Hexagon::R30, 0);
|
2013-05-13 09:16:13 +08:00
|
|
|
MAI->addInitialFrameState(Inst);
|
2011-12-16 06:29:08 +08:00
|
|
|
|
|
|
|
return MAI;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCInstPrinter *createHexagonMCInstPrinter(const Triple &T,
|
2015-03-31 08:10:04 +08:00
|
|
|
unsigned SyntaxVariant,
|
2014-10-16 02:27:40 +08:00
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
const MCInstrInfo &MII,
|
2015-03-31 08:10:04 +08:00
|
|
|
const MCRegisterInfo &MRI) {
|
2015-04-10 03:20:37 +08:00
|
|
|
if (SyntaxVariant == 0)
|
2015-06-17 11:06:16 +08:00
|
|
|
return (new HexagonInstPrinter(MAI, MII, MRI));
|
2015-04-10 03:20:37 +08:00
|
|
|
else
|
2015-06-17 11:06:16 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:51:40 +08:00
|
|
|
static MCTargetStreamer *createMCAsmTargetStreamer(MCStreamer &S,
|
|
|
|
formatted_raw_ostream &OS,
|
|
|
|
MCInstPrinter *InstPrint,
|
|
|
|
bool IsVerboseAsm) {
|
2015-06-19 04:43:50 +08:00
|
|
|
return new HexagonTargetAsmStreamer(S, OS, IsVerboseAsm, *InstPrint);
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCStreamer *createMCStreamer(Triple const &T, MCContext &Context,
|
2015-06-17 11:06:16 +08:00
|
|
|
MCAsmBackend &MAB, raw_pwrite_stream &OS,
|
|
|
|
MCCodeEmitter *Emitter, bool RelaxAll) {
|
|
|
|
return createHexagonELFStreamer(Context, MAB, OS, Emitter);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCTargetStreamer *
|
|
|
|
createHexagonObjectTargetStreamer(MCStreamer &S, MCSubtargetInfo const &STI) {
|
|
|
|
return new HexagonTargetELFStreamer(S, STI);
|
2014-10-16 02:27:40 +08:00
|
|
|
}
|
2011-12-16 06:29:08 +08:00
|
|
|
|
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeHexagonTargetMC() {
|
|
|
|
// Register the MC asm info.
|
2016-10-10 07:00:34 +08:00
|
|
|
RegisterMCAsmInfoFn X(getTheHexagonTarget(), createHexagonMCAsmInfo);
|
2011-12-16 06:29:08 +08:00
|
|
|
|
|
|
|
// Register the MC instruction info.
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCInstrInfo(getTheHexagonTarget(),
|
2014-10-03 21:18:11 +08:00
|
|
|
createHexagonMCInstrInfo);
|
2011-12-16 06:29:08 +08:00
|
|
|
|
|
|
|
// Register the MC register info.
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCRegInfo(getTheHexagonTarget(),
|
2011-12-16 06:29:08 +08:00
|
|
|
createHexagonMCRegisterInfo);
|
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(getTheHexagonTarget(),
|
2011-12-16 06:29:08 +08:00
|
|
|
createHexagonMCSubtargetInfo);
|
2014-10-03 21:18:11 +08:00
|
|
|
|
|
|
|
// Register the MC Code Emitter
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(getTheHexagonTarget(),
|
2014-10-03 21:18:11 +08:00
|
|
|
createHexagonMCCodeEmitter);
|
2014-10-16 02:27:40 +08:00
|
|
|
|
2015-06-04 01:34:16 +08:00
|
|
|
// Register the asm backend
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheHexagonTarget(),
|
2015-06-04 01:34:16 +08:00
|
|
|
createHexagonAsmBackend);
|
|
|
|
|
2015-06-17 11:06:16 +08:00
|
|
|
// Register the obj streamer
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterELFStreamer(getTheHexagonTarget(), createMCStreamer);
|
2015-06-17 11:06:16 +08:00
|
|
|
|
2015-06-19 04:43:50 +08:00
|
|
|
// Register the asm streamer
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterAsmTargetStreamer(getTheHexagonTarget(),
|
2015-06-19 04:43:50 +08:00
|
|
|
createMCAsmTargetStreamer);
|
|
|
|
|
2014-10-16 02:27:40 +08:00
|
|
|
// Register the MC Inst Printer
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCInstPrinter(getTheHexagonTarget(),
|
2014-10-16 02:27:40 +08:00
|
|
|
createHexagonMCInstPrinter);
|
2015-06-17 11:06:16 +08:00
|
|
|
|
|
|
|
TargetRegistry::RegisterObjectTargetStreamer(
|
2016-10-10 07:00:34 +08:00
|
|
|
getTheHexagonTarget(), createHexagonObjectTargetStreamer);
|
2011-12-16 06:29:08 +08:00
|
|
|
}
|