2012-03-17 17:39:20 +08:00
|
|
|
//===-- HexagonMCTargetDesc.cpp - Hexagon Target Descriptions -------------===//
|
2011-12-16 06:29:08 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08: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
|
2011-12-16 06:29:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-03-17 17:28:37 +08:00
|
|
|
// This file provides Hexagon specific target descriptions.
|
2011-12-16 06:29:08 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCTargetDesc.h"
|
2017-12-12 02:57:54 +08:00
|
|
|
#include "HexagonDepArch.h"
|
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"
|
2019-05-15 07:04:55 +08:00
|
|
|
#include "TargetInfo/HexagonTargetInfo.h"
|
2017-12-12 02:57:54 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2016-12-17 09:09:05 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-06-07 11:48:56 +08:00
|
|
|
#include "llvm/BinaryFormat/ELF.h"
|
2017-10-11 09:57:21 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCCodeEmitter.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"
|
2017-02-07 03:35:46 +08:00
|
|
|
#include "llvm/MC/MCInstrAnalysis.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
2018-05-19 02:26:45 +08:00
|
|
|
#include "llvm/MC/MCObjectWriter.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#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"
|
2012-02-05 15:21:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-12-16 06:29:08 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/Support/raw_ostream.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"));
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
namespace { // These flags are to be deprecated
|
|
|
|
cl::opt<bool> MV5("mv5", cl::Hidden, cl::desc("Build for Hexagon V5"),
|
|
|
|
cl::init(false));
|
|
|
|
cl::opt<bool> MV55("mv55", cl::Hidden, cl::desc("Build for Hexagon V55"),
|
|
|
|
cl::init(false));
|
|
|
|
cl::opt<bool> MV60("mv60", cl::Hidden, cl::desc("Build for Hexagon V60"),
|
|
|
|
cl::init(false));
|
|
|
|
cl::opt<bool> MV62("mv62", cl::Hidden, cl::desc("Build for Hexagon V62"),
|
|
|
|
cl::init(false));
|
|
|
|
cl::opt<bool> MV65("mv65", cl::Hidden, cl::desc("Build for Hexagon V65"),
|
|
|
|
cl::init(false));
|
2018-12-06 04:18:09 +08:00
|
|
|
cl::opt<bool> MV66("mv66", cl::Hidden, cl::desc("Build for Hexagon V66"),
|
|
|
|
cl::init(false));
|
2017-12-12 02:57:54 +08:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
cl::opt<Hexagon::ArchEnum>
|
|
|
|
EnableHVX("mhvx",
|
|
|
|
cl::desc("Enable Hexagon Vector eXtensions"),
|
|
|
|
cl::values(
|
|
|
|
clEnumValN(Hexagon::ArchEnum::V60, "v60", "Build for HVX v60"),
|
|
|
|
clEnumValN(Hexagon::ArchEnum::V62, "v62", "Build for HVX v62"),
|
|
|
|
clEnumValN(Hexagon::ArchEnum::V65, "v65", "Build for HVX v65"),
|
2018-12-06 04:18:09 +08:00
|
|
|
clEnumValN(Hexagon::ArchEnum::V66, "v66", "Build for HVX v66"),
|
|
|
|
// Sentinel for no value specified.
|
2018-10-20 01:31:11 +08:00
|
|
|
clEnumValN(Hexagon::ArchEnum::Generic, "", "")),
|
2018-12-06 04:18:09 +08:00
|
|
|
// Sentinel for flag not present.
|
2018-10-20 01:31:11 +08:00
|
|
|
cl::init(Hexagon::ArchEnum::NoArch), cl::ValueOptional);
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
static cl::opt<bool>
|
2018-10-20 01:31:11 +08:00
|
|
|
DisableHVX("mno-hvx", cl::Hidden,
|
|
|
|
cl::desc("Disable Hexagon Vector eXtensions"));
|
2016-04-21 05:17:40 +08:00
|
|
|
|
2017-03-10 01:05:11 +08:00
|
|
|
|
2016-04-21 05:17:40 +08:00
|
|
|
static StringRef DefaultArch = "hexagonv60";
|
|
|
|
|
|
|
|
static StringRef HexagonGetArchVariant() {
|
2017-12-12 02:57:54 +08:00
|
|
|
if (MV5)
|
2016-04-21 05:17:40 +08:00
|
|
|
return "hexagonv5";
|
2017-12-12 02:57:54 +08:00
|
|
|
if (MV55)
|
2016-04-21 05:17:40 +08:00
|
|
|
return "hexagonv55";
|
2017-12-12 02:57:54 +08:00
|
|
|
if (MV60)
|
2016-04-21 05:17:40 +08:00
|
|
|
return "hexagonv60";
|
2017-12-12 02:57:54 +08:00
|
|
|
if (MV62)
|
2017-02-11 07:46:45 +08:00
|
|
|
return "hexagonv62";
|
2017-12-12 02:57:54 +08:00
|
|
|
if (MV65)
|
|
|
|
return "hexagonv65";
|
2018-12-06 04:18:09 +08:00
|
|
|
if (MV66)
|
|
|
|
return "hexagonv66";
|
2016-04-21 05:17:40 +08:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
StringRef Hexagon_MC::selectHexagonCPU(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
|
|
|
}
|
|
|
|
|
2018-10-20 01:31:11 +08:00
|
|
|
unsigned llvm::HexagonGetLastSlot() { return HexagonItinerariesV5FU::SLOT3; }
|
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,
|
2017-02-07 03:35:46 +08:00
|
|
|
formatted_raw_ostream &OS,
|
|
|
|
bool isVerboseAsm,
|
|
|
|
MCInstPrinter &IP)
|
2015-06-19 05:03:13 +08:00
|
|
|
: 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";
|
2018-03-31 03:30:28 +08:00
|
|
|
StringRef Indent = "\t";
|
2015-11-10 08:22:00 +08:00
|
|
|
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');
|
|
|
|
}
|
2017-12-12 02:57:54 +08:00
|
|
|
|
|
|
|
if (HexagonMCInstrInfo::isMemReorderDisabled(Inst))
|
2018-03-31 03:30:28 +08:00
|
|
|
OS << "\n\t} :mem_noshuf" << PacketBundle.second;
|
2017-12-12 02:57:54 +08:00
|
|
|
else
|
|
|
|
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:
|
2017-02-07 03:35:46 +08:00
|
|
|
MCELFStreamer &getStreamer() {
|
|
|
|
return static_cast<MCELFStreamer &>(Streamer);
|
|
|
|
}
|
2015-06-17 11:06:16 +08:00
|
|
|
HexagonTargetELFStreamer(MCStreamer &S, MCSubtargetInfo const &STI)
|
|
|
|
: HexagonTargetStreamer(S) {
|
2017-02-07 03:35:46 +08:00
|
|
|
MCAssembler &MCA = getStreamer().getAssembler();
|
|
|
|
MCA.setELFHeaderEFlags(Hexagon_MC::GetELFFlags(STI));
|
2015-06-17 11:06:16 +08:00
|
|
|
}
|
2016-12-17 09:09:05 +08:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
llvm::MCInstrInfo *llvm::createHexagonMCInstrInfo() {
|
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitHexagonMCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCRegisterInfo *createHexagonMCRegisterInfo(const Triple &TT) {
|
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitHexagonMCRegisterInfo(X, Hexagon::R31);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
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 =
|
2017-02-07 03:35:46 +08:00
|
|
|
MCCFIInstruction::createDefCfa(nullptr,
|
|
|
|
MRI.getDwarfRegNum(Hexagon::R30, true), 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,
|
2017-02-07 03:35:46 +08:00
|
|
|
const MCRegisterInfo &MRI)
|
|
|
|
{
|
2015-04-10 03:20:37 +08:00
|
|
|
if (SyntaxVariant == 0)
|
2017-02-07 03:35:46 +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;
|
|
|
|
}
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
static MCTargetStreamer *
|
|
|
|
createMCAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS,
|
|
|
|
MCInstPrinter *IP, bool IsVerboseAsm) {
|
|
|
|
return new HexagonTargetAsmStreamer(S, OS, IsVerboseAsm, *IP);
|
2015-06-19 04:43:50 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 09:57:21 +08:00
|
|
|
static MCStreamer *createMCStreamer(Triple const &T, MCContext &Context,
|
|
|
|
std::unique_ptr<MCAsmBackend> &&MAB,
|
2018-05-19 02:26:45 +08:00
|
|
|
std::unique_ptr<MCObjectWriter> &&OW,
|
2017-10-12 07:34:47 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> &&Emitter,
|
|
|
|
bool RelaxAll) {
|
2018-05-19 02:26:45 +08:00
|
|
|
return createHexagonELFStreamer(T, Context, std::move(MAB), std::move(OW),
|
2017-10-12 07:34:47 +08:00
|
|
|
std::move(Emitter));
|
2015-06-17 11:06:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MCTargetStreamer *
|
2017-02-07 03:35:46 +08:00
|
|
|
createHexagonObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
2015-06-17 11:06:16 +08:00
|
|
|
return new HexagonTargetELFStreamer(S, STI);
|
2014-10-16 02:27:40 +08:00
|
|
|
}
|
2011-12-16 06:29:08 +08:00
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
static void LLVM_ATTRIBUTE_UNUSED clearFeature(MCSubtargetInfo* STI, uint64_t F) {
|
|
|
|
uint64_t FB = STI->getFeatureBits().to_ullong();
|
|
|
|
if (FB & (1ULL << F))
|
|
|
|
STI->ToggleFeature(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool LLVM_ATTRIBUTE_UNUSED checkFeature(MCSubtargetInfo* STI, uint64_t F) {
|
|
|
|
uint64_t FB = STI->getFeatureBits().to_ullong();
|
|
|
|
return (FB & (1ULL << F)) != 0;
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
namespace {
|
|
|
|
std::string selectHexagonFS(StringRef CPU, StringRef FS) {
|
|
|
|
SmallVector<StringRef, 3> Result;
|
|
|
|
if (!FS.empty())
|
|
|
|
Result.push_back(FS);
|
|
|
|
|
|
|
|
switch (EnableHVX) {
|
2018-10-20 01:31:11 +08:00
|
|
|
case Hexagon::ArchEnum::V5:
|
2017-12-12 02:57:54 +08:00
|
|
|
case Hexagon::ArchEnum::V55:
|
|
|
|
break;
|
|
|
|
case Hexagon::ArchEnum::V60:
|
|
|
|
Result.push_back("+hvxv60");
|
|
|
|
break;
|
|
|
|
case Hexagon::ArchEnum::V62:
|
|
|
|
Result.push_back("+hvxv62");
|
|
|
|
break;
|
|
|
|
case Hexagon::ArchEnum::V65:
|
|
|
|
Result.push_back("+hvxv65");
|
|
|
|
break;
|
2018-12-06 04:18:09 +08:00
|
|
|
case Hexagon::ArchEnum::V66:
|
|
|
|
Result.push_back("+hvxv66");
|
|
|
|
break;
|
2018-10-20 01:31:11 +08:00
|
|
|
case Hexagon::ArchEnum::Generic:{
|
2017-12-12 02:57:54 +08:00
|
|
|
Result.push_back(StringSwitch<StringRef>(CPU)
|
|
|
|
.Case("hexagonv60", "+hvxv60")
|
|
|
|
.Case("hexagonv62", "+hvxv62")
|
2018-12-06 04:18:09 +08:00
|
|
|
.Case("hexagonv65", "+hvxv65")
|
|
|
|
.Case("hexagonv66", "+hvxv66"));
|
2017-12-12 02:57:54 +08:00
|
|
|
break;
|
2017-03-10 01:05:11 +08:00
|
|
|
}
|
2018-10-20 01:31:11 +08:00
|
|
|
case Hexagon::ArchEnum::NoArch:
|
2017-12-12 02:57:54 +08:00
|
|
|
// Sentinal if -mhvx isn't specified
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return join(Result.begin(), Result.end(), ",");
|
|
|
|
}
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isCPUValid(std::string CPU)
|
|
|
|
{
|
2018-10-20 01:31:11 +08:00
|
|
|
std::vector<std::string> table {
|
|
|
|
"generic", "hexagonv5", "hexagonv55", "hexagonv60",
|
2018-12-06 04:18:09 +08:00
|
|
|
"hexagonv62", "hexagonv65", "hexagonv66",
|
2017-02-07 03:35:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return std::find(table.begin(), table.end(), CPU) != table.end();
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
namespace {
|
|
|
|
std::pair<std::string, std::string> selectCPUAndFS(StringRef CPU,
|
|
|
|
StringRef FS) {
|
|
|
|
std::pair<std::string, std::string> Result;
|
|
|
|
Result.first = Hexagon_MC::selectHexagonCPU(CPU);
|
|
|
|
Result.second = selectHexagonFS(Result.first, FS);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FeatureBitset Hexagon_MC::completeHVXFeatures(const FeatureBitset &S) {
|
|
|
|
using namespace Hexagon;
|
|
|
|
// Make sure that +hvx-length turns hvx on, and that "hvx" alone
|
|
|
|
// turns on hvxvNN, corresponding to the existing ArchVNN.
|
|
|
|
FeatureBitset FB = S;
|
2018-10-20 01:31:11 +08:00
|
|
|
unsigned CpuArch = ArchV5;
|
2018-12-06 04:18:09 +08:00
|
|
|
for (unsigned F : {ArchV66, ArchV65, ArchV62, ArchV60, ArchV55, ArchV5}) {
|
2017-12-12 02:57:54 +08:00
|
|
|
if (!FB.test(F))
|
|
|
|
continue;
|
|
|
|
CpuArch = F;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool UseHvx = false;
|
2018-04-04 00:06:36 +08:00
|
|
|
for (unsigned F : {ExtensionHVX, ExtensionHVX64B, ExtensionHVX128B}) {
|
2017-12-12 02:57:54 +08:00
|
|
|
if (!FB.test(F))
|
|
|
|
continue;
|
|
|
|
UseHvx = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bool HasHvxVer = false;
|
2018-12-06 04:18:09 +08:00
|
|
|
for (unsigned F : {ExtensionHVXV60, ExtensionHVXV62, ExtensionHVXV65,
|
|
|
|
ExtensionHVXV66}) {
|
2017-12-12 02:57:54 +08:00
|
|
|
if (!FB.test(F))
|
|
|
|
continue;
|
|
|
|
HasHvxVer = true;
|
|
|
|
UseHvx = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!UseHvx || HasHvxVer)
|
|
|
|
return FB;
|
|
|
|
|
|
|
|
// HasHvxVer is false, and UseHvx is true.
|
|
|
|
switch (CpuArch) {
|
2018-12-06 04:18:09 +08:00
|
|
|
case ArchV66:
|
|
|
|
FB.set(ExtensionHVXV66);
|
|
|
|
LLVM_FALLTHROUGH;
|
2017-12-12 02:57:54 +08:00
|
|
|
case ArchV65:
|
|
|
|
FB.set(ExtensionHVXV65);
|
2017-12-19 02:51:57 +08:00
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case ArchV62:
|
|
|
|
FB.set(ExtensionHVXV62);
|
|
|
|
LLVM_FALLTHROUGH;
|
|
|
|
case ArchV60:
|
|
|
|
FB.set(ExtensionHVXV60);
|
2017-12-12 02:57:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FB;
|
|
|
|
}
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
MCSubtargetInfo *Hexagon_MC::createHexagonMCSubtargetInfo(const Triple &TT,
|
|
|
|
StringRef CPU,
|
|
|
|
StringRef FS) {
|
2017-12-12 02:57:54 +08:00
|
|
|
std::pair<std::string, std::string> Features = selectCPUAndFS(CPU, FS);
|
|
|
|
StringRef CPUName = Features.first;
|
|
|
|
StringRef ArchFS = Features.second;
|
|
|
|
|
2017-02-11 07:46:45 +08:00
|
|
|
if (!isCPUValid(CPUName.str())) {
|
|
|
|
errs() << "error: invalid CPU \"" << CPUName.str().c_str()
|
|
|
|
<< "\" specified\n";
|
2017-02-07 03:35:46 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(TT, CPUName, ArchFS);
|
2017-12-12 02:57:54 +08:00
|
|
|
if (HexagonDisableDuplex) {
|
2017-02-07 03:35:46 +08:00
|
|
|
llvm::FeatureBitset Features = X->getFeatureBits();
|
2017-12-12 02:57:54 +08:00
|
|
|
X->setFeatureBits(Features.set(Hexagon::FeatureDuplex, false));
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
2017-12-12 02:57:54 +08:00
|
|
|
|
|
|
|
X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
|
2017-02-07 03:35:46 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned Hexagon_MC::GetELFFlags(const MCSubtargetInfo &STI) {
|
|
|
|
static std::map<StringRef,unsigned> ElfFlags = {
|
|
|
|
{"hexagonv5", ELF::EF_HEXAGON_MACH_V5},
|
|
|
|
{"hexagonv55", ELF::EF_HEXAGON_MACH_V55},
|
|
|
|
{"hexagonv60", ELF::EF_HEXAGON_MACH_V60},
|
2017-02-11 07:46:45 +08:00
|
|
|
{"hexagonv62", ELF::EF_HEXAGON_MACH_V62},
|
2017-12-12 02:57:54 +08:00
|
|
|
{"hexagonv65", ELF::EF_HEXAGON_MACH_V65},
|
2018-12-06 04:18:09 +08:00
|
|
|
{"hexagonv66", ELF::EF_HEXAGON_MACH_V66},
|
2017-02-07 03:35:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
auto F = ElfFlags.find(STI.getCPU());
|
|
|
|
assert(F != ElfFlags.end() && "Unrecognized Architecture");
|
|
|
|
return F->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
class HexagonMCInstrAnalysis : public MCInstrAnalysis {
|
|
|
|
public:
|
|
|
|
HexagonMCInstrAnalysis(MCInstrInfo const *Info) : MCInstrAnalysis(Info) {}
|
|
|
|
|
|
|
|
bool isUnconditionalBranch(MCInst const &Inst) const override {
|
|
|
|
//assert(!HexagonMCInstrInfo::isBundle(Inst));
|
|
|
|
return MCInstrAnalysis::isUnconditionalBranch(Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isConditionalBranch(MCInst const &Inst) const override {
|
|
|
|
//assert(!HexagonMCInstrInfo::isBundle(Inst));
|
|
|
|
return MCInstrAnalysis::isConditionalBranch(Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool evaluateBranch(MCInst const &Inst, uint64_t Addr,
|
|
|
|
uint64_t Size, uint64_t &Target) const override {
|
|
|
|
//assert(!HexagonMCInstrInfo::isBundle(Inst));
|
|
|
|
if(!HexagonMCInstrInfo::isExtendable(*Info, Inst))
|
|
|
|
return false;
|
|
|
|
auto const &Extended(HexagonMCInstrInfo::getExtendableOperand(*Info, Inst));
|
|
|
|
assert(Extended.isExpr());
|
|
|
|
int64_t Value;
|
|
|
|
if(!Extended.getExpr()->evaluateAsAbsolute(Value))
|
|
|
|
return false;
|
|
|
|
Target = Value;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCInstrAnalysis *createHexagonMCInstrAnalysis(const MCInstrInfo *Info) {
|
|
|
|
return new HexagonMCInstrAnalysis(Info);
|
|
|
|
}
|
|
|
|
|
2011-12-16 06:29:08 +08:00
|
|
|
// Force static initialization.
|
2019-06-11 11:21:13 +08:00
|
|
|
extern "C" void LLVMInitializeHexagonTargetMC() {
|
2011-12-16 06:29:08 +08:00
|
|
|
// 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(),
|
2017-02-07 03:35:46 +08:00
|
|
|
Hexagon_MC::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);
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
|
|
|
|
// Register the MC instruction analyzer.
|
|
|
|
TargetRegistry::RegisterMCInstrAnalysis(getTheHexagonTarget(),
|
|
|
|
createHexagonMCInstrAnalysis);
|
|
|
|
|
2015-06-17 11:06:16 +08:00
|
|
|
// Register the obj streamer
|
2017-02-07 03:35:46 +08:00
|
|
|
TargetRegistry::RegisterELFStreamer(getTheHexagonTarget(),
|
|
|
|
createMCStreamer);
|
|
|
|
|
|
|
|
// Register the obj target streamer
|
|
|
|
TargetRegistry::RegisterObjectTargetStreamer(getTheHexagonTarget(),
|
|
|
|
createHexagonObjectTargetStreamer);
|
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);
|
2011-12-16 06:29:08 +08:00
|
|
|
}
|