[llvm] r270246 - [X86] Reduce memory allocations in X86TargetMachine::getSubtargetImpl

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 13:47:59 PDT 2016


Good call, r270270.

On Fri, May 20, 2016 at 11:33 AM, Benjamin Kramer <benny.kra at gmail.com>
wrote:

> On Fri, May 20, 2016 at 8:17 PM, David Majnemer via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: majnemer
> > Date: Fri May 20 13:16:06 2016
> > New Revision: 270246
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=270246&view=rev
> > Log:
> > [X86] Reduce memory allocations in X86TargetMachine::getSubtargetImpl
> >
> > We performed a number of memory allocations each time getTTI was called,
> > remove them by using SmallString.
> > No functionality change intended.
> >
> > Modified:
> >     llvm/trunk/lib/Target/X86/X86Subtarget.cpp
> >     llvm/trunk/lib/Target/X86/X86Subtarget.h
> >     llvm/trunk/lib/Target/X86/X86TargetMachine.cpp
> >
> > Modified: llvm/trunk/lib/Target/X86/X86Subtarget.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Subtarget.cpp?rev=270246&r1=270245&r2=270246&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/X86/X86Subtarget.cpp (original)
> > +++ llvm/trunk/lib/Target/X86/X86Subtarget.cpp Fri May 20 13:16:06 2016
> > @@ -353,8 +353,8 @@ X86Subtarget &X86Subtarget::initializeSu
> >    return *this;
> >  }
> >
> > -X86Subtarget::X86Subtarget(const Triple &TT, const std::string &CPU,
> > -                           const std::string &FS, const
> X86TargetMachine &TM,
> > +X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef
> FS,
> > +                           const X86TargetMachine &TM,
> >                             unsigned StackAlignOverride)
> >      : X86GenSubtargetInfo(TT, CPU, FS), X86ProcFamily(Others),
> >        PICStyle(PICStyles::None), TM(TM), TargetTriple(TT),
> >
> > Modified: llvm/trunk/lib/Target/X86/X86Subtarget.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86Subtarget.h?rev=270246&r1=270245&r2=270246&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/X86/X86Subtarget.h (original)
> > +++ llvm/trunk/lib/Target/X86/X86Subtarget.h Fri May 20 13:16:06 2016
> > @@ -313,7 +313,7 @@ public:
> >    /// This constructor initializes the data members to match that
> >    /// of the specified triple.
> >    ///
> > -  X86Subtarget(const Triple &TT, const std::string &CPU, const
> std::string &FS,
> > +  X86Subtarget(const Triple &TT, StringRef CPU, StringRef FS,
> >                 const X86TargetMachine &TM, unsigned StackAlignOverride);
> >
> >    const X86TargetLowering *getTargetLowering() const override {
> >
> > Modified: llvm/trunk/lib/Target/X86/X86TargetMachine.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetMachine.cpp?rev=270246&r1=270245&r2=270246&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/lib/Target/X86/X86TargetMachine.cpp (original)
> > +++ llvm/trunk/lib/Target/X86/X86TargetMachine.cpp Fri May 20 13:16:06
> 2016
> > @@ -182,12 +182,12 @@ X86TargetMachine::getSubtargetImpl(const
> >    Attribute CPUAttr = F.getFnAttribute("target-cpu");
> >    Attribute FSAttr = F.getFnAttribute("target-features");
> >
> > -  std::string CPU = !CPUAttr.hasAttribute(Attribute::None)
> > -                        ? CPUAttr.getValueAsString().str()
> > -                        : TargetCPU;
> > -  std::string FS = !FSAttr.hasAttribute(Attribute::None)
> > -                       ? FSAttr.getValueAsString().str()
> > -                       : TargetFS;
> > +  SmallString<32> CPU = !CPUAttr.hasAttribute(Attribute::None)
> > +                            ? CPUAttr.getValueAsString()
> > +                            : (StringRef)TargetCPU;
>
> This could be a StringRef, conserves precious stack space and avoids a
> copy.
>
> > +  SmallString<512> FS = !FSAttr.hasAttribute(Attribute::None)
> > +                            ? FSAttr.getValueAsString()
> > +                            : (StringRef)TargetFS;
>
> same, but then append directly to Key instead of FS below for the
> softfloat stuff.
>
> >
> >    // FIXME: This is related to the code below to reset the target
> options,
> >    // we need to know whether or not the soft float flag is set on the
> > @@ -201,7 +201,12 @@ X86TargetMachine::getSubtargetImpl(const
> >    if (SoftFloat)
> >      FS += FS.empty() ? "+soft-float" : ",+soft-float";
> >
> > -  auto &I = SubtargetMap[CPU + FS];
> > +  SmallString<544> Key;
>
> 512+32 = not a round number :(
>
> > +  Key.reserve(CPU.size() + FS.size());
> > +  Key += CPU;
> > +  Key += FS;
> > +
> > +  auto &I = SubtargetMap[Key];
> >    if (!I) {
> >      // This needs to be done before we create a new subtarget since any
> >      // creation will depend on the TM and the code generation flags on
> the
> >
> >
> > _______________________________________________
> > llvm-commits mailing list
> > llvm-commits at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160520/699bb11d/attachment.html>


More information about the llvm-commits mailing list