[llvm] r279113 - Add a version of Intrinsic::getName which is more efficient when there are no overloads.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 11:30:54 PDT 2016


Author: pete
Date: Thu Aug 18 13:30:54 2016
New Revision: 279113

URL: http://llvm.org/viewvc/llvm-project?rev=279113&view=rev
Log:
Add a version of Intrinsic::getName which is more efficient when there are no overloads.

When running 'opt -O2 verify-uselistorder-nodbg.lto.bc', there are 33m allocations.  8.2m
come from std::string allocations in Intrinsic::getName().  Turns out this method only
returns a std::string because it needs to handle overloads, but that is not the common case.

This adds an overload of getName which just returns a StringRef when there are no overloads
and so saves on the allocations.

Modified:
    llvm/trunk/include/llvm/IR/Intrinsics.h
    llvm/trunk/lib/IR/Function.cpp

Modified: llvm/trunk/include/llvm/IR/Intrinsics.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Intrinsics.h?rev=279113&r1=279112&r2=279113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Intrinsics.h (original)
+++ llvm/trunk/include/llvm/IR/Intrinsics.h Thu Aug 18 13:30:54 2016
@@ -45,7 +45,10 @@ namespace Intrinsic {
   };
 
   /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
-  std::string getName(ID id, ArrayRef<Type*> Tys = None);
+  StringRef getName(ID id);
+
+  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
+  std::string getName(ID id, ArrayRef<Type*> Tys);
 
   /// Return the function type for an intrinsic.
   FunctionType *getType(LLVMContext &Context, ID id,

Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=279113&r1=279112&r2=279113&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Thu Aug 18 13:30:54 2016
@@ -551,6 +551,11 @@ static std::string getMangledTypeStr(Typ
   return Result;
 }
 
+StringRef Intrinsic::getName(ID id) {
+  assert(id < num_intrinsics && "Invalid intrinsic ID!");
+  return IntrinsicNameTable[id];
+}
+
 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
   assert(id < num_intrinsics && "Invalid intrinsic ID!");
   std::string Result(IntrinsicNameTable[id]);




More information about the llvm-commits mailing list