2012-02-18 20:03:15 +08:00
|
|
|
//===-- PPCMCTargetDesc.cpp - PowerPC 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 PowerPC specific target descriptions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "PPCMCTargetDesc.h"
|
2011-07-26 05:20:24 +08:00
|
|
|
#include "InstPrinter/PPCInstPrinter.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "PPCMCAsmInfo.h"
|
2013-10-08 21:08:17 +08:00
|
|
|
#include "PPCTargetStreamer.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"
|
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
|
|
|
|
|
|
|
#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;
|
|
|
|
|
2013-11-19 08:57:56 +08:00
|
|
|
// Pin the vtable to this file.
|
|
|
|
PPCTargetStreamer::~PPCTargetStreamer() {}
|
|
|
|
|
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);
|
2013-07-26 09:35:43 +08:00
|
|
|
bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 ||
|
|
|
|
TheTriple.getArch() == Triple::ppc64le);
|
2011-07-19 04:57:22 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-05-13 09:16:13 +08:00
|
|
|
static MCAsmInfo *createPPCMCAsmInfo(const MCRegisterInfo &MRI, StringRef TT) {
|
2011-07-15 07:50:31 +08:00
|
|
|
Triple TheTriple(TT);
|
2013-07-26 09:35:43 +08:00
|
|
|
bool isPPC64 = (TheTriple.getArch() == Triple::ppc64 ||
|
|
|
|
TheTriple.getArch() == Triple::ppc64le);
|
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.
|
2013-05-13 09:16:13 +08:00
|
|
|
unsigned Reg = isPPC64 ? PPC::X1 : PPC::R1;
|
|
|
|
MCCFIInstruction Inst =
|
|
|
|
MCCFIInstruction::createDefCfa(0, MRI.getDwarfRegNum(Reg, true), 0);
|
|
|
|
MAI->addInitialFrameState(Inst);
|
2011-07-19 06:29:13 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-11-28 07:36:26 +08:00
|
|
|
if (CM == CodeModel::Default) {
|
|
|
|
Triple T(TT);
|
2013-07-26 09:35:43 +08:00
|
|
|
if (!T.isOSDarwin() &&
|
|
|
|
(T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le))
|
2012-11-28 07:36:26 +08:00
|
|
|
CM = CodeModel::Medium;
|
|
|
|
}
|
2011-11-16 16:38:26 +08:00
|
|
|
X->InitMCCodeGenInfo(RM, CM, OL);
|
2011-07-19 14:37:02 +08:00
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2013-10-08 21:08:17 +08:00
|
|
|
namespace {
|
|
|
|
class PPCTargetAsmStreamer : public PPCTargetStreamer {
|
|
|
|
formatted_raw_ostream &OS;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PPCTargetAsmStreamer(formatted_raw_ostream &OS) : OS(OS) {}
|
|
|
|
virtual void emitTCEntry(const MCSymbol &S) {
|
|
|
|
OS << "\t.tc ";
|
|
|
|
OS << S.getName();
|
|
|
|
OS << "[TC],";
|
|
|
|
OS << S.getName();
|
|
|
|
OS << '\n';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class PPCTargetELFStreamer : public PPCTargetStreamer {
|
|
|
|
virtual void emitTCEntry(const MCSymbol &S) {
|
|
|
|
// Creates a R_PPC64_TOC relocation
|
|
|
|
Streamer->EmitSymbolValue(&S, 8);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-10-08 21:08:17 +08:00
|
|
|
PPCTargetStreamer *S = new PPCTargetELFStreamer();
|
|
|
|
return createELFStreamer(Ctx, S, MAB, OS, Emitter, RelaxAll, NoExecStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MCStreamer *
|
|
|
|
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
|
|
|
|
bool isVerboseAsm, bool useLoc, bool useCFI,
|
|
|
|
bool useDwarfDirectory, MCInstPrinter *InstPrint,
|
|
|
|
MCCodeEmitter *CE, MCAsmBackend *TAB, bool ShowInst) {
|
|
|
|
PPCTargetStreamer *S = new PPCTargetAsmStreamer(OS);
|
|
|
|
|
|
|
|
return llvm::createAsmStreamer(Ctx, S, OS, isVerboseAsm, useLoc, useCFI,
|
|
|
|
useDwarfDirectory, InstPrint, CE, TAB,
|
|
|
|
ShowInst);
|
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,
|
2012-04-02 14:09:36 +08:00
|
|
|
const MCInstrInfo &MII,
|
2012-03-06 03:33:20 +08:00
|
|
|
const MCRegisterInfo &MRI,
|
2011-09-08 01:24:38 +08:00
|
|
|
const MCSubtargetInfo &STI) {
|
[PowerPC] Always use "assembler dialect" 1
A setting in MCAsmInfo defines the "assembler dialect" to use. This is used
by common code to choose between alternatives in a multi-alternative GNU
inline asm statement like the following:
__asm__ ("{sfe|subfe} %0,%1,%2" : "=r" (out) : "r" (in1), "r" (in2));
The meaning of these dialects is platform specific, and GCC defines those
for PowerPC to use dialect 0 for old-style (POWER) mnemonics and 1 for
new-style (PowerPC) mnemonics, like in the example above.
To be compatible with inline asm used with GCC, LLVM ought to do the same.
Specifically, this means we should always use assembler dialect 1 since
old-style mnemonics really aren't supported on any current platform.
However, the current LLVM back-end uses:
AssemblerDialect = 1; // New-Style mnemonics.
in PPCMCAsmInfoDarwin, and
AssemblerDialect = 0; // Old-Style mnemonics.
in PPCLinuxMCAsmInfo.
The Linux setting really isn't correct, we should be using new-style
mnemonics everywhere. This is changed by this commit.
Unfortunately, the setting of this variable is overloaded in the back-end
to decide whether or not we are on a Darwin target. This is done in
PPCInstPrinter (the "SyntaxVariant" is initialized from the MCAsmInfo
AssemblerDialect setting), and also in PPCMCExpr. Setting AssemblerDialect
to 1 for both Darwin and Linux no longer allows us to make this distinction.
Instead, this patch uses the MCSubtargetInfo passed to createPPCMCInstPrinter
to distinguish Darwin targets, and ignores the SyntaxVariant parameter.
As to PPCMCExpr, this patch adds an explicit isDarwin argument that needs
to be passed in by the caller when creating a target MCExpr. (To do so
this patch implicitly also reverts commit 184441.)
llvm-svn: 185858
2013-07-09 04:20:51 +08:00
|
|
|
bool isDarwin = Triple(STI.getTargetTriple()).isOSDarwin();
|
|
|
|
return new PPCInstPrinter(MAI, MII, MRI, isDarwin);
|
2011-07-26 05:20:24 +08:00
|
|
|
}
|
|
|
|
|
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);
|
2013-07-26 09:35:43 +08:00
|
|
|
RegisterMCAsmInfoFn E(ThePPC64LETarget, createPPCMCAsmInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC codegen info.
|
2011-07-19 14:37:02 +08:00
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(ThePPC32Target, createPPCMCCodeGenInfo);
|
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(ThePPC64Target, createPPCMCCodeGenInfo);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCCodeGenInfo(ThePPC64LETarget,
|
|
|
|
createPPCMCCodeGenInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC instruction info.
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(ThePPC32Target, createPPCMCInstrInfo);
|
|
|
|
TargetRegistry::RegisterMCInstrInfo(ThePPC64Target, createPPCMCInstrInfo);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCInstrInfo(ThePPC64LETarget,
|
|
|
|
createPPCMCInstrInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC register info.
|
|
|
|
TargetRegistry::RegisterMCRegInfo(ThePPC32Target, createPPCMCRegisterInfo);
|
|
|
|
TargetRegistry::RegisterMCRegInfo(ThePPC64Target, createPPCMCRegisterInfo);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCRegInfo(ThePPC64LETarget, createPPCMCRegisterInfo);
|
2011-07-23 05:58:54 +08:00
|
|
|
|
|
|
|
// Register the MC subtarget info.
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(ThePPC32Target,
|
|
|
|
createPPCMCSubtargetInfo);
|
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(ThePPC64Target,
|
|
|
|
createPPCMCSubtargetInfo);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCSubtargetInfo(ThePPC64LETarget,
|
|
|
|
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);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCCodeEmitter(ThePPC64LETarget,
|
|
|
|
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);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCAsmBackend(ThePPC64LETarget, 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);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCObjectStreamer(ThePPC64LETarget, createMCStreamer);
|
2011-07-26 05:20:24 +08:00
|
|
|
|
2013-10-08 21:08:17 +08:00
|
|
|
// Register the asm streamer.
|
|
|
|
TargetRegistry::RegisterAsmStreamer(ThePPC32Target, createMCAsmStreamer);
|
|
|
|
TargetRegistry::RegisterAsmStreamer(ThePPC64Target, createMCAsmStreamer);
|
|
|
|
TargetRegistry::RegisterAsmStreamer(ThePPC64LETarget, createMCAsmStreamer);
|
|
|
|
|
2011-07-26 05:20:24 +08:00
|
|
|
// Register the MCInstPrinter.
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
|
|
|
|
TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter);
|
2013-07-26 09:35:43 +08:00
|
|
|
TargetRegistry::RegisterMCInstPrinter(ThePPC64LETarget,
|
|
|
|
createPPCMCInstPrinter);
|
2011-07-19 14:37:02 +08:00
|
|
|
}
|