2014-05-24 20:50:23 +08:00
|
|
|
//===-- AArch64MCTargetDesc.cpp - AArch64 Target Descriptions ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides AArch64 specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "AArch64MCTargetDesc.h"
|
|
|
|
#include "AArch64ELFStreamer.h"
|
|
|
|
#include "AArch64MCAsmInfo.h"
|
2017-06-28 07:58:19 +08:00
|
|
|
#include "AArch64WinCOFFStreamer.h"
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "InstPrinter/AArch64InstPrinter.h"
|
2017-10-12 07:34:47 +08:00
|
|
|
#include "llvm/MC/MCAsmBackend.h"
|
|
|
|
#include "llvm/MC/MCCodeEmitter.h"
|
2016-08-13 04:28:05 +08:00
|
|
|
#include "llvm/MC/MCInstrAnalysis.h"
|
2014-05-24 20:50:23 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "AArch64GenInstrInfo.inc"
|
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "AArch64GenSubtargetInfo.inc"
|
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "AArch64GenRegisterInfo.inc"
|
|
|
|
|
|
|
|
static MCInstrInfo *createAArch64MCInstrInfo() {
|
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitAArch64MCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCSubtargetInfo *
|
|
|
|
createAArch64MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
|
2014-05-24 20:50:23 +08:00
|
|
|
if (CPU.empty())
|
|
|
|
CPU = "generic";
|
|
|
|
|
2015-07-11 06:43:42 +08:00
|
|
|
return createAArch64MCSubtargetInfoImpl(TT, CPU, FS);
|
2014-05-24 20:50:23 +08:00
|
|
|
}
|
|
|
|
|
[COFF, ARM64, CodeView] Add support to emit CodeView debug info for ARM64 COFF
Reviewers: compnerd, ruiu, rnk, zturner
Reviewed By: rnk
Subscribers: majnemer, aemerson, aprantl, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D35518
llvm-svn: 308665
2017-07-21 04:20:00 +08:00
|
|
|
void AArch64_MC::initLLVMToCVRegMapping(MCRegisterInfo *MRI) {
|
|
|
|
for (unsigned Reg = AArch64::NoRegister + 1;
|
|
|
|
Reg < AArch64::NUM_TARGET_REGS; ++Reg) {
|
|
|
|
unsigned CV = MRI->getEncodingValue(Reg);
|
|
|
|
MRI->mapLLVMRegToCVReg(Reg, CV);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCRegisterInfo *createAArch64MCRegisterInfo(const Triple &Triple) {
|
2014-05-24 20:50:23 +08:00
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitAArch64MCRegisterInfo(X, AArch64::LR);
|
[COFF, ARM64, CodeView] Add support to emit CodeView debug info for ARM64 COFF
Reviewers: compnerd, ruiu, rnk, zturner
Reviewed By: rnk
Subscribers: majnemer, aemerson, aprantl, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D35518
llvm-svn: 308665
2017-07-21 04:20:00 +08:00
|
|
|
AArch64_MC::initLLVMToCVRegMapping(X);
|
2014-05-24 20:50:23 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI,
|
2015-09-16 00:17:27 +08:00
|
|
|
const Triple &TheTriple) {
|
2014-05-24 20:50:23 +08:00
|
|
|
MCAsmInfo *MAI;
|
2015-09-16 00:17:27 +08:00
|
|
|
if (TheTriple.isOSBinFormatMachO())
|
2014-05-24 20:50:23 +08:00
|
|
|
MAI = new AArch64MCAsmInfoDarwin();
|
2017-08-14 03:42:05 +08:00
|
|
|
else if (TheTriple.isWindowsMSVCEnvironment())
|
|
|
|
MAI = new AArch64MCAsmInfoMicrosoftCOFF();
|
2017-06-28 07:58:19 +08:00
|
|
|
else if (TheTriple.isOSBinFormatCOFF())
|
2017-08-14 03:42:05 +08:00
|
|
|
MAI = new AArch64MCAsmInfoGNUCOFF();
|
2014-05-24 20:50:23 +08:00
|
|
|
else {
|
2017-06-29 03:37:38 +08:00
|
|
|
assert(TheTriple.isOSBinFormatELF() && "Invalid target");
|
2015-09-16 00:17:27 +08:00
|
|
|
MAI = new AArch64MCAsmInfoELF(TheTriple);
|
2014-05-24 20:50:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initial state of the frame pointer is SP.
|
|
|
|
unsigned Reg = MRI.getDwarfRegNum(AArch64::SP, true);
|
|
|
|
MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, Reg, 0);
|
|
|
|
MAI->addInitialFrameState(Inst);
|
|
|
|
|
|
|
|
return MAI;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCInstPrinter *createAArch64MCInstPrinter(const Triple &T,
|
2015-03-31 08:10:04 +08:00
|
|
|
unsigned SyntaxVariant,
|
2014-05-24 20:50:23 +08:00
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
const MCInstrInfo &MII,
|
2015-03-31 08:10:04 +08:00
|
|
|
const MCRegisterInfo &MRI) {
|
2014-05-24 20:50:23 +08:00
|
|
|
if (SyntaxVariant == 0)
|
2015-03-31 05:52:26 +08:00
|
|
|
return new AArch64InstPrinter(MAI, MII, MRI);
|
2014-05-24 20:50:23 +08:00
|
|
|
if (SyntaxVariant == 1)
|
2015-03-31 05:52:26 +08:00
|
|
|
return new AArch64AppleInstPrinter(MAI, MII, MRI);
|
2014-05-24 20:50:23 +08:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-16 00:17:27 +08:00
|
|
|
static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
|
2017-10-11 09:57:21 +08:00
|
|
|
std::unique_ptr<MCAsmBackend> &&TAB,
|
|
|
|
raw_pwrite_stream &OS,
|
2017-10-12 07:34:47 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> &&Emitter,
|
|
|
|
bool RelaxAll) {
|
|
|
|
return createAArch64ELFStreamer(Ctx, std::move(TAB), OS, std::move(Emitter),
|
|
|
|
RelaxAll);
|
2014-05-24 20:50:23 +08:00
|
|
|
}
|
|
|
|
|
2017-10-11 09:57:21 +08:00
|
|
|
static MCStreamer *createMachOStreamer(MCContext &Ctx,
|
|
|
|
std::unique_ptr<MCAsmBackend> &&TAB,
|
2015-04-15 06:14:34 +08:00
|
|
|
raw_pwrite_stream &OS,
|
2017-10-12 07:34:47 +08:00
|
|
|
std::unique_ptr<MCCodeEmitter> &&Emitter,
|
|
|
|
bool RelaxAll,
|
2015-03-21 04:00:01 +08:00
|
|
|
bool DWARFMustBeAtTheEnd) {
|
2017-10-12 07:34:47 +08:00
|
|
|
return createMachOStreamer(Ctx, std::move(TAB), OS, std::move(Emitter),
|
|
|
|
RelaxAll, DWARFMustBeAtTheEnd,
|
2015-03-19 09:50:16 +08:00
|
|
|
/*LabelSections*/ true);
|
|
|
|
}
|
|
|
|
|
2017-10-12 07:34:47 +08:00
|
|
|
static MCStreamer *
|
|
|
|
createWinCOFFStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
|
|
|
|
raw_pwrite_stream &OS,
|
|
|
|
std::unique_ptr<MCCodeEmitter> &&Emitter, bool RelaxAll,
|
|
|
|
bool IncrementalLinkerCompatible) {
|
|
|
|
return createAArch64WinCOFFStreamer(Ctx, std::move(TAB), OS,
|
|
|
|
std::move(Emitter), RelaxAll,
|
|
|
|
IncrementalLinkerCompatible);
|
2017-06-28 07:58:19 +08:00
|
|
|
}
|
|
|
|
|
2016-08-13 04:28:05 +08:00
|
|
|
static MCInstrAnalysis *createAArch64InstrAnalysis(const MCInstrInfo *Info) {
|
|
|
|
return new MCInstrAnalysis(Info);
|
|
|
|
}
|
|
|
|
|
2014-05-24 20:50:23 +08:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeAArch64TargetMC() {
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T : {&getTheAArch64leTarget(), &getTheAArch64beTarget(),
|
|
|
|
&getTheARM64Target()}) {
|
2015-03-19 07:15:49 +08:00
|
|
|
// Register the MC asm info.
|
|
|
|
RegisterMCAsmInfoFn X(*T, createAArch64MCAsmInfo);
|
|
|
|
|
|
|
|
// Register the MC instruction info.
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(*T, createAArch64MCInstrInfo);
|
|
|
|
|
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(*T, createAArch64MCRegisterInfo);
|
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(*T, createAArch64MCSubtargetInfo);
|
|
|
|
|
2016-08-13 04:28:05 +08:00
|
|
|
// Register the MC instruction analyzer.
|
|
|
|
TargetRegistry::RegisterMCInstrAnalysis(*T, createAArch64InstrAnalysis);
|
|
|
|
|
2015-03-19 07:15:49 +08:00
|
|
|
// Register the MC Code Emitter
|
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createAArch64MCCodeEmitter);
|
|
|
|
|
2015-03-19 09:50:16 +08:00
|
|
|
// Register the obj streamers.
|
|
|
|
TargetRegistry::RegisterELFStreamer(*T, createELFStreamer);
|
|
|
|
TargetRegistry::RegisterMachOStreamer(*T, createMachOStreamer);
|
2017-06-28 07:58:19 +08:00
|
|
|
TargetRegistry::RegisterCOFFStreamer(*T, createWinCOFFStreamer);
|
2015-03-19 09:50:16 +08:00
|
|
|
|
|
|
|
// Register the obj target streamer.
|
|
|
|
TargetRegistry::RegisterObjectTargetStreamer(
|
|
|
|
*T, createAArch64ObjectTargetStreamer);
|
2015-03-19 07:15:49 +08:00
|
|
|
|
|
|
|
// Register the asm streamer.
|
|
|
|
TargetRegistry::RegisterAsmTargetStreamer(*T,
|
|
|
|
createAArch64AsmTargetStreamer);
|
|
|
|
// Register the MCInstPrinter.
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(*T, createAArch64MCInstPrinter);
|
|
|
|
}
|
2014-05-24 20:50:23 +08:00
|
|
|
|
|
|
|
// Register the asm backend.
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T : {&getTheAArch64leTarget(), &getTheARM64Target()})
|
2015-03-19 07:15:49 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(*T, createAArch64leAsmBackend);
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheAArch64beTarget(),
|
2014-05-24 20:50:23 +08:00
|
|
|
createAArch64beAsmBackend);
|
|
|
|
}
|