Make the PowerPC AsmPrinter independent of global subtarget

initialization. Initialize the subtarget once per function and
migrate EmitStartOfAsmFile to either use attributes on the
TargetMachine or get information from all of the various
subtargets.

llvm-svn: 229475
This commit is contained in:
Eric Christopher 2015-02-17 07:21:21 +00:00
parent 96f9a573b5
commit 5c0e009d3a
1 changed files with 24 additions and 15 deletions

View File

@ -74,9 +74,7 @@ namespace {
public: public:
explicit PPCAsmPrinter(TargetMachine &TM, explicit PPCAsmPrinter(TargetMachine &TM,
std::unique_ptr<MCStreamer> Streamer) std::unique_ptr<MCStreamer> Streamer)
: AsmPrinter(TM, std::move(Streamer)), : AsmPrinter(TM, std::move(Streamer)), TOCLabelID(0), SM(*this) {}
Subtarget(&TM.getSubtarget<PPCSubtarget>()), TOCLabelID(0),
SM(*this) {}
const char *getPassName() const override { const char *getPassName() const override {
return "PowerPC Assembly Printer"; return "PowerPC Assembly Printer";
@ -102,6 +100,10 @@ namespace {
void LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM, void LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
const MachineInstr &MI); const MachineInstr &MI);
void EmitTlsCall(const MachineInstr *MI, MCSymbolRefExpr::VariantKind VK); void EmitTlsCall(const MachineInstr *MI, MCSymbolRefExpr::VariantKind VK);
bool runOnMachineFunction(MachineFunction &MF) override {
Subtarget = &MF.getSubtarget<PPCSubtarget>();
return AsmPrinter::runOnMachineFunction(MF);
}
}; };
/// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
@ -992,7 +994,7 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
} }
void PPCLinuxAsmPrinter::EmitStartOfAsmFile(Module &M) { void PPCLinuxAsmPrinter::EmitStartOfAsmFile(Module &M) {
if (Subtarget->isELFv2ABI()) { if (static_cast<const PPCTargetMachine &>(TM).isELFv2ABI()) {
PPCTargetStreamer *TS = PPCTargetStreamer *TS =
static_cast<PPCTargetStreamer *>(OutStreamer.getTargetStreamer()); static_cast<PPCTargetStreamer *>(OutStreamer.getTargetStreamer());
@ -1000,7 +1002,8 @@ void PPCLinuxAsmPrinter::EmitStartOfAsmFile(Module &M) {
TS->emitAbiVersion(2); TS->emitAbiVersion(2);
} }
if (Subtarget->isPPC64() || TM.getRelocationModel() != Reloc::PIC_) if (static_cast<const PPCTargetMachine &>(TM).isPPC64() ||
TM.getRelocationModel() != Reloc::PIC_)
return AsmPrinter::EmitStartOfAsmFile(M); return AsmPrinter::EmitStartOfAsmFile(M);
if (M.getPICLevel() == PICLevel::Small) if (M.getPICLevel() == PICLevel::Small)
@ -1242,13 +1245,21 @@ void PPCDarwinAsmPrinter::EmitStartOfAsmFile(Module &M) {
"ppc64le" "ppc64le"
}; };
unsigned Directive = Subtarget->getDarwinDirective(); // Get the numerically largest directive.
if (Subtarget->hasMFOCRF() && Directive < PPC::DIR_970) // FIXME: How should we merge darwin directives?
Directive = PPC::DIR_970; unsigned Directive = PPC::DIR_NONE;
if (Subtarget->hasAltivec() && Directive < PPC::DIR_7400) for (const Function &F : M) {
Directive = PPC::DIR_7400; const PPCSubtarget &STI = TM.getSubtarget<PPCSubtarget>(&F);
if (Subtarget->isPPC64() && Directive < PPC::DIR_64) unsigned FDir = STI.getDarwinDirective();
Directive = PPC::DIR_64; Directive = Directive > FDir ? FDir : STI.getDarwinDirective();
if (STI.hasMFOCRF() && Directive < PPC::DIR_970)
Directive = PPC::DIR_970;
if (STI.hasAltivec() && Directive < PPC::DIR_7400)
Directive = PPC::DIR_7400;
if (STI.isPPC64() && Directive < PPC::DIR_64)
Directive = PPC::DIR_64;
}
assert(Directive <= PPC::DIR_64 && "Directive out of range."); assert(Directive <= PPC::DIR_64 && "Directive out of range.");
assert(Directive < array_lengthof(CPUDirectives) && assert(Directive < array_lengthof(CPUDirectives) &&
@ -1525,9 +1536,7 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
static AsmPrinter * static AsmPrinter *
createPPCAsmPrinterPass(TargetMachine &tm, createPPCAsmPrinterPass(TargetMachine &tm,
std::unique_ptr<MCStreamer> &&Streamer) { std::unique_ptr<MCStreamer> &&Streamer) {
const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>(); if (Triple(tm.getTargetTriple()).isMacOSX())
if (Subtarget->isDarwin())
return new PPCDarwinAsmPrinter(tm, std::move(Streamer)); return new PPCDarwinAsmPrinter(tm, std::move(Streamer));
return new PPCLinuxAsmPrinter(tm, std::move(Streamer)); return new PPCLinuxAsmPrinter(tm, std::move(Streamer));
} }