2012-02-17 16:55:11 +08:00
|
|
|
//===-- MipsMCTargetDesc.cpp - Mips Target Descriptions -------------------===//
|
2011-07-15 04:59:42 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file provides Mips specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-07-26 05:20:24 +08:00
|
|
|
#include "InstPrinter/MipsInstPrinter.h"
|
2014-03-27 19:39:03 +08:00
|
|
|
#include "MipsELFStreamer.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "MipsMCAsmInfo.h"
|
2014-02-28 18:00:38 +08:00
|
|
|
#include "MipsMCNaCl.h"
|
|
|
|
#include "MipsMCTargetDesc.h"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "MipsTargetStreamer.h"
|
2015-09-15 21:46:21 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2011-08-24 04:15:21 +08:00
|
|
|
#include "llvm/MC/MCCodeGenInfo.h"
|
2013-10-06 00:42:21 +08:00
|
|
|
#include "llvm/MC/MCELFStreamer.h"
|
2011-07-15 04:59:42 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "llvm/MC/MCSymbol.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/MC/MachineLocation.h"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2012-02-05 15:21:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2011-07-15 04:59:42 +08:00
|
|
|
|
2014-04-22 10:03:14 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-15 04:59:42 +08:00
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "MipsGenInstrInfo.inc"
|
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "MipsGenSubtargetInfo.inc"
|
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "MipsGenRegisterInfo.inc"
|
|
|
|
|
2014-02-20 21:13:33 +08:00
|
|
|
/// Select the Mips CPU for the given triple and cpu name.
|
|
|
|
/// FIXME: Merge with the copy in MipsSubtarget.cpp
|
2015-09-15 21:46:21 +08:00
|
|
|
StringRef MIPS_MC::selectMipsCPU(const Triple &TT, StringRef CPU) {
|
2014-02-26 18:20:15 +08:00
|
|
|
if (CPU.empty() || CPU == "generic") {
|
2015-09-15 21:46:21 +08:00
|
|
|
if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel)
|
2014-02-20 21:13:33 +08:00
|
|
|
CPU = "mips32";
|
|
|
|
else
|
|
|
|
CPU = "mips64";
|
|
|
|
}
|
|
|
|
return CPU;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:50:31 +08:00
|
|
|
static MCInstrInfo *createMipsMCInstrInfo() {
|
2011-07-15 04:59:42 +08:00
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitMipsMCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:46:21 +08:00
|
|
|
static MCRegisterInfo *createMipsMCRegisterInfo(const Triple &TT) {
|
2011-07-19 04:57:22 +08:00
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitMipsMCRegisterInfo(X, Mips::RA);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:46:21 +08:00
|
|
|
static MCSubtargetInfo *createMipsMCSubtargetInfo(const Triple &TT,
|
2015-06-10 20:11:26 +08:00
|
|
|
StringRef CPU, StringRef FS) {
|
2015-02-18 08:55:06 +08:00
|
|
|
CPU = MIPS_MC::selectMipsCPU(TT, CPU);
|
2015-07-11 06:43:42 +08:00
|
|
|
return createMipsMCSubtargetInfoImpl(TT, CPU, FS);
|
2011-07-15 04:59:42 +08:00
|
|
|
}
|
|
|
|
|
2015-06-04 21:12:25 +08:00
|
|
|
static MCAsmInfo *createMipsMCAsmInfo(const MCRegisterInfo &MRI,
|
2015-09-15 21:46:21 +08:00
|
|
|
const Triple &TT) {
|
2013-05-11 02:16:59 +08:00
|
|
|
MCAsmInfo *MAI = new MipsMCAsmInfo(TT);
|
2011-07-19 06:29:13 +08:00
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
unsigned SP = MRI.getDwarfRegNum(Mips::SP, true);
|
2014-04-25 13:30:21 +08:00
|
|
|
MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0);
|
2013-05-13 09:16:13 +08:00
|
|
|
MAI->addInitialFrameState(Inst);
|
2011-07-19 06:29:13 +08:00
|
|
|
|
|
|
|
return MAI;
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:46:21 +08:00
|
|
|
static MCCodeGenInfo *createMipsMCCodeGenInfo(const Triple &TT, Reloc::Model RM,
|
2011-11-16 16:38:26 +08:00
|
|
|
CodeModel::Model CM,
|
|
|
|
CodeGenOpt::Level OL) {
|
2011-07-19 14:37:02 +08:00
|
|
|
MCCodeGenInfo *X = new MCCodeGenInfo();
|
2012-03-31 10:38:36 +08:00
|
|
|
if (CM == CodeModel::JITDefault)
|
|
|
|
RM = Reloc::Static;
|
|
|
|
else if (RM == Reloc::Default)
|
2011-09-14 02:55:33 +08:00
|
|
|
RM = Reloc::PIC_;
|
2015-05-16 03:13:31 +08:00
|
|
|
X->initMCCodeGenInfo(RM, CM, OL);
|
2011-07-19 14:37:02 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:46:21 +08:00
|
|
|
static MCInstPrinter *createMipsMCInstPrinter(const Triple &T,
|
2015-03-31 08:10:04 +08:00
|
|
|
unsigned SyntaxVariant,
|
2011-09-08 01:24:38 +08:00
|
|
|
const MCAsmInfo &MAI,
|
2012-04-02 14:09:36 +08:00
|
|
|
const MCInstrInfo &MII,
|
2015-03-31 08:10:04 +08:00
|
|
|
const MCRegisterInfo &MRI) {
|
2012-04-02 14:09:36 +08:00
|
|
|
return new MipsInstPrinter(MAI, MII, MRI);
|
2011-07-26 05:20:24 +08:00
|
|
|
}
|
|
|
|
|
2015-09-15 21:46:21 +08:00
|
|
|
static MCStreamer *createMCStreamer(const Triple &T, MCContext &Context,
|
2015-04-15 06:14:34 +08:00
|
|
|
MCAsmBackend &MAB, raw_pwrite_stream &OS,
|
2015-03-19 09:50:16 +08:00
|
|
|
MCCodeEmitter *Emitter, bool RelaxAll) {
|
2014-02-28 18:00:38 +08:00
|
|
|
MCStreamer *S;
|
2015-03-17 06:29:29 +08:00
|
|
|
if (!T.isOSNaCl())
|
2015-03-19 09:50:16 +08:00
|
|
|
S = createMipsELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
|
2014-02-28 18:00:38 +08:00
|
|
|
else
|
2015-03-19 09:50:16 +08:00
|
|
|
S = createMipsNaClELFStreamer(Context, MAB, OS, Emitter, RelaxAll);
|
2014-01-26 14:06:37 +08:00
|
|
|
return S;
|
2013-10-08 21:08:17 +08:00
|
|
|
}
|
|
|
|
|
2015-03-17 05:43:42 +08:00
|
|
|
static MCTargetStreamer *createMipsAsmTargetStreamer(MCStreamer &S,
|
|
|
|
formatted_raw_ostream &OS,
|
|
|
|
MCInstPrinter *InstPrint,
|
|
|
|
bool isVerboseAsm) {
|
|
|
|
return new MipsTargetAsmStreamer(S, OS);
|
2011-10-01 05:29:38 +08:00
|
|
|
}
|
|
|
|
|
2015-02-19 08:45:07 +08:00
|
|
|
static MCTargetStreamer *createMipsNullTargetStreamer(MCStreamer &S) {
|
|
|
|
return new MipsTargetStreamer(S);
|
2014-06-24 03:43:40 +08:00
|
|
|
}
|
|
|
|
|
2015-03-19 09:50:16 +08:00
|
|
|
static MCTargetStreamer *
|
|
|
|
createMipsObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
|
|
|
|
return new MipsTargetELFStreamer(S, STI);
|
|
|
|
}
|
|
|
|
|
2011-07-23 05:58:54 +08:00
|
|
|
extern "C" void LLVMInitializeMipsTargetMC() {
|
2015-03-19 07:15:49 +08:00
|
|
|
for (Target *T : {&TheMipsTarget, &TheMipselTarget, &TheMips64Target,
|
|
|
|
&TheMips64elTarget}) {
|
|
|
|
// Register the MC asm info.
|
|
|
|
RegisterMCAsmInfoFn X(*T, createMipsMCAsmInfo);
|
|
|
|
|
|
|
|
// Register the MC codegen info.
|
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(*T, createMipsMCCodeGenInfo);
|
|
|
|
|
|
|
|
// Register the MC instruction info.
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(*T, createMipsMCInstrInfo);
|
|
|
|
|
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(*T, createMipsMCRegisterInfo);
|
|
|
|
|
2015-03-19 09:50:16 +08:00
|
|
|
// Register the elf streamer.
|
|
|
|
TargetRegistry::RegisterELFStreamer(*T, createMCStreamer);
|
2015-03-19 07:15:49 +08:00
|
|
|
|
|
|
|
// Register the asm target streamer.
|
|
|
|
TargetRegistry::RegisterAsmTargetStreamer(*T, createMipsAsmTargetStreamer);
|
|
|
|
|
|
|
|
TargetRegistry::RegisterNullTargetStreamer(*T,
|
|
|
|
createMipsNullTargetStreamer);
|
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(*T, createMipsMCSubtargetInfo);
|
|
|
|
|
|
|
|
// Register the MCInstPrinter.
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(*T, createMipsMCInstPrinter);
|
2015-03-19 09:50:16 +08:00
|
|
|
|
|
|
|
TargetRegistry::RegisterObjectTargetStreamer(
|
|
|
|
*T, createMipsObjectTargetStreamer);
|
2015-03-19 07:15:49 +08:00
|
|
|
}
|
2011-07-23 05:58:54 +08:00
|
|
|
|
2011-10-01 04:40:03 +08:00
|
|
|
// Register the MC Code Emitter
|
2015-03-19 07:15:49 +08:00
|
|
|
for (Target *T : {&TheMipsTarget, &TheMips64Target})
|
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEB);
|
|
|
|
|
|
|
|
for (Target *T : {&TheMipselTarget, &TheMips64elTarget})
|
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEL);
|
2014-06-24 03:43:40 +08:00
|
|
|
|
2011-10-01 05:23:45 +08:00
|
|
|
// Register the asm backend.
|
2012-01-11 12:04:14 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheMipsTarget,
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEB32);
|
2012-01-11 12:04:14 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheMipselTarget,
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEL32);
|
2012-01-11 12:04:14 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheMips64Target,
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEB64);
|
2012-01-11 12:04:14 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheMips64elTarget,
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEL64);
|
2011-11-12 06:58:42 +08:00
|
|
|
|
2011-07-19 14:37:02 +08:00
|
|
|
}
|