From 0d6199b3af7f6e5f118979a017c355a4917c49cd Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Thu, 19 Mar 2015 22:36:37 +0000 Subject: [PATCH] Add an MCSubtargetInfo variable to the TargetMachine. This enables us to remove calls to the subtarget from the TargetMachine and with a small hack for backends that require global subtarget information for module level code generation, e.g. mips abi flags, as mentioned in a fixme in the code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232776 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/TargetMachine.h | 3 +++ lib/CodeGen/LLVMTargetMachine.cpp | 10 ++++++++-- lib/Target/TargetMachine.cpp | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/include/llvm/Target/TargetMachine.h b/include/llvm/Target/TargetMachine.h index 460b758a1e3..cd43532fb65 100644 --- a/include/llvm/Target/TargetMachine.h +++ b/include/llvm/Target/TargetMachine.h @@ -32,6 +32,7 @@ class MCCodeGenInfo; class MCContext; class MCInstrInfo; class MCRegisterInfo; +class MCSubtargetInfo; class MCSymbol; class Target; class DataLayout; @@ -90,6 +91,7 @@ protected: // Can only create subclasses. const MCAsmInfo *AsmInfo; const MCRegisterInfo *MRI; const MCInstrInfo *MII; + const MCSubtargetInfo *STI; unsigned RequireStructuredCFG : 1; @@ -140,6 +142,7 @@ public: const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; } const MCRegisterInfo *getMCRegisterInfo() const { return MRI; } const MCInstrInfo *getMCInstrInfo() const { return MII; } + const MCSubtargetInfo *getMCSubtargetInfo() const { return STI; } /// getIntrinsicInfo - If intrinsic information is available, return it. If /// not, return null. diff --git a/lib/CodeGen/LLVMTargetMachine.cpp b/lib/CodeGen/LLVMTargetMachine.cpp index eadc3f9ad9d..0e948a80c48 100644 --- a/lib/CodeGen/LLVMTargetMachine.cpp +++ b/lib/CodeGen/LLVMTargetMachine.cpp @@ -49,6 +49,12 @@ EnableFastISelOption("fast-isel", cl::Hidden, void LLVMTargetMachine::initAsmInfo() { MRI = TheTarget.createMCRegInfo(getTargetTriple()); MII = TheTarget.createMCInstrInfo(); + // FIXME: Having an MCSubtargetInfo on the target machine is a hack due + // to some backends having subtarget feature dependent module level + // code generation. This is similar to the hack in the AsmPrinter for + // module level assembly etc. + STI = TheTarget.createMCSubtargetInfo(getTargetTriple(), getTargetCPU(), + getTargetFeatureString()); MCAsmInfo *TmpAsmInfo = TheTarget.createMCAsmInfo(*MRI, getTargetTriple()); // TargetSelect.h moved to a different directory between LLVM 2.9 and 3.0, @@ -163,7 +169,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, if (Options.MCOptions.MCSaveTempLabels) Context->setAllowTemporaryLabels(false); - const MCSubtargetInfo &STI = getSubtarget(); + const MCSubtargetInfo &STI = *getMCSubtargetInfo(); const MCAsmInfo &MAI = *getMCAsmInfo(); const MCRegisterInfo &MRI = *getMCRegisterInfo(); const MCInstrInfo &MII = *getMCInstrInfo(); @@ -249,7 +255,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, return true; Triple T(getTargetTriple()); - const MCSubtargetInfo &STI = getSubtarget(); + const MCSubtargetInfo &STI = *getMCSubtargetInfo(); std::unique_ptr AsmStreamer(getTarget().createMCObjectStreamer( T, *Ctx, *MAB, Out, MCE, STI, Options.MCOptions.MCRelaxAll)); diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index 31dbdc6f9a7..dd07f818477 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -42,13 +42,15 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString, const TargetOptions &Options) : TheTarget(T), DL(DataLayoutString), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), CodeGenInfo(nullptr), AsmInfo(nullptr), MRI(nullptr), - MII(nullptr), RequireStructuredCFG(false), Options(Options) {} + MII(nullptr), STI(nullptr), RequireStructuredCFG(false), + Options(Options) {} TargetMachine::~TargetMachine() { delete CodeGenInfo; delete AsmInfo; delete MRI; delete MII; + delete STI; } /// \brief Reset the target options based on the function's attributes.