2011-07-07 06:02:34 +08:00
|
|
|
//===-- ARMMCTargetDesc.cpp - ARM 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 ARM specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMMCTargetDesc.h"
|
2011-07-15 07:50:31 +08:00
|
|
|
#include "ARMMCAsmInfo.h"
|
2011-08-09 02:56:44 +08:00
|
|
|
#include "ARMBaseInfo.h"
|
2011-07-26 05:20:24 +08:00
|
|
|
#include "InstPrinter/ARMInstPrinter.h"
|
2011-08-24 04:15:21 +08:00
|
|
|
#include "llvm/MC/MCCodeGenInfo.h"
|
|
|
|
#include "llvm/MC/MCInstrAnalysis.h"
|
2011-07-07 06:02:34 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2011-07-23 08:00:19 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-07 06:02:34 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2011-07-23 08:00:19 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2011-07-07 06:02:34 +08:00
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "ARMGenRegisterInfo.inc"
|
|
|
|
|
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "ARMGenInstrInfo.inc"
|
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "ARMGenSubtargetInfo.inc"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-07 16:26:46 +08:00
|
|
|
std::string ARM_MC::ParseARMTriple(StringRef TT) {
|
2011-07-07 08:08:19 +08:00
|
|
|
// Set the boolean corresponding to the current target triple, or the default
|
|
|
|
// if one cannot be determined, to true.
|
|
|
|
unsigned Len = TT.size();
|
|
|
|
unsigned Idx = 0;
|
|
|
|
|
2011-09-06 02:35:03 +08:00
|
|
|
// FIXME: Enhance Triple helper class to extract ARM version.
|
2011-07-07 16:26:46 +08:00
|
|
|
bool isThumb = false;
|
2011-07-07 08:08:19 +08:00
|
|
|
if (Len >= 5 && TT.substr(0, 4) == "armv")
|
|
|
|
Idx = 4;
|
|
|
|
else if (Len >= 6 && TT.substr(0, 5) == "thumb") {
|
2011-07-07 16:26:46 +08:00
|
|
|
isThumb = true;
|
2011-07-07 08:08:19 +08:00
|
|
|
if (Len >= 7 && TT[5] == 'v')
|
|
|
|
Idx = 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ARMArchFeature;
|
|
|
|
if (Idx) {
|
|
|
|
unsigned SubVer = TT[Idx];
|
|
|
|
if (SubVer >= '7' && SubVer <= '9') {
|
|
|
|
if (Len >= Idx+2 && TT[Idx+1] == 'm') {
|
2011-09-28 22:21:38 +08:00
|
|
|
// v7m: FeatureNoARM, FeatureDB, FeatureHWDiv, FeatureMClass
|
|
|
|
ARMArchFeature = "+v7,+noarm,+db,+hwdiv,+mclass";
|
2011-07-07 08:08:19 +08:00
|
|
|
} else if (Len >= Idx+3 && TT[Idx+1] == 'e'&& TT[Idx+2] == 'm') {
|
2011-07-07 11:55:05 +08:00
|
|
|
// v7em: FeatureNoARM, FeatureDB, FeatureHWDiv, FeatureDSPThumb2,
|
2011-09-28 22:21:38 +08:00
|
|
|
// FeatureT2XtPk, FeatureMClass
|
|
|
|
ARMArchFeature = "+v7,+noarm,+db,+hwdiv,+t2dsp,t2xtpk,+mclass";
|
2011-07-07 11:55:05 +08:00
|
|
|
} else
|
2011-09-15 07:16:34 +08:00
|
|
|
// v7a: FeatureNEON, FeatureDB, FeatureDSPThumb2, FeatureT2XtPk
|
|
|
|
ARMArchFeature = "+v7,+neon,+db,+t2dsp,+t2xtpk";
|
2011-07-07 08:08:19 +08:00
|
|
|
} else if (SubVer == '6') {
|
2012-02-10 10:21:49 +08:00
|
|
|
Triple TheTriple(TT);
|
|
|
|
if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2') {
|
2011-07-07 08:08:19 +08:00
|
|
|
ARMArchFeature = "+v6t2";
|
2012-02-10 10:21:49 +08:00
|
|
|
// On darwin, v6 implies VFP.
|
|
|
|
if (TheTriple.isOSDarwin())
|
|
|
|
ARMArchFeature += ",+vfp2";
|
|
|
|
} else if (Len >= Idx+2 && TT[Idx+1] == 'm')
|
2011-09-28 22:21:38 +08:00
|
|
|
// v6m: FeatureNoARM, FeatureMClass
|
|
|
|
ARMArchFeature = "+v6t2,+noarm,+mclass";
|
2012-02-10 10:21:49 +08:00
|
|
|
else {
|
2011-07-07 11:55:05 +08:00
|
|
|
ARMArchFeature = "+v6";
|
2012-02-10 10:21:49 +08:00
|
|
|
// On darwin, v6 implies VFP.
|
|
|
|
if (TheTriple.isOSDarwin())
|
|
|
|
ARMArchFeature += ",+vfp2";
|
|
|
|
}
|
2011-07-07 08:08:19 +08:00
|
|
|
} else if (SubVer == '5') {
|
2011-07-07 11:55:05 +08:00
|
|
|
if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == 'e')
|
2011-07-07 08:08:19 +08:00
|
|
|
ARMArchFeature = "+v5te";
|
2011-07-07 11:55:05 +08:00
|
|
|
else
|
|
|
|
ARMArchFeature = "+v5t";
|
|
|
|
} else if (SubVer == '4' && Len >= Idx+2 && TT[Idx+1] == 't')
|
|
|
|
ARMArchFeature = "+v4t";
|
2011-07-07 08:08:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 16:26:46 +08:00
|
|
|
if (isThumb) {
|
|
|
|
if (ARMArchFeature.empty())
|
2011-07-08 03:05:12 +08:00
|
|
|
ARMArchFeature = "+thumb-mode";
|
2011-07-07 16:26:46 +08:00
|
|
|
else
|
2011-07-08 03:05:12 +08:00
|
|
|
ARMArchFeature += ",+thumb-mode";
|
2011-07-07 16:26:46 +08:00
|
|
|
}
|
|
|
|
|
2011-07-07 08:08:19 +08:00
|
|
|
return ARMArchFeature;
|
|
|
|
}
|
2011-07-08 09:53:10 +08:00
|
|
|
|
|
|
|
MCSubtargetInfo *ARM_MC::createARMMCSubtargetInfo(StringRef TT, StringRef CPU,
|
|
|
|
StringRef FS) {
|
|
|
|
std::string ArchFS = ARM_MC::ParseARMTriple(TT);
|
|
|
|
if (!FS.empty()) {
|
|
|
|
if (!ArchFS.empty())
|
|
|
|
ArchFS = ArchFS + "," + FS.str();
|
|
|
|
else
|
|
|
|
ArchFS = FS;
|
|
|
|
}
|
|
|
|
|
|
|
|
MCSubtargetInfo *X = new MCSubtargetInfo();
|
2011-07-11 11:57:24 +08:00
|
|
|
InitARMMCSubtargetInfo(X, TT, CPU, ArchFS);
|
2011-07-08 09:53:10 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:50:31 +08:00
|
|
|
static MCInstrInfo *createARMMCInstrInfo() {
|
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitARMMCInstrInfo(X);
|
2011-07-08 09:53:10 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-19 04:57:22 +08:00
|
|
|
static MCRegisterInfo *createARMMCRegisterInfo(StringRef Triple) {
|
2011-07-15 07:50:31 +08:00
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
2011-07-19 04:57:22 +08:00
|
|
|
InitARMMCRegisterInfo(X, ARM::LR);
|
2011-07-15 07:50:31 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-15 10:09:41 +08:00
|
|
|
static MCAsmInfo *createARMMCAsmInfo(const Target &T, StringRef TT) {
|
2011-07-15 07:50:31 +08:00
|
|
|
Triple TheTriple(TT);
|
|
|
|
|
|
|
|
if (TheTriple.isOSDarwin())
|
|
|
|
return new ARMMCAsmInfoDarwin();
|
|
|
|
|
|
|
|
return new ARMELFMCAsmInfo();
|
|
|
|
}
|
|
|
|
|
2011-07-23 08:00:19 +08:00
|
|
|
static MCCodeGenInfo *createARMMCCodeGenInfo(StringRef 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();
|
2011-10-01 01:41:35 +08:00
|
|
|
if (RM == Reloc::Default) {
|
|
|
|
Triple TheTriple(TT);
|
|
|
|
// Default relocation model on Darwin is PIC, not DynamicNoPIC.
|
|
|
|
RM = TheTriple.isOSDarwin() ? Reloc::PIC_ : Reloc::DynamicNoPIC;
|
|
|
|
}
|
2011-11-16 16:38:26 +08:00
|
|
|
X->InitMCCodeGenInfo(RM, CM, OL);
|
2011-07-19 14:37:02 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-23 08:00:19 +08:00
|
|
|
// This is duplicated code. Refactor this.
|
2011-07-26 08:42:34 +08:00
|
|
|
static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
|
2011-07-26 07:24:55 +08:00
|
|
|
MCContext &Ctx, MCAsmBackend &MAB,
|
2011-07-23 08:00:19 +08:00
|
|
|
raw_ostream &OS,
|
|
|
|
MCCodeEmitter *Emitter,
|
|
|
|
bool RelaxAll,
|
|
|
|
bool NoExecStack) {
|
|
|
|
Triple TheTriple(TT);
|
|
|
|
|
|
|
|
if (TheTriple.isOSDarwin())
|
2011-07-26 07:24:55 +08:00
|
|
|
return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
|
2011-07-23 08:00:19 +08:00
|
|
|
|
|
|
|
if (TheTriple.isOSWindows()) {
|
|
|
|
llvm_unreachable("ARM does not support Windows COFF format");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-26 07:24:55 +08:00
|
|
|
return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
|
2011-07-23 08:00:19 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 05:20:24 +08:00
|
|
|
static MCInstPrinter *createARMMCInstPrinter(const Target &T,
|
|
|
|
unsigned SyntaxVariant,
|
2011-09-08 01:24:38 +08:00
|
|
|
const MCAsmInfo &MAI,
|
|
|
|
const MCSubtargetInfo &STI) {
|
2011-07-26 05:20:24 +08:00
|
|
|
if (SyntaxVariant == 0)
|
2011-09-08 01:24:38 +08:00
|
|
|
return new ARMInstPrinter(MAI, STI);
|
2011-07-26 05:20:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-09 02:56:44 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class ARMMCInstrAnalysis : public MCInstrAnalysis {
|
|
|
|
public:
|
|
|
|
ARMMCInstrAnalysis(const MCInstrInfo *Info) : MCInstrAnalysis(Info) {}
|
|
|
|
|
|
|
|
virtual bool isUnconditionalBranch(const MCInst &Inst) const {
|
|
|
|
// BCCs with the "always" predicate are unconditional branches.
|
|
|
|
if (Inst.getOpcode() == ARM::Bcc && Inst.getOperand(1).getImm()==ARMCC::AL)
|
|
|
|
return true;
|
|
|
|
return MCInstrAnalysis::isUnconditionalBranch(Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isConditionalBranch(const MCInst &Inst) const {
|
|
|
|
// BCCs with the "always" predicate are unconditional branches.
|
|
|
|
if (Inst.getOpcode() == ARM::Bcc && Inst.getOperand(1).getImm()==ARMCC::AL)
|
|
|
|
return false;
|
|
|
|
return MCInstrAnalysis::isConditionalBranch(Inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t evaluateBranch(const MCInst &Inst, uint64_t Addr,
|
|
|
|
uint64_t Size) const {
|
|
|
|
// We only handle PCRel branches for now.
|
|
|
|
if (Info->get(Inst.getOpcode()).OpInfo[0].OperandType!=MCOI::OPERAND_PCREL)
|
|
|
|
return -1ULL;
|
|
|
|
|
|
|
|
int64_t Imm = Inst.getOperand(0).getImm();
|
|
|
|
// FIXME: This is not right for thumb.
|
|
|
|
return Addr+Imm+8; // In ARM mode the PC is always off by 8 bytes.
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCInstrAnalysis *createARMMCInstrAnalysis(const MCInstrInfo *Info) {
|
|
|
|
return new ARMMCInstrAnalysis(Info);
|
|
|
|
}
|
2011-07-23 08:00:19 +08:00
|
|
|
|
2011-07-23 05:58:54 +08:00
|
|
|
// Force static initialization.
|
|
|
|
extern "C" void LLVMInitializeARMTargetMC() {
|
|
|
|
// Register the MC asm info.
|
|
|
|
RegisterMCAsmInfoFn A(TheARMTarget, createARMMCAsmInfo);
|
|
|
|
RegisterMCAsmInfoFn B(TheThumbTarget, createARMMCAsmInfo);
|
|
|
|
|
|
|
|
// Register the MC codegen info.
|
2011-07-19 14:37:02 +08:00
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(TheARMTarget, createARMMCCodeGenInfo);
|
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(TheThumbTarget, createARMMCCodeGenInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC instruction info.
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(TheARMTarget, createARMMCInstrInfo);
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(TheThumbTarget, createARMMCInstrInfo);
|
|
|
|
|
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(TheARMTarget, createARMMCRegisterInfo);
|
|
|
|
TargetRegistry::RegisterMCRegInfo(TheThumbTarget, createARMMCRegisterInfo);
|
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(TheARMTarget,
|
|
|
|
ARM_MC::createARMMCSubtargetInfo);
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(TheThumbTarget,
|
|
|
|
ARM_MC::createARMMCSubtargetInfo);
|
2011-07-23 08:00:19 +08:00
|
|
|
|
2011-08-24 04:15:21 +08:00
|
|
|
// Register the MC instruction analyzer.
|
|
|
|
TargetRegistry::RegisterMCInstrAnalysis(TheARMTarget,
|
|
|
|
createARMMCInstrAnalysis);
|
|
|
|
TargetRegistry::RegisterMCInstrAnalysis(TheThumbTarget,
|
|
|
|
createARMMCInstrAnalysis);
|
|
|
|
|
2011-07-23 08:00:19 +08:00
|
|
|
// Register the MC Code Emitter
|
2011-07-26 08:42:34 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(TheARMTarget, createARMMCCodeEmitter);
|
|
|
|
TargetRegistry::RegisterMCCodeEmitter(TheThumbTarget, createARMMCCodeEmitter);
|
2011-07-23 08:00:19 +08:00
|
|
|
|
|
|
|
// Register the asm backend.
|
2011-07-26 07:24:55 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheARMTarget, createARMAsmBackend);
|
|
|
|
TargetRegistry::RegisterMCAsmBackend(TheThumbTarget, createARMAsmBackend);
|
2011-07-23 08:00:19 +08:00
|
|
|
|
|
|
|
// Register the object streamer.
|
2011-07-26 08:42:34 +08:00
|
|
|
TargetRegistry::RegisterMCObjectStreamer(TheARMTarget, createMCStreamer);
|
|
|
|
TargetRegistry::RegisterMCObjectStreamer(TheThumbTarget, createMCStreamer);
|
2011-07-26 05:20:24 +08:00
|
|
|
|
|
|
|
// Register the MCInstPrinter.
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(TheARMTarget, createARMMCInstPrinter);
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(TheThumbTarget, createARMMCInstPrinter);
|
2011-07-19 14:37:02 +08:00
|
|
|
}
|