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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-01-18 06:29:40 +08:00
|
|
|
#include "HexagonArch.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"
|
2020-01-18 06:29:40 +08:00
|
|
|
#include "MCTargetDesc/HexagonMCTargetDesc.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>
|
2020-01-22 01:49:59 +08:00
|
|
|
#include <mutex>
|
2016-12-17 09:09:05 +08:00
|
|
|
#include <new>
|
|
|
|
#include <string>
|
2020-01-18 06:29:40 +08:00
|
|
|
#include <unordered_map>
|
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));
|
2020-01-18 06:29:40 +08:00
|
|
|
cl::opt<bool> MV67("mv67", cl::Hidden, cl::desc("Build for Hexagon V67"),
|
|
|
|
cl::init(false));
|
2020-01-14 06:07:30 +08:00
|
|
|
cl::opt<bool> MV67T("mv67t", cl::Hidden, cl::desc("Build for Hexagon V67T"),
|
|
|
|
cl::init(false));
|
2017-12-12 02:57:54 +08:00
|
|
|
|
|
|
|
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"),
|
2020-01-18 06:29:40 +08:00
|
|
|
clEnumValN(Hexagon::ArchEnum::V67, "v67", "Build for HVX v67"),
|
2018-12-06 04:18:09 +08:00
|
|
|
// 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);
|
2019-08-24 03:59:23 +08:00
|
|
|
} // namespace
|
2018-10-20 01:31:11 +08:00
|
|
|
|
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";
|
2020-01-18 06:29:40 +08:00
|
|
|
if (MV67)
|
|
|
|
return "hexagonv67";
|
2020-01-14 06:07:30 +08:00
|
|
|
if (MV67T)
|
|
|
|
return "hexagonv67t";
|
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()) {
|
2020-01-14 06:07:30 +08:00
|
|
|
// Tiny cores have a "t" suffix that is discarded when creating a secondary
|
|
|
|
// non-tiny subtarget. See: addArchSubtarget
|
|
|
|
std::pair<StringRef,StringRef> ArchP = ArchV.split('t');
|
|
|
|
std::pair<StringRef,StringRef> CPUP = CPU.split('t');
|
|
|
|
if (!ArchP.first.equals(CPUP.first))
|
|
|
|
report_fatal_error("conflicting architectures specified.");
|
2016-04-21 05:17:40 +08:00
|
|
|
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
|
|
|
|
2020-01-18 03:13:28 +08:00
|
|
|
unsigned llvm::HexagonConvertUnits(unsigned ItinUnits, unsigned *Lanes) {
|
|
|
|
enum {
|
|
|
|
CVI_NONE = 0,
|
|
|
|
CVI_XLANE = 1 << 0,
|
|
|
|
CVI_SHIFT = 1 << 1,
|
|
|
|
CVI_MPY0 = 1 << 2,
|
|
|
|
CVI_MPY1 = 1 << 3,
|
|
|
|
CVI_ZW = 1 << 4
|
|
|
|
};
|
|
|
|
|
|
|
|
if (ItinUnits == HexagonItinerariesV62FU::CVI_ALL ||
|
|
|
|
ItinUnits == HexagonItinerariesV62FU::CVI_ALL_NOMEM)
|
|
|
|
return (*Lanes = 4, CVI_XLANE);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01 &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
|
|
|
|
return (*Lanes = 2, CVI_XLANE | CVI_MPY0);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY01)
|
|
|
|
return (*Lanes = 2, CVI_MPY0);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLSHF)
|
|
|
|
return (*Lanes = 2, CVI_XLANE);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
|
|
|
|
return (*Lanes = 1, CVI_XLANE | CVI_SHIFT | CVI_MPY0 | CVI_MPY1);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_XLANE &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_SHIFT)
|
|
|
|
return (*Lanes = 1, CVI_XLANE | CVI_SHIFT);
|
|
|
|
else if (ItinUnits & HexagonItinerariesV62FU::CVI_MPY0 &&
|
|
|
|
ItinUnits & HexagonItinerariesV62FU::CVI_MPY1)
|
|
|
|
return (*Lanes = 1, CVI_MPY0 | CVI_MPY1);
|
|
|
|
else if (ItinUnits == HexagonItinerariesV62FU::CVI_ZW)
|
|
|
|
return (*Lanes = 1, CVI_ZW);
|
|
|
|
else if (ItinUnits == HexagonItinerariesV62FU::CVI_XLANE)
|
|
|
|
return (*Lanes = 1, CVI_XLANE);
|
|
|
|
else if (ItinUnits == HexagonItinerariesV62FU::CVI_SHIFT)
|
|
|
|
return (*Lanes = 1, CVI_SHIFT);
|
|
|
|
|
|
|
|
return (*Lanes = 0, CVI_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-14 06:07:30 +08:00
|
|
|
namespace llvm {
|
|
|
|
namespace HexagonFUnits {
|
|
|
|
bool isSlot0Only(unsigned units) {
|
|
|
|
return HexagonItinerariesV62FU::SLOT0 == units;
|
|
|
|
}
|
|
|
|
} // namespace HexagonFUnits
|
|
|
|
} // namespace llvm
|
|
|
|
|
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
|
|
|
|
2020-01-04 02:55:30 +08:00
|
|
|
void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
|
|
|
|
const MCInst &Inst, const MCSubtargetInfo &STI,
|
|
|
|
raw_ostream &OS) override {
|
2015-06-19 04:43:50 +08:00
|
|
|
assert(HexagonMCInstrInfo::isBundle(Inst));
|
|
|
|
assert(HexagonMCInstrInfo::bundleSize(Inst) <= HEXAGON_PACKET_SIZE);
|
|
|
|
std::string Buffer;
|
|
|
|
{
|
|
|
|
raw_string_ostream TempStream(Buffer);
|
2020-01-04 02:55:30 +08:00
|
|
|
InstPrinter.printInst(&Inst, Address, "", STI, TempStream);
|
2015-06-19 04:43:50 +08:00
|
|
|
}
|
|
|
|
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,
|
2019-10-23 18:24:35 +08:00
|
|
|
const Triple &TT,
|
|
|
|
const MCTargetOptions &Options) {
|
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) {
|
2019-08-24 23:02:44 +08:00
|
|
|
if (STI->getFeatureBits()[F])
|
2017-02-07 03:35:46 +08:00
|
|
|
STI->ToggleFeature(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool LLVM_ATTRIBUTE_UNUSED checkFeature(MCSubtargetInfo* STI, uint64_t F) {
|
2019-08-24 23:02:44 +08:00
|
|
|
return STI->getFeatureBits()[F];
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
|
|
|
|
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;
|
2020-01-18 06:29:40 +08:00
|
|
|
case Hexagon::ArchEnum::V67:
|
|
|
|
Result.push_back("+hvxv67");
|
|
|
|
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")
|
2020-01-18 06:29:40 +08:00
|
|
|
.Case("hexagonv66", "+hvxv66")
|
2020-01-14 06:07:30 +08:00
|
|
|
.Case("hexagonv67", "+hvxv67")
|
|
|
|
.Case("hexagonv67t", "+hvxv67"));
|
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:
|
2020-01-18 06:29:40 +08:00
|
|
|
// Sentinel if -mhvx isn't specified
|
2017-12-12 02:57:54 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return join(Result.begin(), Result.end(), ",");
|
|
|
|
}
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
|
|
|
|
2020-01-18 06:29:40 +08:00
|
|
|
static bool isCPUValid(const std::string &CPU) {
|
|
|
|
return Hexagon::CpuTable.find(CPU) != Hexagon::CpuTable.cend();
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2020-01-14 06:07:30 +08:00
|
|
|
std::mutex ArchSubtargetMutex;
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<MCSubtargetInfo const>>
|
|
|
|
ArchSubtarget;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
MCSubtargetInfo const *
|
|
|
|
Hexagon_MC::getArchSubtarget(MCSubtargetInfo const *STI) {
|
|
|
|
std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
|
|
|
|
auto Existing = ArchSubtarget.find(std::string(STI->getCPU()));
|
|
|
|
if (Existing == ArchSubtarget.end())
|
|
|
|
return nullptr;
|
|
|
|
return Existing->second.get();
|
2017-12-12 02:57:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2020-01-18 06:29:40 +08:00
|
|
|
for (unsigned F : {ArchV67, 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,
|
2020-01-18 06:29:40 +08:00
|
|
|
ExtensionHVXV66, ExtensionHVXV67}) {
|
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) {
|
2020-01-18 06:29:40 +08:00
|
|
|
case ArchV67:
|
|
|
|
FB.set(ExtensionHVXV67);
|
|
|
|
LLVM_FALLTHROUGH;
|
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;
|
|
|
|
|
2020-01-18 06:29:40 +08:00
|
|
|
MCSubtargetInfo *X = createHexagonMCSubtargetInfoImpl(TT, CPUName, ArchFS);
|
2020-01-14 06:07:30 +08:00
|
|
|
if (X != nullptr && (CPUName == "hexagonv67t"))
|
|
|
|
addArchSubtarget(X, ArchFS);
|
2020-01-18 06:29:40 +08:00
|
|
|
|
|
|
|
if (CPU.equals("help"))
|
|
|
|
exit(0);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-12-12 02:57:54 +08:00
|
|
|
if (HexagonDisableDuplex) {
|
2017-02-07 03:35:46 +08:00
|
|
|
llvm::FeatureBitset Features = X->getFeatureBits();
|
2019-08-24 23:02:44 +08:00
|
|
|
X->setFeatureBits(Features.reset(Hexagon::FeatureDuplex));
|
2017-02-07 03:35:46 +08:00
|
|
|
}
|
2017-12-12 02:57:54 +08:00
|
|
|
|
|
|
|
X->setFeatureBits(completeHVXFeatures(X->getFeatureBits()));
|
2020-01-18 06:29:40 +08:00
|
|
|
|
|
|
|
// The Z-buffer instructions are grandfathered in for current
|
|
|
|
// architectures but omitted for new ones. Future instruction
|
|
|
|
// sets may introduce new/conflicting z-buffer instructions.
|
|
|
|
const bool ZRegOnDefault =
|
|
|
|
(CPUName == "hexagonv67") || (CPUName == "hexagonv66");
|
|
|
|
if (ZRegOnDefault) {
|
|
|
|
llvm::FeatureBitset Features = X->getFeatureBits();
|
|
|
|
X->setFeatureBits(Features.set(Hexagon::ExtensionZReg));
|
|
|
|
}
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2020-01-14 06:07:30 +08:00
|
|
|
void Hexagon_MC::addArchSubtarget(MCSubtargetInfo const *STI,
|
|
|
|
StringRef FS) {
|
|
|
|
assert(STI != nullptr);
|
|
|
|
if (STI->getCPU().contains("t")) {
|
|
|
|
auto ArchSTI = createHexagonMCSubtargetInfo(
|
|
|
|
STI->getTargetTriple(),
|
|
|
|
STI->getCPU().substr(0, STI->getCPU().size() - 1), FS);
|
|
|
|
std::lock_guard<std::mutex> Lock(ArchSubtargetMutex);
|
|
|
|
ArchSubtarget[std::string(STI->getCPU())] =
|
|
|
|
std::unique_ptr<MCSubtargetInfo const>(ArchSTI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
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},
|
2020-01-18 06:29:40 +08:00
|
|
|
{"hexagonv67", ELF::EF_HEXAGON_MACH_V67},
|
2020-01-14 06:07:30 +08:00
|
|
|
{"hexagonv67t", ELF::EF_HEXAGON_MACH_V67T},
|
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 {
|
2020-01-18 06:29:40 +08:00
|
|
|
if (!(isCall(Inst) || isUnconditionalBranch(Inst) ||
|
|
|
|
isConditionalBranch(Inst)))
|
|
|
|
return false;
|
|
|
|
|
2017-02-07 03:35:46 +08:00
|
|
|
//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.
|
CMake: Make most target symbols hidden by default
Summary:
For builds with LLVM_BUILD_LLVM_DYLIB=ON and BUILD_SHARED_LIBS=OFF
this change makes all symbols in the target specific libraries hidden
by default.
A new macro called LLVM_EXTERNAL_VISIBILITY has been added to mark symbols in these
libraries public, which is mainly needed for the definitions of the
LLVMInitialize* functions.
This patch reduces the number of public symbols in libLLVM.so by about
25%. This should improve load times for the dynamic library and also
make abi checker tools, like abidiff require less memory when analyzing
libLLVM.so
One side-effect of this change is that for builds with
LLVM_BUILD_LLVM_DYLIB=ON and LLVM_LINK_LLVM_DYLIB=ON some unittests that
access symbols that are no longer public will need to be statically linked.
Before and after public symbol counts (using gcc 8.2.1, ld.bfd 2.31.1):
nm before/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
36221
nm after/libLLVM-9svn.so | grep ' [A-Zuvw] ' | wc -l
26278
Reviewers: chandlerc, beanz, mgorny, rnk, hans
Reviewed By: rnk, hans
Subscribers: merge_guards_bot, luismarques, smeenai, ldionne, lenary, s.egerton, pzheng, sameer.abuasal, MaskRay, wuzish, echristo, Jim, hiraditya, michaelplatings, chapuni, jholewinski, arsenm, dschuff, jyknight, dylanmckay, sdardis, nemanjai, jvesely, javed.absar, sbc100, jgravelle-google, aheejin, kbarton, fedor.sergeev, asb, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, jrtc27, zzheng, edward-jones, mgrang, atanasyan, rogfer01, MartinMosbeck, brucehoult, the_o, PkmX, jocewei, kristina, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D54439
2020-01-15 11:15:07 +08:00
|
|
|
extern "C" LLVM_EXTERNAL_VISIBILITY 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
|
|
|
}
|