[PATCH] D18022: Do not specialize IRBuilder to strip names in SROA

Mehdi AMINI via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 18:23:31 PST 2016


joker.eph created this revision.
joker.eph added a reviewer: chandlerc.
joker.eph added a subscriber: llvm-commits.

Following r263086, we are replacing this by a runtime check.
More cleanup will follow on the IRBuilder itself, but I submitted
this patch separately as SROA has a fancy "prefixInserter" class
that needs extra-love.

http://reviews.llvm.org/D18022

Files:
  lib/Transforms/Scalar/SROA.cpp

Index: lib/Transforms/Scalar/SROA.cpp
===================================================================
--- lib/Transforms/Scalar/SROA.cpp
+++ lib/Transforms/Scalar/SROA.cpp
@@ -87,40 +87,33 @@
                                         cl::Hidden);
 
 namespace {
-/// \brief A custom IRBuilder inserter which prefixes all names if they are
-/// preserved.
-template <bool preserveNames = true>
-class IRBuilderPrefixedInserter
-    : public IRBuilderDefaultInserter<preserveNames> {
+/// \brief A custom IRBuilder inserter which prefixes all names, but only in
+/// Assert builds.
+class IRBuilderPrefixedInserter : public IRBuilderDefaultInserter<true> {
+#ifndef NDEBUG
   std::string Prefix;
+  const Twine getNameWithPrefix(const Twine &Name) const {
+    return Name.isTriviallyEmpty() ? Name : Prefix + Name;
+  }
 
 public:
   void SetNamePrefix(const Twine &P) { Prefix = P.str(); }
+#else
+  const Twine getNameWithPrefix(const Twine &Name) const { return Name; }
+  void SetNamePrefix(const Twine &P) {}
+#endif
 
 protected:
   void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB,
                     BasicBlock::iterator InsertPt) const {
-    IRBuilderDefaultInserter<preserveNames>::InsertHelper(
-        I, Name.isTriviallyEmpty() ? Name : Prefix + Name, BB, InsertPt);
+    IRBuilderDefaultInserter<true>::InsertHelper(I, getNameWithPrefix(Name), BB,
+                                                 InsertPt);
   }
 };
 
-// Specialization for not preserving the name is trivial.
-template <>
-class IRBuilderPrefixedInserter<false>
-    : public IRBuilderDefaultInserter<false> {
-public:
-  void SetNamePrefix(const Twine &P) {}
-};
-
 /// \brief Provide a typedef for IRBuilder that drops names in release builds.
-#ifndef NDEBUG
-typedef llvm::IRBuilder<true, ConstantFolder, IRBuilderPrefixedInserter<true>>
-    IRBuilderTy;
-#else
-typedef llvm::IRBuilder<false, ConstantFolder, IRBuilderPrefixedInserter<false>>
-    IRBuilderTy;
-#endif
+using IRBuilderTy =
+    llvm::IRBuilder<true, ConstantFolder, IRBuilderPrefixedInserter>;
 }
 
 namespace {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18022.50222.patch
Type: text/x-patch
Size: 2094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160310/0dd08e61/attachment.bin>


More information about the llvm-commits mailing list