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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-04-18 17:17:29 +08:00
|
|
|
#include "MipsMCTargetDesc.h"
|
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"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "MipsTargetStreamer.h"
|
2015-09-16 00:17:27 +08:00
|
|
|
#include "llvm/ADT/Triple.h"
|
2013-10-06 00:42:21 +08:00
|
|
|
#include "llvm/MC/MCELFStreamer.h"
|
2016-03-25 01:18:14 +08:00
|
|
|
#include "llvm/MC/MCInstrAnalysis.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"
|
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-16 00:17:27 +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-16 00:17:27 +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-16 00:17:27 +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-16 00:17:27 +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-16 00:17:27 +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-16 00:17:27 +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-16 00:17:27 +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);
|
|
|
|
}
|
|
|
|
|
2016-03-25 01:18:14 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class MipsMCInstrAnalysis : public MCInstrAnalysis {
|
|
|
|
public:
|
|
|
|
MipsMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
|
|
|
|
|
|
|
|
bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size,
|
|
|
|
uint64_t &Target) const override {
|
|
|
|
unsigned NumOps = Inst.getNumOperands();
|
|
|
|
if (NumOps == 0)
|
|
|
|
return false;
|
|
|
|
switch (Info->get(Inst.getOpcode()).OpInfo[NumOps - 1].OperandType) {
|
|
|
|
case MCOI::OPERAND_UNKNOWN:
|
|
|
|
case MCOI::OPERAND_IMMEDIATE:
|
|
|
|
// jal, bal ...
|
|
|
|
Target = Inst.getOperand(NumOps - 1).getImm();
|
|
|
|
return true;
|
|
|
|
case MCOI::OPERAND_PCREL:
|
|
|
|
// b, j, beq ...
|
|
|
|
Target = Addr + Inst.getOperand(NumOps - 1).getImm();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCInstrAnalysis *createMipsMCInstrAnalysis(const MCInstrInfo *Info) {
|
|
|
|
return new MipsMCInstrAnalysis(Info);
|
|
|
|
}
|
|
|
|
|
2011-07-23 05:58:54 +08:00
|
|
|
extern "C" void LLVMInitializeMipsTargetMC() {
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T : {&getTheMipsTarget(), &getTheMipselTarget(),
|
|
|
|
&getTheMips64Target(), &getTheMips64elTarget()}) {
|
2015-03-19 07:15:49 +08:00
|
|
|
// Register the MC asm info.
|
|
|
|
RegisterMCAsmInfoFn X(*T, createMipsMCAsmInfo);
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2016-03-25 01:18:14 +08:00
|
|
|
// Register the MC instruction analyzer.
|
|
|
|
TargetRegistry::RegisterMCInstrAnalysis(*T, createMipsMCInstrAnalysis);
|
|
|
|
|
2015-03-19 07:15:49 +08:00
|
|
|
// 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
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T : {&getTheMipsTarget(), &getTheMips64Target()})
|
2015-03-19 07:15:49 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEB);
|
|
|
|
|
2016-10-10 07:00:34 +08:00
|
|
|
for (Target *T : {&getTheMipselTarget(), &getTheMips64elTarget()})
|
2015-03-19 07:15:49 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(*T, createMipsMCCodeEmitterEL);
|
2014-06-24 03:43:40 +08:00
|
|
|
|
2011-10-01 05:23:45 +08:00
|
|
|
// Register the asm backend.
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheMipsTarget(),
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEB32);
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheMipselTarget(),
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEL32);
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheMips64Target(),
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEB64);
|
2016-10-10 07:00:34 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(getTheMips64elTarget(),
|
2012-04-03 03:25:22 +08:00
|
|
|
createMipsAsmBackendEL64);
|
2011-07-19 14:37:02 +08:00
|
|
|
}
|