[PATCH] D38174: [TableGen] Return StringRef from ValueTypeByHwMode::getMVTName

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 22 05:29:55 PDT 2017


Who calls getAsString? I just noticed it's using a std::stringstream again,
which has terrible performance. One of the biggest improvements i made
originally was converting stringstream operations to llvm streams.

Is it possible to change this function to not return a std::string but to
instead accept a llvm::raw_ostream&?
On Fri, Sep 22, 2017 at 5:22 AM Simon Pilgrim via Phabricator <
reviews at reviews.llvm.org> wrote:

> RKSimon created this revision.
>
> Avoid unnecessary std::string creations during
> TypeSetByHwMode::writeToStream.
>
> Found during investigations into PR28222
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D38174
>
> Files:
>   utils/TableGen/InfoByHwMode.cpp
>   utils/TableGen/InfoByHwMode.h
>
>
> Index: utils/TableGen/InfoByHwMode.h
> ===================================================================
> --- utils/TableGen/InfoByHwMode.h
> +++ utils/TableGen/InfoByHwMode.h
> @@ -129,7 +129,7 @@
>    MVT getType(unsigned Mode) const { return get(Mode); }
>    MVT &getOrCreateTypeForMode(unsigned Mode, MVT Type);
>
> -  static std::string getMVTName(MVT T);
> +  static StringRef getMVTName(MVT T);
>    std::string getAsString() const;
>    void dump() const;
>  };
> Index: utils/TableGen/InfoByHwMode.cpp
> ===================================================================
> --- utils/TableGen/InfoByHwMode.cpp
> +++ utils/TableGen/InfoByHwMode.cpp
> @@ -70,10 +70,9 @@
>    return Map.insert(std::make_pair(Mode, Type)).first->second;
>  }
>
> -std::string ValueTypeByHwMode::getMVTName(MVT T) {
> -  std::string N = llvm::getEnumName(T.SimpleTy);
> -  if (N.substr(0,5) == "MVT::")
> -    N = N.substr(5);
> +StringRef ValueTypeByHwMode::getMVTName(MVT T) {
> +  StringRef N = llvm::getEnumName(T.SimpleTy);
> +  N.consume_front("MVT::");
>    return N;
>  }
>
> @@ -91,7 +90,7 @@
>    for (unsigned i = 0, e = Pairs.size(); i != e; ++i) {
>      const PairType *P = Pairs[i];
>      str << '(' << getModeName(P->first)
> -        << ':' << getMVTName(P->second) << ')';
> +        << ':' << getMVTName(P->second).str() << ')';
>      if (i != e-1)
>        str << ',';
>    }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170922/7ab38c8e/attachment.html>


More information about the llvm-commits mailing list