2011-07-15 04:59:42 +08:00
|
|
|
//===-- PPCMCTargetDesc.cpp - PowerPC 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 PowerPC specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PPCMCTargetDesc.h"
|
2011-07-15 07:50:31 +08:00
|
|
|
#include "PPCMCAsmInfo.h"
|
2011-07-26 05:20:24 +08:00
|
|
|
#include "InstPrinter/PPCInstPrinter.h"
|
2011-07-19 06:29:13 +08:00
|
|
|
#include "llvm/MC/MachineLocation.h"
|
2011-08-24 04:15:21 +08:00
|
|
|
#include "llvm/MC/MCCodeGenInfo.h"
|
2011-07-15 04:59:42 +08:00
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
2011-07-26 03:53:23 +08:00
|
|
|
#include "llvm/MC/MCStreamer.h"
|
2011-07-15 04:59:42 +08:00
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2012-02-05 15:21:30 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-25 02:08:43 +08:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2011-07-15 04:59:42 +08:00
|
|
|
|
|
|
|
#define GET_INSTRINFO_MC_DESC
|
|
|
|
#include "PPCGenInstrInfo.inc"
|
|
|
|
|
|
|
|
#define GET_SUBTARGETINFO_MC_DESC
|
|
|
|
#include "PPCGenSubtargetInfo.inc"
|
|
|
|
|
|
|
|
#define GET_REGINFO_MC_DESC
|
|
|
|
#include "PPCGenRegisterInfo.inc"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2011-07-15 07:50:31 +08:00
|
|
|
static MCInstrInfo *createPPCMCInstrInfo() {
|
2011-07-15 04:59:42 +08:00
|
|
|
MCInstrInfo *X = new MCInstrInfo();
|
|
|
|
InitPPCMCInstrInfo(X);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-19 04:57:22 +08:00
|
|
|
static MCRegisterInfo *createPPCMCRegisterInfo(StringRef TT) {
|
|
|
|
Triple TheTriple(TT);
|
|
|
|
bool isPPC64 = (TheTriple.getArch() == Triple::ppc64);
|
|
|
|
unsigned Flavour = isPPC64 ? 0 : 1;
|
|
|
|
unsigned RA = isPPC64 ? PPC::LR8 : PPC::LR;
|
|
|
|
|
|
|
|
MCRegisterInfo *X = new MCRegisterInfo();
|
|
|
|
InitPPCMCRegisterInfo(X, RA, Flavour, Flavour);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-15 07:50:31 +08:00
|
|
|
static MCSubtargetInfo *createPPCMCSubtargetInfo(StringRef TT, StringRef CPU,
|
|
|
|
StringRef FS) {
|
2011-07-15 04:59:42 +08:00
|
|
|
MCSubtargetInfo *X = new MCSubtargetInfo();
|
|
|
|
InitPPCMCSubtargetInfo(X, TT, CPU, FS);
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2011-07-19 06:29:13 +08:00
|
|
|
static MCAsmInfo *createPPCMCAsmInfo(const Target &T, StringRef TT) {
|
2011-07-15 07:50:31 +08:00
|
|
|
Triple TheTriple(TT);
|
|
|
|
bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
|
2011-07-19 06:29:13 +08:00
|
|
|
|
|
|
|
MCAsmInfo *MAI;
|
2011-07-15 07:50:31 +08:00
|
|
|
if (TheTriple.isOSDarwin())
|
2011-07-19 06:29:13 +08:00
|
|
|
MAI = new PPCMCAsmInfoDarwin(isPPC64);
|
|
|
|
else
|
|
|
|
MAI = new PPCLinuxMCAsmInfo(isPPC64);
|
|
|
|
|
|
|
|
// Initial state of the frame pointer is R1.
|
|
|
|
MachineLocation Dst(MachineLocation::VirtualFP);
|
|
|
|
MachineLocation Src(PPC::R1, 0);
|
|
|
|
MAI->addInitialFrameState(0, Dst, Src);
|
|
|
|
|
|
|
|
return MAI;
|
2011-07-15 07:50:31 +08:00
|
|
|
}
|
|
|
|
|
2011-07-23 08:01:04 +08:00
|
|
|
static MCCodeGenInfo *createPPCMCCodeGenInfo(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();
|
|
|
|
|
|
|
|
if (RM == Reloc::Default) {
|
|
|
|
Triple T(TT);
|
|
|
|
if (T.isOSDarwin())
|
|
|
|
RM = Reloc::DynamicNoPIC;
|
|
|
|
else
|
|
|
|
RM = Reloc::Static;
|
|
|
|
}
|
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-26 03:53:23 +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-26 03:53:23 +08:00
|
|
|
raw_ostream &OS,
|
|
|
|
MCCodeEmitter *Emitter,
|
|
|
|
bool RelaxAll,
|
|
|
|
bool NoExecStack) {
|
|
|
|
if (Triple(TT).isOSDarwin())
|
2011-07-26 07:24:55 +08:00
|
|
|
return createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
|
2011-07-26 03:53:23 +08:00
|
|
|
|
2011-08-02 23:54:03 +08:00
|
|
|
return createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
|
2011-07-26 03:53:23 +08:00
|
|
|
}
|
|
|
|
|
2011-07-26 05:20:24 +08:00
|
|
|
static MCInstPrinter *createPPCMCInstPrinter(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
|
|
|
return new PPCInstPrinter(MAI, SyntaxVariant);
|
|
|
|
}
|
|
|
|
|
2011-07-23 05:58:54 +08:00
|
|
|
extern "C" void LLVMInitializePowerPCTargetMC() {
|
|
|
|
// Register the MC asm info.
|
|
|
|
RegisterMCAsmInfoFn C(ThePPC32Target, createPPCMCAsmInfo);
|
|
|
|
RegisterMCAsmInfoFn D(ThePPC64Target, createPPCMCAsmInfo);
|
|
|
|
|
|
|
|
// Register the MC codegen info.
|
2011-07-19 14:37:02 +08:00
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
|
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC instruction info.
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
|
|
|
|
|
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
|
|
|
|
TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
|
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
|
|
|
|
createPPCMCSubtargetInfo);
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
|
|
|
|
createPPCMCSubtargetInfo);
|
2011-07-26 03:53:23 +08:00
|
|
|
|
|
|
|
// Register the MC Code Emitter
|
2011-07-26 08:42:34 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
|
|
|
|
TargetRegistry::RegisterMCCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
|
2011-07-26 03:53:23 +08:00
|
|
|
|
|
|
|
// Register the asm backend.
|
2011-07-26 07:24:55 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(ThePPC32Target, createPPCAsmBackend);
|
|
|
|
TargetRegistry::RegisterMCAsmBackend(ThePPC64Target, createPPCAsmBackend);
|
2011-07-26 03:53:23 +08:00
|
|
|
|
|
|
|
// Register the object streamer.
|
2011-07-26 08:42:34 +08:00
|
|
|
TargetRegistry::RegisterMCObjectStreamer(ThePPC32Target, createMCStreamer);
|
|
|
|
TargetRegistry::RegisterMCObjectStreamer(ThePPC64Target, createMCStreamer);
|
2011-07-26 05:20:24 +08:00
|
|
|
|
|
|
|
// Register the MCInstPrinter.
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter);
|
2011-07-19 14:37:02 +08:00
|
|
|
}
|