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() {}
|
2014-01-26 14:06:37 +08:00
|
|
|
PPCTargetStreamer::PPCTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
|
2013-11-19 08:57:56 +08:00
|
|
|
|
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())
|
2013-12-11 05:37:41 +08:00
|
|
|
MAI = new PPCMCAsmInfoDarwin(isPPC64, TheTriple);
|
2011-07-19 06:29:13 +08:00
|
|
|
else
|
2014-02-13 22:44:26 +08:00
|
|
|
MAI = new PPCLinuxMCAsmInfo(isPPC64, TheTriple);
|
2011-07-19 06:29:13 +08:00
|
|
|
|
|
|
|
// 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:
|
2014-01-26 14:06:37 +08:00
|
|
|
PPCTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS)
|
|
|
|
: PPCTargetStreamer(S), OS(OS) {}
|
2013-10-08 21:08:17 +08:00
|
|
|
virtual void emitTCEntry(const MCSymbol &S) {
|
|
|
|
OS << "\t.tc ";
|
|
|
|
OS << S.getName();
|
|
|
|
OS << "[TC],";
|
|
|
|
OS << S.getName();
|
|
|
|
OS << '\n';
|
|
|
|
}
|
2014-01-25 10:35:56 +08:00
|
|
|
virtual void emitMachine(StringRef CPU) {
|
|
|
|
OS << "\t.machine " << CPU << '\n';
|
|
|
|
}
|
2013-10-08 21:08:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class PPCTargetELFStreamer : public PPCTargetStreamer {
|
2014-01-26 14:06:37 +08:00
|
|
|
public:
|
|
|
|
PPCTargetELFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
|
2013-10-08 21:08:17 +08:00
|
|
|
virtual void emitTCEntry(const MCSymbol &S) {
|
|
|
|
// Creates a R_PPC64_TOC relocation
|
2014-01-26 14:06:37 +08:00
|
|
|
Streamer.EmitSymbolValue(&S, 8);
|
2013-10-08 21:08:17 +08:00
|
|
|
}
|
2014-01-25 10:35:56 +08:00
|
|
|
virtual void emitMachine(StringRef CPU) {
|
|
|
|
// FIXME: Is there anything to do in here or does this directive only
|
|
|
|
// limit the parser?
|
|
|
|
}
|
2013-10-08 21:08:17 +08:00
|
|
|
};
|
2014-01-28 19:03:17 +08:00
|
|
|
|
|
|
|
class PPCTargetMachOStreamer : public PPCTargetStreamer {
|
|
|
|
public:
|
|
|
|
PPCTargetMachOStreamer(MCStreamer &S) : PPCTargetStreamer(S) {}
|
|
|
|
virtual void emitTCEntry(const MCSymbol &S) {
|
|
|
|
llvm_unreachable("Unknown pseudo-op: .tc");
|
|
|
|
}
|
|
|
|
virtual void emitMachine(StringRef CPU) {
|
|
|
|
// FIXME: We should update the CPUType, CPUSubType in the Object file if
|
|
|
|
// the new values are different from the defaults.
|
|
|
|
}
|
|
|
|
};
|
2013-10-08 21:08:17 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2014-01-26 14:38:58 +08:00
|
|
|
const MCSubtargetInfo &STI,
|
2011-07-26 03:53:23 +08:00
|
|
|
bool RelaxAll,
|
|
|
|
bool NoExecStack) {
|
2014-01-28 19:03:17 +08:00
|
|
|
if (Triple(TT).isOSDarwin()) {
|
|
|
|
MCStreamer *S = createMachOStreamer(Ctx, MAB, OS, Emitter, RelaxAll);
|
|
|
|
new PPCTargetMachOStreamer(*S);
|
|
|
|
return S;
|
|
|
|
}
|
2011-07-26 03:53:23 +08:00
|
|
|
|
2014-01-26 14:06:37 +08:00
|
|
|
MCStreamer *S =
|
|
|
|
createELFStreamer(Ctx, MAB, OS, Emitter, RelaxAll, NoExecStack);
|
|
|
|
new PPCTargetELFStreamer(*S);
|
|
|
|
return S;
|
2013-10-08 21:08:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static MCStreamer *
|
|
|
|
createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
|
2014-02-06 02:00:21 +08:00
|
|
|
bool isVerboseAsm, bool useCFI, bool useDwarfDirectory,
|
|
|
|
MCInstPrinter *InstPrint, MCCodeEmitter *CE,
|
|
|
|
MCAsmBackend *TAB, bool ShowInst) {
|
2013-10-08 21:08:17 +08:00
|
|
|
|
2014-01-26 14:06:37 +08:00
|
|
|
MCStreamer *S =
|
2014-02-06 02:00:21 +08:00
|
|
|
llvm::createAsmStreamer(Ctx, OS, isVerboseAsm, useCFI, useDwarfDirectory,
|
|
|
|
InstPrint, CE, TAB, ShowInst);
|
2014-01-26 14:06:37 +08:00
|
|
|
new PPCTargetAsmStreamer(*S, OS);
|
|
|
|
return S;
|
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
|
|
|
}
|