[llvm] r232776 - Add an MCSubtargetInfo variable to the TargetMachine.

Eric Christopher echristo at gmail.com
Thu Mar 19 15:54:26 PDT 2015


As a followup to this commit:

Yes, it's a hack.

I hope it's temporary, but rewriting more huge swaths of the target
infrastructure in both the TargetStreamer (mips) and/or the AsmPrinter
which does this exact thing for a very similar reason is less on
correctness and more on API level. Fixing this inside both of those is
going to take some major reworking that may involve fairly significant
internal API changes. So, we workaround for the moment so we can ensure the
middle end code generation is clean and go from there.

-eric

On Thu, Mar 19, 2015 at 3:47 PM Eric Christopher <echristo at gmail.com> wrote:

> Author: echristo
> Date: Thu Mar 19 17:36:37 2015
> New Revision: 232776
>
> URL: http://llvm.org/viewvc/llvm-project?rev=232776&view=rev
> Log:
> 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.
>
> Modified:
>     llvm/trunk/include/llvm/Target/TargetMachine.h
>     llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
>     llvm/trunk/lib/Target/TargetMachine.cpp
>
> Modified: llvm/trunk/include/llvm/Target/TargetMachine.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/
> llvm/Target/TargetMachine.h?rev=232776&r1=232775&r2=232776&view=diff
> ============================================================
> ==================
> --- llvm/trunk/include/llvm/Target/TargetMachine.h (original)
> +++ llvm/trunk/include/llvm/Target/TargetMachine.h Thu Mar 19 17:36:37
> 2015
> @@ -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.
>
> Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/
> CodeGen/LLVMTargetMachine.cpp?rev=232776&r1=232775&r2=232776&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
> +++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Thu Mar 19 17:36:37 2015
> @@ -49,6 +49,12 @@ EnableFastISelOption("fast-isel", cl::Hi
>  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::addPassesToEmitF
>    if (Options.MCOptions.MCSaveTempLabels)
>      Context->setAllowTemporaryLabels(false);
>
> -  const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
> +  const MCSubtargetInfo &STI = *getMCSubtargetInfo();
>    const MCAsmInfo &MAI = *getMCAsmInfo();
>    const MCRegisterInfo &MRI = *getMCRegisterInfo();
>    const MCInstrInfo &MII = *getMCInstrInfo();
> @@ -249,7 +255,7 @@ bool LLVMTargetMachine::addPassesToEmitM
>      return true;
>
>    Triple T(getTargetTriple());
> -  const MCSubtargetInfo &STI = getSubtarget<MCSubtargetInfo>();
> +  const MCSubtargetInfo &STI = *getMCSubtargetInfo();
>    std::unique_ptr<MCStreamer> AsmStreamer(getTarget().
> createMCObjectStreamer(
>        T, *Ctx, *MAB, Out, MCE, STI, Options.MCOptions.MCRelaxAll));
>
>
> Modified: llvm/trunk/lib/Target/TargetMachine.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/
> TargetMachine.cpp?rev=232776&r1=232775&r2=232776&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/Target/TargetMachine.cpp (original)
> +++ llvm/trunk/lib/Target/TargetMachine.cpp Thu Mar 19 17:36:37 2015
> @@ -42,13 +42,15 @@ TargetMachine::TargetMachine(const Targe
>                               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.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150319/3ddef7ff/attachment.html>


More information about the llvm-commits mailing list